diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-09-23 19:43:20 +0200 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-09-23 19:43:20 +0200 |
commit | b0347ba9295364761e0348289ded0a71e394cae9 (patch) | |
tree | b4a150380ee885813680a3b38a4e2762fc5eb130 /src/main/java | |
parent | 5bf81ac737a929acf85f8593fd5f92ec7fbc51ce (diff) |
do not parse invites from type=groupchat
Diffstat (limited to 'src/main/java')
3 files changed, 34 insertions, 26 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index a8d568d71..ed587b851 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -246,31 +246,28 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return null; } - private Invite extractInvite(Account account, Element message) { - Element x = message.findChild("x", "http://jabber.org/protocol/muc#user"); - if (x != null) { - Element invite = x.findChild("invite"); + private Invite extractInvite(Element message) { + final Element mucUser = message.findChild("x", Namespace.MUC_USER); + if (mucUser != null) { + Element invite = mucUser.findChild("invite"); if (invite != null) { - String password = x.findChildContent("password"); + String password = mucUser.findChildContent("password"); Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from")); - Contact contact = from == null ? null : account.getRoster().getContact(from); Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); if (room == null) { return null; } - return new Invite(room, password, contact); + return new Invite(room, password, false, from); } - } else { - x = message.findChild("x", "jabber:x:conference"); - if (x != null) { - Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); - Contact contact = from == null ? null : account.getRoster().getContact(from); - Jid room = InvalidJid.getNullForInvalid(x.getAttributeAsJid("jid")); - if (room == null) { - return null; - } - return new Invite(room, x.getAttribute("password"), contact); + } + final Element conference = message.findChild("x", "jabber:x:conference"); + if (conference != null) { + Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); + Jid room = InvalidJid.getNullForInvalid(conference.getAttributeAsJid("jid")); + if (room == null) { + return null; } + return new Invite(room, conference.getAttribute("password"), true, from); } return null; } @@ -437,7 +434,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece timestamp = AbstractParser.parseTimestamp(original, AbstractParser.parseTimestamp(packet)); } final LocalizedContent body = packet.getBody(); - final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user"); + final Element mucUserElement = packet.findChild("x", Namespace.MUC_USER); final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted"); final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0"); final Element oob = packet.findChild("x", Namespace.OOB); @@ -486,9 +483,16 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece selfAddressed = false; } - Invite invite = extractInvite(account, packet); - if (invite != null && invite.execute(account)) { - return; + final Invite invite = extractInvite(packet); + if (invite != null) { + if (isTypeGroupChat) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring invite to " + invite.jid + " because type=groupchat"); + } else if (invite.direct && (mucUserElement != null || invite.inviter == null || mXmppConnectionService.isMuc(account, invite.inviter))) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring direct invite to " + invite.jid + " because it was received in MUC"); + } else { + invite.execute(account); + return; + } } if ((body != null || pgpEncrypted != null || (axolotlEncrypted != null && axolotlEncrypted.hasChild("payload")) || oobUrl != null || xP1S3 != null) && !isMucStatusMessage) { @@ -1016,11 +1020,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece private class Invite { final Jid jid; final String password; - final Contact inviter; + final boolean direct; + final Jid inviter; - Invite(Jid jid, String password, Contact inviter) { + Invite(Jid jid, String password, boolean direct, Jid inviter) { this.jid = jid; this.password = password; + this.direct = direct; this.inviter = inviter; } @@ -1033,7 +1039,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else { conversation.getMucOptions().setPassword(password); mXmppConnectionService.databaseBackend.updateConversation(conversation); - mXmppConnectionService.joinMuc(conversation, inviter != null && inviter.mutualPresenceSubscription()); + final Contact contact = inviter != null ? account.getRoster().getContactFromContactList(inviter) : null; + mXmppConnectionService.joinMuc(conversation, contact != null && contact.mutualPresenceSubscription()); mXmppConnectionService.updateConversationUi(); } return true; diff --git a/src/main/java/de/pixart/messenger/parser/PresenceParser.java b/src/main/java/de/pixart/messenger/parser/PresenceParser.java index 0c90dd4ac..a2f97149b 100644 --- a/src/main/java/de/pixart/messenger/parser/PresenceParser.java +++ b/src/main/java/de/pixart/messenger/parser/PresenceParser.java @@ -59,7 +59,7 @@ public class PresenceParser extends AbstractParser implements final Jid from = packet.getFrom(); if (!from.isBareJid()) { final String type = packet.getAttribute("type"); - final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user"); + final Element x = packet.findChild("x", Namespace.MUC_USER); Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); final List<String> codes = getStatusCodes(x); if (type == null) { @@ -361,7 +361,7 @@ public class PresenceParser extends AbstractParser implements @Override public void onPresencePacketReceived(Account account, PresencePacket packet) { - if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { + if (packet.hasChild("x", Namespace.MUC_USER)) { this.parseConferencePresence(packet, account); } else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) { this.parseConferencePresence(packet, account); diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java index d8bd1728e..a7bf70f54 100644 --- a/src/main/java/de/pixart/messenger/utils/Namespace.java +++ b/src/main/java/de/pixart/messenger/utils/Namespace.java @@ -32,4 +32,5 @@ public final class Namespace { public static final String COMMANDS = "http://jabber.org/protocol/commands"; public static final String JINGLE_ENCRYPTED_TRANSPORT = "urn:xmpp:jingle:jet:0"; public static final String JINGLE_ENCRYPTED_TRANSPORT_OMEMO = "urn:xmpp:jingle:jet-omemo:0"; + public static final String MUC_USER = "http://jabber.org/protocol/muc#user"; } |