aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r--src/eu/siacs/conversations/entities/Account.java187
-rw-r--r--src/eu/siacs/conversations/entities/Contact.java32
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java49
-rw-r--r--src/eu/siacs/conversations/entities/Message.java67
-rw-r--r--src/eu/siacs/conversations/entities/MucOptions.java118
5 files changed, 328 insertions, 125 deletions
diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java
index b19889bf..d31d2324 100644
--- a/src/eu/siacs/conversations/entities/Account.java
+++ b/src/eu/siacs/conversations/entities/Account.java
@@ -1,7 +1,6 @@
package eu.siacs.conversations.entities;
import java.security.interfaces.DSAPublicKey;
-import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -12,28 +11,33 @@ import net.java.otr4j.crypto.OtrCryptoException;
import org.json.JSONException;
import org.json.JSONObject;
+import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.OtrEngine;
+import eu.siacs.conversations.persistance.FileBackend;
+import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.XmppConnection;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.graphics.Bitmap;
+
+public class Account extends AbstractEntity {
-public class Account extends AbstractEntity{
-
public static final String TABLENAME = "accounts";
-
+
public static final String USERNAME = "username";
public static final String SERVER = "server";
public static final String PASSWORD = "password";
public static final String OPTIONS = "options";
public static final String ROSTERVERSION = "rosterversion";
public static final String KEYS = "keys";
-
+ public static final String AVATAR = "avatar";
+
public static final int OPTION_USETLS = 0;
public static final int OPTION_DISABLED = 1;
public static final int OPTION_REGISTER = 2;
public static final int OPTION_USECOMPRESSION = 3;
-
+
public static final int STATUS_CONNECTING = 0;
public static final int STATUS_DISABLED = -2;
public static final int STATUS_OFFLINE = -1;
@@ -42,13 +46,11 @@ public class Account extends AbstractEntity{
public static final int STATUS_UNAUTHORIZED = 3;
public static final int STATUS_SERVER_NOT_FOUND = 5;
- public static final int STATUS_SERVER_REQUIRES_TLS = 6;
-
public static final int STATUS_REGISTRATION_FAILED = 7;
public static final int STATUS_REGISTRATION_CONFLICT = 8;
public static final int STATUS_REGISTRATION_SUCCESSFULL = 9;
public static final int STATUS_REGISTRATION_NOT_SUPPORTED = 10;
-
+
protected String username;
protected String server;
protected String password;
@@ -57,30 +59,34 @@ public class Account extends AbstractEntity{
protected String resource = "mobile";
protected int status = -1;
protected JSONObject keys = new JSONObject();
-
+ protected String avatar;
+
protected boolean online = false;
-
+
transient OtrEngine otrEngine = null;
transient XmppConnection xmppConnection = null;
transient protected Presences presences = new Presences();
private String otrFingerprint;
-
+
private Roster roster = null;
- private List<Bookmark> bookmarks = new ArrayList<Bookmark>();
-
+ private List<Bookmark> bookmarks = new CopyOnWriteArrayList<Bookmark>();
+
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<Conversation>();
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<Conversation>();
-
+
public Account() {
this.uuid = "0";
}
-
+
public Account(String username, String server, String password) {
- this(java.util.UUID.randomUUID().toString(),username,server,password,0,null,"");
+ this(java.util.UUID.randomUUID().toString(), username, server,
+ password, 0, null, "",null);
}
- public Account(String uuid, String username, String server,String password, int options, String rosterVersion, String keys) {
+
+ public Account(String uuid, String username, String server,
+ String password, int options, String rosterVersion, String keys, String avatar) {
this.uuid = uuid;
this.username = username;
this.server = server;
@@ -90,14 +96,15 @@ public class Account extends AbstractEntity{
try {
this.keys = new JSONObject(keys);
} catch (JSONException e) {
-
+
}
+ this.avatar = avatar;
}
-
+
public boolean isOptionSet(int option) {
return ((options & (1 << option)) != 0);
}
-
+
public void setOption(int option, boolean value) {
if (value) {
this.options |= 1 << option;
@@ -105,7 +112,7 @@ public class Account extends AbstractEntity{
this.options &= ~(1 << option);
}
}
-
+
public String getUsername() {
return username;
}
@@ -129,11 +136,11 @@ public class Account extends AbstractEntity{
public void setPassword(String password) {
this.password = password;
}
-
+
public void setStatus(int status) {
this.status = status;
}
-
+
public int getStatus() {
if (isOptionSet(OPTION_DISABLED)) {
return STATUS_DISABLED;
@@ -141,27 +148,34 @@ public class Account extends AbstractEntity{
return this.status;
}
}
-
+
+ public boolean errorStatus() {
+ int s = getStatus();
+ return (s == STATUS_REGISTRATION_FAILED || s == STATUS_REGISTRATION_CONFLICT || s == STATUS_REGISTRATION_NOT_SUPPORTED || s == STATUS_SERVER_NOT_FOUND || s == STATUS_UNAUTHORIZED);
+ }
+
public boolean hasErrorStatus() {
- return getStatus() > STATUS_NO_INTERNET && (getXmppConnection().getAttempt() >= 2);
+ return getStatus() > STATUS_NO_INTERNET
+ && (getXmppConnection().getAttempt() >= 2);
}
-
+
public void setResource(String resource) {
this.resource = resource;
}
-
+
public String getResource() {
return this.resource;
}
-
+
public String getJid() {
- return username.toLowerCase(Locale.getDefault())+"@"+server.toLowerCase(Locale.getDefault());
+ return username.toLowerCase(Locale.getDefault()) + "@"
+ + server.toLowerCase(Locale.getDefault());
}
-
+
public JSONObject getKeys() {
return keys;
}
-
+
public String getSSLFingerprint() {
if (keys.has("ssl_cert")) {
try {
@@ -173,11 +187,11 @@ public class Account extends AbstractEntity{
return null;
}
}
-
+
public void setSSLCertFingerprint(String fingerprint) {
this.setKey("ssl_cert", fingerprint);
}
-
+
public boolean setKey(String keyName, String keyValue) {
try {
this.keys.put(keyName, keyValue);
@@ -190,16 +204,17 @@ public class Account extends AbstractEntity{
@Override
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
- values.put(UUID,uuid);
+ values.put(UUID, uuid);
values.put(USERNAME, username);
values.put(SERVER, server);
values.put(PASSWORD, password);
- values.put(OPTIONS,options);
- values.put(KEYS,this.keys.toString());
- values.put(ROSTERVERSION,rosterVersion);
+ values.put(OPTIONS, options);
+ values.put(KEYS, this.keys.toString());
+ values.put(ROSTERVERSION, rosterVersion);
+ values.put(AVATAR, avatar);
return values;
}
-
+
public static Account fromCursor(Cursor cursor) {
return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(USERNAME)),
@@ -207,14 +222,13 @@ public class Account extends AbstractEntity{
cursor.getString(cursor.getColumnIndex(PASSWORD)),
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
cursor.getString(cursor.getColumnIndex(ROSTERVERSION)),
- cursor.getString(cursor.getColumnIndex(KEYS))
- );
+ cursor.getString(cursor.getColumnIndex(KEYS)),
+ cursor.getString(cursor.getColumnIndex(AVATAR)));
}
-
public OtrEngine getOtrEngine(Context context) {
- if (otrEngine==null) {
- otrEngine = new OtrEngine(context,this);
+ if (otrEngine == null) {
+ otrEngine = new OtrEngine(context, this);
}
return this.otrEngine;
}
@@ -228,37 +242,39 @@ public class Account extends AbstractEntity{
}
public String getFullJid() {
- return this.getJid()+"/"+this.resource;
+ return this.getJid() + "/" + this.resource;
}
-
+
public String getOtrFingerprint() {
if (this.otrFingerprint == null) {
try {
- DSAPublicKey pubkey = (DSAPublicKey) this.otrEngine.getPublicKey();
+ DSAPublicKey pubkey = (DSAPublicKey) this.otrEngine
+ .getPublicKey();
if (pubkey == null) {
return null;
}
- StringBuilder builder = new StringBuilder(new OtrCryptoEngineImpl().getFingerprint(pubkey));
+ StringBuilder builder = new StringBuilder(
+ new OtrCryptoEngineImpl().getFingerprint(pubkey));
builder.insert(8, " ");
builder.insert(17, " ");
builder.insert(26, " ");
builder.insert(35, " ");
this.otrFingerprint = builder.toString();
} catch (OtrCryptoException e) {
-
+
}
}
return this.otrFingerprint;
}
public String getRosterVersion() {
- if (this.rosterVersion==null) {
+ if (this.rosterVersion == null) {
return "";
} else {
return this.rosterVersion;
}
}
-
+
public void setRosterVersion(String version) {
this.rosterVersion = version;
}
@@ -267,7 +283,7 @@ public class Account extends AbstractEntity{
this.getOtrEngine(applicationContext);
return this.getOtrFingerprint();
}
-
+
public void updatePresence(String resource, int status) {
this.presences.updatePresence(resource, status);
}
@@ -275,7 +291,7 @@ public class Account extends AbstractEntity{
public void removePresence(String resource) {
this.presences.removePresence(resource);
}
-
+
public void clearPresences() {
this.presences = new Presences();
}
@@ -295,9 +311,9 @@ public class Account extends AbstractEntity{
return null;
}
}
-
+
public Roster getRoster() {
- if (this.roster==null) {
+ if (this.roster == null) {
this.roster = new Roster(this);
}
return this.roster;
@@ -306,17 +322,74 @@ public class Account extends AbstractEntity{
public void setBookmarks(List<Bookmark> bookmarks) {
this.bookmarks = bookmarks;
}
-
+
public List<Bookmark> getBookmarks() {
return this.bookmarks;
}
public boolean hasBookmarkFor(String conferenceJid) {
- for(Bookmark bmark : this.bookmarks) {
+ for (Bookmark bmark : this.bookmarks) {
if (bmark.getJid().equals(conferenceJid)) {
return true;
}
}
return false;
}
+
+ public Bitmap getImage(Context context, int size) {
+ if (this.avatar != null) {
+ Bitmap bm = FileBackend.getAvatar(this.avatar, size, context);
+ if (bm == null) {
+ return UIHelper.getContactPicture(getJid(), size, context,
+ false);
+ } else {
+ return bm;
+ }
+ } else {
+ return UIHelper.getContactPicture(getJid(), size, context, false);
+ }
+ }
+
+ public boolean setAvatar(String filename) {
+ if (this.avatar != null && this.avatar.equals(filename)) {
+ return false;
+ } else {
+ this.avatar = filename;
+ return true;
+ }
+ }
+
+ public String getAvatar() {
+ return this.avatar;
+ }
+
+ public int getReadableStatusId() {
+ switch (getStatus()) {
+
+ case Account.STATUS_DISABLED:
+ return R.string.account_status_disabled;
+ case Account.STATUS_ONLINE:
+ return R.string.account_status_online;
+ case Account.STATUS_CONNECTING:
+ return R.string.account_status_connecting;
+ case Account.STATUS_OFFLINE:
+ return R.string.account_status_offline;
+ case Account.STATUS_UNAUTHORIZED:
+ return R.string.account_status_unauthorized;
+ case Account.STATUS_SERVER_NOT_FOUND:
+ return R.string.account_status_not_found;
+ case Account.STATUS_NO_INTERNET:
+ return R.string.account_status_no_internet;
+ case Account.STATUS_REGISTRATION_FAILED:
+ return R.string.account_status_regis_fail;
+ case Account.STATUS_REGISTRATION_CONFLICT:
+ return R.string.account_status_regis_conflict;
+ case Account.STATUS_REGISTRATION_SUCCESSFULL:
+ return R.string.account_status_regis_success;
+ case Account.STATUS_REGISTRATION_NOT_SUPPORTED:
+ return R.string.account_status_regis_not_sup;
+ default:
+ return R.string.account_status_unknown;
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java
index 8f8e38a5..ab05b9d1 100644
--- a/src/eu/siacs/conversations/entities/Contact.java
+++ b/src/eu/siacs/conversations/entities/Contact.java
@@ -8,6 +8,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element;
import android.content.ContentValues;
@@ -26,6 +27,7 @@ public class Contact implements ListItem {
public static final String PHOTOURI = "photouri";
public static final String KEYS = "pgpkey";
public static final String ACCOUNT = "accountUuid";
+ public static final String AVATAR = "avatar";
protected String accountUuid;
protected String systemName;
@@ -34,6 +36,7 @@ public class Contact implements ListItem {
protected int subscription = 0;
protected String systemAccount;
protected String photoUri;
+ protected String avatar;
protected JSONObject keys = new JSONObject();
protected Presences presences = new Presences();
@@ -45,7 +48,7 @@ public class Contact implements ListItem {
public Contact(String account, String systemName, String serverName,
String jid, int subscription, String photoUri,
- String systemAccount, String keys) {
+ String systemAccount, String keys, String avatar) {
this.accountUuid = account;
this.systemName = systemName;
this.serverName = serverName;
@@ -61,6 +64,7 @@ public class Contact implements ListItem {
} catch (JSONException e) {
this.keys = new JSONObject();
}
+ this.avatar = avatar;
}
public Contact(String jid) {
@@ -102,6 +106,7 @@ public class Contact implements ListItem {
values.put(SYSTEMACCOUNT, systemAccount);
values.put(PHOTOURI, photoUri);
values.put(KEYS, keys.toString());
+ values.put(AVATAR,avatar);
return values;
}
@@ -113,7 +118,8 @@ public class Contact implements ListItem {
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
cursor.getString(cursor.getColumnIndex(PHOTOURI)),
cursor.getString(cursor.getColumnIndex(SYSTEMACCOUNT)),
- cursor.getString(cursor.getColumnIndex(KEYS)));
+ cursor.getString(cursor.getColumnIndex(KEYS)),
+ cursor.getString(cursor.getColumnIndex(AVATAR)));
}
public int getSubscription() {
@@ -316,7 +322,25 @@ public class Contact implements ListItem {
}
@Override
- public Bitmap getImage(int dpSize, Context context) {
- return UIHelper.getContactPicture(this, dpSize, context, false);
+ public Bitmap getImage(int size, Context context) {
+ if (this.avatar!=null) {
+ Bitmap bm = FileBackend.getAvatar(avatar, size, context);
+ if (bm==null) {
+ return UIHelper.getContactPicture(this, size, context, false);
+ } else {
+ return bm;
+ }
+ } else {
+ return UIHelper.getContactPicture(this, size, context, false);
+ }
+ }
+
+ public boolean setAvatar(String filename) {
+ if (this.avatar != null && this.avatar.equals(filename)) {
+ return false;
+ } else {
+ this.avatar = filename;
+ return true;
+ }
}
}
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index 76fe84cf..439f9f22 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -1,8 +1,10 @@
package eu.siacs.conversations.entities;
import java.security.interfaces.DSAPublicKey;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import eu.siacs.conversations.utils.UIHelper;
import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
@@ -13,7 +15,7 @@ import net.java.otr4j.session.SessionStatus;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
-import android.net.Uri;
+import android.graphics.Bitmap;
public class Conversation extends AbstractEntity {
public static final String TABLENAME = "conversations";
@@ -43,7 +45,7 @@ public class Conversation extends AbstractEntity {
private String nextPresence;
- private transient List<Message> messages = null;
+ private transient CopyOnWriteArrayList<Message> messages = null;
private transient Account account = null;
private transient SessionImpl otrSession;
@@ -85,8 +87,9 @@ 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 CopyOnWriteArrayList<Message>(); // prevent null pointer
+ }
// populate with Conversation (this)
@@ -133,7 +136,7 @@ public class Conversation extends AbstractEntity {
}
}
- public void setMessages(List<Message> msgs) {
+ public void setMessages(CopyOnWriteArrayList<Message> msgs) {
this.messages = msgs;
}
@@ -173,13 +176,6 @@ public class Conversation extends AbstractEntity {
return this.contactJid;
}
- public Uri getProfilePhotoUri() {
- if (this.getProfilePhotoString() != null) {
- return Uri.parse(this.getProfilePhotoString());
- }
- return null;
- }
-
public int getStatus() {
return this.status;
}
@@ -339,6 +335,16 @@ public class Conversation extends AbstractEntity {
if ((latestEncryption == Message.ENCRYPTION_DECRYPTED)
|| (latestEncryption == Message.ENCRYPTION_DECRYPTION_FAILED)) {
return Message.ENCRYPTION_PGP;
+ } else if (latestEncryption == Message.ENCRYPTION_NONE) {
+ if (getContact().getPresences().size() == 1) {
+ if (getContact().getOtrFingerprints().size() >= 1) {
+ return Message.ENCRYPTION_OTR;
+ } else {
+ return latestEncryption;
+ }
+ } else {
+ return latestEncryption;
+ }
} else {
return latestEncryption;
}
@@ -395,4 +401,21 @@ public class Conversation extends AbstractEntity {
public Bookmark getBookmark() {
return this.bookmark;
}
+
+ public Bitmap getImage(Context context, int size) {
+ if (mode==MODE_SINGLE) {
+ return getContact().getImage(size, context);
+ } else {
+ return UIHelper.getContactPicture(this, size, context, false);
+ }
+ }
+
+ public boolean hasDuplicateMessage(Message message) {
+ for(int i = this.getMessages().size() -1; i >= 0; --i) {
+ if (this.messages.get(i).equals(message)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java
index 49c5ce58..6d70b66d 100644
--- a/src/eu/siacs/conversations/entities/Message.java
+++ b/src/eu/siacs/conversations/entities/Message.java
@@ -33,17 +33,21 @@ public class Message extends AbstractEntity {
public static final int TYPE_IMAGE = 1;
public static final int TYPE_AUDIO = 2;
public static final int TYPE_STATUS = 3;
+ public static final int TYPE_PRIVATE = 4;
public static String CONVERSATION = "conversationUuid";
public static String COUNTERPART = "counterpart";
+ public static String TRUE_COUNTERPART = "trueCounterpart";
public static String BODY = "body";
public static String TIME_SENT = "timeSent";
public static String ENCRYPTION = "encryption";
public static String STATUS = "status";
public static String TYPE = "type";
+ public static String REMOTE_MSG_ID = "remoteMsgId";
protected String conversationUuid;
protected String counterpart;
+ protected String trueCounterpart;
protected String body;
protected String encryptedBody;
protected long timeSent;
@@ -51,6 +55,7 @@ public class Message extends AbstractEntity {
protected int status;
protected int type;
protected boolean read = true;
+ protected String remoteMsgId = null;
protected transient Conversation conversation = null;
@@ -62,26 +67,28 @@ public class Message extends AbstractEntity {
public Message(Conversation conversation, String body, int encryption) {
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
- conversation.getContactJid(), body, System.currentTimeMillis(), encryption,
- Message.STATUS_UNSEND,TYPE_TEXT);
+ conversation.getContactJid(), null, body, System.currentTimeMillis(), encryption,
+ Message.STATUS_UNSEND,TYPE_TEXT,null);
this.conversation = conversation;
}
public Message(Conversation conversation, String counterpart, String body, int encryption, int status) {
- this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),counterpart, body, System.currentTimeMillis(), encryption,status,TYPE_TEXT);
+ this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),counterpart, null, body, System.currentTimeMillis(), encryption,status,TYPE_TEXT,null);
this.conversation = conversation;
}
- public Message(String uuid, String conversationUUid, String counterpart,
- String body, long timeSent, int encryption, int status, int type) {
+ public Message(String uuid, String conversationUUid, String counterpart, String trueCounterpart,
+ String body, long timeSent, int encryption, int status, int type, String remoteMsgId) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
+ this.trueCounterpart = trueCounterpart;
this.body = body;
this.timeSent = timeSent;
this.encryption = encryption;
this.status = status;
this.type = type;
+ this.remoteMsgId = remoteMsgId;
}
@Override
@@ -90,11 +97,13 @@ public class Message extends AbstractEntity {
values.put(UUID, uuid);
values.put(CONVERSATION, conversationUuid);
values.put(COUNTERPART, counterpart);
+ values.put(TRUE_COUNTERPART,trueCounterpart);
values.put(BODY, body);
values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption);
values.put(STATUS, status);
values.put(TYPE, type);
+ values.put(REMOTE_MSG_ID,remoteMsgId);
return values;
}
@@ -109,6 +118,24 @@ public class Message extends AbstractEntity {
public String getCounterpart() {
return counterpart;
}
+
+ public Contact getContact() {
+ if (this.conversation.getMode() == Conversation.MODE_SINGLE) {
+ return this.conversation.getContact();
+ } else {
+ if (this.trueCounterpart == null) {
+ return null;
+ } else {
+ Account account = this.conversation.getAccount();
+ Contact contact = account.getRoster().getContact(this.trueCounterpart);
+ if (contact.showInRoster()) {
+ return contact;
+ } else {
+ return null;
+ }
+ }
+ }
+ }
public String getBody() {
return body;
@@ -139,16 +166,26 @@ public class Message extends AbstractEntity {
public int getStatus() {
return status;
}
+
+ public String getRemoteMsgId() {
+ return this.remoteMsgId;
+ }
+
+ public void setRemoteMsgId(String id) {
+ this.remoteMsgId = id;
+ }
public static Message fromCursor(Cursor cursor) {
return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(CONVERSATION)),
cursor.getString(cursor.getColumnIndex(COUNTERPART)),
+ cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)),
cursor.getString(cursor.getColumnIndex(BODY)),
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
cursor.getInt(cursor.getColumnIndex(STATUS)),
- cursor.getInt(cursor.getColumnIndex(TYPE)));
+ cursor.getInt(cursor.getColumnIndex(TYPE)),
+ cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)));
}
public void setConversation(Conversation conv) {
@@ -200,13 +237,17 @@ public class Message extends AbstractEntity {
}
public void setPresence(String presence) {
- if (presence == null) {
+ if (presence == null || presence.isEmpty()) {
this.counterpart = this.counterpart.split("/")[0];
} else {
this.counterpart = this.counterpart.split("/")[0] + "/" + presence;
}
}
+ public void setTrueCounterpart(String trueCounterpart) {
+ this.trueCounterpart = trueCounterpart;
+ }
+
public String getPresence() {
String[] counterparts = this.counterpart.split("/");
if (counterparts.length == 2) {
@@ -230,4 +271,16 @@ public class Message extends AbstractEntity {
message.setConversation(conversation);
return message;
}
+
+ public void setCounterpart(String counterpart) {
+ this.counterpart = counterpart;
+ }
+
+ public boolean equals(Message message) {
+ if ((this.remoteMsgId!=null) && (this.body != null) && (this.counterpart != null)) {
+ return this.remoteMsgId.equals(message.getRemoteMsgId()) && this.body.equals(message.getBody()) && this.counterpart.equals(message.getCounterpart());
+ } else {
+ return false;
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java
index 0bb9b295..61b2732d 100644
--- a/src/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/eu/siacs/conversations/entities/MucOptions.java
@@ -2,6 +2,7 @@ package eu.siacs.conversations.entities;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.xml.Element;
@@ -13,11 +14,11 @@ public class MucOptions {
public static final int ERROR_NO_ERROR = 0;
public static final int ERROR_NICK_IN_USE = 1;
public static final int ERROR_ROOM_NOT_FOUND = 2;
-
+
public interface OnRenameListener {
public void onRename(boolean success);
}
-
+
public class User {
public static final int ROLE_MODERATOR = 3;
public static final int ROLE_NONE = 0;
@@ -28,22 +29,33 @@ public class MucOptions {
public static final int AFFILIATION_MEMBER = 2;
public static final int AFFILIATION_OUTCAST = 1;
public static final int AFFILIATION_NONE = 0;
-
+
private int role;
private int affiliation;
private String name;
+ private String jid;
private long pgpKeyId = 0;
-
+
public String getName() {
return name;
}
+
public void setName(String user) {
this.name = user;
}
-
+
+ public void setJid(String jid) {
+ this.jid = jid;
+ }
+
+ public String getJid() {
+ return this.jid;
+ }
+
public int getRole() {
return this.role;
}
+
public void setRole(String role) {
role = role.toLowerCase();
if (role.equals("moderator")) {
@@ -56,9 +68,11 @@ public class MucOptions {
this.role = ROLE_NONE;
}
}
+
public int getAffiliation() {
return this.affiliation;
}
+
public void setAffiliation(String affiliation) {
if (affiliation.equalsIgnoreCase("admin")) {
this.affiliation = AFFILIATION_ADMIN;
@@ -72,16 +86,18 @@ public class MucOptions {
this.affiliation = AFFILIATION_NONE;
}
}
+
public void setPgpKeyId(long id) {
this.pgpKeyId = id;
}
-
+
public long getPgpKeyId() {
return this.pgpKeyId;
}
}
+
private Account account;
- private ArrayList<User> users = new ArrayList<User>();
+ private List<User> users = new CopyOnWriteArrayList<User>();
private Conversation conversation;
private boolean isOnline = false;
private int error = ERROR_ROOM_NOT_FOUND;
@@ -94,44 +110,47 @@ public class MucOptions {
public MucOptions(Account account) {
this.account = account;
}
-
+
public void deleteUser(String name) {
- for(int i = 0; i < users.size(); ++i) {
+ for (int i = 0; i < users.size(); ++i) {
if (users.get(i).getName().equals(name)) {
users.remove(i);
return;
}
}
}
-
+
public void addUser(User user) {
- for(int i = 0; i < users.size(); ++i) {
+ for (int i = 0; i < users.size(); ++i) {
if (users.get(i).getName().equals(user.getName())) {
users.set(i, user);
return;
}
}
users.add(user);
- }
-
+ }
+
public void processPacket(PresencePacket packet, PgpEngine pgp) {
String[] fromParts = packet.getFrom().split("/");
- if (fromParts.length>=2) {
+ if (fromParts.length >= 2) {
String name = fromParts[1];
String type = packet.getAttribute("type");
- if (type==null) {
+ if (type == null) {
User user = new User();
- Element item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");
+ Element item = packet.findChild("x",
+ "http://jabber.org/protocol/muc#user")
+ .findChild("item");
user.setName(name);
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
+ user.setJid(item.getAttribute("jid"));
user.setName(name);
if (name.equals(this.joinnick)) {
this.isOnline = true;
this.error = ERROR_NO_ERROR;
self = user;
if (aboutToRename) {
- if (renameListener!=null) {
+ if (renameListener != null) {
renameListener.onRename(true);
}
aboutToRename = false;
@@ -140,8 +159,7 @@ public class MucOptions {
addUser(user);
}
if (pgp != null) {
- Element x = packet.findChild("x",
- "jabber:x:signed");
+ Element x = packet.findChild("x", "jabber:x:signed");
if (x != null) {
Element status = packet.findChild("status");
String msg;
@@ -150,7 +168,8 @@ public class MucOptions {
} else {
msg = "";
}
- user.setPgpKeyId(pgp.fetchKeyId(account,msg, x.getContent()));
+ user.setPgpKeyId(pgp.fetchKeyId(account, msg,
+ x.getContent()));
}
}
} else if (type.equals("unavailable")) {
@@ -159,26 +178,27 @@ public class MucOptions {
Element error = packet.findChild("error");
if (error.hasChild("conflict")) {
if (aboutToRename) {
- if (renameListener!=null) {
+ if (renameListener != null) {
renameListener.onRename(false);
}
aboutToRename = false;
this.setJoinNick(getActualNick());
} else {
- this.error = ERROR_NICK_IN_USE;
+ this.error = ERROR_NICK_IN_USE;
}
}
}
}
}
-
+
public List<User> getUsers() {
return this.users;
}
-
+
public String getProposedNick() {
String[] mucParts = conversation.getContactJid().split("/");
- if (conversation.getBookmark() != null && conversation.getBookmark().getNick() != null) {
+ if (conversation.getBookmark() != null
+ && conversation.getBookmark().getNick() != null) {
return conversation.getBookmark().getNick();
} else {
if (mucParts.length == 2) {
@@ -188,27 +208,27 @@ public class MucOptions {
}
}
}
-
+
public String getActualNick() {
- if (this.self.getName()!=null) {
+ if (this.self.getName() != null) {
return this.self.getName();
} else {
return this.getProposedNick();
}
}
-
+
public void setJoinNick(String nick) {
this.joinnick = nick;
}
-
+
public void setConversation(Conversation conversation) {
this.conversation = conversation;
}
-
+
public boolean online() {
return this.isOnline;
}
-
+
public int getError() {
return this.error;
}
@@ -216,7 +236,7 @@ public class MucOptions {
public void setOnRenameListener(OnRenameListener listener) {
this.renameListener = listener;
}
-
+
public OnRenameListener getOnRenameListener() {
return this.renameListener;
}
@@ -234,7 +254,7 @@ public class MucOptions {
public void setSubject(String content) {
this.subject = content;
}
-
+
public String getSubject() {
return this.subject;
}
@@ -242,33 +262,33 @@ public class MucOptions {
public void flagAboutToRename() {
this.aboutToRename = true;
}
-
+
public long[] getPgpKeyIds() {
List<Long> ids = new ArrayList<Long>();
- for(User user : getUsers()) {
- if(user.getPgpKeyId()!=0) {
+ for (User user : getUsers()) {
+ if (user.getPgpKeyId() != 0) {
ids.add(user.getPgpKeyId());
}
}
long[] primitivLongArray = new long[ids.size()];
- for(int i = 0; i < ids.size(); ++i) {
+ for (int i = 0; i < ids.size(); ++i) {
primitivLongArray[i] = ids.get(i);
}
return primitivLongArray;
}
-
+
public boolean pgpKeysInUse() {
- for(User user : getUsers()) {
- if (user.getPgpKeyId()!=0) {
+ for (User user : getUsers()) {
+ if (user.getPgpKeyId() != 0) {
return true;
}
}
return false;
}
-
+
public boolean everybodyHasKeys() {
- for(User user : getUsers()) {
- if (user.getPgpKeyId()==0) {
+ for (User user : getUsers()) {
+ if (user.getPgpKeyId() == 0) {
return false;
}
}
@@ -276,6 +296,16 @@ public class MucOptions {
}
public String getJoinJid() {
- return this.conversation.getContactJid().split("/")[0]+"/"+this.joinnick;
+ return this.conversation.getContactJid().split("/")[0] + "/"
+ + this.joinnick;
+ }
+
+ public String getTrueCounterpart(String counterpart) {
+ for(User user : this.getUsers()) {
+ if (user.getName().equals(counterpart)) {
+ return user.getJid();
+ }
+ }
+ return null;
}
} \ No newline at end of file