From aca6842c490c52b6460b7d9ebd7cc77eec4b97ef Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 23 Mar 2017 16:34:54 +0100 Subject: Select corresponding conversation when clicking on notification --- main/src/ui/notifications.vala | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'main/src/ui/notifications.vala') diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 3efa7dc7..9d91598a 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -1,3 +1,5 @@ +using Gee; + using Dino.Entities; using Xmpp; @@ -5,8 +7,17 @@ namespace Dino.Ui { public class Notifications : Object { + public signal void conversation_selected(Conversation conversation); + private StreamInteractor stream_interactor; - private Notify.Notification notification = new Notify.Notification("", null, null); + private HashMap notifications = new HashMap(Conversation.hash_func, Conversation.equals_func); + + private enum ClosedReason { // org.freedesktop.Notifications.NotificationClosed + EXPIRED = 1, + USER_DISMISSED = 2, + CLOSE_NOTIFICATION = 3, + UNDEFINED = 4 + } public Notifications(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; @@ -18,17 +29,28 @@ public class Notifications : Object { } private void on_message_received(Entities.Message message, Conversation conversation) { + if (!notifications.has_key(conversation)) { + notifications[conversation] = new Notify.Notification("", null, null); + notifications[conversation].set_hint("transient", true); + notifications[conversation].closed.connect(() => { + if (notifications[conversation].closed_reason == ClosedReason.USER_DISMISSED) { + // USER_DISMISSED + transient = very probably clicked on + conversation_selected(conversation); + } + }); + } if (!stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) { string display_name = Util.get_conversation_display_name(stream_interactor, conversation); + string text = message.body; if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)) { string muc_occupant = Util.get_display_name(stream_interactor, message.from, conversation.account); - display_name = muc_occupant + " in " + display_name; + text = @"$muc_occupant $text"; } - notification.update(display_name, message.body, null); - notification.set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)); - notification.set_timeout(3); + notifications[conversation].update(display_name, text, null); + notifications[conversation].set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)); + notifications[conversation].set_timeout(3); try { - notification.show(); + notifications[conversation].show(); } catch (Error error) { } } } -- cgit v1.2.3-54-g00ecf