Match message with previously arrived marker
This commit is contained in:
parent
dc2dde5378
commit
bbbfdf0551
|
@ -27,8 +27,8 @@ public class ConversationManager : StreamInteractionModule, Object {
|
|||
stream_interactor.add_module(this);
|
||||
stream_interactor.account_added.connect(on_account_added);
|
||||
stream_interactor.get_module(MucManager.IDENTITY).joined.connect(on_groupchat_joined);
|
||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received);
|
||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_message_sent);
|
||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(handle_new_message);
|
||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_new_message);
|
||||
}
|
||||
|
||||
public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) {
|
||||
|
@ -117,13 +117,15 @@ public class ConversationManager : StreamInteractionModule, Object {
|
|||
}
|
||||
}
|
||||
|
||||
private void on_message_received(Entities.Message message, Conversation conversation) {
|
||||
private void handle_new_message(Entities.Message message, Conversation conversation) {
|
||||
conversation.last_active = message.time;
|
||||
start_conversation(conversation);
|
||||
}
|
||||
|
||||
private void on_message_sent(Entities.Message message, Conversation conversation) {
|
||||
conversation.last_active = message.time;
|
||||
if (message.stanza != null) {
|
||||
bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null;
|
||||
bool is_recent = message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0;
|
||||
if (is_mam_message && !is_recent) return;
|
||||
}
|
||||
start_conversation(conversation);
|
||||
}
|
||||
|
||||
private void on_groupchat_joined(Account account, Jid jid, string nick) {
|
||||
|
|
|
@ -15,6 +15,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
|
|||
|
||||
private StreamInteractor stream_interactor;
|
||||
private HashMap<Jid, string> chat_states = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
|
||||
private HashMap<string, string> marker_wo_message = new HashMap<string, string>();
|
||||
|
||||
public static void start(StreamInteractor stream_interactor) {
|
||||
CounterpartInteractionManager m = new CounterpartInteractionManager(stream_interactor);
|
||||
|
@ -25,6 +26,7 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
|
|||
this.stream_interactor = stream_interactor;
|
||||
stream_interactor.account_added.connect(on_account_added);
|
||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received);
|
||||
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_if_got_marker);
|
||||
}
|
||||
|
||||
public string? get_chat_state(Account account, Jid jid) {
|
||||
|
@ -67,10 +69,23 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
|
|||
message.marked = Entities.Message.Marked.READ;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (marker_wo_message.has_key(stanza_id) &&
|
||||
marker_wo_message[stanza_id] == Xep.ChatMarkers.MARKER_DISPLAYED && marker == Xep.ChatMarkers.MARKER_RECEIVED) {
|
||||
return;
|
||||
}
|
||||
marker_wo_message[stanza_id] = marker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void check_if_got_marker(Entities.Message message, Conversation conversation) {
|
||||
if (marker_wo_message.has_key(message.stanza_id)) {
|
||||
on_chat_marker_received(conversation.account, conversation.counterpart, marker_wo_message[message.stanza_id], message.stanza_id);
|
||||
marker_wo_message.unset(message.stanza_id);
|
||||
}
|
||||
}
|
||||
|
||||
private void on_message_received(Entities.Message message, Conversation conversation) {
|
||||
on_chat_state_received(conversation.account, conversation.counterpart, Xep.ChatStateNotifications.STATE_ACTIVE);
|
||||
}
|
||||
|
@ -79,4 +94,5 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
|
|||
on_chat_marker_received(account, jid, Xep.ChatMarkers.MARKER_RECEIVED, id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,16 +104,13 @@ public class MessageProcessor : StreamInteractionModule, Object {
|
|||
(!is_uuid && !db.contains_message(new_message, conversation.account))) {
|
||||
stream_interactor.get_module(MessageStorage.IDENTITY).add_message(new_message, conversation);
|
||||
|
||||
bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null;
|
||||
bool is_recent = new_message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0;
|
||||
if (!is_mam_message || is_recent) {
|
||||
if (new_message.direction == Entities.Message.DIRECTION_SENT) {
|
||||
message_sent(new_message, conversation);
|
||||
} else {
|
||||
message_received(new_message, conversation);
|
||||
}
|
||||
if (new_message.direction == Entities.Message.DIRECTION_SENT) {
|
||||
message_sent(new_message, conversation);
|
||||
} else {
|
||||
message_received(new_message, conversation);
|
||||
}
|
||||
|
||||
bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null;
|
||||
Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
|
||||
Xep.MessageArchiveManagement.Flag? mam_flag = stream != null ? stream.get_flag(Xep.MessageArchiveManagement.Flag.IDENTITY) : null;
|
||||
if (is_mam_message || (mam_flag != null && mam_flag.cought_up == true)) {
|
||||
|
|
Loading…
Reference in a new issue