aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-14 22:40:56 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-14 22:40:56 +0100
commitb1a3d09ca6a4be59b57e2f7b1cdc8a245d60a858 (patch)
treeca6d7f5eafd7bbe3deff4e9ad7a1f4a9a0a77bf3 /src/eu
parent4e4a767743a62d1f88814e5cf024bf983772df2c (diff)
use conference subject to identiy room
Diffstat (limited to 'src/eu')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java117
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java9
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java6
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java11
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java8
-rw-r--r--src/eu/siacs/conversations/ui/MucDetailsActivity.java6
-rw-r--r--src/eu/siacs/conversations/ui/ShareWithActivity.java7
-rw-r--r--src/eu/siacs/conversations/utils/MessageParser.java7
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java11
9 files changed, 114 insertions, 68 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index aad072cf..b4ec210c 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -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;
@@ -23,13 +20,13 @@ import android.util.Log;
public class Conversation extends AbstractEntity {
private static final long serialVersionUID = -6727528868973996739L;
-
+
public static final String TABLENAME = "conversations";
-
+
public static final int STATUS_AVAILABLE = 0;
public static final int STATUS_ARCHIVED = 1;
public static final int STATUS_DELETED = 2;
-
+
public static final int MODE_MULTI = 1;
public static final int MODE_SINGLE = 0;
@@ -52,24 +49,26 @@ public class Conversation extends AbstractEntity {
private transient List<Message> messages = null;
private transient Account account = null;
private transient Contact contact;
-
+
private transient SessionImpl otrSession;
-
+
private transient String otrFingerprint = null;
-
+
public int nextMessageEncryption = Message.ENCRYPTION_NONE;
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,33 +80,37 @@ public class Conversation extends AbstractEntity {
}
public List<Message> getMessages() {
- if (messages == null) this.messages = new ArrayList<Message>(); //prevent null pointer
-
- //populate with Conversation (this)
-
- for(Message msg : messages) {
+ if (messages == null)
+ this.messages = new ArrayList<Message>(); // prevent null pointer
+
+ // populate with Conversation (this)
+
+ for (Message msg : messages) {
msg.setConversation(this);
}
-
+
return messages;
}
-
+
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();
@@ -138,18 +143,18 @@ public class Conversation extends AbstractEntity {
public String getAccountUuid() {
return this.accountUuid;
}
-
+
public Account getAccount() {
return this.account;
}
-
+
public Contact getContact() {
return this.contact;
}
-
+
public void setContact(Contact contact) {
this.contact = contact;
- if (contact!=null) {
+ if (contact != null) {
this.contactUuid = contact.getUuid();
}
}
@@ -157,7 +162,7 @@ public class Conversation extends AbstractEntity {
public void setAccount(Account account) {
this.account = account;
}
-
+
public String getContactJid() {
return this.contactJid;
}
@@ -172,7 +177,7 @@ public class Conversation extends AbstractEntity {
public int getStatus() {
return this.status;
}
-
+
public long getCreated() {
return this.created;
}
@@ -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;
}
@@ -212,18 +217,20 @@ public class Conversation extends AbstractEntity {
public void setMode(int mode) {
this.mode = mode;
}
-
+
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");
}
}
-
+
public SessionImpl getOtrSession() {
return this.otrSession;
}
@@ -231,9 +238,9 @@ public class Conversation extends AbstractEntity {
public void resetOtrSession() {
this.otrSession = null;
}
-
+
public void endOtrIfNeeded() {
- if (this.otrSession!=null) {
+ if (this.otrSession != null) {
if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
try {
this.otrSession.endSession();
@@ -257,32 +264,34 @@ public class Conversation extends AbstractEntity {
return true;
}
}
-
+
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, " ");
builder.insert(35, " ");
this.otrFingerprint = builder.toString();
} catch (OtrCryptoException e) {
-
+
}
}
return this.otrFingerprint;
}
-
+
public MucOptions getMucOptions() {
if (this.mucOptions == null) {
this.mucOptions = new MucOptions();
}
this.mucOptions.setConversation(this);
- return this.mucOptions ;
+ return this.mucOptions;
}
-
+
public void resetMucOptions() {
this.mucOptions = null;
}
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java
index 9bc6fb21..16d9c6a8 100644
--- a/src/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/eu/siacs/conversations/entities/MucOptions.java
@@ -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;
+ }
} \ No newline at end of file
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index c7f1bdb7..17a2d76f 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1225,4 +1225,10 @@ public class XmppConnectionService extends Service {
}
}).start();
}
+
+ public void updateConversationInGui() {
+ if (convChangedListener!=null) {
+ convChangedListener.onConversationListChanged();
+ }
+ }
} \ No newline at end of file
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 1577fdc5..ad643c31 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -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();
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 71d4100f..d8ead9a6 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -62,6 +62,8 @@ public class ConversationFragment extends Fragment {
private String pastedText = null;
protected Bitmap selfBitmap;
+
+ private boolean useSubject = true;
private IntentSender askForPassphraseIntent = null;
@@ -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();
}
diff --git a/src/eu/siacs/conversations/ui/MucDetailsActivity.java b/src/eu/siacs/conversations/ui/MucDetailsActivity.java
index 478397e7..39097895 100644
--- a/src/eu/siacs/conversations/ui/MucDetailsActivity.java
+++ b/src/eu/siacs/conversations/ui/MucDetailsActivity.java
@@ -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);
diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java
index 81616212..51bad721 100644
--- a/src/eu/siacs/conversations/ui/ShareWithActivity.java
+++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java
@@ -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
diff --git a/src/eu/siacs/conversations/utils/MessageParser.java b/src/eu/siacs/conversations/utils/MessageParser.java
index 2e948b13..4abd781e 100644
--- a/src/eu/siacs/conversations/utils/MessageParser.java
+++ b/src/eu/siacs/conversations/utils/MessageParser.java
@@ -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];
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index f66cc734..5d879714 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -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");