Select corresponding conversation when clicking on notification

This commit is contained in:
fiaxh 2017-03-23 16:34:54 +01:00
parent 492baaf084
commit aca6842c49
3 changed files with 40 additions and 17 deletions

View file

@ -17,6 +17,7 @@ public class Dino.Ui.Application : Dino.Application {
activate.connect(() => { activate.connect(() => {
create_set_app_menu(); create_set_app_menu();
window = new UnifiedWindow(this, stream_interaction); window = new UnifiedWindow(this, stream_interaction);
notifications.conversation_selected.connect(window.on_conversation_selected);
window.show(); window.show();
}); });
} }

View file

@ -1,3 +1,5 @@
using Gee;
using Dino.Entities; using Dino.Entities;
using Xmpp; using Xmpp;
@ -5,8 +7,17 @@ namespace Dino.Ui {
public class Notifications : Object { public class Notifications : Object {
public signal void conversation_selected(Conversation conversation);
private StreamInteractor stream_interactor; 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) { public Notifications(StreamInteractor stream_interactor) {
this.stream_interactor = 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) { 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()) { if (!stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) {
string display_name = Util.get_conversation_display_name(stream_interactor, conversation); 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)) { 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); 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); notifications[conversation].update(display_name, text, null);
notification.set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)); notifications[conversation].set_image_from_pixbuf((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation));
notification.set_timeout(3); notifications[conversation].set_timeout(3);
try { try {
notification.show(); notifications[conversation].show();
} catch (Error error) { } } catch (Error error) { }
} }
} }

View file

@ -50,6 +50,17 @@ public class UnifiedWindow : Window {
check_stack(); 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() { private void setup_unified() {
chat_input = new ChatInput(stream_interactor) { visible=true }; chat_input = new ChatInput(stream_interactor) { visible=true };
conversation_frame = new ConversationSummary.View(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() { private bool on_focus_in_event() {
stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation); stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation);
return false; return false;