extract stanza-id from muc reflections

This commit is contained in:
Daniel Gultsch 2017-03-06 13:30:13 +01:00
parent 4a7dbaab1e
commit 5a00b11594
2 changed files with 24 additions and 17 deletions

View file

@ -212,6 +212,20 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
return null;
}
private static String extractStanzaid(Element packet, boolean isTypeGroupChat, Conversation conversation) {
final Jid by;
final boolean safeToExtract;
if (isTypeGroupChat) {
by = conversation.getJid().toBareJid();
safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS);
} else {
Account account = conversation.getAccount();
by = account.getJid().toBareJid();
safeToExtract = account.getXmppConnection().getFeatures().stanzaIds();
}
return safeToExtract ? extractStanzaId(packet, by) : null;
}
private static String extractStanzaId(Element packet, Jid by) {
for(Element child : packet.getChildren()) {
if (child.getName().equals("stanza-id")
@ -385,11 +399,16 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query);
final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI;
if (serverMsgId == null) {
extractStanzaid(packet, isTypeGroupChat, conversation);
}
if (isTypeGroupChat) {
if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
status = Message.STATUS_SEND_RECEIVED;
isCarbon = true; //not really carbon but received from another resource
if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) {
if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status, serverMsgId)) {
return;
} else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) {
Message message = conversation.findSentMessageWithBody(packet.getBody());
@ -438,21 +457,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
}
if (serverMsgId == null) {
final Jid by;
final boolean safeToExtract;
if (isTypeGroupChat) {
by = conversation.getJid().toBareJid();
safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS);
} else {
by = account.getJid().toBareJid();
safeToExtract = account.getXmppConnection().getFeatures().stanzaIds();
}
if (safeToExtract) {
serverMsgId = extractStanzaId(packet, by);
}
}
message.setCounterpart(counterpart);
message.setRemoteMsgId(remoteMsgId);
message.setServerMsgId(serverMsgId);

View file

@ -3180,12 +3180,15 @@ public class XmppConnectionService extends Service {
return null;
}
public boolean markMessage(Conversation conversation, String uuid, int status) {
public boolean markMessage(Conversation conversation, String uuid, int status, String serverMessageId) {
if (uuid == null) {
return false;
} else {
Message message = conversation.findSentMessageWithUuid(uuid);
if (message != null) {
if (message.getServerMsgId() == null) {
message.setServerMsgId(serverMessageId);
}
markMessage(message, status);
return true;
} else {