use conference subject to identiy room

This commit is contained in:
Daniel Gultsch 2014-03-14 22:40:56 +01:00
parent 4e4a767743
commit b1a3d09ca6
11 changed files with 119 additions and 69 deletions

View file

@ -10,7 +10,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="monospace"
android:text="@string/no_otr_fingerprint"/>

View file

@ -49,5 +49,10 @@
android:title="Use Phones self contact picture"
android:summary="You may no longer be able to distinguish which account you are using in a conversation"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="use_subject_in_muc"
android:title="Conference Name"
android:summary="Use rooms subject to identify Conferences"
android:defaultValue="true"/>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -4,9 +4,6 @@ import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.crypto.OtrEngine;
import eu.siacs.conversations.xmpp.XmppConnection;
import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException;
@ -61,15 +58,17 @@ public class Conversation extends AbstractEntity {
private transient MucOptions mucOptions = null;
public Conversation(String name, Account account,
String contactJid, int mode) {
this(java.util.UUID.randomUUID().toString(), name, null, account.getUuid(), contactJid, System
.currentTimeMillis(), STATUS_AVAILABLE,mode);
public Conversation(String name, Account account, String contactJid,
int mode) {
this(java.util.UUID.randomUUID().toString(), name, null, account
.getUuid(), contactJid, System.currentTimeMillis(),
STATUS_AVAILABLE, mode);
this.account = account;
}
public Conversation(String uuid, String name, String contactUuid,
String accountUuid, String contactJid, long created, int status, int mode) {
String accountUuid, String contactJid, long created, int status,
int mode) {
this.uuid = uuid;
this.name = name;
this.contactUuid = contactUuid;
@ -81,11 +80,12 @@ public class Conversation extends AbstractEntity {
}
public List<Message> getMessages() {
if (messages == null) this.messages = new ArrayList<Message>(); //prevent null pointer
if (messages == null)
this.messages = new ArrayList<Message>(); // prevent null pointer
//populate with Conversation (this)
// populate with Conversation (this)
for(Message msg : messages) {
for (Message msg : messages) {
msg.setConversation(this);
}
@ -93,21 +93,24 @@ public class Conversation extends AbstractEntity {
}
public boolean isRead() {
if ((this.messages == null)||(this.messages.size() == 0)) return true;
if ((this.messages == null) || (this.messages.size() == 0))
return true;
return this.messages.get(this.messages.size() - 1).isRead();
}
public void markRead() {
if (this.messages == null) return;
for(int i = this.messages.size() -1; i >= 0; --i) {
if (messages.get(i).isRead()) return;
if (this.messages == null)
return;
for (int i = this.messages.size() - 1; i >= 0; --i) {
if (messages.get(i).isRead())
return;
this.messages.get(i).markRead();
}
}
public Message getLatestMessage() {
if ((this.messages == null)||(this.messages.size()==0)) {
Message message = new Message(this,"",Message.ENCRYPTION_NONE);
if ((this.messages == null) || (this.messages.size() == 0)) {
Message message = new Message(this, "", Message.ENCRYPTION_NONE);
message.setTime(getCreated());
return message;
} else {
@ -119,8 +122,10 @@ public class Conversation extends AbstractEntity {
this.messages = msgs;
}
public String getName() {
if (this.contact!=null) {
public String getName(boolean useSubject) {
if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) && useSubject) {
return getMucOptions().getSubject();
} else if (this.contact != null) {
return this.contact.getDisplayName();
} else {
return this.name;
@ -128,7 +133,7 @@ public class Conversation extends AbstractEntity {
}
public String getProfilePhotoString() {
if (this.contact==null) {
if (this.contact == null) {
return null;
} else {
return this.contact.getProfilePhoto();
@ -149,7 +154,7 @@ public class Conversation extends AbstractEntity {
public void setContact(Contact contact) {
this.contact = contact;
if (contact!=null) {
if (contact != null) {
this.contactUuid = contact.getUuid();
}
}
@ -186,7 +191,7 @@ public class Conversation extends AbstractEntity {
values.put(CONTACTJID, contactJid);
values.put(CREATED, created);
values.put(STATUS, status);
values.put(MODE,mode);
values.put(MODE, mode);
return values;
}
@ -214,13 +219,15 @@ public class Conversation extends AbstractEntity {
}
public void startOtrSession(Context context, String presence) {
Log.d("xmppService","starting otr session with "+presence);
SessionID sessionId = new SessionID(this.getContactJid(),presence,"xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(context));
Log.d("xmppService", "starting otr session with " + presence);
SessionID sessionId = new SessionID(this.getContactJid(), presence,
"xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
context));
try {
this.otrSession.startSession();
} catch (OtrException e) {
Log.d("xmppServic","couldnt start otr");
Log.d("xmppServic", "couldnt start otr");
}
}
@ -233,7 +240,7 @@ public class Conversation extends AbstractEntity {
}
public void endOtrIfNeeded() {
if (this.otrSession!=null) {
if (this.otrSession != null) {
if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
try {
this.otrSession.endSession();
@ -261,8 +268,10 @@ public class Conversation extends AbstractEntity {
public String getOtrFingerprint() {
if (this.otrFingerprint == null) {
try {
DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession().getRemotePublicKey();
StringBuilder builder = new StringBuilder(new OtrCryptoEngineImpl().getFingerprint(remotePubKey));
DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession()
.getRemotePublicKey();
StringBuilder builder = new StringBuilder(
new OtrCryptoEngineImpl().getFingerprint(remotePubKey));
builder.insert(8, " ");
builder.insert(17, " ");
builder.insert(26, " ");
@ -280,7 +289,7 @@ public class Conversation extends AbstractEntity {
this.mucOptions = new MucOptions();
}
this.mucOptions.setConversation(this);
return this.mucOptions ;
return this.mucOptions;
}
public void resetMucOptions() {

View file

@ -77,6 +77,7 @@ public class MucOptions {
private int error = 0;
private OnRenameListener renameListener = null;
private User self = new User();
private String subject = null;
public void deleteUser(String name) {
@ -186,4 +187,12 @@ public class MucOptions {
public User getSelf() {
return self;
}
public void setSubject(String content) {
this.subject = content;
}
public String getSubject() {
return this.subject;
}
}

View file

@ -1225,4 +1225,10 @@ public class XmppConnectionService extends Service {
}
}).start();
}
public void updateConversationInGui() {
if (convChangedListener!=null) {
convChangedListener.onConversationListChanged();
}
}
}

View file

@ -12,11 +12,13 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.UIHelper;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v4.widget.SlidingPaneLayout;
@ -53,6 +55,7 @@ public class ConversationActivity extends XmppActivity {
private ListView listView;
private boolean paneShouldBeOpen = true;
private boolean useSubject = true;
private ArrayAdapter<Conversation> listAdapter;
private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() {
@ -163,7 +166,7 @@ public class ConversationActivity extends XmppActivity {
view.setBackgroundColor(Color.TRANSPARENT);
}
TextView convName = (TextView) view.findViewById(R.id.conversation_name);
convName.setText(conv.getName());
convName.setText(conv.getName(useSubject));
TextView convLastMsg = (TextView) view.findViewById(R.id.conversation_lastmsg);
convLastMsg.setText(conv.getLatestMessage().getBody());
@ -179,7 +182,7 @@ public class ConversationActivity extends XmppActivity {
.setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent()));
ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image);
imageView.setImageBitmap(UIHelper.getContactPicture(conv.getContact(), conv.getName(),200, activity.getApplicationContext()));
imageView.setImageBitmap(UIHelper.getContactPicture(conv.getContact(), conv.getName(useSubject),200, activity.getApplicationContext()));
return view;
}
@ -221,7 +224,7 @@ public class ConversationActivity extends XmppActivity {
paneShouldBeOpen = false;
if (conversationList.size() > 0) {
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle(getSelectedConversation().getName());
getActionBar().setTitle(getSelectedConversation().getName(useSubject));
invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) {
getSelectedConversation().markRead();
@ -399,6 +402,8 @@ public class ConversationActivity extends XmppActivity {
public void onStart() {
super.onStart();
this.registerListener();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (conversationList.size()>=1) {
onConvChanged.onConversationListChanged();
}

View file

@ -63,6 +63,8 @@ public class ConversationFragment extends Fragment {
protected Bitmap selfBitmap;
private boolean useSubject = true;
private IntentSender askForPassphraseIntent = null;
private OnClickListener sendMsgListener = new OnClickListener() {
@ -214,7 +216,7 @@ public class ConversationFragment extends Fragment {
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
viewHolder.imageView.setImageBitmap(mBitmapCache
.get(item.getConversation().getName(), item
.get(item.getConversation().getName(useSubject), item
.getConversation().getContact(),
getActivity()
.getApplicationContext()));
@ -250,7 +252,7 @@ public class ConversationFragment extends Fragment {
.getApplicationContext()));
} else {
viewHolder.imageView.setImageBitmap(mBitmapCache
.get(item.getConversation().getName(),
.get(item.getConversation().getName(useSubject),
null, getActivity()
.getApplicationContext()));
}
@ -330,7 +332,7 @@ public class ConversationFragment extends Fragment {
if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane();
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
activity.getActionBar().setTitle(conversation.getName());
activity.getActionBar().setTitle(conversation.getName(useSubject));
activity.invalidateOptionsMenu();
}

View file

@ -9,7 +9,9 @@ import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.utils.UIHelper;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@ -99,6 +101,8 @@ public class MucDetailsActivity extends XmppActivity {
@Override
void onBackendConnected() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (uuid != null) {
for (Conversation mConv : xmppConnectionService.getConversations()) {
if (mConv.getUuid().equals(uuid)) {
@ -106,7 +110,7 @@ public class MucDetailsActivity extends XmppActivity {
}
}
if (this.conversation != null) {
setTitle(conversation.getName());
setTitle(conversation.getName(useSubject));
mFullJid.setText(conversation.getContactJid().split("/")[0]);
mYourNick.setText(conversation.getMucOptions().getNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);

View file

@ -13,8 +13,10 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.utils.UIHelper;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@ -66,6 +68,9 @@ public class ShareWithActivity extends XmppActivity {
@Override
void onBackendConnected() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
Set<String> displayedContacts = new HashSet<String>();
conversations.removeAllViews();
List<Conversation> convList = xmppConnectionService.getConversations();
@ -76,7 +81,7 @@ public class ShareWithActivity extends XmppActivity {
}
});
for(final Conversation conversation : convList) {
View view = createContactView(conversation.getName(), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(), 90,this.getApplicationContext()));
View view = createContactView(conversation.getName(useSubject), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(useSubject), 90,this.getApplicationContext()));
view.setOnClickListener(new OnClickListener() {
@Override

View file

@ -96,7 +96,12 @@ public class MessageParser {
int status;
String[] fromParts = packet.getFrom().split("/");
Conversation conversation = service.findOrCreateConversation(account, fromParts[0],true);
if ((fromParts.length == 1) || (packet.hasChild("subject"))) {
if (packet.hasChild("subject")) {
conversation.getMucOptions().setSubject(packet.findChild("subject").getContent());
service.updateConversationInGui();
return null;
}
if ((fromParts.length == 1)) {
return null;
}
String counterPart = fromParts[1];

View file

@ -133,6 +133,7 @@ public class UIHelper {
.getSystemService(Context.NOTIFICATION_SERVICE);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
boolean showNofifications = preferences.getBoolean("show_notification",true);
boolean vibrate = preferences.getBoolean("vibrate_on_notification", true);
boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false);
@ -171,9 +172,9 @@ public class UIHelper {
conversation.getName(),
(int) res
.getDimension(android.R.dimen.notification_large_icon_width)));*/
mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(), (int) res
mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(useSubject), (int) res
.getDimension(android.R.dimen.notification_large_icon_width), context));
mBuilder.setContentTitle(conversation.getName());
mBuilder.setContentTitle(conversation.getName(useSubject));
if (notify) {
mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
}
@ -203,11 +204,11 @@ public class UIHelper {
for (int i = 0; i < unread.size(); ++i) {
targetUuid = unread.get(i).getUuid();
if (i < unread.size() - 1) {
names.append(unread.get(i).getName() + ", ");
names.append(unread.get(i).getName(useSubject) + ", ");
} else {
names.append(unread.get(i).getName());
names.append(unread.get(i).getName(useSubject));
}
style.addLine(Html.fromHtml("<b>" + unread.get(i).getName()
style.addLine(Html.fromHtml("<b>" + unread.get(i).getName(useSubject)
+ "</b> " + unread.get(i).getLatestMessage().getBody().trim()));
}
mBuilder.setContentTitle(unread.size() + " unread Conversations");