aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-23 16:34:54 +0100
committerfiaxh <git@mx.ax.lt>2017-03-23 16:34:54 +0100
commitaca6842c490c52b6460b7d9ebd7cc77eec4b97ef (patch)
treeb78b07581392c1140aa3bee70fc969b122e07843 /main/src
parent492baaf0845fee2495b9d181cd9fd50403eb61f8 (diff)
downloaddino-aca6842c490c52b6460b7d9ebd7cc77eec4b97ef.tar.gz
dino-aca6842c490c52b6460b7d9ebd7cc77eec4b97ef.zip
Select corresponding conversation when clicking on notification
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/application.vala1
-rw-r--r--main/src/ui/notifications.vala34
-rw-r--r--main/src/ui/unified_window.vala22
3 files changed, 40 insertions, 17 deletions
diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala
index e78fa90a..57b03bb3 100644
--- a/main/src/ui/application.vala
+++ b/main/src/ui/application.vala
@@ -17,6 +17,7 @@ public class Dino.Ui.Application : Dino.Application {
activate.connect(() => {
create_set_app_menu();
window = new UnifiedWindow(this, stream_interaction);
+ notifications.conversation_selected.connect(window.on_conversation_selected);
window.show();
});
}
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<Conversation, Notify.Notification> notifications = new HashMap<Conversation, Notify.Notification>(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 = @"<b>$muc_occupant</b> $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) { }
}
}
diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala
index 2eb4317a..4a409128 100644
--- a/main/src/ui/unified_window.vala
+++ b/main/src/ui/unified_window.vala
@@ -50,6 +50,17 @@ public class UnifiedWindow : Window {
check_stack();
}
+ public void on_conversation_selected(Conversation conversation) {
+ this.conversation = conversation;
+ stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation);
+ conversation.active = true; // only for conversation_selected
+ filterable_conversation_list.conversation_list.on_conversation_selected(conversation); // only for conversation_opened
+
+ chat_input.initialize_for_conversation(conversation);
+ conversation_frame.initialize_for_conversation(conversation);
+ conversation_titlebar.initialize_for_conversation(conversation);
+ }
+
private void setup_unified() {
chat_input = new ChatInput(stream_interactor) { visible=true };
conversation_frame = new ConversationSummary.View(stream_interactor) { visible=true };
@@ -97,17 +108,6 @@ public class UnifiedWindow : Window {
}
}
- private void on_conversation_selected(Conversation conversation) {
- this.conversation = conversation;
- stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation);
- conversation.active = true; // only for conversation_selected
- filterable_conversation_list.conversation_list.on_conversation_selected(conversation); // only for conversation_opened
-
- chat_input.initialize_for_conversation(conversation);
- conversation_frame.initialize_for_conversation(conversation);
- conversation_titlebar.initialize_for_conversation(conversation);
- }
-
private bool on_focus_in_event() {
stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation);
return false;