From 555187deb9a5ce1af94d241868de6babdd6166b6 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 22 Oct 2017 02:43:04 +0200 Subject: Offline messages for MUCs fixes #187 --- libdino/src/service/database.vala | 5 ++++- libdino/src/service/message_processor.vala | 22 +++++++++++----------- libdino/src/service/muc_manager.vala | 6 ++++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 1678c077..532d9f0d 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -253,11 +253,14 @@ public class Database : Qlite.Database { return ret; } - public Gee.List get_unsend_messages(Account account) { + public Gee.List get_unsend_messages(Account account, Jid? jid = null) { Gee.List ret = new ArrayList(); var select = message.select() .with(message.account_id, "=", account.id) .with(message.marked, "=", (int) Message.Marked.UNSENT); + if (jid != null) { + select.with(message.counterpart_id, "=", get_jid_id(jid)); + } foreach (Row row in select) { ret.add(new Message.from_row(this, row)); } diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 25e8f91a..3ba3320c 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -40,6 +40,16 @@ public class MessageProcessor : StreamInteractionModule, Object { message_sent(message, conversation); } + public void send_unsent_messages(Account account, Jid? jid = null) { + Gee.List unsend_messages = db.get_unsend_messages(account, jid); + foreach (Entities.Message message in unsend_messages) { + Conversation? msg_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account); + if (msg_conv != null) { + send_xmpp_message(message, msg_conv, true); + } + } + } + private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, Xmpp.Message.Module.IDENTITY).received_message.connect( (stream, message) => { on_message_received(account, message); @@ -50,16 +60,6 @@ public class MessageProcessor : StreamInteractionModule, Object { }); } - private void send_unsent_messages(Account account) { - Gee.List unsend_messages = db.get_unsend_messages(account); - foreach (Entities.Message message in unsend_messages) { - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account); - if (conversation != null) { - send_xmpp_message(message, conversation, true); - } - } - } - private void on_message_received(Account account, Xmpp.Message.Stanza message) { if (message.body == null) return; @@ -168,7 +168,7 @@ public class MessageProcessor : StreamInteractionModule, Object { message.direction = Entities.Message.DIRECTION_SENT; message.counterpart = conversation.counterpart; if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { - message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); + message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; message.real_jid = conversation.account.bare_jid; } else { message.ourpart = new Jid.with_resource(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 51b3822e..f9a67e7a 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -207,8 +207,10 @@ public class MucManager : StreamInteractionModule, Object { } private void on_account_added(Account account) { - stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid, nick) => { - joined(account, new Jid(jid), nick); + stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid_string, nick) => { + Jid jid = new Jid(jid_string); + joined(account, jid, nick); + stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid); }); stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid, error) => { enter_errors[new Jid(jid)] = error; -- cgit v1.2.3-70-g09d2