diff options
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/parser/MessageParser.java | 84 |
1 files changed, 62 insertions, 22 deletions
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 0d46074d..bd136a33 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -1,9 +1,9 @@ package eu.siacs.conversations.parser; import android.os.SystemClock; -import android.util.Log; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; +import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -18,7 +18,7 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket; public class MessageParser extends AbstractParser implements OnMessagePacketReceived { - private long lastCarbonMessageReceived = -XmppConnectionService.CARBON_GRACE_PERIOD; + private long lastCarbonMessageReceived = -(Config.CARBON_GRACE_PERIOD * 1000); public MessageParser(XmppConnectionService service) { super(service); @@ -70,11 +70,13 @@ public class MessageParser extends AbstractParser implements } updateLastseen(packet, account, true); String body = packet.getBody(); + if (body.matches("^\\?OTRv\\d*\\?")) { + conversation.resetOtrSession(); + } if (!conversation.hasValidOtrSession()) { if (properlyAddressed) { - conversation.startOtrSession( - mXmppConnectionService.getApplicationContext(), - presence, false); + conversation.startOtrSession(mXmppConnectionService, presence, + false); } else { return null; } @@ -84,8 +86,7 @@ public class MessageParser extends AbstractParser implements if (!foreignPresence.equals(presence)) { conversation.endOtrIfNeeded(); if (properlyAddressed) { - conversation.startOtrSession( - mXmppConnectionService.getApplicationContext(), + conversation.startOtrSession(mXmppConnectionService, presence, false); } else { return null; @@ -124,7 +125,7 @@ public class MessageParser extends AbstractParser implements if (receivedId != null) { mXmppConnectionService.replyWithNotAcceptable(account, packet); } - conversation.endOtrIfNeeded(); + conversation.resetOtrSession(); return null; } } @@ -173,7 +174,8 @@ public class MessageParser extends AbstractParser implements finishedMessage.setTrueCounterpart(conversation.getMucOptions() .getTrueCounterpart(counterPart)); } - if (packet.hasChild("delay") && conversation.hasDuplicateMessage(finishedMessage)) { + if (packet.hasChild("delay") + && conversation.hasDuplicateMessage(finishedMessage)) { return null; } finishedMessage.setTime(getTimestamp(packet)); @@ -198,7 +200,8 @@ public class MessageParser extends AbstractParser implements } Element message = forwarded.findChild("message"); if ((message == null) || (!message.hasChild("body"))) { - if (status == Message.STATUS_RECEIVED && message.getAttribute("from")!=null) { + if (status == Message.STATUS_RECEIVED + && message.getAttribute("from") != null) { parseNormal(message, account); } return null; @@ -220,7 +223,7 @@ public class MessageParser extends AbstractParser implements Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, parts[0], false); conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); - + String pgpBody = getPgpBody(message); Message finishedMessage; if (pgpBody != null) { @@ -243,7 +246,7 @@ public class MessageParser extends AbstractParser implements return null; } } - + return finishedMessage; } @@ -282,6 +285,11 @@ public class MessageParser extends AbstractParser implements .findOrCreateConversation(account, packet.getAttribute("from"), true); if (!conversation.getMucOptions().online()) { + if (x.hasChild("password")) { + Element password = x.findChild("password"); + conversation.getMucOptions().setPassword( + password.getContent()); + } mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.updateConversationUi(); } @@ -290,10 +298,14 @@ public class MessageParser extends AbstractParser implements } else if (packet.hasChild("x", "jabber:x:conference")) { Element x = packet.findChild("x", "jabber:x:conference"); String jid = x.getAttribute("jid"); + String password = x.getAttribute("password"); if (jid != null) { Conversation conversation = mXmppConnectionService .findOrCreateConversation(account, jid, true); if (!conversation.getMucOptions().online()) { + if (password != null) { + conversation.getMucOptions().setPassword(password); + } mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.updateConversationUi(); } @@ -307,28 +319,38 @@ public class MessageParser extends AbstractParser implements if (node != null) { if (node.equals("urn:xmpp:avatar:metadata")) { Avatar avatar = Avatar.parseMetadata(items); - if (avatar!=null) { + if (avatar != null) { avatar.owner = from; if (mXmppConnectionService.getFileBackend().isAvatarCached( avatar)) { if (account.getJid().equals(from)) { if (account.setAvatar(avatar.getFilename())) { - mXmppConnectionService.databaseBackend.updateAccount(account); + mXmppConnectionService.databaseBackend + .updateAccount(account); } } else { - Contact contact = account.getRoster().getContact(from); + Contact contact = account.getRoster().getContact( + from); contact.setAvatar(avatar.getFilename()); } } else { mXmppConnectionService.fetchAvatar(account, avatar); } } - } else { - Log.d("xmppService", account.getJid() + ": " + node + " from " - + from); + } else if (node.equals("http://jabber.org/protocol/nick")) { + Element item = items.findChild("item"); + if (item != null) { + Element nick = item.findChild("nick", + "http://jabber.org/protocol/nick"); + if (nick != null) { + if (from != null) { + Contact contact = account.getRoster().getContact( + from); + contact.setPresenceName(nick.getContent()); + } + } + } } - } else { - Log.d("xmppService", event.toString()); } } @@ -355,9 +377,11 @@ public class MessageParser extends AbstractParser implements boolean notify = true; if (mXmppConnectionService.getPreferences().getBoolean( "notification_grace_period_after_carbon_received", true)) { - notify = (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > XmppConnectionService.CARBON_GRACE_PERIOD; + notify = (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > (Config.CARBON_GRACE_PERIOD * 1000); } + this.parseNick(packet, account); + if ((packet.getType() == MessagePacket.TYPE_CHAT)) { if ((packet.getBody() != null) && (packet.getBody().startsWith("?OTR"))) { @@ -428,8 +452,12 @@ public class MessageParser extends AbstractParser implements Conversation conversation = message.getConversation(); conversation.getMessages().add(message); if (packet.getType() != MessagePacket.TYPE_ERROR) { - mXmppConnectionService.databaseBackend.createMessage(message); + if (message.getEncryption() == Message.ENCRYPTION_NONE + || mXmppConnectionService.saveEncryptedMessages()) { + mXmppConnectionService.databaseBackend.createMessage(message); + } } + notify = notify && !conversation.isMuted(); mXmppConnectionService.notifyUi(conversation, notify); } @@ -440,4 +468,16 @@ public class MessageParser extends AbstractParser implements parseEvent(event, packet.getFrom(), account); } } + + private void parseNick(MessagePacket packet, Account account) { + Element nick = packet.findChild("nick", + "http://jabber.org/protocol/nick"); + if (nick != null) { + if (packet.getFrom() != null) { + Contact contact = account.getRoster().getContact( + packet.getFrom()); + contact.setPresenceName(nick.getContent()); + } + } + } } |