Fix own message marker marking conversations as read

This commit is contained in:
fiaxh 2020-10-15 19:43:17 +02:00
parent 518307d1ac
commit 5954f7764f
2 changed files with 17 additions and 8 deletions

View file

@ -84,15 +84,20 @@ public class ConversationManager : StreamInteractionModule, Object {
return null; return null;
} }
public Conversation? approx_conversation_for_stanza(Jid jid, Account account, string msg_ty) { public Conversation? approx_conversation_for_stanza(Jid from, Jid to, Account account, string msg_ty) {
if (msg_ty == Xmpp.MessageStanza.TYPE_GROUPCHAT) { if (msg_ty == Xmpp.MessageStanza.TYPE_GROUPCHAT) {
return get_conversation(jid.bare_jid, account, Conversation.Type.GROUPCHAT); return get_conversation(from.bare_jid, account, Conversation.Type.GROUPCHAT);
} else if (msg_ty == Xmpp.MessageStanza.TYPE_CHAT && jid.is_full() && }
get_conversation(jid.bare_jid, account, Conversation.Type.GROUPCHAT) != null) {
var pm = get_conversation(jid, account, Conversation.Type.GROUPCHAT_PM); Jid counterpart = from.equals_bare(account.bare_jid) ? to : from;
if (msg_ty == Xmpp.MessageStanza.TYPE_CHAT && counterpart.is_full() &&
get_conversation(counterpart.bare_jid, account, Conversation.Type.GROUPCHAT) != null) {
var pm = get_conversation(counterpart, account, Conversation.Type.GROUPCHAT_PM);
if (pm != null) return pm; if (pm != null) return pm;
} }
return get_conversation(jid.bare_jid, account, Conversation.Type.CHAT);
return get_conversation(counterpart.bare_jid, account, Conversation.Type.CHAT);
} }
public Conversation? get_conversation_by_id(int id) { public Conversation? get_conversation_by_id(int id) {

View file

@ -95,7 +95,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
// Don't show our own (other devices) typing notification // Don't show our own (other devices) typing notification
if (jid.equals_bare(account.bare_jid)) return; if (jid.equals_bare(account.bare_jid)) return;
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(jid, account, stanza.type_); Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(stanza.from, stanza.to, account, stanza.type_);
if (conversation == null) return; if (conversation == null) return;
// Don't show our own typing notification in MUCs // Don't show our own typing notification in MUCs
@ -118,7 +118,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
} }
private async void on_chat_marker_received(Account account, Jid jid, string marker, string stanza_id, MessageStanza message_stanza) { private async void on_chat_marker_received(Account account, Jid jid, string marker, string stanza_id, MessageStanza message_stanza) {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(jid, account, message_stanza.type_); Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).approx_conversation_for_stanza(message_stanza.from, message_stanza.to, account, message_stanza.type_);
if (conversation == null) return; if (conversation == null) return;
handle_chat_marker(conversation, jid, marker, stanza_id); handle_chat_marker(conversation, jid, marker, stanza_id);
} }
@ -141,6 +141,10 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
Entities.Message? message = null; Entities.Message? message = null;
if (conversation.type_ == Conversation.Type.GROUPCHAT || conversation.type_ == Conversation.Type.GROUPCHAT_PM) { if (conversation.type_ == Conversation.Type.GROUPCHAT || conversation.type_ == Conversation.Type.GROUPCHAT_PM) {
message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_server_id(stanza_id, conversation); message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_server_id(stanza_id, conversation);
// Outdated clients might use the message id. Or in MUCs that don't send server ids.
if (message == null) {
message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation);
}
} else { } else {
message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation); message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation);
} }