Show subscription request in conversation summary

This commit is contained in:
fiaxh 2017-12-14 02:01:55 +01:00
parent f25fadde2d
commit b4bb0912fc
15 changed files with 204 additions and 91 deletions

View File

@ -1,3 +0,0 @@
the .tito/packages directory contains metadata files
named after their packages. Each file has the latest tagged
version and the project's relative directory.

View File

@ -1 +0,0 @@
0.0-1 ./

View File

@ -1,5 +0,0 @@
[buildconfig]
builder = tito.builder.Builder
tagger = tito.tagger.VersionTagger
changelog_do_not_remove_cherrypick = 0
changelog_format = %s (%ae)

View File

@ -38,6 +38,8 @@ public interface Dino.Application : GLib.Application {
ChatInteraction.start(stream_interactor);
FileManager.start(stream_interactor, db);
create_actions();
activate.connect(() => {
stream_interactor.connection_manager.log_options = print_xmpp;
Idle.add(() => {
@ -93,6 +95,17 @@ public interface Dino.Application : GLib.Application {
return (Dino.Application) GLib.Application.get_default();
}
public void create_actions() {
SimpleAction accept_subscription_action = new SimpleAction("accept-subscription", VariantType.INT32);
accept_subscription_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation == null) return;
stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(conversation.account, conversation.counterpart);
stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(conversation.account, conversation.counterpart);
});
add_action(accept_subscription_action);
}
protected void add_connection(Account account) {
stream_interactor.connect(account);
}

View File

@ -14,6 +14,7 @@ public class PresenceManager : StreamInteractionModule, Object {
private StreamInteractor stream_interactor;
private HashMap<Jid, HashMap<Jid, ArrayList<Show>>> shows = new HashMap<Jid, HashMap<Jid, ArrayList<Show>>>(Jid.hash_bare_func, Jid.equals_bare_func);
private HashMap<Jid, ArrayList<Jid>> resources = new HashMap<Jid, ArrayList<Jid>>(Jid.hash_bare_func, Jid.equals_bare_func);
private Gee.List<Jid> subscription_requests = new ArrayList<Jid>(Jid.equals_func);
public static void start(StreamInteractor stream_interactor) {
PresenceManager m = new PresenceManager(stream_interactor);
@ -59,6 +60,10 @@ public class PresenceManager : StreamInteractionModule, Object {
return null;
}
public bool exists_subscription_request(Account account, Jid jid) {
return subscription_requests.contains(jid);
}
public void request_subscription(Account account, Jid jid) {
Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).request_subscription(stream, jid.bare_jid.to_string());
@ -66,12 +71,18 @@ public class PresenceManager : StreamInteractionModule, Object {
public void approve_subscription(Account account, Jid jid) {
Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid.to_string());
if (stream != null) {
stream.get_module(Xmpp.Presence.Module.IDENTITY).approve_subscription(stream, jid.bare_jid.to_string());
subscription_requests.remove(jid);
}
}
public void deny_subscription(Account account, Jid jid) {
Core.XmppStream stream = stream_interactor.get_stream(account);
if (stream != null) stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string());
if (stream != null) {
stream.get_module(Xmpp.Presence.Module.IDENTITY).deny_subscription(stream, jid.bare_jid.to_string());
subscription_requests.remove(jid);
}
}
public void cancel_subscription(Account account, Jid jid) {
@ -86,9 +97,13 @@ public class PresenceManager : StreamInteractionModule, Object {
stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_unavailable.connect((stream, presence) =>
on_received_unavailable(account, new Jid(presence.from))
);
stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid) =>
received_subscription_request(new Jid(jid), account)
);
stream_interactor.module_manager.get_module(account, Presence.Module.IDENTITY).received_subscription_request.connect((stream, jid_str) => {
Jid jid = new Jid(jid_str);
if (!subscription_requests.contains(jid)) {
subscription_requests.add(jid);
}
received_subscription_request(jid, account);
});
}
private void on_received_available_show(Account account, Jid jid, string show) {

View File

@ -109,6 +109,7 @@ SOURCES
src/ui/conversation_summary/message_populator.vala
src/ui/conversation_summary/message_textview.vala
src/ui/conversation_summary/slashme_message_display.vala
src/ui/conversation_summary/subscription_notification.vala
src/ui/conversation_titlebar/file_entry.vala
src/ui/conversation_titlebar/menu_entry.vala
src/ui/conversation_titlebar/occupants_entry.vala

View File

@ -5,6 +5,7 @@
<property name="modal">True</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="title" translatable="yes">Add Contact</property>
<property name="visible">True</property>
<child>
<object class="GtkButton" id="cancel_button">
@ -123,20 +124,6 @@
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="subscribe_checkbutton">
<property name="active">True</property>
<property name="label" translatable="yes">Request presence updates</property>
<property name="xalign">0</property>
<property name="visible">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>

View File

@ -4,7 +4,7 @@
<property name="modal">True</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="title">Conversation Details</property>
<property name="title" translatable="yes">Conversation Details</property>
<property name="show_close_button">True</property>
<property name="visible">True</property>
</object>

View File

@ -10,26 +10,63 @@
<property name="transition_type">crossfade</property>
<property name="visible">True</property>
<child>
<object class="GtkScrolledWindow" id="scrolled">
<property name="hscrollbar_policy">never</property>
<object class="GtkOverlay">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="margin">15</property>
<property name="orientation">vertical</property>
<object class="GtkScrolledWindow" id="scrolled">
<property name="hscrollbar_policy">never</property>
<property name="visible">True</property>
<child>
<object class="GtkBox" id="main">
<property name="expand">False</property>
<object class="GtkBox">
<property name="margin">15</property>
<property name="orientation">vertical</property>
<property name="spacing">15</property>
<property name="visible">True</property>
<child>
<object class="GtkBox" id="main">
<property name="expand">False</property>
<property name="orientation">vertical</property>
<property name="spacing">15</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkBox" id="filler">
<property name="expand">True</property>
<property name="visible">True</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="index">-1</property>
</packing>
</child>
<child type="overlay">
<object class="GtkRevealer" id="notification_revealer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">start</property>
<child>
<object class="GtkBox" id="filler">
<property name="expand">True</property>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<style>
<class name="app-notification"/>
</style>
<child>
<object class="GtkBox" id="notifications">
<property name="expand">False</property>
<property name="orientation">vertical</property>
<property name="visible">True</property>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
</child>
</object>

View File

@ -23,7 +23,6 @@ protected class AddContactDialog : Gtk.Dialog {
[GtkChild] private Button cancel_button;
[GtkChild] private Entry jid_entry;
[GtkChild] private Entry alias_entry;
[GtkChild] private CheckButton subscribe_checkbutton;
private StreamInteractor stream_interactor;
@ -41,9 +40,7 @@ protected class AddContactDialog : Gtk.Dialog {
string? alias = alias_entry.text == "" ? null : alias_entry.text;
Jid jid = new Jid(jid_entry.text);
stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias);
if (subscribe_checkbutton.active) {
stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid);
}
stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid);
close();
}

View File

@ -23,6 +23,8 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
provider.load_from_resource("/im/dino/Dino/theme.css");
StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
create_actions();
activate.connect(() => {
if (window == null) {
create_set_app_menu();
@ -76,9 +78,27 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
}
}
private void create_actions() {
SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32);
open_conversation_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation != null) window.on_conversation_selected(conversation);
window.present();
});
add_action(open_conversation_action);
SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32);
deny_subscription_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation == null) return;
stream_interactor.get_module(PresenceManager.IDENTITY).deny_subscription(conversation.account, conversation.counterpart);
});
add_action(deny_subscription_action);
}
private void show_accounts_window() {
ManageAccounts.Dialog dialog = new ManageAccounts.Dialog(stream_interactor, db);
dialog.set_transient_for(window);
dialog.set_transient_for(get_active_window());
dialog.account_enabled.connect(add_connection);
dialog.account_disabled.connect(remove_connection);
dialog.present();
@ -86,7 +106,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
private void show_settings_window() {
SettingsDialog dialog = new SettingsDialog();
dialog.set_transient_for(window);
dialog.set_transient_for(get_active_window());
dialog.present();
}

View File

@ -12,6 +12,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
public Conversation? conversation { get; private set; }
[GtkChild] private ScrolledWindow scrolled;
[GtkChild] private Revealer notification_revealer;
[GtkChild] private Box notifications;
[GtkChild] private Box main;
[GtkChild] private Stack stack;
@ -22,6 +24,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
private Gee.HashMap<Plugins.MetaConversationItem, Widget> widgets = new Gee.HashMap<Plugins.MetaConversationItem, Widget>();
private Gee.List<ConversationItemSkeleton> item_skeletons = new Gee.ArrayList<ConversationItemSkeleton>();
private MessagePopulator message_item_populator;
private SubscriptionNotitication subscription_notification;
private double? was_value;
private double? was_upper;
@ -36,6 +39,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
scrolled.vadjustment.notify["value"].connect(on_value_notify);
message_item_populator = new MessagePopulator(stream_interactor);
subscription_notification = new SubscriptionNotitication(stream_interactor);
insert_item.connect(on_insert_item);
remove_item.connect(on_remove_item);
@ -77,6 +81,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
message_item_populator.populate_latest(conversation, 40);
Idle.add(() => { on_value_notify(); return false; });
subscription_notification.init(conversation, this);
stack.set_visible_child_name("main");
}
@ -104,6 +110,20 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
}
}
public void add_notification(Widget widget) {
notifications.add(widget);
Timeout.add(20, () => {
notification_revealer.transition_duration = 200;
notification_revealer.reveal_child = true;
return false;
});
}
public void remove_notification(Widget widget) {
notification_revealer.reveal_child = false;
widget.destroy();
}
private bool merge_back(Plugins.MetaConversationItem item) {
Plugins.MetaConversationItem? lower_item = meta_items.lower(item);
if (lower_item != null) {
@ -246,6 +266,9 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
item_item_skeletons.clear();
widgets.clear();
main.@foreach((widget) => { widget.destroy(); });
notifications.@foreach((widget) => { widget.destroy(); });
notification_revealer.transition_duration = 0;
notification_revealer.set_reveal_child(false);
}
}

View File

@ -0,0 +1,55 @@
using Gee;
using Gtk;
using Dino.Entities;
namespace Dino.Ui.ConversationSummary {
public class SubscriptionNotitication : Object {
private StreamInteractor stream_interactor;
private Conversation conversation;
private ConversationView conversation_view;
public SubscriptionNotitication(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect((jid, account) => {
Conversation relevant_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(relevant_conversation, true);
if (conversation != null && account.equals(conversation.account) && jid.equals(conversation.counterpart)) {
show_notification();
}
});
}
public void init(Conversation conversation, ConversationView conversation_view) {
this.conversation = conversation;
this.conversation_view = conversation_view;
if (stream_interactor.get_module(PresenceManager.IDENTITY).exists_subscription_request(conversation.account, conversation.counterpart)) {
show_notification();
}
}
private void show_notification() {
Box box = new Box(Orientation.HORIZONTAL, 5) { visible=true };
Button accept_button = new Button() { label=_("Accept"), visible=true };
Button deny_button = new Button() { label=_("Deny"), visible=true };
GLib.Application app = GLib.Application.get_default();
accept_button.clicked.connect(() => {
app.activate_action("accept-subscription", conversation.id);
conversation_view.remove_notification(box);
});
deny_button.clicked.connect(() => {
app.activate_action("deny-subscription", conversation.id);
conversation_view.remove_notification(box);
});
box.add(new Label(_("This contact would like to add you to their contact list")) { margin_end=10, visible=true });
box.add(accept_button);
box.add(deny_button);
conversation_view.add_notification(box);
}
}
}

View File

@ -12,63 +12,32 @@ public class Notifications : Object {
private StreamInteractor stream_interactor;
private Gtk.Window window;
private HashMap<Conversation, Notification> notifications = new HashMap<Conversation, Notification>(Conversation.hash_func, Conversation.equals_func);
private Set<string>? active_notification_ids = null;
private enum ClosedReason { // org.freedesktop.Notifications.NotificationClosed
EXPIRED = 1,
USER_DISMISSED = 2,
CLOSE_NOTIFICATION = 3,
UNDEFINED = 4
}
private Set<string>? active_conversation_ids = null;
private Set<string>? active_ids = new HashSet<string>();
public Notifications(StreamInteractor stream_interactor, Gtk.Window window) {
this.stream_interactor = stream_interactor;
this.window = window;
stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect(() => {
if (active_notification_ids == null) {
stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect((focused_conversation) => {
if (active_conversation_ids == null) {
Gee.List<Conversation> conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations();
foreach (Conversation conversation in conversations) {
GLib.Application.get_default().withdraw_notification(conversation.id.to_string());
}
active_notification_ids = new HashSet<string>();
active_conversation_ids = new HashSet<string>();
} else {
foreach (string id in active_notification_ids) {
foreach (string id in active_conversation_ids) {
GLib.Application.get_default().withdraw_notification(id);
}
active_notification_ids.clear();
active_conversation_ids.clear();
}
string subscription_id = focused_conversation.id.to_string() + "-subscription";
if (active_ids.contains(subscription_id)) {
GLib.Application.get_default().withdraw_notification(subscription_id);
}
});
SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32);
open_conversation_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation != null) conversation_selected(conversation);
window.present();
});
GLib.Application.get_default().add_action(open_conversation_action);
SimpleAction accept_subscription_action = new SimpleAction("accept-subscription", VariantType.INT32);
accept_subscription_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation == null) return;
stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(conversation.account, conversation.counterpart);
if (stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(conversation.account, conversation.counterpart) == null) {
AddContactDialog dialog = new AddContactDialog(stream_interactor);
dialog.jid = conversation.counterpart.bare_jid.to_string();
dialog.account = conversation.account;
dialog.present();
}
});
GLib.Application.get_default().add_action(accept_subscription_action);
SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32);
deny_subscription_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
if (conversation == null) return;
stream_interactor.get_module(PresenceManager.IDENTITY).deny_subscription(conversation.account, conversation.counterpart);
});
GLib.Application.get_default().add_action(deny_subscription_action);
}
public void start() {
@ -96,21 +65,25 @@ public class Notifications : Object {
notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation)));
} catch (Error e) { }
window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]);
active_notification_ids.add(conversation.id.to_string());
active_conversation_ids.add(conversation.id.to_string());
window.urgency_hint = 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;
Notification notification = new Notification(_("Subscription request"));
notification.set_body(jid.bare_jid.to_string());
try {
notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account)));
} catch (Error e) { }
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
notification.set_default_action_and_target_value("app.open-conversation", new Variant.int32(conversation.id));
notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id);
notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id);
window.get_application().send_notification(null, notification);
window.get_application().send_notification(conversation.id.to_string() + "-subscription", notification);
active_ids.add(conversation.id.to_string() + "-subscription");
}
private bool should_notify_message(Entities.Message message, Conversation conversation) {

View File

@ -82,6 +82,7 @@ namespace Xmpp.Presence {
received_subscription_request(stream, presence.from);
break;
case Presence.Stanza.TYPE_UNSUBSCRIBE:
stream.get_flag(Flag.IDENTITY).remove_presence(presence.from);
received_unsubscription(stream, presence.from);
break;
}