dismiss notification only if displayed id matches last remote id

This commit is contained in:
Daniel Gultsch 2020-06-24 12:12:35 +02:00
parent fada3a63c9
commit 13d8eb1c7e
2 changed files with 30 additions and 8 deletions

View file

@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.common.collect.ComparisonChain; import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -169,6 +170,22 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return first; return first;
} }
public String findMostRecentRemoteDisplayableId() {
final boolean multi = mode == Conversation.MODE_MULTI;
synchronized (this.messages) {
for(final Message message : Lists.reverse(this.messages)) {
if (message.getStatus() == Message.STATUS_RECEIVED) {
final String serverMsgId = message.getServerMsgId();
if (serverMsgId != null && multi) {
return serverMsgId;
}
return message.getRemoteMsgId();
}
}
}
return null;
}
public Message findUnsentMessageWithUuid(String uuid) { public Message findUnsentMessageWithUuid(String uuid) {
synchronized (this.messages) { synchronized (this.messages) {
for (final Message message : this.messages) { for (final Message message : this.messages) {

View file

@ -952,7 +952,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
final String id = displayed.getAttribute("id"); final String id = displayed.getAttribute("id");
final Jid sender = InvalidJid.getNullForInvalid(displayed.getAttributeAsJid("sender")); final Jid sender = InvalidJid.getNullForInvalid(displayed.getAttributeAsJid("sender"));
if (packet.fromAccount(account) && !selfAddressed) { if (packet.fromAccount(account) && !selfAddressed) {
dismissNotification(account, counterpart, query); dismissNotification(account, counterpart, query, id);
if (query == null) { if (query == null) {
activateGracePeriod(account); activateGracePeriod(account);
} }
@ -993,7 +993,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
message = message.prev(); message = message.prev();
} }
if (displayedMessage != null && selfAddressed) { if (displayedMessage != null && selfAddressed) {
dismissNotification(account, counterpart, query); dismissNotification(account, counterpart, query, id);
} }
} }
} }
@ -1018,10 +1018,15 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} }
} }
private void dismissNotification(Account account, Jid counterpart, MessageArchiveService.Query query) { private void dismissNotification(Account account, Jid counterpart, MessageArchiveService.Query query, final String id) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid()); final Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid());
if (conversation != null && (query == null || query.isCatchup())) { if (conversation != null && (query == null || query.isCatchup())) {
mXmppConnectionService.markRead(conversation); //TODO only mark messages read that are older than timestamp final String displayableId = conversation.findMostRecentRemoteDisplayableId();
if (displayableId != null && displayableId.equals(id)) {
mXmppConnectionService.markRead(conversation);
} else {
Log.w(Config.LOGTAG, account.getJid().asBareJid() + ": received dismissing display marker that did not match our last id in that conversation");
}
} }
} }