MessageParser: dismiss notification when receiving read marker from another client

This commit is contained in:
Daniel Gultsch 2017-11-21 13:26:23 +01:00
parent 05b6fdb9f1
commit 702d6cf2a5

View file

@ -712,15 +712,20 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (conversation != null && id != null) { if (conversation != null && id != null) {
Message message = conversation.findMessageWithRemoteId(id); Message message = conversation.findMessageWithRemoteId(id);
if (message != null) { if (message != null) {
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); if (conversation.getMucOptions().isSelf(counterpart)) {
Jid trueJid = getTrueCounterpart(query != null ? mucUserElement : null, fallback); if (!message.isRead() && (query == null || query.isCatchup())) { //checking if message is unread fixes race conditions with reflections
ReadByMarker readByMarker = ReadByMarker.from(counterpart,trueJid); mXmppConnectionService.markRead(conversation);
if (!conversation.getMucOptions().isSelf(counterpart) && message.addReadByMarker(readByMarker)) { }
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": added read by ("+readByMarker.getRealJid()+") to message '"+message.getBody()+"'"); } else {
mXmppConnectionService.updateMessage(message); final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
Jid trueJid = getTrueCounterpart(query != null ? mucUserElement : null, fallback);
ReadByMarker readByMarker = ReadByMarker.from(counterpart, trueJid);
if (message.addReadByMarker(readByMarker)) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": added read by (" + readByMarker.getRealJid() + ") to message '" + message.getBody() + "'");
mXmppConnectionService.updateMessage(message);
}
} }
} }
} }
} else { } else {
final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED); final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED);