]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/gui/gtk/JubGtkRosterUI.m
Move chat window creation to JubChatClient
[jubjub.git] / src / gui / gtk / JubGtkRosterUI.m
index 4102e3432e3cf0307ffb90c9ff4908a613b1d4a2..e474bf9bc2438b946860a277f5e477960a27ea73 100644 (file)
@@ -9,12 +9,13 @@
 static void roster_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
     GtkTreeViewColumn *column, gpointer data)
 {
-       JubGtkRosterUI *roster = data;
+       OFAutoreleasePool *pool;
+       XMPPContact *contact;
+       JubChatClient *client = data;
        GtkTreeIter row_iter;
        GtkTreeModel *tree_model;
        gchar *jid_s;
-       XMPPJID *jid;
-       OFAutoreleasePool *pool;
+       OFString *jid;
 
        tree_model = gtk_tree_view_get_model(tree_view);
        gtk_tree_model_get_iter(tree_model, &row_iter, path);
@@ -24,10 +25,12 @@ static void roster_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
        if (!jid_s) return;
 
        pool = [OFAutoreleasePool new];
-       jid = [XMPPJID JIDWithString: [OFString stringWithUTF8String: jid_s]];
 
-       [roster performSelectorOnMainThread: @selector(chatForJID:)
-                                withObject: jid
+       jid = [OFString stringWithUTF8String: jid_s];
+       contact = [client.contactManager.contacts objectForKey: jid];
+
+       [client performSelectorOnMainThread: @selector(chatForContact:)
+                                withObject: contact
                              waitUntilDone: NO];
        [pool release];
 }
@@ -82,7 +85,6 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
                    initWithKeyFunctions: keyFunctions
                          valueFunctions: rowRefFunctions];
                contactMap = [[OFMutableDictionary alloc] init];
-               chatMap = [[OFMutableDictionary alloc] init];
                client = [client_ retain];
 
                [client.contactManager addDelegate: self];
@@ -109,7 +111,7 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
                        "RosterTreeView"));
 
                g_signal_connect(roster_view, "row_activated",
-                   G_CALLBACK(roster_row_activated), self);
+                   G_CALLBACK(roster_row_activated), client);
 
                presence_combo = GTK_COMBO_BOX(gtk_builder_get_object(builder,
                        "PresenceComboBox"));
@@ -132,7 +134,6 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
        [client.contactManager removeDelegate: self];
        [groupMap release];
        [contactMap release];
-       [chatMap release];
        [client release];
 
        gtk_widget_destroy(roster_window);
@@ -140,46 +141,13 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
        [super dealloc];
 }
 
-// FIXME: This needs to move somewhere else
-- (JubGtkChatUI*)chatForJID: (XMPPJID*)jid
-{
-       OFAutoreleasePool *pool = [OFAutoreleasePool new];
-       JubGtkChatUI *chat =
-           [chatMap objectForKey: [jid bareJID]];
-       if (chat == nil) {
-               OFString * title = [@"Chat with " stringByAppendingString:
-                   [jid bareJID]];
-
-               chat = [[[JubGtkChatUI alloc]
-                   initWithTitle: title
-                      closeBlock: ^{
-                               [chatMap removeObjectForKey: [jid bareJID]];
-                       }
-                       sendBlock: ^(OFString *text) {
-                               XMPPMessage *msg =
-                                   [XMPPMessage messageWithType: @"chat"];
-                               msg.to = jid;
-                               msg.body = text;
-                               [client.connection sendStanza: msg];
-                       }
-               ] autorelease];
-
-               [chatMap setObject: chat
-                           forKey: [jid bareJID]];
-       }
-
-       [pool release];
-
-       return chat;
-}
-
 -  (void)contact: (XMPPContact*)contact
   didSendMessage: (XMPPMessage*)message
 {
        if (message.body == nil || ![message.type isEqual: @"chat"])
                return;
 
-       JubGtkChatUI *chat = [self chatForJID: message.from];
+       id<JubChatUI> chat = [client chatForContact: contact];
        [chat addMessage: message.body
                  sender: [message.from bareJID]];
 }