aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/chat_interaction.vala37
-rw-r--r--libdino/src/service/counterpart_interaction_manager.vala2
2 files changed, 39 insertions, 0 deletions
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala
index de352e95..b200916a 100644
--- a/libdino/src/service/chat_interaction.vala
+++ b/libdino/src/service/chat_interaction.vala
@@ -31,6 +31,43 @@ public class ChatInteraction : StreamInteractionModule, Object {
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_message_sent);
}
+ public bool has_unread(Conversation conversation) {
+ ContentItem? last_content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_latest(conversation);
+ if (last_content_item == null) return false;
+
+ MessageItem? message_item = last_content_item as MessageItem;
+ if (message_item != null) {
+ Message last_message = message_item.message;
+
+ // We are the message sender
+ if (last_message.from.equals_bare(conversation.account.bare_jid)) return false;
+ // We read up to the message
+ if (conversation.read_up_to != null && last_message.equals(conversation.read_up_to)) return false;
+
+ return true;
+ }
+
+ FileItem? file_item = last_content_item as FileItem;
+ if (file_item != null) {
+ FileTransfer file_transfer = file_item.file_transfer;
+
+ // We are the file sender
+ if (file_transfer.from.equals_bare(conversation.account.bare_jid)) return false;
+
+ if (file_transfer.provider == 0) {
+ // HTTP file transfer: Check if the associated message is the last one
+ Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(int.parse(file_transfer.info), conversation);
+ if (message == null) return false;
+ if (message.equals(conversation.read_up_to)) return false;
+ }
+ if (file_transfer.provider == 1) {
+ if (file_transfer.state == FileTransfer.State.COMPLETE) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
public bool is_active_focus(Conversation? conversation = null) {
if (conversation != null) {
return focus_in && conversation.equals(this.selected_conversation);
diff --git a/libdino/src/service/counterpart_interaction_manager.vala b/libdino/src/service/counterpart_interaction_manager.vala
index 7da65650..5ff74eb7 100644
--- a/libdino/src/service/counterpart_interaction_manager.vala
+++ b/libdino/src/service/counterpart_interaction_manager.vala
@@ -89,6 +89,8 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
if (conversation == null) return;
Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation);
if (message == null) return;
+ // Don't move read marker backwards because we get old info from another client
+ if (conversation.read_up_to.local_time.compare(message.local_time) > 0) return;
conversation.read_up_to = message;
} else {
// We received a marker from someone else. Search the respective message and mark it.