diff options
Diffstat (limited to 'libdino/src/service')
-rw-r--r-- | libdino/src/service/chat_interaction.vala | 10 | ||||
-rw-r--r-- | libdino/src/service/conversation_manager.vala | 49 | ||||
-rw-r--r-- | libdino/src/service/message_manager.vala | 13 | ||||
-rw-r--r-- | libdino/src/service/muc_manager.vala | 4 |
4 files changed, 36 insertions, 40 deletions
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index f6da1ee6..9943c3c3 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -51,8 +51,8 @@ public class ChatInteraction : StreamInteractionModule, Object { if (!last_input_interaction.has_key(conversation)) { send_chat_state_notification(conversation, Xep.ChatStateNotifications.STATE_COMPOSING); } - last_input_interaction[conversation] = new DateTime.now_utc(); - last_interface_interaction[conversation] = new DateTime.now_utc(); + last_input_interaction[conversation] = new DateTime.now_local(); + last_interface_interaction[conversation] = new DateTime.now_local(); } public void on_message_cleared(Conversation? conversation) { @@ -62,7 +62,7 @@ public class ChatInteraction : StreamInteractionModule, Object { } } - public void on_conversation_selected(Conversation? conversation) { + public void on_conversation_selected(Conversation conversation) { on_conversation_unfocused(selected_conversation); selected_conversation = conversation; on_conversation_focused(conversation); @@ -106,7 +106,7 @@ public class ChatInteraction : StreamInteractionModule, Object { if (!iter.valid && iter.has_next()) iter.next(); Conversation conversation = iter.get_key(); if (last_input_interaction.has_key(conversation) && - (new DateTime.now_utc()).difference(last_input_interaction[conversation]) >= 15 * TimeSpan.SECOND) { + (new DateTime.now_local()).difference(last_input_interaction[conversation]) >= 15 * TimeSpan.SECOND) { iter.unset(); send_chat_state_notification(conversation, Xep.ChatStateNotifications.STATE_PAUSED); } @@ -115,7 +115,7 @@ public class ChatInteraction : StreamInteractionModule, Object { if (!iter.valid && iter.has_next()) iter.next(); Conversation conversation = iter.get_key(); if (last_interface_interaction.has_key(conversation) && - (new DateTime.now_utc()).difference(last_interface_interaction[conversation]) >= 1.5 * TimeSpan.MINUTE) { + (new DateTime.now_local()).difference(last_interface_interaction[conversation]) >= 1.5 * TimeSpan.MINUTE) { iter.unset(); send_chat_state_notification(conversation, Xep.ChatStateNotifications.STATE_GONE); } diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 2d046e83..25d355c4 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -31,6 +31,18 @@ public class ConversationManager : StreamInteractionModule, Object { stream_interactor.get_module(MessageManager.IDENTITY).message_sent.connect(on_message_sent); } + public Conversation create_conversation(Jid jid, Account account, Conversation.Type type) { + assert(conversations.has_key(account)); + if (conversations[account].has_key(jid)) { + return conversations[account][jid]; + } else { + Conversation conversation = new Conversation(jid, account, type); + add_conversation(conversation); + conversation.persist(db); + return conversation; + } + } + public Conversation? get_conversation(Jid jid, Account account) { if (conversations.has_key(account)) { return conversations[account][jid]; @@ -48,20 +60,14 @@ public class ConversationManager : StreamInteractionModule, Object { return ret; } - public Conversation get_add_conversation(Jid jid, Account account) { - ensure_add_conversation(jid, account, Conversation.Type.CHAT); - return get_conversation(jid, account); - } - - public void ensure_start_conversation(Jid jid, Account account) { - ensure_add_conversation(jid, account, Conversation.Type.CHAT); - Conversation? conversation = get_conversation(jid, account); - if (conversation != null) { - conversation.last_active = new DateTime.now_utc(); - if (!conversation.active) { - conversation.active = true; - conversation_activated(conversation); - } + public void start_conversation(Conversation conversation, bool push_front = false) { + if (push_front) { + conversation.last_active = new DateTime.now_local(); + if (conversation.active) conversation_activated(conversation); + } + if (!conversation.active) { + conversation.active = true; + conversation_activated(conversation); } } @@ -78,7 +84,8 @@ public class ConversationManager : StreamInteractionModule, Object { } private void on_message_received(Entities.Message message, Xmpp.Message.Stanza message_stanza, Conversation conversation) { - ensure_start_conversation(conversation.counterpart, conversation.account); + conversation.last_active = message.time; + start_conversation(conversation); } private void on_message_sent(Entities.Message message, Conversation conversation) { @@ -86,16 +93,8 @@ public class ConversationManager : StreamInteractionModule, Object { } private void on_groupchat_joined(Account account, Jid jid, string nick) { - ensure_add_conversation(jid, account, Conversation.Type.GROUPCHAT); - ensure_start_conversation(jid, account); - } - - private void ensure_add_conversation(Jid jid, Account account, Conversation.Type type) { - if (conversations.has_key(account) && !conversations[account].has_key(jid)) { - Conversation conversation = new Conversation(jid, account, type); - add_conversation(conversation); - conversation.persist(db); - } + Conversation conversation = create_conversation(jid, account, Conversation.Type.GROUPCHAT); + start_conversation(conversation); } private void add_conversation(Conversation conversation) { diff --git a/libdino/src/service/message_manager.vala b/libdino/src/service/message_manager.vala index 1f0d528b..314a466b 100644 --- a/libdino/src/service/message_manager.vala +++ b/libdino/src/service/message_manager.vala @@ -103,9 +103,9 @@ public class MessageManager : StreamInteractionModule, Object { new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? new Jid(message.from) : new Jid(message.to); new_message.stanza = message; Xep.DelayedDelivery.MessageFlag? deleyed_delivery_flag = Xep.DelayedDelivery.MessageFlag.get_flag(message); - new_message.time = deleyed_delivery_flag != null ? deleyed_delivery_flag.datetime : new DateTime.now_utc(); - new_message.local_time = new DateTime.now_utc(); - Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_add_conversation(new_message.counterpart, account); + new_message.time = deleyed_delivery_flag != null ? deleyed_delivery_flag.datetime : new DateTime.now_local(); + new_message.local_time = new DateTime.now_local(); + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(new_message.counterpart, account, Conversation.Type.CHAT); pre_message_received(new_message, message, conversation); bool is_uuid = new_message.stanza_id != null && Regex.match_simple("""[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}""", new_message.stanza_id); @@ -113,9 +113,6 @@ public class MessageManager : StreamInteractionModule, Object { (!is_uuid && !db.contains_message(new_message, conversation.account))) { new_message.persist(db); add_message(new_message, conversation); - if (new_message.time.difference(conversation.last_active) > 0) { - conversation.last_active = new_message.time; - } if (new_message.direction == Entities.Message.DIRECTION_SENT) { message_sent(new_message, conversation); } else { @@ -137,8 +134,8 @@ public class MessageManager : StreamInteractionModule, Object { message.stanza_id = random_uuid(); message.account = conversation.account; message.body = text; - message.time = new DateTime.now_utc(); - message.local_time = new DateTime.now_utc(); + message.time = new DateTime.now_local(); + message.local_time = new DateTime.now_local(); message.direction = Entities.Message.DIRECTION_SENT; message.counterpart = conversation.counterpart; message.ourpart = new Jid(conversation.account.bare_jid.to_string() + "/" + conversation.account.resourcepart); diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 82d200b0..c5bfb8ba 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -168,8 +168,8 @@ public class MucManager : StreamInteractionModule, Object { message.real_jid = real_jid; } } - string muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid.to_string()); - if (message.from.equals(new Jid(@"$(message.from.bare_jid)/$muc_nick"))) { // TODO better from own + string? muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid.to_string()); + if (muc_nick != null && message.from.equals(new Jid(@"$(message.from.bare_jid)/$muc_nick"))) { // TODO better from own Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageManager.IDENTITY).get_messages(conversation); if (messages != null) { // TODO not here foreach (Entities.Message m in messages) { |