Select corresponding conversation when clicking on notification
This commit is contained in:
parent
492baaf084
commit
aca6842c49
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue