Improve conversation unread status detection
This commit is contained in:
parent
f746ce74ce
commit
1287135ebb
|
@ -31,6 +31,43 @@ public class ChatInteraction : StreamInteractionModule, Object {
|
||||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_message_sent);
|
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) {
|
public bool is_active_focus(Conversation? conversation = null) {
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
return focus_in && conversation.equals(this.selected_conversation);
|
return focus_in && conversation.equals(this.selected_conversation);
|
||||||
|
|
|
@ -89,6 +89,8 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
|
||||||
if (conversation == null) return;
|
if (conversation == null) return;
|
||||||
Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation);
|
Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_stanza_id(stanza_id, conversation);
|
||||||
if (message == null) return;
|
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;
|
conversation.read_up_to = message;
|
||||||
} else {
|
} else {
|
||||||
// We received a marker from someone else. Search the respective message and mark it.
|
// We received a marker from someone else. Search the respective message and mark it.
|
||||||
|
|
|
@ -166,13 +166,10 @@ public class ConversationSelectorRow : ListBoxRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void update_read() {
|
protected void update_read() {
|
||||||
MessageItem? message_item = last_content_item as MessageItem;
|
bool current_read_status = !stream_interactor.get_module(ChatInteraction.IDENTITY).has_unread(conversation);
|
||||||
if (message_item == null) return;
|
if (read == current_read_status) return;
|
||||||
Message last_message = message_item.message;
|
read = current_read_status;
|
||||||
|
|
||||||
bool read_was = read;
|
|
||||||
read = last_message == null || (conversation.read_up_to != null && last_message.equals(conversation.read_up_to));
|
|
||||||
if (read == read_was) return;
|
|
||||||
if (read) {
|
if (read) {
|
||||||
name_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD)));
|
name_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD)));
|
||||||
time_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD)));
|
time_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD)));
|
||||||
|
|
Loading…
Reference in a new issue