aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/device_notification_populator.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-05-11 09:39:02 -0600
committerfiaxh <git@lightrise.org>2019-07-08 18:46:30 +0200
commit837de4063dbe398735a5b1d35bde1821c177b555 (patch)
tree81c46027a32a9ff14f2c4932260ac97d3574b848 /plugins/omemo/src/device_notification_populator.vala
parent701175fcd3b39aff46f52627af74b4de29363058 (diff)
downloaddino-837de4063dbe398735a5b1d35bde1821c177b555.tar.gz
dino-837de4063dbe398735a5b1d35bde1821c177b555.zip
OMEMO: Move files to fitting subdirectory
Diffstat (limited to 'plugins/omemo/src/device_notification_populator.vala')
-rw-r--r--plugins/omemo/src/device_notification_populator.vala99
1 files changed, 0 insertions, 99 deletions
diff --git a/plugins/omemo/src/device_notification_populator.vala b/plugins/omemo/src/device_notification_populator.vala
deleted file mode 100644
index 5b47611c..00000000
--- a/plugins/omemo/src/device_notification_populator.vala
+++ /dev/null
@@ -1,99 +0,0 @@
-using Dino.Entities;
-using Xmpp;
-using Gtk;
-
-namespace Dino.Plugins.Omemo {
-
-public class DeviceNotificationPopulator : NotificationPopulator, Object {
-
- public string id { get { return "device_notification"; } }
-
- private StreamInteractor? stream_interactor;
- private Plugin plugin;
- private Conversation? current_conversation;
- private NotificationCollection? notification_collection;
- private ConversationNotification notification;
-
- public DeviceNotificationPopulator(Plugin plugin, StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
- this.plugin = plugin;
-
- stream_interactor.account_added.connect(on_account_added);
- }
-
- public bool has_new_devices(Jid jid) {
- int identity_id = plugin.db.identity.get_id(current_conversation.account.id);
- if (identity_id < 0) return false;
- return plugin.db.identity_meta.get_new_devices(identity_id, jid.bare_jid.to_string()).count() > 0;
- }
-
- public void init(Conversation conversation, NotificationCollection notification_collection, Plugins.WidgetType type) {
- current_conversation = conversation;
- this.notification_collection = notification_collection;
- if (has_new_devices(conversation.counterpart) && conversation.type_ == Conversation.Type.CHAT) {
- display_notification();
- }
- }
-
- public void close(Conversation conversation) {
- notification = null;
- }
-
- private void display_notification() {
- if (notification == null) {
- notification = new ConversationNotification(plugin, current_conversation.account, current_conversation.counterpart);
- notification.should_hide.connect(should_hide);
- notification_collection.add_meta_notification(notification);
- }
- }
-
- public void should_hide() {
- if (!has_new_devices(current_conversation.counterpart) && notification != null){
- notification_collection.remove_meta_notification(notification);
- notification = null;
- }
- }
-
- private void on_account_added(Account account) {
- stream_interactor.module_manager.get_module(account, StreamModule.IDENTITY).bundle_fetched.connect_after((jid, device_id, bundle) => {
- if (current_conversation != null && jid.equals(current_conversation.counterpart) && has_new_devices(current_conversation.counterpart)) {
- display_notification();
- }
- });
- }
-}
-
-private class ConversationNotification : MetaConversationNotification {
- private Widget widget;
- private Plugin plugin;
- private Jid jid;
- private Account account;
- public signal void should_hide();
-
- public ConversationNotification(Plugin plugin, Account account, Jid jid) {
- this.plugin = plugin;
- this.jid = jid;
- this.account = account;
-
- Box box = new Box(Orientation.HORIZONTAL, 5) { visible=true };
- Button manage_button = new Button() { label=_("Manage"), visible=true };
- manage_button.clicked.connect(() => {
- manage_button.activate();
- ContactDetailsDialog dialog = new ContactDetailsDialog(plugin, account, jid);
- dialog.set_transient_for((Window) manage_button.get_toplevel());
- dialog.response.connect((response_type) => {
- should_hide();
- });
- dialog.present();
- });
- box.add(new Label(_("This contact has new devices")) { margin_end=10, visible=true });
- box.add(manage_button);
- widget = box;
- }
-
- public override Object? get_widget(WidgetType type) {
- return widget;
- }
-}
-
-}