parse stanza-id from messages

This commit is contained in:
Daniel Gultsch 2015-12-04 22:03:46 +01:00
parent cd9a29718b
commit 41dcd8005b
2 changed files with 23 additions and 3 deletions

View file

@ -163,6 +163,17 @@ public class MessageParser extends AbstractParser implements
return null; return null;
} }
private static String extractStanzaId(Element packet, Jid by) {
for(Element child : packet.getChildren()) {
if (child.getName().equals("stanza-id")
&& "urn:xmpp:sid:0".equals(child.getNamespace())
&& by.equals(child.getAttributeAsJid("by"))) {
return child.getAttribute("id");
}
}
return null;
}
private void parseEvent(final Element event, final Jid from, final Account account) { private void parseEvent(final Element event, final Jid from, final Account account) {
Element items = event.findChild("items"); Element items = event.findChild("items");
String node = items == null ? null : items.getAttribute("node"); String node = items == null ? null : items.getAttribute("node");
@ -355,6 +366,11 @@ public class MessageParser extends AbstractParser implements
} else { } else {
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
} }
if (serverMsgId == null) {
serverMsgId = extractStanzaId(packet, isTypeGroupChat ? conversation.getJid().toBareJid() : account.getServer());
}
message.setCounterpart(counterpart); message.setCounterpart(counterpart);
message.setRemoteMsgId(remoteMsgId); message.setRemoteMsgId(remoteMsgId);
message.setServerMsgId(serverMsgId); message.setServerMsgId(serverMsgId);
@ -379,11 +395,11 @@ public class MessageParser extends AbstractParser implements
Log.d(Config.LOGTAG,"skipping duplicate message from "+message.getCounterpart().toString()+" "+message.getBody()); Log.d(Config.LOGTAG,"skipping duplicate message from "+message.getCounterpart().toString()+" "+message.getBody());
return; return;
} }
conversation.add(message);
if (query != null) { if (query != null) {
query.incrementMessageCount(); query.incrementMessageCount();
} } else {
conversation.add(message);
if (serverMsgId == null) {
if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) { if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) {
mXmppConnectionService.markRead(conversation); mXmppConnectionService.markRead(conversation);
account.activateGracePeriod(); account.activateGracePeriod();

View file

@ -182,4 +182,8 @@ public class Element {
String attr = getAttribute(name); String attr = getAttribute(name);
return (attr != null && (attr.equalsIgnoreCase("true") || attr.equalsIgnoreCase("1"))); return (attr != null && (attr.equalsIgnoreCase("true") || attr.equalsIgnoreCase("1")));
} }
public String getNamespace() {
return getAttribute("xmlns");
}
} }