added mam stuff to new message parser

This commit is contained in:
Daniel Gultsch 2015-05-15 06:31:27 +02:00
parent d261feda74
commit b731995a51
3 changed files with 28 additions and 9 deletions

View file

@ -328,7 +328,7 @@ public class Message extends AbstractEntity {
return this.remoteMsgId == null return this.remoteMsgId == null
&& this.counterpart.equals(message.getCounterpart()) && this.counterpart.equals(message.getCounterpart())
&& this.body.equals(message.getBody()) && this.body.equals(message.getBody())
&& Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.PING_TIMEOUT * 500; && Math.abs(this.getTimeSent() - message.getTimeSent()) < Config.MESSAGE_MERGE_WINDOW * 1000;
} }
} }

View file

@ -22,7 +22,7 @@ public abstract class AbstractParser {
} }
public static Long getTimestamp(Element element, Long defaultValue) { public static Long getTimestamp(Element element, Long defaultValue) {
Element delay = element.findChild("delay"); Element delay = element.findChild("delay","urn:xmpp:delay");
if (delay != null) { if (delay != null) {
String stamp = delay.getAttribute("stamp"); String stamp = delay.getAttribute("stamp");
if (stamp != null) { if (stamp != null) {

View file

@ -182,6 +182,8 @@ public class MessageParser extends AbstractParser implements
Long timestamp = null; Long timestamp = null;
final boolean isForwarded; final boolean isForwarded;
boolean carbon = false; //live carbons or mam-sub boolean carbon = false; //live carbons or mam-sub
MessageArchiveService.Query query = null;
String serverMsgId = null;
if (original.fromServer(account)) { if (original.fromServer(account)) {
Pair<MessagePacket, Long> f; Pair<MessagePacket, Long> f;
f = original.getForwardedMessagePacket("received", "urn:xmpp:carbons:2"); f = original.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
@ -198,6 +200,14 @@ public class MessageParser extends AbstractParser implements
return; return;
} }
final Element result = packet.findChild("result","urn:xmpp:mam:0");
if (result != null) {
query = mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid"));
if (query != null) {
query.incrementTotalCount();
}
serverMsgId = result.getAttribute("id");
}
} else { } else {
packet = original; packet = original;
isForwarded = false; isForwarded = false;
@ -211,7 +221,7 @@ public class MessageParser extends AbstractParser implements
final Jid to = packet.getTo(); final Jid to = packet.getTo();
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
final Jid counterpart; final Jid counterpart;
final String id = packet.getId(); final String remoteMsgId = packet.getId();
boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT; boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT;
boolean properlyAddressed = !to.isBareJid() || account.countPresences() == 1; boolean properlyAddressed = !to.isBareJid() || account.countPresences() == 1;
if (packet.fromAccount(account)) { if (packet.fromAccount(account)) {
@ -229,7 +239,7 @@ public class MessageParser extends AbstractParser implements
Invite invite = extractInvite(packet); Invite invite = extractInvite(packet);
if (invite != null && invite.jid != null) { if (invite != null && invite.jid != null) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, invite.jid, true); Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, invite.jid, true,query);
if (!conversation.getMucOptions().online()) { if (!conversation.getMucOptions().online()) {
conversation.getMucOptions().setPassword(invite.password); conversation.getMucOptions().setPassword(invite.password);
mXmppConnectionService.databaseBackend.updateConversation(conversation); mXmppConnectionService.databaseBackend.updateConversation(conversation);
@ -248,9 +258,9 @@ public class MessageParser extends AbstractParser implements
if (isTypeGroupChat) { if (isTypeGroupChat) {
if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) { if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
status = Message.STATUS_SEND; status = Message.STATUS_SEND;
if (mXmppConnectionService.markMessage(conversation, id, Message.STATUS_SEND_RECEIVED)) { if (mXmppConnectionService.markMessage(conversation, remoteMsgId, Message.STATUS_SEND_RECEIVED)) {
return; return;
} else if (id == null) { } else if (remoteMsgId == null) {
Message message = conversation.findSentMessageWithBody(packet.getBody()); Message message = conversation.findSentMessageWithBody(packet.getBody());
if (message != null) { if (message != null) {
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_RECEIVED); mXmppConnectionService.markMessage(message, Message.STATUS_SEND_RECEIVED);
@ -264,7 +274,7 @@ public class MessageParser extends AbstractParser implements
Message message; Message message;
if (body != null && body.startsWith("?OTR")) { if (body != null && body.startsWith("?OTR")) {
if (!isForwarded && !isTypeGroupChat && properlyAddressed) { if (!isForwarded && !isTypeGroupChat && properlyAddressed) {
message = parseOtrChat(body, from, id, conversation); message = parseOtrChat(body, from, remoteMsgId, conversation);
if (message == null) { if (message == null) {
return; return;
} }
@ -277,7 +287,8 @@ public class MessageParser extends AbstractParser implements
message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
} }
message.setCounterpart(counterpart); message.setCounterpart(counterpart);
message.setRemoteMsgId(id); message.setRemoteMsgId(remoteMsgId);
message.setServerMsgId(serverMsgId);
message.setTime(timestamp); message.setTime(timestamp);
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
@ -287,6 +298,14 @@ public class MessageParser extends AbstractParser implements
} }
} }
updateLastseen(packet,account,true); updateLastseen(packet,account,true);
boolean checkForDuplicates = serverMsgId != null || (isTypeGroupChat && packet.hasChild("delay","urn:xmpp:delay"));
if (checkForDuplicates && conversation.hasDuplicateMessage(message)) {
Log.d(Config.LOGTAG,"skipping duplicate message from "+message.getCounterpart().toString()+" "+message.getBody());
return;
}
if (query != null) {
query.incrementMessageCount();
}
conversation.add(message); conversation.add(message);
if (carbon || status == Message.STATUS_RECEIVED) { if (carbon || status == Message.STATUS_RECEIVED) {
mXmppConnectionService.markRead(conversation); mXmppConnectionService.markRead(conversation);
@ -296,7 +315,7 @@ public class MessageParser extends AbstractParser implements
} }
if (mXmppConnectionService.confirmMessages() && id != null && !packet.fromAccount(account)) { if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded) {
if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) { if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
MessagePacket receipt = mXmppConnectionService MessagePacket receipt = mXmppConnectionService
.getMessageGenerator().received(account, packet, "urn:xmpp:chat-markers:0"); .getMessageGenerator().received(account, packet, "urn:xmpp:chat-markers:0");