use stanza-id for display markers in group chats

This commit is contained in:
Daniel Gultsch 2020-04-28 08:25:21 +02:00
parent 27bf871472
commit 8183c54ba0
4 changed files with 1056 additions and 1029 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.http.P1S3UrlStreamHandler; import eu.siacs.conversations.http.P1S3UrlStreamHandler;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -160,15 +161,23 @@ public class MessageGenerator extends AbstractGenerator {
return packet; return packet;
} }
public MessagePacket confirm(final Account account, final Jid to, final String id, final Jid counterpart, final boolean groupChat) { public MessagePacket confirm(final Message message) {
MessagePacket packet = new MessagePacket(); final boolean groupChat = message.getConversation().getMode() == Conversational.MODE_MULTI;
final Jid to = message.getCounterpart();
final MessagePacket packet = new MessagePacket();
packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT); packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
packet.setTo(groupChat ? to.asBareJid() : to); packet.setTo(groupChat ? to.asBareJid() : to);
packet.setFrom(account.getJid()); final Element displayed = packet.addChild("displayed", "urn:xmpp:chat-markers:0");
Element displayed = packet.addChild("displayed", "urn:xmpp:chat-markers:0"); if (groupChat) {
displayed.setAttribute("id", id); final String stanzaId = message.getServerMsgId();
if (groupChat && counterpart != null) { if (stanzaId != null) {
displayed.setAttribute("sender", counterpart.toString()); displayed.setAttribute("id", stanzaId);
} else {
displayed.setAttribute("sender", to.toString());
displayed.setAttribute("id", message.getRemoteMsgId());
}
} else {
displayed.setAttribute("id", message.getRemoteMsgId());
} }
packet.addChild("store", "urn:xmpp:hints"); packet.addChild("store", "urn:xmpp:hints");
return packet; return packet;

View File

@ -927,22 +927,29 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
activateGracePeriod(account); activateGracePeriod(account);
} }
} else if (isTypeGroupChat) { } else if (isTypeGroupChat) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid()); final Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid());
if (conversation != null && id != null && sender != null) { final Message message;
Message message = conversation.findMessageWithRemoteId(id, sender); if (conversation != null && id != null) {
if (message != null) { if (sender != null) {
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); message = conversation.findMessageWithRemoteId(id, sender);
final Jid trueJid = getTrueCounterpart((query != null && query.safeToExtractTrueCounterpart()) ? mucUserElement : null, fallback); } else {
final boolean trueJidMatchesAccount = account.getJid().asBareJid().equals(trueJid == null ? null : trueJid.asBareJid()); message = conversation.findMessageWithServerMsgId(id);
if (trueJidMatchesAccount || conversation.getMucOptions().isSelf(counterpart)) { }
if (!message.isRead() && (query == null || query.isCatchup())) { //checking if message is unread fixes race conditions with reflections } else {
mXmppConnectionService.markRead(conversation); message = null;
} }
} else if (!counterpart.isBareJid() && trueJid != null) { if (message != null) {
final ReadByMarker readByMarker = ReadByMarker.from(counterpart, trueJid); final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
if (message.addReadByMarker(readByMarker)) { final Jid trueJid = getTrueCounterpart((query != null && query.safeToExtractTrueCounterpart()) ? mucUserElement : null, fallback);
mXmppConnectionService.updateMessage(message, false); final boolean trueJidMatchesAccount = account.getJid().asBareJid().equals(trueJid == null ? null : trueJid.asBareJid());
} if (trueJidMatchesAccount || conversation.getMucOptions().isSelf(counterpart)) {
if (!message.isRead() && (query == null || query.isCatchup())) { //checking if message is unread fixes race conditions with reflections
mXmppConnectionService.markRead(conversation);
}
} else if (!counterpart.isBareJid() && trueJid != null) {
final ReadByMarker readByMarker = ReadByMarker.from(counterpart, trueJid);
if (message.addReadByMarker(readByMarker)) {
mXmppConnectionService.updateMessage(message, false);
} }
} }
} }

View File

@ -4062,6 +4062,7 @@ public class XmppConnectionService extends Service {
} }
}; };
mDatabaseWriterExecutor.execute(runnable); mDatabaseWriterExecutor.execute(runnable);
updateConversationUi();
updateUnreadCountBadge(); updateUnreadCountBadge();
return readMessages; return readMessages;
} else { } else {
@ -4094,11 +4095,9 @@ public class XmppConnectionService extends Service {
&& (markable.trusted() || isPrivateAndNonAnonymousMuc) && (markable.trusted() || isPrivateAndNonAnonymousMuc)
&& markable.getRemoteMsgId() != null) { && markable.getRemoteMsgId() != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
Account account = conversation.getAccount(); final Account account = conversation.getAccount();
final Jid to = markable.getCounterpart(); final MessagePacket packet = mMessageGenerator.confirm(markable);
final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI; this.sendMessagePacket(account, packet);
MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId(), markable.getCounterpart(), groupChat);
this.sendMessagePacket(conversation.getAccount(), packet);
} }
} }