diff options
author | steckbrief <steckbrief@chefmail.de> | 2015-02-20 22:19:31 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2015-02-20 22:19:31 +0100 |
commit | 20eae3955700341188bc1907a506970f5817a153 (patch) | |
tree | 6e50d9083a4392875b5f9dbe92b38973cf95c332 /src/main/java/eu/siacs/conversations/entities | |
parent | 980a84a6ce4358e8662addf203695e01d9f931dc (diff) | |
parent | ecbceae88b7a7aa871e5396efec1e2ff8d056d46 (diff) |
Merge master-origin
Conflicts:
src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
src/main/java/eu/siacs/conversations/ui/XmppActivity.java
src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
src/main/java/eu/siacs/conversations/utils/UIHelper.java
src/main/res/values-de/strings.xml
Diffstat (limited to '')
4 files changed, 200 insertions, 80 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 470bd290..036acf63 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -108,9 +108,9 @@ public class Conversation extends AbstractEntity implements Blockable { } } - public void findMessagesWithFiles(OnMessageFound onMessageFound) { + public void findMessagesWithFiles(final OnMessageFound onMessageFound) { synchronized (this.messages) { - for (Message message : this.messages) { + for (final Message message : this.messages) { if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) && message.getEncryption() != Message.ENCRYPTION_PGP) { onMessageFound.onMessageFound(message); @@ -119,14 +119,14 @@ public class Conversation extends AbstractEntity implements Blockable { } } - public Message findMessageWithFileAndUuid(String uuid) { + public Message findMessageWithFileAndUuid(final String uuid) { synchronized (this.messages) { - for (Message message : this.messages) { - if (message.getType() == Message.TYPE_IMAGE + for (final Message message : this.messages) { + if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) && message.getEncryption() != Message.ENCRYPTION_PGP && message.getUuid().equals(uuid)) { return message; - } + } } } return null; diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index b5a1897d..8112f5de 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -36,17 +36,19 @@ public class Message extends AbstractEntity { 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"; - public static String SERVER_MSG_ID = "serverMsgId"; - public static String RELATIVE_FILE_PATH = "relativeFilePath"; + public static final String CONVERSATION = "conversationUuid"; + public static final String COUNTERPART = "counterpart"; + public static final String TRUE_COUNTERPART = "trueCounterpart"; + public static final String BODY = "body"; + public static final String TIME_SENT = "timeSent"; + public static final String ENCRYPTION = "encryption"; + public static final String STATUS = "status"; + public static final String TYPE = "type"; + public static final String REMOTE_MSG_ID = "remoteMsgId"; + public static final String SERVER_MSG_ID = "serverMsgId"; + public static final String RELATIVE_FILE_PATH = "relativeFilePath"; + public static final String ME_COMMAND = "/me "; + public boolean markable = false; protected String conversationUuid; protected Jid counterpart; @@ -310,12 +312,17 @@ public class Message extends AbstractEntity { public boolean equals(Message message) { if (this.serverMsgId != null && message.getServerMsgId() != null) { return this.serverMsgId.equals(message.getServerMsgId()); + } else if (this.body == null || this.counterpart == null) { + return false; + } else if (message.getRemoteMsgId() != null) { + return (message.getRemoteMsgId().equals(this.remoteMsgId) || message.getRemoteMsgId().equals(this.uuid)) + && this.counterpart.equals(message.getCounterpart()) + && this.body.equals(message.getBody()); } else { - return this.body != null - && this.counterpart != null - && ((this.remoteMsgId != null && this.remoteMsgId.equals(message.getRemoteMsgId())) - || this.uuid.equals(message.getRemoteMsgId())) && this.body.equals(message.getBody()) - && this.counterpart.equals(message.getCounterpart()); + return this.remoteMsgId == null + && this.counterpart.equals(message.getCounterpart()) + && this.body.equals(message.getBody()) + && Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.PING_TIMEOUT * 500; } } @@ -348,15 +355,34 @@ public class Message extends AbstractEntity { } public boolean mergeable(final Message message) { - return message != null && (message.getType() == Message.TYPE_TEXT && this.getDownloadable() == null && message.getDownloadable() == null && message.getEncryption() != Message.ENCRYPTION_PGP && this.getType() == message.getType() && this.getStatus() == message.getStatus() && this.getEncryption() == message.getEncryption() && this.getCounterpart() != null && this.getCounterpart().equals(message.getCounterpart()) && (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) && !message.bodyContainsDownloadable() && !this.bodyContainsDownloadable()); + return message != null && + (message.getType() == Message.TYPE_TEXT && + this.getDownloadable() == null && + message.getDownloadable() == null && + message.getEncryption() != Message.ENCRYPTION_PGP && + this.getType() == message.getType() && + this.getStatus() == message.getStatus() && + this.getEncryption() == message.getEncryption() && + this.getCounterpart() != null && + this.getCounterpart().equals(message.getCounterpart()) && + (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) && + !message.bodyContainsDownloadable() && + !this.bodyContainsDownloadable() && + !message.getBody().startsWith(ME_COMMAND) && + !this.getBody().startsWith(ME_COMMAND) + ); } public String getMergedBody() { - Message next = this.next(); + final Message next = this.next(); if (this.mergeable(next)) { - return body.trim() + '\n' + next.getMergedBody(); + return getBody() + '\n' + next.getMergedBody(); } - return body.trim(); + return getBody(); + } + + public boolean hasMeCommand() { + return getMergedBody().startsWith(ME_COMMAND); } public int getMergedStatus() { @@ -395,7 +421,7 @@ public class Message extends AbstractEntity { String[] pathParts = url.getPath().split("/"); String filename; if (pathParts.length > 0) { - filename = pathParts[pathParts.length - 1]; + filename = pathParts[pathParts.length - 1].toLowerCase(); } else { return false; } diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 97a63532..27821c65 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -4,15 +4,77 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; + import android.annotation.SuppressLint; @SuppressLint("DefaultLocale") public class MucOptions { + + public enum Affiliation { + OWNER("owner", 4, R.string.owner), + ADMIN("admin", 3, R.string.admin), + MEMBER("member", 2, R.string.member), + OUTCAST("outcast", 0, R.string.outcast), + NONE("none", 1, R.string.no_affiliation); + + private Affiliation(String string, int rank, int resId) { + this.string = string; + this.resId = resId; + this.rank = rank; + } + + private String string; + private int resId; + private int rank; + + public int getResId() { + return resId; + } + + @Override + public String toString() { + return this.string; + } + + public boolean outranks(Affiliation affiliation) { + return rank > affiliation.rank; + } + + public boolean ranks(Affiliation affiliation) { + return rank >= affiliation.rank; + } + } + + public enum Role { + MODERATOR("moderator", R.string.moderator), + VISITOR("visitor", R.string.visitor), + PARTICIPANT("participant", R.string.participant), + NONE("none", R.string.no_role); + + private Role(String string, int resId) { + this.string = string; + this.resId = resId; + } + + private String string; + private int resId; + + public int getResId() { + return resId; + } + + @Override + public String toString() { + return this.string; + } + } + public static final int ERROR_NO_ERROR = 0; public static final int ERROR_NICK_IN_USE = 1; public static final int ERROR_UNKNOWN = 2; @@ -22,6 +84,7 @@ public class MucOptions { public static final int KICKED_FROM_ROOM = 9; + public static final String STATUS_CODE_ROOM_CONFIG_CHANGED = "104"; public static final String STATUS_CODE_SELF_PRESENCE = "110"; public static final String STATUS_CODE_BANNED = "301"; public static final String STATUS_CODE_CHANGED_NICK = "303"; @@ -30,6 +93,7 @@ public class MucOptions { private interface OnEventListener { public void onSuccess(); + public void onFailure(); } @@ -42,18 +106,8 @@ public class MucOptions { } public class User { - public static final int ROLE_MODERATOR = 3; - public static final int ROLE_NONE = 0; - public static final int ROLE_PARTICIPANT = 2; - public static final int ROLE_VISITOR = 1; - public static final int AFFILIATION_ADMIN = 4; - public static final int AFFILIATION_OWNER = 3; - 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 Role role = Role.NONE; + private Affiliation affiliation = Affiliation.NONE; private String name; private Jid jid; private long pgpKeyId = 0; @@ -74,7 +128,7 @@ public class MucOptions { return this.jid; } - public int getRole() { + public Role getRole() { return this.role; } @@ -82,35 +136,41 @@ public class MucOptions { role = role.toLowerCase(); switch (role) { case "moderator": - this.role = ROLE_MODERATOR; + this.role = Role.MODERATOR; break; case "participant": - this.role = ROLE_PARTICIPANT; + this.role = Role.PARTICIPANT; break; case "visitor": - this.role = ROLE_VISITOR; + this.role = Role.VISITOR; break; default: - this.role = ROLE_NONE; + this.role = Role.NONE; break; } } - public int getAffiliation() { + public Affiliation getAffiliation() { return this.affiliation; } public void setAffiliation(String affiliation) { - if (affiliation.equalsIgnoreCase("admin")) { - this.affiliation = AFFILIATION_ADMIN; - } else if (affiliation.equalsIgnoreCase("owner")) { - this.affiliation = AFFILIATION_OWNER; - } else if (affiliation.equalsIgnoreCase("member")) { - this.affiliation = AFFILIATION_MEMBER; - } else if (affiliation.equalsIgnoreCase("outcast")) { - this.affiliation = AFFILIATION_OUTCAST; - } else { - this.affiliation = AFFILIATION_NONE; + affiliation = affiliation.toLowerCase(); + switch (affiliation) { + case "admin": + this.affiliation = Affiliation.ADMIN; + break; + case "owner": + this.affiliation = Affiliation.OWNER; + break; + case "member": + this.affiliation = Affiliation.MEMBER; + break; + case "outcast": + this.affiliation = Affiliation.OUTCAST; + break; + default: + this.affiliation = Affiliation.NONE; } } @@ -129,6 +189,7 @@ public class MucOptions { private Account account; private List<User> users = new CopyOnWriteArrayList<>(); + private List<String> features = new ArrayList<>(); private Conversation conversation; private boolean isOnline = false; private int error = ERROR_UNKNOWN; @@ -144,6 +205,31 @@ public class MucOptions { this.conversation = conversation; } + public void updateFeatures(ArrayList<String> features) { + this.features.clear(); + this.features.addAll(features); + } + + public boolean hasFeature(String feature) { + return this.features.contains(feature); + } + + public boolean canInvite() { + return !membersOnly() || self.getAffiliation().ranks(Affiliation.ADMIN); + } + + public boolean membersOnly() { + return hasFeature("muc_membersonly"); + } + + public boolean nonanonymous() { + return hasFeature("muc_nonanonymous"); + } + + public boolean persistent() { + return hasFeature("muc_persistent"); + } + public void deleteUser(String name) { for (int i = 0; i < users.size(); ++i) { if (users.get(i).getName().equals(name)) { @@ -168,7 +254,7 @@ public class MucOptions { if (!from.isBareJid()) { final String name = from.getResourcepart(); final String type = packet.getAttribute("type"); - final Element x = packet.findChild("x","http://jabber.org/protocol/muc#user"); + final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user"); final List<String> codes = getStatusCodes(x); if (type == null) { User user = new User(); @@ -204,7 +290,7 @@ public class MucOptions { msg = ""; } user.setPgpKeyId(pgp.fetchKeyId(account, msg, - signed.getContent())); + signed.getContent())); } } } @@ -259,12 +345,12 @@ public class MucOptions { } private List<String> getStatusCodes(Element x) { - List<String> codes = new ArrayList<String>(); + List<String> codes = new ArrayList<>(); if (x != null) { - for(Element child : x.getChildren()) { + for (Element child : x.getChildren()) { if (child.getName().equals("status")) { String code = child.getAttribute("code"); - if (code!=null) { + if (code != null) { codes.add(code); } } @@ -389,7 +475,7 @@ public class MucOptions { public Jid createJoinJid(String nick) { try { - return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/"+nick); + return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick); } catch (final InvalidJidException e) { return null; } diff --git a/src/main/java/eu/siacs/conversations/entities/Roster.java b/src/main/java/eu/siacs/conversations/entities/Roster.java index 1a81a419..ce058004 100644 --- a/src/main/java/eu/siacs/conversations/entities/Roster.java +++ b/src/main/java/eu/siacs/conversations/entities/Roster.java @@ -1,14 +1,14 @@ package eu.siacs.conversations.entities; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; import eu.siacs.conversations.xmpp.jid.Jid; public class Roster { final Account account; - final ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<>(); + final HashMap<String, Contact> contacts = new HashMap<>(); private String version = null; public Roster(Account account) { @@ -19,23 +19,27 @@ public class Roster { if (jid == null) { return null; } - final Contact contact = contacts.get(jid.toBareJid().toString()); - if (contact != null && contact.showInRoster()) { - return contact; - } else { - return null; + synchronized (this.contacts) { + Contact contact = contacts.get(jid.toBareJid().toString()); + if (contact != null && contact.showInRoster()) { + return contact; + } else { + return null; + } } } public Contact getContact(final Jid jid) { - final Jid bareJid = jid.toBareJid(); - if (contacts.containsKey(bareJid.toString())) { - return contacts.get(bareJid.toString()); - } else { - final Contact contact = new Contact(bareJid); - contact.setAccount(account); - contacts.put(bareJid.toString(), contact); - return contact; + synchronized (this.contacts) { + final Jid bareJid = jid.toBareJid(); + if (contacts.containsKey(bareJid.toString())) { + return contacts.get(bareJid.toString()); + } else { + Contact contact = new Contact(bareJid); + contact.setAccount(account); + contacts.put(bareJid.toString(), contact); + return contact; + } } } @@ -46,13 +50,13 @@ public class Roster { } public void markAllAsNotInRoster() { - for (final Contact contact : getContacts()) { + for (Contact contact : getContacts()) { contact.resetOption(Contact.Options.IN_ROSTER); } } public void clearSystemAccounts() { - for (final Contact contact : getContacts()) { + for (Contact contact : getContacts()) { contact.setPhotoUri(null); contact.setSystemName(null); contact.setSystemAccount(null); @@ -60,13 +64,17 @@ public class Roster { } public List<Contact> getContacts() { - return new ArrayList<>(this.contacts.values()); + synchronized (this.contacts) { + return new ArrayList<>(this.contacts.values()); + } } public void initContact(final Contact contact) { contact.setAccount(account); contact.setOption(Contact.Options.IN_ROSTER); - contacts.put(contact.getJid().toBareJid().toString(), contact); + synchronized (this.contacts) { + contacts.put(contact.getJid().toBareJid().toString(), contact); + } } public void setVersion(String version) { |