diff options
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r-- | src/eu/siacs/conversations/entities/AbstractEntity.java | 11 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Account.java | 17 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Bookmark.java | 67 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Contact.java | 40 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 74 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Downloadable.java | 5 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/ListItem.java | 2 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Message.java | 179 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/MucOptions.java | 40 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Presences.java | 17 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/Roster.java | 20 |
11 files changed, 344 insertions, 128 deletions
diff --git a/src/eu/siacs/conversations/entities/AbstractEntity.java b/src/eu/siacs/conversations/entities/AbstractEntity.java index 4891723ee..92b8a7298 100644 --- a/src/eu/siacs/conversations/entities/AbstractEntity.java +++ b/src/eu/siacs/conversations/entities/AbstractEntity.java @@ -4,19 +4,18 @@ import android.content.ContentValues; public abstract class AbstractEntity { - public static final String UUID = "uuid"; - + protected String uuid; - + public String getUuid() { return this.uuid; } - + public abstract ContentValues getContentValues(); - + public boolean equals(AbstractEntity entity) { return this.getUuid().equals(entity.getUuid()); } - + } diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java index d31d23249..eacd172c6 100644 --- a/src/eu/siacs/conversations/entities/Account.java +++ b/src/eu/siacs/conversations/entities/Account.java @@ -14,6 +14,7 @@ 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.services.XmppConnectionService; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.XmppConnection; import android.content.ContentValues; @@ -82,11 +83,12 @@ public class Account extends AbstractEntity { public Account(String username, String server, String password) { this(java.util.UUID.randomUUID().toString(), username, server, - password, 0, null, "",null); + password, 0, null, "", null); } public Account(String uuid, String username, String server, - String password, int options, String rosterVersion, String keys, String avatar) { + String password, int options, String rosterVersion, String keys, + String avatar) { this.uuid = uuid; this.username = username; this.server = server; @@ -151,7 +153,10 @@ public class Account extends AbstractEntity { 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); + 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() { @@ -226,7 +231,7 @@ public class Account extends AbstractEntity { cursor.getString(cursor.getColumnIndex(AVATAR))); } - public OtrEngine getOtrEngine(Context context) { + public OtrEngine getOtrEngine(XmppConnectionService context) { if (otrEngine == null) { otrEngine = new OtrEngine(context, this); } @@ -279,8 +284,8 @@ public class Account extends AbstractEntity { this.rosterVersion = version; } - public String getOtrFingerprint(Context applicationContext) { - this.getOtrEngine(applicationContext); + public String getOtrFingerprint(XmppConnectionService service) { + this.getOtrEngine(service); return this.getOtrFingerprint(); } diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java index 38c034100..14f010e79 100644 --- a/src/eu/siacs/conversations/entities/Bookmark.java +++ b/src/eu/siacs/conversations/entities/Bookmark.java @@ -8,57 +8,75 @@ import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; public class Bookmark implements ListItem { - + private Account account; private String jid; private String nick; private String name; + private String password; private boolean autojoin; + private boolean providePassword; private Conversation mJoinedConversation; - + public Bookmark(Account account, String jid) { this.account = account; this.jid = jid; } public static Bookmark parse(Element element, Account account) { - Bookmark bookmark = new Bookmark(account,element.getAttribute("jid")); + Bookmark bookmark = new Bookmark(account, element.getAttribute("jid")); bookmark.setName(element.getAttribute("name")); String autojoin = element.getAttribute("autojoin"); - if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) { + if (autojoin != null + && (autojoin.equals("true") || autojoin.equals("1"))) { bookmark.setAutojoin(true); } else { bookmark.setAutojoin(false); } Element nick = element.findChild("nick"); - if (nick!=null) { + if (nick != null) { bookmark.setNick(nick.getContent()); } + Element password = element.findChild("password"); + if (password != null) { + bookmark.setPassword(password.getContent()); + bookmark.setProvidePassword(true); + } return bookmark; } public void setAutojoin(boolean autojoin) { this.autojoin = autojoin; } - + public void setName(String name) { this.name = name; } - + public void setNick(String nick) { this.nick = nick; } + public void setPassword(String password) { + this.password = password; + } + + private void setProvidePassword(boolean providePassword) { + this.providePassword = providePassword; + } + @Override public int compareTo(ListItem another) { - return this.getDisplayName().compareToIgnoreCase(another.getDisplayName()); + return this.getDisplayName().compareToIgnoreCase( + another.getDisplayName()); } @Override public String getDisplayName() { - if (this.mJoinedConversation!=null && (this.mJoinedConversation.getMucOptions().getSubject() != null)) { + if (this.mJoinedConversation != null + && (this.mJoinedConversation.getMucOptions().getSubject() != null)) { return this.mJoinedConversation.getMucOptions().getSubject(); - } else if (name!=null) { + } else if (name != null) { return name; } else { return this.jid.split("@")[0]; @@ -69,20 +87,28 @@ public class Bookmark implements ListItem { public String getJid() { return this.jid.toLowerCase(Locale.US); } - + public String getNick() { return this.nick; } - + public boolean autojoin() { return autojoin; } + public String getPassword() { + return this.password; + } + + public boolean isProvidePassword() { + return this.providePassword; + } + public boolean match(String needle) { return needle == null || getJid().contains(needle.toLowerCase(Locale.US)) - || getDisplayName().toLowerCase(Locale.US) - .contains(needle.toLowerCase(Locale.US)); + || getDisplayName().toLowerCase(Locale.US).contains( + needle.toLowerCase(Locale.US)); } public Account getAccount() { @@ -91,10 +117,12 @@ public class Bookmark implements ListItem { @Override public Bitmap getImage(int dpSize, Context context) { - if (this.mJoinedConversation==null) { - return UIHelper.getContactPicture(getDisplayName(), dpSize, context, false); + if (this.mJoinedConversation == null) { + return UIHelper.getContactPicture(getDisplayName(), dpSize, + context, false); } else { - return UIHelper.getContactPicture(this.mJoinedConversation, dpSize, context, false); + return UIHelper.getContactPicture(this.mJoinedConversation, dpSize, + context, false); } } @@ -105,7 +133,7 @@ public class Bookmark implements ListItem { public String getName() { return name; } - + public Element toElement() { Element element = new Element("conference"); element.setAttribute("jid", this.getJid()); @@ -120,6 +148,9 @@ public class Bookmark implements ListItem { if (this.nick != null) { element.addChild("nick").setContent(this.nick); } + if (this.password != null && isProvidePassword()) { + element.addChild("password").setContent(this.password); + } return element; } diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index ab05b9d10..dfd6c0592 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -32,6 +32,7 @@ public class Contact implements ListItem { protected String accountUuid; protected String systemName; protected String serverName; + protected String presenceName; protected String jid; protected int subscription = 0; protected String systemAccount; @@ -76,6 +77,8 @@ public class Contact implements ListItem { return this.systemName; } else if (this.serverName != null) { return this.serverName; + } else if (this.presenceName != null) { + return this.presenceName; } else { return this.jid.split("@")[0]; } @@ -106,7 +109,7 @@ public class Contact implements ListItem { values.put(SYSTEMACCOUNT, systemAccount); values.put(PHOTOURI, photoUri); values.put(KEYS, keys.toString()); - values.put(AVATAR,avatar); + values.put(AVATAR, avatar); return values; } @@ -138,7 +141,7 @@ public class Contact implements ListItem { public Account getAccount() { return this.account; } - + public Presences getPresences() { return this.presences; } @@ -175,6 +178,10 @@ public class Contact implements ListItem { this.systemName = systemName; } + public void setPresenceName(String presenceName) { + this.presenceName = presenceName; + } + public String getSystemAccount() { return systemAccount; } @@ -309,7 +316,8 @@ public class Contact implements ListItem { @Override public int compareTo(ListItem another) { - return this.getDisplayName().compareToIgnoreCase(another.getDisplayName()); + return this.getDisplayName().compareToIgnoreCase( + another.getDisplayName()); } public String getServer() { @@ -323,9 +331,9 @@ public class Contact implements ListItem { @Override public Bitmap getImage(int size, Context context) { - if (this.avatar!=null) { + if (this.avatar != null) { Bitmap bm = FileBackend.getAvatar(avatar, size, context); - if (bm==null) { + if (bm == null) { return UIHelper.getContactPicture(this, size, context, false); } else { return bm; @@ -343,4 +351,26 @@ public class Contact implements ListItem { return true; } } + + public boolean deleteOtrFingerprint(String fingerprint) { + boolean success = false; + try { + if (this.keys.has("otr_fingerprints")) { + JSONArray newPrints = new JSONArray(); + JSONArray oldPrints = this.keys + .getJSONArray("otr_fingerprints"); + for (int i = 0; i < oldPrints.length(); ++i) { + if (!oldPrints.getString(i).equals(fingerprint)) { + newPrints.put(oldPrints.getString(i)); + } else { + success = true; + } + } + this.keys.put("otr_fingerprints", newPrints); + } + return success; + } catch (JSONException e) { + return false; + } + } } diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 439f9f22f..005b83db0 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -4,6 +4,7 @@ import java.security.interfaces.DSAPublicKey; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.UIHelper; import net.java.otr4j.OtrException; @@ -16,6 +17,7 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; +import android.os.SystemClock; public class Conversation extends AbstractEntity { public static final String TABLENAME = "conversations"; @@ -43,6 +45,8 @@ public class Conversation extends AbstractEntity { private long created; private int mode; + private long mutedTill = 0; + private String nextPresence; private transient CopyOnWriteArrayList<Message> messages = null; @@ -88,7 +92,8 @@ public class Conversation extends AbstractEntity { public List<Message> getMessages() { if (messages == null) { - this.messages = new CopyOnWriteArrayList<Message>(); // prevent null pointer + this.messages = new CopyOnWriteArrayList<Message>(); // prevent null + // pointer } // populate with Conversation (this) @@ -140,9 +145,8 @@ public class Conversation extends AbstractEntity { this.messages = msgs; } - public String getName(boolean useSubject) { - if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) - && useSubject) { + public String getName() { + if (getMode() == MODE_MULTI && getMucOptions().getSubject() != null) { return getMucOptions().getSubject(); } else if (getMode() == MODE_MULTI && bookmark != null && bookmark.getName() != null) { @@ -220,15 +224,15 @@ public class Conversation extends AbstractEntity { this.mode = mode; } - public SessionImpl startOtrSession(Context context, String presence, - boolean sendStart) { + public SessionImpl startOtrSession(XmppConnectionService service, + String presence, boolean sendStart) { if (this.otrSession != null) { return this.otrSession; } else { - SessionID sessionId = new SessionID(this.getContactJid(), presence, - "xmpp"); + SessionID sessionId = new SessionID( + this.getContactJid().split("/")[0], presence, "xmpp"); this.otrSession = new SessionImpl(sessionId, getAccount() - .getOtrEngine(context)); + .getOtrEngine(service)); try { if (sendStart) { this.otrSession.startSession(); @@ -287,7 +291,7 @@ public class Conversation extends AbstractEntity { public String getOtrFingerprint() { if (this.otrFingerprint == null) { try { - if (getOtrSession()== null) { + if (getOtrSession() == null) { return ""; } DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession() @@ -335,26 +339,36 @@ 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; } } - public int getNextEncryption() { + public int getNextEncryption(boolean force) { if (this.nextMessageEncryption == -1) { - return this.getLatestEncryption(); + int latest = this.getLatestEncryption(); + if (latest == Message.ENCRYPTION_NONE) { + if (force && getMode() == MODE_SINGLE) { + return Message.ENCRYPTION_OTR; + } else if (getContact().getPresences().size() == 1) { + if (getContact().getOtrFingerprints().size() >= 1) { + return Message.ENCRYPTION_OTR; + } else { + return latest; + } + } else { + return latest; + } + } else { + return latest; + } + } + if (this.nextMessageEncryption == Message.ENCRYPTION_NONE && force + && getMode() == MODE_SINGLE) { + return Message.ENCRYPTION_OTR; + } else { + return this.nextMessageEncryption; } - return this.nextMessageEncryption; } public void setNextEncryption(int encryption) { @@ -403,19 +417,27 @@ public class Conversation extends AbstractEntity { } public Bitmap getImage(Context context, int size) { - if (mode==MODE_SINGLE) { + 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) { + for (int i = this.getMessages().size() - 1; i >= 0; --i) { if (this.messages.get(i).equals(message)) { return true; } } return false; } + + public void setMutedTill(long mutedTill) { + this.mutedTill = mutedTill; + } + + public boolean isMuted() { + return SystemClock.elapsedRealtime() < this.mutedTill; + } } diff --git a/src/eu/siacs/conversations/entities/Downloadable.java b/src/eu/siacs/conversations/entities/Downloadable.java new file mode 100644 index 000000000..8fb4977ef --- /dev/null +++ b/src/eu/siacs/conversations/entities/Downloadable.java @@ -0,0 +1,5 @@ +package eu.siacs.conversations.entities; + +public interface Downloadable { + public void start(); +} diff --git a/src/eu/siacs/conversations/entities/ListItem.java b/src/eu/siacs/conversations/entities/ListItem.java index c89c85d92..19089b287 100644 --- a/src/eu/siacs/conversations/entities/ListItem.java +++ b/src/eu/siacs/conversations/entities/ListItem.java @@ -5,6 +5,8 @@ import android.graphics.Bitmap; public interface ListItem extends Comparable<ListItem> { public String getDisplayName(); + public String getJid(); + public Bitmap getImage(int dpSize, Context context); } diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index 9dea2f8a6..ce496d271 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -1,13 +1,13 @@ package eu.siacs.conversations.entities; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; -import eu.siacs.conversations.xmpp.jingle.JingleConnection; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; public class Message extends AbstractEntity { - + public static final String TABLENAME = "messages"; public static final int STATUS_RECEPTION_FAILED = -3; @@ -28,7 +28,7 @@ public class Message extends AbstractEntity { public static final int ENCRYPTION_OTR = 2; public static final int ENCRYPTION_DECRYPTED = 3; public static final int ENCRYPTION_DECRYPTION_FAILED = 4; - + public static final int TYPE_TEXT = 0; public static final int TYPE_IMAGE = 1; public static final int TYPE_AUDIO = 2; @@ -58,27 +58,32 @@ public class Message extends AbstractEntity { protected String remoteMsgId = null; protected transient Conversation conversation = null; - - protected transient JingleConnection jingleConnection = null; - + + protected transient Downloadable downloadable = null; + private Message() { - + } public Message(Conversation conversation, String body, int encryption) { this(java.util.UUID.randomUUID().toString(), conversation.getUuid(), - conversation.getContactJid(), null, body, System.currentTimeMillis(), encryption, - Message.STATUS_UNSEND,TYPE_TEXT,null); + 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, null, body, System.currentTimeMillis(), encryption,status,TYPE_TEXT,null); + + public Message(Conversation conversation, String counterpart, String body, + int encryption, int status) { + 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 trueCounterpart, - String body, long timeSent, int encryption, int status, int type, String remoteMsgId) { + + 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; @@ -97,20 +102,20 @@ public class Message extends AbstractEntity { values.put(UUID, uuid); values.put(CONVERSATION, conversationUuid); values.put(COUNTERPART, counterpart); - values.put(TRUE_COUNTERPART,trueCounterpart); + 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); + values.put(REMOTE_MSG_ID, remoteMsgId); return values; } public String getConversationUuid() { return conversationUuid; } - + public Conversation getConversation() { return this.conversation; } @@ -118,7 +123,7 @@ public class Message extends AbstractEntity { public String getCounterpart() { return counterpart; } - + public Contact getContact() { if (this.conversation.getMode() == Conversation.MODE_SINGLE) { return this.conversation.getContact(); @@ -127,7 +132,8 @@ public class Message extends AbstractEntity { return null; } else { Account account = this.conversation.getAccount(); - Contact contact = account.getRoster().getContact(this.trueCounterpart); + Contact contact = account.getRoster().getContact( + this.trueCounterpart); if (contact.showInRoster()) { return contact; } else { @@ -140,16 +146,18 @@ public class Message extends AbstractEntity { public String getBody() { return body; } - + public String getReadableBody(Context context) { - if ((encryption == ENCRYPTION_PGP)&&(type == TYPE_TEXT)) { - return ""+context.getText(R.string.encrypted_message_received); - } else if ((encryption == ENCRYPTION_OTR)&&(type == TYPE_IMAGE)) { - return ""+context.getText(R.string.encrypted_image_received); + if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) { + return context.getText(R.string.encrypted_message_received) + .toString(); + } else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) { + return context.getText(R.string.encrypted_image_received) + .toString(); } else if (encryption == ENCRYPTION_DECRYPTION_FAILED) { - return ""+context.getText(R.string.decryption_failed); + return context.getText(R.string.decryption_failed).toString(); } else if (type == TYPE_IMAGE) { - return ""+context.getText(R.string.image_file); + return context.getText(R.string.image_file).toString(); } else { return body.trim(); } @@ -166,11 +174,11 @@ public class Message extends AbstractEntity { public int getStatus() { return status; } - + public String getRemoteMsgId() { return this.remoteMsgId; } - + public void setRemoteMsgId(String id) { this.remoteMsgId = id; } @@ -199,11 +207,11 @@ public class Message extends AbstractEntity { public boolean isRead() { return this.read; } - + public void markRead() { this.read = true; } - + public void markUnread() { this.read = false; } @@ -223,7 +231,7 @@ public class Message extends AbstractEntity { public String getEncryptedBody() { return this.encryptedBody; } - + public void setEncryptedBody(String body) { this.encryptedBody = body; } @@ -231,40 +239,44 @@ public class Message extends AbstractEntity { public void setType(int type) { this.type = type; } - + public int getType() { return this.type; } public void setPresence(String presence) { - if (presence == null || presence.isEmpty()) { + if (presence == null) { 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) { return counterparts[1]; } else { - return null; + if (this.counterpart.contains("/")) { + return ""; + } else { + return null; + } } } - - public void setJingleConnection(JingleConnection connection) { - this.jingleConnection = connection; + + public void setDownloadable(Downloadable downloadable) { + this.downloadable = downloadable; } - - public JingleConnection getJingleConnection() { - return this.jingleConnection; + + public Downloadable getDownloadable() { + return this.downloadable; } - + public static Message createStatusMessage(Conversation conversation) { Message message = new Message(); message.setType(Message.TYPE_STATUS); @@ -275,12 +287,85 @@ public class Message extends AbstractEntity { 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()); + 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; } } + + public Message next() { + int index = this.conversation.getMessages().indexOf(this); + if (index < 0 || index >= this.conversation.getMessages().size() - 1) { + return null; + } else { + return this.conversation.getMessages().get(index + 1); + } + } + + public Message prev() { + int index = this.conversation.getMessages().indexOf(this); + if (index <= 0 || index > this.conversation.getMessages().size()) { + return null; + } else { + return this.conversation.getMessages().get(index - 1); + } + } + + public boolean mergable(Message message) { + if (message == null) { + return false; + } + return (message.getType() == Message.TYPE_TEXT + && message.getEncryption() != Message.ENCRYPTION_PGP + && this.getType() == message.getType() + && this.getEncryption() == message.getEncryption() + && this.getCounterpart().equals(message.getCounterpart()) + && (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) && ((this + .getStatus() == message.getStatus()) || ((this.getStatus() == Message.STATUS_SEND || this + .getStatus() == Message.STATUS_SEND_RECEIVED) && (message + .getStatus() == Message.STATUS_UNSEND + || message.getStatus() == Message.STATUS_SEND || message + .getStatus() == Message.STATUS_SEND_DISPLAYED)))); + } + + public String getMergedBody() { + Message next = this.next(); + if (this.mergable(next)) { + return body.trim() + '\n' + next.getMergedBody(); + } + return body.trim(); + } + + public int getMergedStatus() { + Message next = this.next(); + if (this.mergable(next)) { + return next.getMergedStatus(); + } else { + return getStatus(); + } + } + + public long getMergedTimeSent() { + Message next = this.next(); + if (this.mergable(next)) { + return next.getMergedTimeSent(); + } else { + return getTimeSent(); + } + } + + public boolean wasMergedIntoPrevious() { + Message prev = this.prev(); + if (prev == null) { + return false; + } else { + return prev.mergable(this); + } + } } diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index 61b2732df..e9ab6908a 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -14,6 +14,7 @@ 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 static final int ERROR_PASSWORD_REQUIRED = 3; public interface OnRenameListener { public void onRename(boolean success); @@ -106,6 +107,8 @@ public class MucOptions { private User self = new User(); private String subject = null; private String joinnick; + private String password = null; + private boolean passwordChanged = false; public MucOptions(Account account) { this.account = account; @@ -155,6 +158,10 @@ public class MucOptions { } aboutToRename = false; } + if (conversation.getBookmark() != null + && conversation.getBookmark().isProvidePassword()) { + this.passwordChanged = false; + } } else { addUser(user); } @@ -186,6 +193,12 @@ public class MucOptions { } else { this.error = ERROR_NICK_IN_USE; } + } else if (error.hasChild("not-authorized")) { + if (conversation.getBookmark() != null + && conversation.getBookmark().isProvidePassword()) { + this.passwordChanged = true; + } + this.error = ERROR_PASSWORD_REQUIRED; } } } @@ -299,13 +312,36 @@ public class MucOptions { return this.conversation.getContactJid().split("/")[0] + "/" + this.joinnick; } - + public String getTrueCounterpart(String counterpart) { - for(User user : this.getUsers()) { + for (User user : this.getUsers()) { if (user.getName().equals(counterpart)) { return user.getJid(); } } return null; } + + public String getPassword() { + if (conversation.getBookmark() != null + && conversation.getBookmark().getPassword() != null) { + return conversation.getBookmark().getPassword(); + } else { + return this.password; + } + } + + public void setPassword(String password) { + if (conversation.getBookmark() != null + && conversation.getBookmark().isProvidePassword()) { + conversation.getBookmark().setPassword(password); + } else { + this.password = password; + } + } + + public boolean isPasswordChanged() { + return this.passwordChanged; + } + }
\ No newline at end of file diff --git a/src/eu/siacs/conversations/entities/Presences.java b/src/eu/siacs/conversations/entities/Presences.java index acd80735a..b58998473 100644 --- a/src/eu/siacs/conversations/entities/Presences.java +++ b/src/eu/siacs/conversations/entities/Presences.java @@ -14,7 +14,7 @@ public class Presences { public static final int XA = 2; public static final int DND = 3; public static final int OFFLINE = 4; - + private Hashtable<String, Integer> presences = new Hashtable<String, Integer>(); public Hashtable<String, Integer> getPresences() { @@ -28,23 +28,24 @@ public class Presences { public void removePresence(String resource) { this.presences.remove(resource); } - + public void clearPresences() { this.presences.clear(); } - + public int getMostAvailableStatus() { int status = OFFLINE; Iterator<Entry<String, Integer>> it = presences.entrySet().iterator(); while (it.hasNext()) { Entry<String, Integer> entry = it.next(); - if (entry.getValue()<status) status = entry.getValue(); + if (entry.getValue() < status) + status = entry.getValue(); } return status; } public static int parseShow(Element show) { - if ((show == null)||(show.getContent() == null)) { + if ((show == null) || (show.getContent() == null)) { return Presences.ONLINE; } else if (show.getContent().equals("away")) { return Presences.AWAY; @@ -53,16 +54,16 @@ public class Presences { } else if (show.getContent().equals("chat")) { return Presences.CHAT; } else if (show.getContent().equals("dnd")) { - return Presences.DND; + return Presences.DND; } else { return Presences.OFFLINE; } } - + public int size() { return presences.size(); } - + public String[] asStringArray() { final String[] presencesArray = new String[presences.size()]; presences.keySet().toArray(presencesArray); diff --git a/src/eu/siacs/conversations/entities/Roster.java b/src/eu/siacs/conversations/entities/Roster.java index aa3286641..c6212f773 100644 --- a/src/eu/siacs/conversations/entities/Roster.java +++ b/src/eu/siacs/conversations/entities/Roster.java @@ -9,16 +9,16 @@ public class Roster { Account account; ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<String, Contact>(); private String version = null; - + public Roster(Account account) { this.account = account; } - + public boolean hasContact(String jid) { String cleanJid = jid.split("/")[0]; return contacts.containsKey(cleanJid); } - + public Contact getContact(String jid) { String cleanJid = jid.split("/")[0].toLowerCase(Locale.getDefault()); if (contacts.containsKey(cleanJid)) { @@ -32,19 +32,19 @@ public class Roster { } public void clearPresences() { - for(Contact contact : getContacts()) { + for (Contact contact : getContacts()) { contact.clearPresences(); } } - + public void markAllAsNotInRoster() { - for(Contact contact : getContacts()) { + for (Contact contact : getContacts()) { contact.resetOption(Contact.Options.IN_ROSTER); } } - + public void clearSystemAccounts() { - for(Contact contact : getContacts()) { + for (Contact contact : getContacts()) { contact.setPhotoUri(null); contact.setSystemName(null); contact.setSystemAccount(null); @@ -58,13 +58,13 @@ public class Roster { public void initContact(Contact contact) { contact.setAccount(account); contact.setOption(Contact.Options.IN_ROSTER); - contacts.put(contact.getJid(),contact); + contacts.put(contact.getJid(), contact); } public void setVersion(String version) { this.version = version; } - + public String getVersion() { return this.version; } |