aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-05-11 19:10:36 +0200
committerfiaxh <git@lightrise.org>2019-05-11 20:01:20 +0200
commit9d19cdbf4ec5109f078193daf6ab55df6f69ec93 (patch)
tree5041b1ee8882d91412ff37b0b1c23e6693335974 /libdino/src/service
parentf4778ef3e66bda41831251c486e497075cb82d66 (diff)
downloaddino-9d19cdbf4ec5109f078193daf6ab55df6f69ec93.tar.gz
dino-9d19cdbf4ec5109f078193daf6ab55df6f69ec93.zip
Process read marker from other devices for MUCs to adjust read-up-to state
Diffstat (limited to 'libdino/src/service')
-rw-r--r--libdino/src/service/counterpart_interaction_manager.vala14
1 files changed, 14 insertions, 0 deletions
diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala
index b4df9b8d..68589003 100644
--- a/libdino/src/service/counterpart_interaction_manager.vala
+++ b/libdino/src/service/counterpart_interaction_manager.vala
@@ -64,8 +64,18 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
}
private void on_chat_marker_received(Account account, Jid jid, string marker, string stanza_id) {
+
+ // Check if the marker comes from ourselves (own jid or our jid in a MUC)
bool own_marker = account.bare_jid.to_string() == jid.bare_jid.to_string();
+ if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
+ Jid? own_muc_jid = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(jid.bare_jid, account);
+ if (own_muc_jid != null && own_muc_jid.equals(jid)) {
+ own_marker = true;
+ }
+ }
+
if (own_marker) {
+ // If we received a display marker from ourselves (other device), set the conversation read up to that message.
if (marker != Xep.ChatMarkers.MARKER_DISPLAYED && marker != Xep.ChatMarkers.MARKER_ACKNOWLEDGED) return;
Conversation? conversation = stream_interactor.get_module(MessageStorage.IDENTITY).get_conversation_for_stanza_id(account, stanza_id);
if (conversation == null) return;
@@ -73,15 +83,18 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
if (message == null) return;
conversation.read_up_to = message;
} else {
+ // We received a marker from someone else. Search the respective message and mark it.
foreach (Conversation conversation in stream_interactor.get_module(ConversationManager.IDENTITY).get_conversations(jid, account)) {
Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation);
if (message != null) {
switch (marker) {
case Xep.ChatMarkers.MARKER_RECEIVED:
+ // If we got a received marker, mark the respective message received.
received_message_received(account, jid, message);
message.marked = Entities.Message.Marked.RECEIVED;
break;
case Xep.ChatMarkers.MARKER_DISPLAYED:
+ // If we got a display marker, set all messages up to that message as read (if we know they've been received).
received_message_displayed(account, jid, message);
Gee.List<Entities.Message> messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation);
foreach (Entities.Message m in messages) {
@@ -92,6 +105,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
break;
}
} else {
+ // We might get a marker before the actual message (on catchup). Save the marker.
if (marker_wo_message.has_key(stanza_id) &&
marker_wo_message[stanza_id] == Xep.ChatMarkers.MARKER_DISPLAYED && marker == Xep.ChatMarkers.MARKER_RECEIVED) {
return;