From 063f30ded2f8222264959fd895edba45916fe407 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 17 Oct 2023 07:22:22 +0200 Subject: [PATCH] ignore outgoing invite outgoing, mediated invites are of type=normal and can end up in MAM. We want to ignore those if they get mirrored back to us --- .../generator/MessageGenerator.java | 4 ++-- .../conversations/parser/MessageParser.java | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 4b055e158..4e99ab086 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -194,8 +194,8 @@ public class MessageGenerator extends AbstractGenerator { return packet; } - public MessagePacket invite(Conversation conversation, Jid contact) { - MessagePacket packet = new MessagePacket(); + public MessagePacket invite(final Conversation conversation, final Jid contact) { + final MessagePacket packet = new MessagePacket(); packet.setTo(conversation.getJid().asBareJid()); packet.setFrom(conversation.getAccount().getJid()); Element x = new Element("x"); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 2d1cbcf32..97910f3bb 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -170,14 +170,19 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return null; } - private Invite extractInvite(Element message) { + private Invite extractInvite(final Element message) { final Element mucUser = message.findChild("x", Namespace.MUC_USER); if (mucUser != null) { - Element invite = mucUser.findChild("invite"); + final Element invite = mucUser.findChild("invite"); if (invite != null) { - String password = mucUser.findChildContent("password"); - Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from")); - Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); + final String password = mucUser.findChildContent("password"); + final Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from")); + final Jid to = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("to")); + if (to != null && from == null) { + Log.d(Config.LOGTAG,"do not parse outgoing mediated invite "+message); + return null; + } + final Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from")); if (room == null) { return null; } @@ -454,8 +459,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece 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"); + if (invite.jid.asBareJid().equals(account.getJid().asBareJid())) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ignore invite to "+invite.jid+" because it matches account"); + } else if (isTypeGroupChat) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring invite to " + invite.jid + " because it was received as group chat"); } 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 {