From 064264c20b6a371ebdb46813fc8af62adfb9f500 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 31 Aug 2020 11:06:26 +0200 Subject: [PATCH] parse 'received' carbon-copied error messages. fixes #3803 --- .../generator/PresenceGenerator.java | 136 +++++++++--------- .../conversations/parser/MessageParser.java | 8 +- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java index d3143f01e..0701afcfe 100644 --- a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java @@ -13,81 +13,81 @@ import eu.siacs.conversations.xmpp.stanzas.PresencePacket; public class PresenceGenerator extends AbstractGenerator { - public PresenceGenerator(XmppConnectionService service) { - super(service); - } + public PresenceGenerator(XmppConnectionService service) { + super(service); + } - private PresencePacket subscription(String type, Contact contact) { - PresencePacket packet = new PresencePacket(); - packet.setAttribute("type", type); - packet.setTo(contact.getJid()); - packet.setFrom(contact.getAccount().getJid().asBareJid()); - return packet; - } + private PresencePacket subscription(String type, Contact contact) { + PresencePacket packet = new PresencePacket(); + packet.setAttribute("type", type); + packet.setTo(contact.getJid()); + packet.setFrom(contact.getAccount().getJid().asBareJid()); + return packet; + } - public PresencePacket requestPresenceUpdatesFrom(Contact contact) { - PresencePacket packet = subscription("subscribe", contact); - String displayName = contact.getAccount().getDisplayName(); - if (!TextUtils.isEmpty(displayName)) { - packet.addChild("nick",Namespace.NICK).setContent(displayName); - } - return packet; - } + public PresencePacket requestPresenceUpdatesFrom(Contact contact) { + PresencePacket packet = subscription("subscribe", contact); + String displayName = contact.getAccount().getDisplayName(); + if (!TextUtils.isEmpty(displayName)) { + packet.addChild("nick", Namespace.NICK).setContent(displayName); + } + return packet; + } - public PresencePacket stopPresenceUpdatesFrom(Contact contact) { - return subscription("unsubscribe", contact); - } + public PresencePacket stopPresenceUpdatesFrom(Contact contact) { + return subscription("unsubscribe", contact); + } - public PresencePacket stopPresenceUpdatesTo(Contact contact) { - return subscription("unsubscribed", contact); - } + public PresencePacket stopPresenceUpdatesTo(Contact contact) { + return subscription("unsubscribed", contact); + } - public PresencePacket sendPresenceUpdatesTo(Contact contact) { - return subscription("subscribed", contact); - } + public PresencePacket sendPresenceUpdatesTo(Contact contact) { + return subscription("subscribed", contact); + } - public PresencePacket selfPresence(Account account, Presence.Status status) { - return selfPresence(account, status, true); - } + public PresencePacket selfPresence(Account account, Presence.Status status) { + return selfPresence(account, status, true); + } - public PresencePacket selfPresence(final Account account, final Presence.Status status, final boolean personal) { - final PresencePacket packet = new PresencePacket(); - if (personal) { - final String sig = account.getPgpSignature(); - final String message = account.getPresenceStatusMessage(); - if(status.toShowString() != null) { - packet.addChild("show").setContent(status.toShowString()); - } - if (!TextUtils.isEmpty(message)) { - packet.addChild(new Element("status").setContent(message)); - } - if (sig != null && mXmppConnectionService.getPgpEngine() != null) { - packet.addChild("x", "jabber:x:signed").setContent(sig); - } - } - final String capHash = getCapHash(account); - if (capHash != null) { - Element cap = packet.addChild("c", - "http://jabber.org/protocol/caps"); - cap.setAttribute("hash", "sha-1"); - cap.setAttribute("node", "http://conversations.im"); - cap.setAttribute("ver", capHash); - } - return packet; - } + public PresencePacket selfPresence(final Account account, final Presence.Status status, final boolean personal) { + final PresencePacket packet = new PresencePacket(); + if (personal) { + final String sig = account.getPgpSignature(); + final String message = account.getPresenceStatusMessage(); + if (status.toShowString() != null) { + packet.addChild("show").setContent(status.toShowString()); + } + if (!TextUtils.isEmpty(message)) { + packet.addChild(new Element("status").setContent(message)); + } + if (sig != null && mXmppConnectionService.getPgpEngine() != null) { + packet.addChild("x", "jabber:x:signed").setContent(sig); + } + } + final String capHash = getCapHash(account); + if (capHash != null) { + Element cap = packet.addChild("c", + "http://jabber.org/protocol/caps"); + cap.setAttribute("hash", "sha-1"); + cap.setAttribute("node", "http://conversations.im"); + cap.setAttribute("ver", capHash); + } + return packet; + } - public PresencePacket leave(final MucOptions mucOptions) { - PresencePacket presencePacket = new PresencePacket(); - presencePacket.setTo(mucOptions.getSelf().getFullJid()); - presencePacket.setFrom(mucOptions.getAccount().getJid()); - presencePacket.setAttribute("type", "unavailable"); - return presencePacket; - } + public PresencePacket leave(final MucOptions mucOptions) { + PresencePacket presencePacket = new PresencePacket(); + presencePacket.setTo(mucOptions.getSelf().getFullJid()); + presencePacket.setFrom(mucOptions.getAccount().getJid()); + presencePacket.setAttribute("type", "unavailable"); + return presencePacket; + } - public PresencePacket sendOfflinePresence(Account account) { - PresencePacket packet = new PresencePacket(); - packet.setFrom(account.getJid()); - packet.setAttribute("type","unavailable"); - return packet; - } + public PresencePacket sendOfflinePresence(Account account) { + PresencePacket packet = new PresencePacket(); + packet.setFrom(account.getJid()); + packet.setAttribute("type", "unavailable"); + return packet; + } } diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 7a82b092d..588af4c1e 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -308,8 +308,14 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece mXmppConnectionService.updateAccountUi(); } - private boolean handleErrorMessage(Account account, MessagePacket packet) { + private boolean handleErrorMessage(final Account account, final MessagePacket packet) { if (packet.getType() == MessagePacket.TYPE_ERROR) { + if (packet.fromServer(account)) { + final Pair forwarded = packet.getForwardedMessagePacket("received", "urn:xmpp:carbons:2"); + if (forwarded != null) { + return handleErrorMessage(account, forwarded.first); + } + } final Jid from = packet.getFrom(); final String id = packet.getId(); if (from != null && id != null) {