diff options
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/application.vala | 1 | ||||
-rw-r--r-- | libdino/src/entity/conversation.vala | 4 | ||||
-rw-r--r-- | libdino/src/entity/settings.vala | 10 | ||||
-rw-r--r-- | libdino/src/service/notification_events.vala | 53 |
4 files changed, 54 insertions, 14 deletions
diff --git a/libdino/src/application.vala b/libdino/src/application.vala index f6e651a4..4ea33fb7 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -37,6 +37,7 @@ public interface Dino.Application : GLib.Application { ConversationManager.start(stream_interactor, db); ChatInteraction.start(stream_interactor); FileManager.start(stream_interactor, db); + NotificationEvents.start(stream_interactor); create_actions(); diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index 0dfa64f2..9026e33f 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -101,10 +101,6 @@ public class Conversation : Object { return notify_setting != NotifySetting.DEFAULT ? notify_setting : get_notification_default_setting(stream_interactor); } - public bool get_sound_setting(StreamInteractor stream_interactor) { - return Application.get_default().settings.sound; - } - 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; diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala index 32d38c90..f94a92ca 100644 --- a/libdino/src/entity/settings.vala +++ b/libdino/src/entity/settings.vala @@ -10,7 +10,6 @@ public class Settings : Object { send_typing_ = col_to_bool_or_default("send_typing", true); send_marker_ = col_to_bool_or_default("send_marker", true); notifications_ = col_to_bool_or_default("notifications", true); - sound_ = col_to_bool_or_default("sound", true); convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true); current_width = col_to_int_or_default("window_width", 1200); @@ -57,15 +56,6 @@ public class Settings : Object { } } - private bool sound_; - public bool sound { - get { return sound_; } - set { - db.settings.insert().or("REPLACE").value(db.settings.key, "sound").value(db.settings.value, value.to_string()).perform(); - sound_ = value; - } - } - private bool convert_utf8_smileys_; public bool convert_utf8_smileys { get { return convert_utf8_smileys_; } diff --git a/libdino/src/service/notification_events.vala b/libdino/src/service/notification_events.vala new file mode 100644 index 00000000..5db581ba --- /dev/null +++ b/libdino/src/service/notification_events.vala @@ -0,0 +1,53 @@ +using Gee; + +using Dino.Entities; +using Xmpp; + +namespace Dino { + +public class NotificationEvents : StreamInteractionModule, Object { + public static ModuleIdentity<NotificationEvents> IDENTITY = new ModuleIdentity<NotificationEvents>("notification_events"); + public string id { get { return IDENTITY.id; } } + + public signal void notify_message(Message message, Conversation conversation); + public signal void notify_subscription_request(Conversation conversation); + + private StreamInteractor stream_interactor; + + public static void start(StreamInteractor stream_interactor) { + NotificationEvents m = new NotificationEvents(stream_interactor); + stream_interactor.add_module(m); + } + + public NotificationEvents(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + + stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); + stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); + } + + private void on_message_received(Entities.Message message, Conversation conversation) { + if (!should_notify_message(message, conversation)) return; + if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) return; + notify_message(message, conversation); + } + + private bool should_notify_message(Entities.Message message, Conversation conversation) { + Conversation.NotifySetting notify = conversation.get_notification_setting(stream_interactor); + if (notify == Conversation.NotifySetting.OFF) return false; + Jid? nick = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); + if (notify == Conversation.NotifySetting.HIGHLIGHT && nick != null) { + return Regex.match_simple("""\b""" + Regex.escape_string(nick.resourcepart) + """\b""", message.body, RegexCompileFlags.CASELESS); + } + return true; + } + + private void on_received_subscription_request(Jid jid, Account account) { + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); + if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus(conversation)) return; + + notify_subscription_request(conversation); + } +} + +} |