diff options
author | fiaxh <git@lightrise.org> | 2019-08-22 16:05:28 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-08-22 16:05:28 +0200 |
commit | 130965f322ea58d3d2bbce5ee6ac31dae2d3a659 (patch) | |
tree | 1ece66670d82eac674ee82ebe84a7ca487047d69 | |
parent | 0521afa3d828ea0dfc79e6c5c76697e2a3a270c0 (diff) | |
download | dino-130965f322ea58d3d2bbce5ee6ac31dae2d3a659.tar.gz dino-130965f322ea58d3d2bbce5ee6ac31dae2d3a659.zip |
Add incoming mediated invitation support (#162)
Co-authored-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
-rw-r--r-- | libdino/src/service/muc_manager.vala | 4 | ||||
-rw-r--r-- | libdino/src/service/notification_events.vala | 4 | ||||
-rw-r--r-- | main/src/ui/application.vala | 49 | ||||
-rw-r--r-- | main/src/ui/notifications.vala | 18 | ||||
-rw-r--r-- | xmpp-vala/src/module/message/module.vala | 4 | ||||
-rw-r--r-- | xmpp-vala/src/module/util.vala | 5 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0045_muc/module.vala | 48 | ||||
-rw-r--r-- | xmpp-vala/src/module/xep/0363_http_file_upload.vala | 2 |
8 files changed, 112 insertions, 22 deletions
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 21d11f5d..392339c1 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -15,6 +15,7 @@ public class MucManager : StreamInteractionModule, Object { public signal void room_name_set(Account account, Jid jid, string? room_name); public signal void private_room_occupant_updated(Account account, Jid room, Jid occupant); public signal void bookmarks_updated(Account account, Gee.List<Xep.Bookmarks.Conference> conferences); + public signal void invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason); private StreamInteractor stream_interactor; private HashMap<Jid, Xep.Muc.MucEnterError> enter_errors = new HashMap<Jid, Xep.Muc.MucEnterError>(Jid.hash_func, Jid.equals_func); @@ -264,6 +265,9 @@ public class MucManager : StreamInteractionModule, Object { stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).subject_set.connect( (stream, subject, jid) => { subject_set(account, jid, subject); }); + stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).invite_received.connect( (stream, room_jid, from_jid, password, reason) => { + invite_received(account, room_jid, from_jid, password, reason); + }); stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_name_set.connect( (stream, jid, room_name) => { room_name_set(account, jid, room_name); }); diff --git a/libdino/src/service/notification_events.vala b/libdino/src/service/notification_events.vala index 1beeb4ed..f47b9a0a 100644 --- a/libdino/src/service/notification_events.vala +++ b/libdino/src/service/notification_events.vala @@ -12,6 +12,7 @@ public class NotificationEvents : StreamInteractionModule, Object { public signal void notify_content_item(ContentItem content_item, Conversation conversation); public signal void notify_subscription_request(Conversation conversation); public signal void notify_connection_error(Account account, ConnectionManager.ConnectionError error); + public signal void notify_muc_invite(Account account, Jid room_jid, Jid from_jid, string? password, string? reason); private StreamInteractor stream_interactor; @@ -28,6 +29,8 @@ public class NotificationEvents : StreamInteractionModule, Object { stream_interactor.get_module(ContentItemStore.IDENTITY).new_item.connect(on_content_item_received); stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); + stream_interactor.get_module(MucManager.IDENTITY).invite_received.connect((account, room_jid, from_jid, password, reason) => notify_muc_invite(account, room_jid, from_jid, password, reason)); + stream_interactor.connection_manager.connection_error.connect((account, error) => notify_connection_error(account, error)); stream_interactor.get_module(MessageProcessor.IDENTITY).history_synced.connect((account) => { synced_accounts.add(account); if (!mam_potential_new.has_key(account)) return; @@ -40,7 +43,6 @@ public class NotificationEvents : StreamInteractionModule, Object { } mam_potential_new[account].clear(); }); - stream_interactor.connection_manager.connection_error.connect((account, error) => notify_connection_error(account, error)); } private void on_content_item_received(ContentItem item, Conversation conversation) { diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index 57ebe11a..d5ec0170 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -44,23 +44,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { public void handle_uri(string jid, string query, Gee.Map<string, string> options) { switch (query) { case "join": - Dialog dialog = new Dialog.with_buttons(_("Join Conference"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL); - dialog.modal = true; - Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button; - ok_button.get_style_context().add_class("suggested-action"); - ConferenceDetailsFragment conference_fragment = new ConferenceDetailsFragment(stream_interactor) { ok_button=ok_button }; - conference_fragment.jid = jid; - Box content_area = dialog.get_content_area(); - content_area.add(conference_fragment); - dialog.response.connect((response_id) => { - if (response_id == ResponseType.OK) { - stream_interactor.get_module(MucManager.IDENTITY).join(conference_fragment.account, new Jid(conference_fragment.jid), conference_fragment.nick, conference_fragment.password); - dialog.destroy(); - } else if (response_id == ResponseType.CANCEL) { - dialog.destroy(); - } - }); - dialog.present(); + show_join_muc_dialog(null, new Jid(jid)); break; case "message": Gee.List<Account> accounts = stream_interactor.get_accounts(); @@ -133,6 +117,14 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { add_action(conference_action); set_accels_for_action("app.add_conference", new string[]{"<Ctrl>G"}); + SimpleAction accept_muc_invite_action = new SimpleAction("open-muc-join", VariantType.INT32); + accept_muc_invite_action.activate.connect((variant) => { + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); + if (conversation == null) return; + show_join_muc_dialog(conversation.account, conversation.counterpart); + }); + add_action(accept_muc_invite_action); + SimpleAction loop_conversations_action = new SimpleAction("loop_conversations", null); loop_conversations_action.activate.connect(() => { window.loop_conversations(false); }); add_action(loop_conversations_action); @@ -161,5 +153,28 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { dialog.set_transient_for(get_active_window()); dialog.present(); } + + private void show_join_muc_dialog(Account? account, Jid jid) { + Dialog dialog = new Dialog.with_buttons(_("Join Conference"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL); + dialog.modal = true; + Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button; + ok_button.get_style_context().add_class("suggested-action"); + ConferenceDetailsFragment conference_fragment = new ConferenceDetailsFragment(stream_interactor) { ok_button=ok_button }; + conference_fragment.jid = jid.to_string(); + if (account != null) { + conference_fragment.account = account; + } + Box content_area = dialog.get_content_area(); + content_area.add(conference_fragment); + dialog.response.connect((response_id) => { + if (response_id == ResponseType.OK) { + stream_interactor.get_module(MucManager.IDENTITY).join(conference_fragment.account, new Jid(conference_fragment.jid), conference_fragment.nick, conference_fragment.password); + dialog.destroy(); + } else if (response_id == ResponseType.CANCEL) { + dialog.destroy(); + } + }); + dialog.present(); + } } diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 78e8f47e..b8792bee 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -44,6 +44,7 @@ public class Notifications : Object { stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect((content_item, conversation) => notify_content_item.begin(content_item, conversation)); stream_interactor.get_module(NotificationEvents.IDENTITY).notify_subscription_request.connect(notify_subscription_request); stream_interactor.get_module(NotificationEvents.IDENTITY).notify_connection_error.connect(notify_connection_error); + stream_interactor.get_module(NotificationEvents.IDENTITY).notify_muc_invite.connect(on_invite_received); } private async void notify_content_item(ContentItem content_item, Conversation conversation) { @@ -117,6 +118,23 @@ public class Notifications : Object { window.get_application().send_notification(account.id.to_string() + "-connection-error", notification); } + private async void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) { + string display_name = Util.get_display_name(stream_interactor, from_jid, account); + string display_room = room_jid.bare_jid.to_string(); + Notification notification = new Notification(_("Invitation to %s").printf(display_room)); + string body = _("%s invited you to %s").printf(display_name, display_room); + notification.set_body(body); + + Cairo.ImageSurface jid_avatar = yield (new AvatarGenerator(40, 40)).draw_jid(stream_interactor, from_jid, account); + notification.set_icon(get_pixbuf_icon(jid_avatar)); + + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(room_jid, account, Conversation.Type.GROUPCHAT); + notification.set_default_action_and_target_value("app.open-muc-join", new Variant.int32(conversation.id)); + notification.add_button_with_target_value(_("Deny"), "app.deny-invite", conversation.id); + notification.add_button_with_target_value(_("Accept"), "app.open-muc-join", conversation.id); + window.get_application().send_notification(null, notification); + } + private Icon get_pixbuf_icon(Cairo.ImageSurface surface) throws Error { Gdk.Pixbuf avatar = Gdk.pixbuf_get_from_surface(surface, 0, 0, surface.get_width(), surface.get_height()); uint8[] buffer; diff --git a/xmpp-vala/src/module/message/module.vala b/xmpp-vala/src/module/message/module.vala index 6db2dcb5..ab3a7d80 100644 --- a/xmpp-vala/src/module/message/module.vala +++ b/xmpp-vala/src/module/message/module.vala @@ -22,7 +22,9 @@ namespace Xmpp { public async void received_message_stanza_async(XmppStream stream, StanzaNode node) { MessageStanza message = new MessageStanza.from_stanza(node, stream.get_flag(Bind.Flag.IDENTITY).my_jid); if (!message.is_error()) { - yield received_pipeline.run(stream, message); + bool abort = yield received_pipeline.run(stream, message); + if (abort) return; + received_message(stream, message); } } diff --git a/xmpp-vala/src/module/util.vala b/xmpp-vala/src/module/util.vala index cb11418c..28f1a5f8 100644 --- a/xmpp-vala/src/module/util.vala +++ b/xmpp-vala/src/module/util.vala @@ -19,7 +19,7 @@ public abstract class StanzaListener<T> : OrderedListener { public class StanzaListenerHolder<T> : ListenerHolder { - public async void run(XmppStream stream, T stanza) { + public async bool run(XmppStream stream, T stanza) { // listeners can change e.g. when switching to another stream ArrayList<OrderedListener> listeners_copy = new ArrayList<OrderedListener>(); @@ -28,8 +28,9 @@ public class StanzaListenerHolder<T> : ListenerHolder { foreach (OrderedListener ol in listeners_copy) { StanzaListener<T> l = ol as StanzaListener<T>; bool stop = yield l.run(stream, stanza); - if (stop) break; + if (stop) return true; } + return false; } } diff --git a/xmpp-vala/src/module/xep/0045_muc/module.vala b/xmpp-vala/src/module/xep/0045_muc/module.vala index 7b136d8c..db7a299f 100644 --- a/xmpp-vala/src/module/xep/0045_muc/module.vala +++ b/xmpp-vala/src/module/xep/0045_muc/module.vala @@ -61,12 +61,19 @@ public class Module : XmppStreamModule { public signal void received_occupant_role(XmppStream stream, Jid jid, Role? role); public signal void subject_set(XmppStream stream, string? subject, Jid jid); public signal void room_name_set(XmppStream stream, Jid jid, string? room_name); + public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason); public signal void room_entered(XmppStream stream, Jid jid, string nick); public signal void room_enter_error(XmppStream stream, Jid jid, MucEnterError? error); // TODO "?" shoudln't be necessary (vala bug), remove someday public signal void self_removed_from_room(XmppStream stream, Jid jid, StatusCode code); public signal void removed_from_room(XmppStream stream, Jid jid, StatusCode? code); + private ReceivedPipelineListener received_pipeline_listener; + + public Module() { + received_pipeline_listener = new ReceivedPipelineListener(this); + } + public void enter(XmppStream stream, Jid bare_jid, string nick, string? password, DateTime? history_since) { Presence.Stanza presence = new Presence.Stanza(); presence.to = bare_jid.with_resource(nick); @@ -175,6 +182,7 @@ public class Module : XmppStreamModule { public override void attach(XmppStream stream) { stream.add_flag(new Flag()); stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message); + stream.get_module(MessageModule.IDENTITY).received_pipeline.connect(received_pipeline_listener); stream.get_module(Presence.Module.IDENTITY).received_presence.connect(check_for_enter_error); stream.get_module(Presence.Module.IDENTITY).received_available.connect(on_received_available); stream.get_module(Presence.Module.IDENTITY).received_unavailable.connect(on_received_unavailable); @@ -191,6 +199,7 @@ public class Module : XmppStreamModule { public override void detach(XmppStream stream) { stream.get_module(MessageModule.IDENTITY).received_message.disconnect(on_received_message); + stream.get_module(MessageModule.IDENTITY).received_pipeline.disconnect(received_pipeline_listener); stream.get_module(Presence.Module.IDENTITY).received_presence.disconnect(check_for_enter_error); stream.get_module(Presence.Module.IDENTITY).received_available.disconnect(on_received_available); stream.get_module(Presence.Module.IDENTITY).received_unavailable.disconnect(on_received_unavailable); @@ -429,4 +438,43 @@ public class Module : XmppStreamModule { } } +public class ReceivedPipelineListener : StanzaListener<MessageStanza> { + + private const string[] after_actions_const = {"EXTRACT_MESSAGE_2"}; + + public override string action_group { get { return ""; } } + public override string[] after_actions { get { return after_actions_const; } } + + Module outer; + + public ReceivedPipelineListener(Module outer) { + this.outer = outer; + } + + public override async bool run(XmppStream stream, MessageStanza message) { + if (message.type_ == MessageStanza.TYPE_NORMAL) { + StanzaNode? x_node = message.stanza.get_subnode("x", NS_URI_USER); + if (x_node != null) { + StanzaNode? invite_node = x_node.get_subnode("invite", NS_URI_USER); + string? password = null; + StanzaNode? password_node = x_node.get_subnode("password", NS_URI_USER); + if (password_node != null) + password = password_node.get_string_content(); + if (invite_node != null) { + string? from_jid = invite_node.get_attribute("from"); + if (from_jid != null) { + StanzaNode? reason_node = invite_node.get_subnode("reason", NS_URI_USER); + string? reason = null; + if (reason_node != null) + reason = reason_node.get_string_content(); + outer.invite_received(stream, message.from, new Jid(from_jid), password, reason); + return true; + } + } + } + } + return false; + } +} + } diff --git a/xmpp-vala/src/module/xep/0363_http_file_upload.vala b/xmpp-vala/src/module/xep/0363_http_file_upload.vala index 822ddc6b..8829ad15 100644 --- a/xmpp-vala/src/module/xep/0363_http_file_upload.vala +++ b/xmpp-vala/src/module/xep/0363_http_file_upload.vala @@ -166,7 +166,7 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> { if (oob_url != null && oob_url == message.body) { stream.get_module(Module.IDENTITY).received_url(stream, message); } - return true; + return false; } } |