use stanza-id for display markers in group chats
This commit is contained in:
parent
27bf871472
commit
8183c54ba0
File diff suppressed because it is too large
Load diff
|
@ -12,6 +12,7 @@ import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
|||
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.http.P1S3UrlStreamHandler;
|
||||
import eu.siacs.conversations.services.XmppConnectionService;
|
||||
|
@ -160,15 +161,23 @@ public class MessageGenerator extends AbstractGenerator {
|
|||
return packet;
|
||||
}
|
||||
|
||||
public MessagePacket confirm(final Account account, final Jid to, final String id, final Jid counterpart, final boolean groupChat) {
|
||||
MessagePacket packet = new MessagePacket();
|
||||
public MessagePacket confirm(final Message message) {
|
||||
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.setTo(groupChat ? to.asBareJid() : to);
|
||||
packet.setFrom(account.getJid());
|
||||
Element displayed = packet.addChild("displayed", "urn:xmpp:chat-markers:0");
|
||||
displayed.setAttribute("id", id);
|
||||
if (groupChat && counterpart != null) {
|
||||
displayed.setAttribute("sender", counterpart.toString());
|
||||
final Element displayed = packet.addChild("displayed", "urn:xmpp:chat-markers:0");
|
||||
if (groupChat) {
|
||||
final String stanzaId = message.getServerMsgId();
|
||||
if (stanzaId != null) {
|
||||
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");
|
||||
return packet;
|
||||
|
|
|
@ -927,22 +927,29 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
activateGracePeriod(account);
|
||||
}
|
||||
} else if (isTypeGroupChat) {
|
||||
Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid());
|
||||
if (conversation != null && id != null && sender != null) {
|
||||
Message message = conversation.findMessageWithRemoteId(id, sender);
|
||||
if (message != null) {
|
||||
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
|
||||
final Jid trueJid = getTrueCounterpart((query != null && query.safeToExtractTrueCounterpart()) ? mucUserElement : null, fallback);
|
||||
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);
|
||||
}
|
||||
final Conversation conversation = mXmppConnectionService.find(account, counterpart.asBareJid());
|
||||
final Message message;
|
||||
if (conversation != null && id != null) {
|
||||
if (sender != null) {
|
||||
message = conversation.findMessageWithRemoteId(id, sender);
|
||||
} else {
|
||||
message = conversation.findMessageWithServerMsgId(id);
|
||||
}
|
||||
} else {
|
||||
message = null;
|
||||
}
|
||||
if (message != null) {
|
||||
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
|
||||
final Jid trueJid = getTrueCounterpart((query != null && query.safeToExtractTrueCounterpart()) ? mucUserElement : null, fallback);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4062,6 +4062,7 @@ public class XmppConnectionService extends Service {
|
|||
}
|
||||
};
|
||||
mDatabaseWriterExecutor.execute(runnable);
|
||||
updateConversationUi();
|
||||
updateUnreadCountBadge();
|
||||
return readMessages;
|
||||
} else {
|
||||
|
@ -4094,11 +4095,9 @@ public class XmppConnectionService extends Service {
|
|||
&& (markable.trusted() || isPrivateAndNonAnonymousMuc)
|
||||
&& markable.getRemoteMsgId() != null) {
|
||||
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
|
||||
Account account = conversation.getAccount();
|
||||
final Jid to = markable.getCounterpart();
|
||||
final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI;
|
||||
MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId(), markable.getCounterpart(), groupChat);
|
||||
this.sendMessagePacket(conversation.getAccount(), packet);
|
||||
final Account account = conversation.getAccount();
|
||||
final MessagePacket packet = mMessageGenerator.confirm(markable);
|
||||
this.sendMessagePacket(account, packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue