do not parse invites from type=groupchat

This commit is contained in:
Daniel Gultsch 2019-09-22 10:00:09 +02:00
parent d2ef0728a3
commit 426090c301
3 changed files with 34 additions and 26 deletions

View file

@ -153,31 +153,28 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
return null; return null;
} }
private Invite extractInvite(Account account, Element message) { private Invite extractInvite(Element message) {
Element x = message.findChild("x", "http://jabber.org/protocol/muc#user"); final Element mucUser = message.findChild("x", Namespace.MUC_USER);
if (x != null) { if (mucUser != null) {
Element invite = x.findChild("invite"); Element invite = mucUser.findChild("invite");
if (invite != null) { if (invite != null) {
String password = x.findChildContent("password"); String password = mucUser.findChildContent("password");
Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from")); Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from"));
Contact contact = from == null ? null : account.getRoster().getContact(from);
Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
if (room == null) { if (room == null) {
return null; return null;
} }
return new Invite(room, password, contact); return new Invite(room, password, false, from);
} }
} else { }
x = message.findChild("x", "jabber:x:conference"); final Element conference = message.findChild("x", "jabber:x:conference");
if (x != null) { if (conference != null) {
Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
Contact contact = from == null ? null : account.getRoster().getContact(from); Jid room = InvalidJid.getNullForInvalid(conference.getAttributeAsJid("jid"));
Jid room = InvalidJid.getNullForInvalid(x.getAttributeAsJid("jid")); if (room == null) {
if (room == null) { return null;
return null;
}
return new Invite(room, x.getAttribute("password"), contact);
} }
return new Invite(room, conference.getAttribute("password"), true, from);
} }
return null; return null;
} }
@ -335,7 +332,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
timestamp = AbstractParser.parseTimestamp(original, AbstractParser.parseTimestamp(packet)); timestamp = AbstractParser.parseTimestamp(original, AbstractParser.parseTimestamp(packet));
} }
final LocalizedContent body = packet.getBody(); 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 String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0"); final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0");
final Element oob = packet.findChild("x", Namespace.OOB); final Element oob = packet.findChild("x", Namespace.OOB);
@ -383,9 +380,16 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
selfAddressed = false; selfAddressed = false;
} }
Invite invite = extractInvite(account, packet); final Invite invite = extractInvite(packet);
if (invite != null && invite.execute(account)) { if (invite != null) {
return; 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) { if ((body != null || pgpEncrypted != null || (axolotlEncrypted != null && axolotlEncrypted.hasChild("payload")) || oobUrl != null || xP1S3 != null) && !isMucStatusMessage) {
@ -884,11 +888,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
private class Invite { private class Invite {
final Jid jid; final Jid jid;
final String password; 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.jid = jid;
this.password = password; this.password = password;
this.direct = direct;
this.inviter = inviter; this.inviter = inviter;
} }
@ -901,7 +907,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else { } else {
conversation.getMucOptions().setPassword(password); conversation.getMucOptions().setPassword(password);
mXmppConnectionService.databaseBackend.updateConversation(conversation); 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(); mXmppConnectionService.updateConversationUi();
} }
return true; return true;

View file

@ -60,7 +60,7 @@ public class PresenceParser extends AbstractParser implements
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
if (!from.isBareJid()) { if (!from.isBareJid()) {
final String type = packet.getAttribute("type"); 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")); Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
final List<String> codes = getStatusCodes(x); final List<String> codes = getStatusCodes(x);
if (type == null) { if (type == null) {
@ -364,7 +364,7 @@ public class PresenceParser extends AbstractParser implements
@Override @Override
public void onPresencePacketReceived(Account account, PresencePacket packet) { 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); this.parseConferencePresence(packet, account);
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) { } else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
this.parseConferencePresence(packet, account); this.parseConferencePresence(packet, account);

View file

@ -32,4 +32,5 @@ public final class Namespace {
public static final String COMMANDS = "http://jabber.org/protocol/commands"; 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 = "urn:xmpp:jingle:jet:0";
public static final String JINGLE_ENCRYPTED_TRANSPORT_OMEMO = "urn:xmpp:jingle:jet-omemo: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";
} }