]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Close subscription dialogs, when answered on another client
authorFlorian Zeitz <florob@babelmonkeys.de>
Mon, 10 Jun 2013 16:14:19 +0000 (18:14 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Mon, 10 Jun 2013 16:14:19 +0000 (18:14 +0200)
src/core/JubAvatarManager.m
src/gui/gtk/JubGtkRosterUI.h
src/gui/gtk/JubGtkRosterUI.m

index 7d2fe8fb97c6ebb83cd0004c2e3f6c015c5f1773..048af0e182f69ac90222bf6a0335bd872baa6db7 100644 (file)
@@ -52,7 +52,7 @@
 }
 
 - (void)connection: (XMPPConnection*)connection
     didReceiveMessage: (XMPPMessage*)message
+ didReceiveMessage: (XMPPMessage*)message
 {
        OFXMLElement *event = [message elementForName: @"event"
                                            namespace: JUB_NS_PUBSUB_EVENT];
index 9769c761ea4f47c972674af4fd82ddf77ae51bb6..0fc8e2d43e0a25fe835aed68878b9b7defe06fe2 100644 (file)
@@ -16,6 +16,7 @@
        GtkComboBox *_presence_combo;
        gulong _presence_combo_changed_handler_id;
        OFMapTable *_groupMap;
+       OFMapTable *_subDialogMap;
        OFMutableDictionary *_contactMap;
        JubChatClient *_client;
 }
index dcd6f7d8b42553d6e50049a3ea1a39739f366417..e7e36f723a86fa53a1ca67ca533e3dbcd12e9abd 100644 (file)
@@ -69,7 +69,6 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
        void (^block)(gint) = user_data;
        block(response_id);
        [block release];
-       gtk_widget_destroy(GTK_WIDGET(dialog));
 }
 
 @implementation JubGtkRosterUI
@@ -84,6 +83,9 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
                _groupMap = [[OFMapTable alloc]
                    initWithKeyFunctions: keyFunctions
                          valueFunctions: rowRefFunctions];
+               _subDialogMap = [[OFMapTable alloc]
+                   initWithKeyFunctions: keyFunctions
+                   valueFunctions: gObjectFunctions];
                _contactMap = [[OFMutableDictionary alloc] init];
                _client = [client retain];
 
@@ -134,6 +136,7 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
 {
        [_client.avatarManager setDelegate: nil];
        [_client.contactManager removeDelegate: self];
+       [_subDialogMap release];
        [_groupMap release];
        [_contactMap release];
        [_client release];
@@ -143,6 +146,19 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
        [super dealloc];
 }
 
+- (void)Jub_closeSubscribeDialogForRosterItem: (XMPPRosterItem*)rosterItem
+{
+       // Close subscripton dialogs, answered on another client
+       GtkDialog *dialog;
+       OFString *subscription = rosterItem.subscription;
+       OFString *bareJID = [rosterItem.JID bareJID];
+
+       if (([subscription isEqual: @"from"] ||
+            [subscription isEqual: @"both"]) &&
+           (dialog = [_subDialogMap valueForKey: bareJID]) != NULL)
+               gtk_dialog_response(dialog, GTK_RESPONSE_NONE);
+}
+
 /* Roster Delegate methods */
 - (void)Jub_addRosterItem: (XMPPRosterItem*)item
                    group: (OFString*)group
@@ -266,6 +282,8 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
                    Jub_addRosterItem:group:)
                                       withObject: rosterItem
                                       withObject: group];
+
+       [self Jub_closeSubscribeDialogForRosterItem: rosterItem];
 }
 
 - (void)contactManager: (XMPPContactManager*)manager
@@ -288,11 +306,15 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
   didReceiveSubscriptionRequest: (XMPPPresence*)presence
 {
        XMPPJID *JID = presence.from;
+       OFString *bareJID = [JID bareJID];
        OFString *message = [OFString stringWithFormat: @"<b>%@</b> would like "
-           @"to subscribe to your presence.", JID];
-       of_log(@"%@", message);
+           @"to subscribe to your presence.", bareJID];
        g_idle_add_block(^{
                GtkWidget *dialog, *content_area, *label;
+
+               if ([_subDialogMap valueForKey: JID] != NULL)
+                       return;
+
                dialog = gtk_dialog_new_with_buttons("Subscription Request",
                    GTK_WINDOW(_roster_window), GTK_DIALOG_DESTROY_WITH_PARENT,
                    "Accept", GTK_RESPONSE_ACCEPT,
@@ -301,6 +323,7 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
                content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
                label = gtk_label_new(NULL);
                gtk_label_set_markup(GTK_LABEL(label), [message UTF8String]);
+               gtk_container_add(GTK_CONTAINER(content_area), label);
 
                g_signal_connect(dialog, "response",
                    G_CALLBACK(dialog_response_callback),
@@ -309,9 +332,13 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
                                [manager sendSubscribedToJID: JID];
                        else if (response_id == GTK_RESPONSE_REJECT)
                                [manager sendUnsubscribedToJID: JID];
+                       [_subDialogMap removeValueForKey: bareJID];
+                       gtk_widget_destroy(GTK_WIDGET(dialog));
                } copy]);
 
-               gtk_container_add(GTK_CONTAINER(content_area), label);
+               [_subDialogMap setValue: dialog
+                                forKey: bareJID];
+
                gtk_widget_show_all(dialog);
        });
 }
@@ -319,6 +346,8 @@ static void dialog_response_callback(GtkDialog *dialog, gint response_id,
 -           (void)contact: (XMPPContact*)contact
   willUpdateWithRosterItem: (XMPPRosterItem*)rosterItem;
 {
+       [self Jub_closeSubscribeDialogForRosterItem: rosterItem];
+
        // Remove contact from old set of groups
        XMPPRosterItem *oldItem = contact.rosterItem;
        OFArray *groups = oldItem.groups;