From 03f25e1f87dd4608c7cf4d0f97d1cb2e0141094d Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 21 May 2019 21:42:39 +0200 Subject: [PATCH] Remove Message.stanza field --- libdino/src/entity/conversation.vala | 20 ++++--- libdino/src/entity/message.vala | 1 - libdino/src/service/chat_interaction.vala | 52 ++++++++++--------- libdino/src/service/connection_manager.vala | 2 +- libdino/src/service/conversation_manager.vala | 16 +++--- libdino/src/service/message_processor.vala | 2 - libdino/src/service/muc_manager.vala | 2 +- plugins/http-files/src/file_provider.vala | 2 +- .../src/device_notification_populator.vala | 2 +- 9 files changed, 51 insertions(+), 48 deletions(-) diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index 145dc977..9e8a3406 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -102,27 +102,31 @@ public class Conversation : Object { } public NotifySetting get_notification_default_setting(StreamInteractor stream_interactor) { - Xmpp.XmppStream? stream = stream_interactor.get_stream(account); if (!Application.get_default().settings.notifications) return NotifySetting.OFF; + if (type_ == Type.GROUPCHAT) { - Xmpp.Xep.Muc.Flag? flag = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY); - if (flag != null) { - bool members_only = flag.has_room_feature(counterpart.bare_jid, Xmpp.Xep.Muc.Feature.MEMBERS_ONLY); - return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT; + if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(this.account, this.counterpart)) { + return NotifySetting.ON; } else { - return NotifySetting.OFF; + return NotifySetting.HIGHLIGHT; } } return NotifySetting.ON; } - public Setting get_send_typing_setting() { + public Setting get_send_typing_setting(StreamInteractor stream_interactor) { if (send_typing != Setting.DEFAULT) return send_typing; + + if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(this.account, this.counterpart)) return Setting.OFF; + return Application.get_default().settings.send_typing ? Setting.ON : Setting.OFF; } - public Setting get_send_marker_setting() { + public Setting get_send_marker_setting(StreamInteractor stream_interactor) { if (send_marker != Setting.DEFAULT) return send_marker; + + if (stream_interactor.get_module(MucManager.IDENTITY).is_public_room(this.account, this.counterpart)) return Setting.OFF; + return Application.get_default().settings.send_marker ? Setting.ON : Setting.OFF; } diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index ac54a7c2..a93b37ac 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -52,7 +52,6 @@ public class Message : Object { marked_ = value; } } - public Xmpp.MessageStanza stanza { get; set; } private Database? db; diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index 77176d93..9fc471fb 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -95,10 +95,9 @@ public class ChatInteraction : StreamInteractionModule, Object { private void check_send_read() { if (selected_conversation == null || selected_conversation.type_ == Conversation.Type.GROUPCHAT) return; Entities.Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_last_message(selected_conversation); - if (message != null && message.direction == Entities.Message.DIRECTION_RECEIVED && - message.stanza != null && !message.equals(selected_conversation.read_up_to)) { + if (message != null && message.direction == Entities.Message.DIRECTION_RECEIVED && !message.equals(selected_conversation.read_up_to)) { selected_conversation.read_up_to = message; - send_chat_marker(selected_conversation, message, Xep.ChatMarkers.MARKER_DISPLAYED); + send_chat_marker(message, null, selected_conversation, Xep.ChatMarkers.MARKER_DISPLAYED); } } @@ -137,47 +136,52 @@ public class ChatInteraction : StreamInteractionModule, Object { } public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) { - if (Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null) return false; + if (Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null) return false; ChatInteraction outer = stream_interactor.get_module(ChatInteraction.IDENTITY); - outer.send_delivery_receipt(conversation, message); + outer.send_delivery_receipt(message, stanza, conversation); if (outer.is_active_focus(conversation)) { outer.check_send_read(); conversation.read_up_to = message; - outer.send_chat_marker(conversation, message, Xep.ChatMarkers.MARKER_DISPLAYED); + outer.send_chat_marker(message, stanza, conversation, Xep.ChatMarkers.MARKER_DISPLAYED); } else { - outer.send_chat_marker(conversation, message, Xep.ChatMarkers.MARKER_RECEIVED); + outer.send_chat_marker(message, stanza, conversation, Xep.ChatMarkers.MARKER_RECEIVED); } return false; } } - private void send_chat_marker(Conversation conversation, Entities.Message message, string marker) { - XmppStream stream = stream_interactor.get_stream(conversation.account); - if (stream != null && - (marker == Xep.ChatMarkers.MARKER_RECEIVED || conversation.get_send_marker_setting() == Conversation.Setting.ON) && - Xep.ChatMarkers.Module.requests_marking(message.stanza)) { - stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.stanza.from, message.stanza_id, message.get_type_string(), marker); + private void send_chat_marker(Entities.Message message, Xmpp.MessageStanza? stanza, Conversation conversation, string marker) { + XmppStream? stream = stream_interactor.get_stream(conversation.account); + if (stream == null) return; + + switch (marker) { + case Xep.ChatMarkers.MARKER_RECEIVED: + if (stanza != null && Xep.ChatMarkers.Module.requests_marking(stanza)) { + stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.from, message.stanza_id, message.get_type_string(), Xep.ChatMarkers.MARKER_RECEIVED); + } + break; + case Xep.ChatMarkers.MARKER_DISPLAYED: + if (conversation.get_send_marker_setting(stream_interactor) == Conversation.Setting.ON) { + stream.get_module(Xep.ChatMarkers.Module.IDENTITY).send_marker(stream, message.from, message.stanza_id, message.get_type_string(), Xep.ChatMarkers.MARKER_DISPLAYED); + } + break; } } - private void send_delivery_receipt(Conversation conversation, Entities.Message message) { - XmppStream stream = stream_interactor.get_stream(conversation.account); - if (stream != null && Xep.MessageDeliveryReceipts.Module.requests_receipt(message.stanza)) { + private void send_delivery_receipt(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) { + XmppStream? stream = stream_interactor.get_stream(conversation.account); + if (stream != null && conversation.type_ != Conversation.Type.GROUPCHAT && Xep.MessageDeliveryReceipts.Module.requests_receipt(stanza)) { stream.get_module(Xep.MessageDeliveryReceipts.Module.IDENTITY).send_received(stream, message.from, message.stanza_id); } } private void send_chat_state_notification(Conversation conversation, string state) { - XmppStream stream = stream_interactor.get_stream(conversation.account); - if (stream != null && conversation.get_send_typing_setting() == Conversation.Setting.ON) { - if (conversation.type_ != Conversation.Type.GROUPCHAT) { - stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, Xmpp.MessageStanza.TYPE_CHAT, state); - } - if (stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart)) { - stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, Xmpp.MessageStanza.TYPE_GROUPCHAT, state); - } + XmppStream? stream = stream_interactor.get_stream(conversation.account); + if (stream != null && conversation.get_send_typing_setting(stream_interactor) == Conversation.Setting.ON) { + string message_type = conversation.type_ == Conversation.Type.GROUPCHAT ? Xmpp.MessageStanza.TYPE_GROUPCHAT : Xmpp.MessageStanza.TYPE_GROUPCHAT; + stream.get_module(Xep.ChatStateNotifications.Module.IDENTITY).send_state(stream, conversation.counterpart, message_type, state); } } } diff --git a/libdino/src/service/connection_manager.vala b/libdino/src/service/connection_manager.vala index e81b9b99..0a129717 100644 --- a/libdino/src/service/connection_manager.vala +++ b/libdino/src/service/connection_manager.vala @@ -171,7 +171,7 @@ public class ConnectionManager : Object { set_connection_error(account, new ConnectionError(ConnectionError.Source.TLS, null) { reconnect_recomendation=ConnectionError.Reconnect.NEVER}); }); stream.received_node.connect(() => { - connections[account].last_activity = new DateTime.now_utc(); + connection.last_activity = new DateTime.now_utc(); }); connect_async.begin(account, stream); stream_opened(account, stream); diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 66efe56e..77205c57 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -27,7 +27,7 @@ public class ConversationManager : StreamInteractionModule, Object { stream_interactor.add_module(this); stream_interactor.account_added.connect(on_account_added); stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(new MessageListener(stream_interactor)); - stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_new_message); + stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_sent_message); } public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) { @@ -133,8 +133,8 @@ public class ConversationManager : StreamInteractionModule, Object { public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) { conversation.last_active = message.time; - if (message.stanza != null) { - bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(message.stanza) != null; + if (stanza != null) { + bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null; bool is_recent = message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0; if (is_mam_message && !is_recent) return false; } @@ -143,15 +143,13 @@ public class ConversationManager : StreamInteractionModule, Object { } } - private void handle_new_message(Entities.Message message, Conversation conversation) { + private void handle_sent_message(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; + bool is_recent = message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0; + if (is_recent) { + start_conversation(conversation); } - start_conversation(conversation); } private void add_conversation(Conversation conversation) { diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index aa3cba4c..612c3fcc 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -104,7 +104,6 @@ public class MessageProcessor : StreamInteractionModule, Object { } new_message.counterpart = counterpart_override ?? (new_message.direction == Entities.Message.DIRECTION_SENT ? message.to : message.from); new_message.ourpart = new_message.direction == Entities.Message.DIRECTION_SENT ? message.from : message.to; - new_message.stanza = message; Xep.MessageArchiveManagement.MessageFlag? mam_message_flag = Xep.MessageArchiveManagement.MessageFlag.get_flag(message); if (mam_message_flag != null) new_message.local_time = mam_message_flag.server_time; @@ -271,7 +270,6 @@ public class MessageProcessor : StreamInteractionModule, Object { } stream.get_module(Xmpp.MessageModule.IDENTITY).send_message(stream, new_message); message.stanza_id = new_message.id; - message.stanza = new_message; } else { message.marked = Entities.Message.Marked.UNSENT; } diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index c376a5d9..21d11f5d 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -393,7 +393,7 @@ public class MucManager : StreamInteractionModule, Object { if (conversation.type_ != Conversation.Type.GROUPCHAT) return false; XmppStream stream = stream_interactor.get_stream(conversation.account); if (stream == null) return false; - if (Xep.DelayedDelivery.MessageFlag.get_flag(message.stanza) == null) { + if (Xep.DelayedDelivery.MessageFlag.get_flag(stanza) == null) { Jid? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart); if (real_jid != null && !real_jid.equals(message.counterpart)) { message.real_jid = real_jid.bare_jid; diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala index 34106d42..06b20e92 100644 --- a/plugins/http-files/src/file_provider.vala +++ b/plugins/http-files/src/file_provider.vala @@ -37,7 +37,7 @@ public class FileProvider : Dino.FileProvider, Object { public override async bool run(Entities.Message message, Xmpp.MessageStanza stanza, Conversation conversation) { if (outer.url_regex.match(message.body)) { - string? oob_url = Xmpp.Xep.OutOfBandData.get_url_from_message(message.stanza); + string? oob_url = Xmpp.Xep.OutOfBandData.get_url_from_message(stanza); if (oob_url != null && oob_url == message.body) { yield outer.on_file_message(message, conversation); } diff --git a/plugins/omemo/src/device_notification_populator.vala b/plugins/omemo/src/device_notification_populator.vala index bcb99f11..5b47611c 100644 --- a/plugins/omemo/src/device_notification_populator.vala +++ b/plugins/omemo/src/device_notification_populator.vala @@ -56,7 +56,7 @@ public class DeviceNotificationPopulator : NotificationPopulator, Object { private void on_account_added(Account account) { stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).bundle_fetched.connect_after((jid, device_id, bundle) => { - if (jid.equals(current_conversation.counterpart) && has_new_devices(current_conversation.counterpart)) { + if (current_conversation != null && jid.equals(current_conversation.counterpart) && has_new_devices(current_conversation.counterpart)) { display_notification(); } });