aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-12-04 22:03:46 +0100
committerDaniel Gultsch <daniel@gultsch.de>2015-12-04 22:03:46 +0100
commit41dcd8005b07cf7a2362dc349ba281defef514dc (patch)
tree5680940e8a3dbd9ee75051138c67bb324b571100 /src/main/java/eu/siacs
parentcd9a29718bcf961cdae2bb88ad65066e7347bfb5 (diff)
parse stanza-id from messages
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java22
-rw-r--r--src/main/java/eu/siacs/conversations/xml/Element.java4
2 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 3e923af1..137cd456 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -163,6 +163,17 @@ public class MessageParser extends AbstractParser implements
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) {
Element items = event.findChild("items");
String node = items == null ? null : items.getAttribute("node");
@@ -355,6 +366,11 @@ public class MessageParser extends AbstractParser implements
} else {
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.setRemoteMsgId(remoteMsgId);
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());
return;
}
+
+ conversation.add(message);
if (query != null) {
query.incrementMessageCount();
- }
- conversation.add(message);
- if (serverMsgId == null) {
+ } else {
if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) {
mXmppConnectionService.markRead(conversation);
account.activateGracePeriod();
diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java
index e82c446b..34794be1 100644
--- a/src/main/java/eu/siacs/conversations/xml/Element.java
+++ b/src/main/java/eu/siacs/conversations/xml/Element.java
@@ -182,4 +182,8 @@ public class Element {
String attr = getAttribute(name);
return (attr != null && (attr.equalsIgnoreCase("true") || attr.equalsIgnoreCase("1")));
}
+
+ public String getNamespace() {
+ return getAttribute("xmlns");
+ }
}