diff options
author | fiaxh <git@lightrise.org> | 2020-03-03 15:14:31 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-03-03 15:14:31 +0100 |
commit | b8b3e1c6f517a18a917250f17a64ba1bd19140a8 (patch) | |
tree | d209b6786b75a01d4b5670a125ec945218e686a5 /libdino/src | |
parent | 17acdd9f414a9e4d6a0607e94b03792581ff03df (diff) | |
download | dino-b8b3e1c6f517a18a917250f17a64ba1bd19140a8.tar.gz dino-b8b3e1c6f517a18a917250f17a64ba1bd19140a8.zip |
Improve MUC message resending
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/database.vala | 18 | ||||
-rw-r--r-- | libdino/src/service/message_processor.vala | 34 | ||||
-rw-r--r-- | libdino/src/service/muc_manager.vala | 2 | ||||
-rw-r--r-- | libdino/src/service/util.vala | 16 |
4 files changed, 42 insertions, 28 deletions
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 39dcf234..238d8f46 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -400,24 +400,6 @@ public class Database : Qlite.Database { return ret; } - public Gee.List<Message> get_unsend_messages(Account account, Jid? jid = null) { - Gee.List<Message> ret = new ArrayList<Message>(); - 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) { - try { - ret.add(new Message.from_row(this, row)); - } catch (InvalidJidError e) { - warning("Ignoring message with invalid Jid: %s", e.message); - } - } - return ret; - } - public Message? get_message_by_id(int id) { Row? row = message.row_with(message.id, id).inner; if (row != null) { diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 7a9d3348..f1526b16 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -46,7 +46,7 @@ public class MessageProcessor : StreamInteractionModule, Object { stream_interactor.account_added.connect(on_account_added); stream_interactor.connection_manager.connection_state_changed.connect((account, state) => { - if (state == ConnectionManager.ConnectionState.CONNECTED) send_unsent_messages(account); + if (state == ConnectionManager.ConnectionState.CONNECTED) send_unsent_chat_messages(account); }); stream_interactor.connection_manager.stream_opened.connect((account, stream) => { @@ -68,12 +68,32 @@ public class MessageProcessor : StreamInteractionModule, Object { return message; } - public void send_unsent_messages(Account account, Jid? jid = null) { - Gee.List<Entities.Message> 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 send_unsent_chat_messages(Account account) { + var select = db.message.select() + .with(db.message.account_id, "=", account.id) + .with(db.message.marked, "=", (int) Message.Marked.UNSENT) + .with(db.message.type_, "=", (int) Message.Type.CHAT); + send_unsent_messages(account, select); + } + + public void send_unsent_muc_messages(Account account, Jid muc_jid) { + var select = db.message.select() + .with(db.message.account_id, "=", account.id) + .with(db.message.marked, "=", (int) Message.Marked.UNSENT) + .with(db.message.counterpart_id, "=", db.get_jid_id(muc_jid)); + send_unsent_messages(account, select); + } + + private void send_unsent_messages(Account account, QueryBuilder select) { + foreach (Row row in select) { + try { + Message message = new Message.from_row(db, row); + Conversation? msg_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(message.counterpart, account, Util.get_conversation_type_for_message(message)); + if (msg_conv != null) { + send_xmpp_message(message, msg_conv, true); + } + } catch (InvalidJidError e) { + warning("Ignoring message with invalid Jid: %s", e.message); } } } diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index cd27e392..39d66213 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -58,7 +58,7 @@ public class MucManager : StreamInteractionModule, Object { // Join completed enter_errors.unset(jid); set_autojoin(account, stream, jid, nick, password); - stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid); + stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_muc_messages(account, jid); Conversation joined_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT); joined_conversation.nickname = nick; diff --git a/libdino/src/service/util.vala b/libdino/src/service/util.vala index d0e19dc3..4f9b94ce 100644 --- a/libdino/src/service/util.vala +++ b/libdino/src/service/util.vala @@ -3,7 +3,7 @@ using Dino.Entities; namespace Dino { public class Util { - public static Entities.Message.Type get_message_type_for_conversation(Conversation conversation) { + public static Message.Type get_message_type_for_conversation(Conversation conversation) { switch (conversation.type_) { case Conversation.Type.CHAT: return Entities.Message.Type.CHAT; @@ -14,6 +14,18 @@ public class Util { } assert_not_reached(); } + + public static Conversation.Type get_conversation_type_for_message(Message message) { + switch (message.type_) { + case Entities.Message.Type.CHAT: + return Conversation.Type.CHAT; + case Entities.Message.Type.GROUPCHAT: + return Conversation.Type.GROUPCHAT; + case Entities.Message.Type.GROUPCHAT_PM: + return Conversation.Type.GROUPCHAT_PM; + } + assert_not_reached(); + } } -}
\ No newline at end of file +} |