diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-05-16 17:54:53 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-05-16 17:54:53 +0200 |
commit | bceee45b463dc6113301ba82cb636ecd9e0c509c (patch) | |
tree | ab1ca8f9e85354d72441cacf0f75ed01b16896e7 | |
parent | bd1a2228d2f3392ee4cf891bcc07c30ccb363bfa (diff) | |
parent | 6f1a4494eb89b0b5db8bbfa4718593b5c236e477 (diff) |
Merge remote-tracking branch 'refs/remotes/siacs/master'
5 files changed, 53 insertions, 25 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 1cdf0d673..a708b0ce8 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -450,7 +450,7 @@ public class Account extends AbstractEntity { } public int countPresences() { - return this.getRoster().getContact(this.getJid().toBareJid()).getPresences().size(); + return this.getSelfContact().getPresences().size(); } public String getPgpSignature() { diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java index c4fc30abc..9accec95d 100644 --- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java +++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java @@ -53,6 +53,7 @@ public class ServiceDiscoveryResult { } public Identity(final JSONObject o) { + this( o.optString("category", null), o.optString("type", null), @@ -145,7 +146,7 @@ public class ServiceDiscoveryResult { this.hash = hash; this.ver = ver; - JSONArray identities = o.optJSONArray("identities"); + JSONArray identities = o.optJSONArray("identites"); if (identities != null) { for (int i = 0; i < identities.length(); i++) { this.identities.add(new Identity(identities.getJSONObject(i))); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 21bdbdf63..3d07c0fad 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.parser; +import android.text.Html; import android.util.Log; import android.util.Pair; @@ -7,6 +8,9 @@ import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.UUID; @@ -20,6 +24,8 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; +import eu.siacs.conversations.entities.Presence; +import eu.siacs.conversations.entities.ServiceDiscoveryResult; import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.XmppConnectionService; @@ -31,8 +37,10 @@ import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.pep.Avatar; import eu.siacs.conversations.xmpp.stanzas.MessagePacket; -public class MessageParser extends AbstractParser implements - OnMessagePacketReceived { +public class MessageParser extends AbstractParser implements OnMessagePacketReceived { + + private static final List<String> CLIENTS_SENDING_HTML_IN_OTR = Arrays.asList(new String[]{"Pidgin","Adium"}); + public MessageParser(XmppConnectionService service) { super(service); } @@ -95,6 +103,11 @@ public class MessageParser extends AbstractParser implements conversation.setSymmetricKey(CryptoHelper.hexToBytes(key)); return null; } + if (clientMightSendHtml(conversation.getAccount(), from)) { + Log.d(Config.LOGTAG,conversation.getAccount().getJid().toBareJid()+": received OTR message from bad behaving client. escaping HTML…"); + body = Html.fromHtml(body).toString(); + } + final OtrService otrService = conversation.getAccount().getOtrService(); Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED); finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey())); @@ -107,6 +120,30 @@ public class MessageParser extends AbstractParser implements } } + private static boolean clientMightSendHtml(Account account, Jid from) { + String resource = from.getResourcepart(); + if (resource == null) { + return false; + } + Presence presence = account.getRoster().getContact(from).getPresences().getPresences().get(resource); + ServiceDiscoveryResult disco = presence == null ? null : presence.getServiceDiscoveryResult(); + if (disco == null) { + return false; + } + return hasIdentityKnowForSendingHtml(disco.getIdentities()); + } + + private static boolean hasIdentityKnowForSendingHtml(List<ServiceDiscoveryResult.Identity> identities) { + for(ServiceDiscoveryResult.Identity identity : identities) { + if (identity.getName() != null) { + if (CLIENTS_SENDING_HTML_IN_OTR.contains(identity.getName())) { + return true; + } + } + } + return false; + } + private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status) { Message finishedMessage = null; AxolotlService service = conversation.getAccount().getAxolotlService(); @@ -311,7 +348,7 @@ public class MessageParser extends AbstractParser implements } boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT; - boolean isProperlyAddressed = (to != null ) && (!to.isBareJid() || account.countPresences() <= 1); + boolean isProperlyAddressed = (to != null ) && (!to.isBareJid() || account.countPresences() == 0); boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status"); if (packet.fromAccount(account)) { status = Message.STATUS_SEND; diff --git a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java index aa9b2e50f..2db20a447 100644 --- a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java @@ -41,7 +41,6 @@ public class GeoHelper { return intents; } final Conversation conversation = message.getConversation(); - final Contact contact = message.getContact(); String label; if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) { try { @@ -56,25 +55,16 @@ public class GeoHelper { Intent locationPluginIntent = new Intent("eu.siacs.conversations.location.show"); locationPluginIntent.putExtra("latitude",latitude); locationPluginIntent.putExtra("longitude",longitude); - if (conversation.getMode() == Conversation.MODE_SINGLE) { - if (message.getStatus() == Message.STATUS_RECEIVED) { - locationPluginIntent.putExtra("name",conversation.getName()); - locationPluginIntent.putExtra("jid",message.getCounterpart().toString()); - } - else { - locationPluginIntent.putExtra("name", conversation.getAccount().getUsername()); - locationPluginIntent.putExtra("jid",conversation.getAccount().getJid().toString()); - } + if (message.getStatus() != Message.STATUS_RECEIVED) { + locationPluginIntent.putExtra("jid",conversation.getAccount().getJid().toString()); + locationPluginIntent.putExtra("name",conversation.getAccount().getJid().getLocalpart()); } else { - if (message.getStatus() == Message.STATUS_RECEIVED) { - if (contact != null) { - locationPluginIntent.putExtra("name",contact.getDisplayName()); - } - locationPluginIntent.putExtra("jid",message.getCounterpart().toString()); - } - else { - locationPluginIntent.putExtra("name", conversation.getAccount().getUsername()); - locationPluginIntent.putExtra("jid",conversation.getAccount().getJid().toString()); + Contact contact = message.getContact(); + if (contact != null) { + locationPluginIntent.putExtra("name", contact.getDisplayName()); + locationPluginIntent.putExtra("jid", contact.getJid().toString()); + } else { + locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart())); } } intents.add(locationPluginIntent); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 5ab058d14..6ca5370a3 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -249,7 +249,7 @@ public class UIHelper { } } - private static String getDisplayedMucCounterpart(final Jid counterpart) { + public static String getDisplayedMucCounterpart(final Jid counterpart) { if (counterpart==null) { return ""; } else if (!counterpart.isBareJid()) { |