]> cgit.babelmonkeys.de Git - jubjub.git/commitdiff
Move presence changing to JubChatClient
authorFlorian Zeitz <florob@babelmonkeys.de>
Wed, 27 Feb 2013 23:26:05 +0000 (00:26 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Wed, 27 Feb 2013 23:26:05 +0000 (00:26 +0100)
src/core/JubChatClient.h
src/core/JubChatClient.m
src/gui/cli/JubCLIUI.m
src/gui/gtk/JubGtkRosterUI.m

index 95bda4296d989aa396cadfd46d8c24bf4f90189b..cacb72dcf2aae0721340362168e60a2e1046d1c4 100644 (file)
@@ -24,4 +24,7 @@
 
 - initWithConfig: (JubConfig*)config;
 - (id<JubChatUI>)chatForContact: (XMPPContact*)contact;
+- (void)sendPresenceWithStatus: (OFString*)status;
+- (void)sendPresenceWithStatus: (OFString*)status
+                         text: (OFString*)text;
 @end
index b46c14cf8fa3def40723d60a671770961a1e437f..eea1b8a98fd0af6df0e898a3e951c850cd102d8a 100644 (file)
        return chat;
 }
 
+- (void)sendPresenceWithStatus: (OFString*)status
+{
+       [self sendPresenceWithStatus: status
+                               text: nil];
+}
+
+- (void)sendPresenceWithStatus: (OFString*)status
+                         text: (OFString*)text
+{
+       XMPPPresence *presence;
+
+       if ([status isEqual: @"unavailable"])
+               presence = [XMPPPresence presenceWithType: @"unavailable"];
+       else
+               presence = [XMPPPresence presence];
+
+       if (!([status isEqual: @"available"] ||
+             [status isEqual: @"unavailable"]))
+               presence.show = status;
+
+       if (text != nil)
+               presence.status = text;
+
+       [_connection sendStanza: presence];
+}
+
 - (void)connection: (XMPPConnection*)connection
      wasBoundToJID: (XMPPJID*)jid
 {
index e44a3f31fc621387e04d9d705afd7c0844c58c25..16083c04c120761d9a82b6a5438f6d06dab88e11 100644 (file)
@@ -77,34 +77,26 @@ BEGINCLICOMMAND(JubCLIPresenceCommand, @":t", @"<status> [<message>]",
                return;
        }
 
-       XMPPPresence *presence;
        OFString *show = parameters[0];
 
        if (![@[ @"available", @"away", @"dnd", @"xa", @"chat", @"unavailable" ]
            containsObject: show]) {
-               [of_stdout writeLine: @"<status> must be one of:"
+               [of_stdout writeLine: @"<status> must be one of: "
                    @"available, away, dnd, xa, chat, unavailable"];
                return;
        }
 
-       if ([show isEqual: @"unavailable"])
-               presence = [XMPPPresence presenceWithType: show];
-       else
-               presence = [XMPPPresence presence];
-
-       if (![@[ @"available", @"unavailable" ] containsObject: show])
-               presence.show = show;
-
        if ([parameters count] == 2) {
-               [_ui.client.connection sendStanza: presence];
+               [_ui.client sendPresenceWithStatus: show];
                return;
        }
 
-       OFArray *message =
-           [parameters arrayByRemovingObject: [parameters firstObject]];
-       presence.status = [message componentsJoinedByString: @" "];
+       OFString *message = [[parameters
+           arrayByRemovingObject: [parameters firstObject]]
+               componentsJoinedByString: @" "];
 
-       [_ui.client.connection sendStanza: presence];
+       [_ui.client sendPresenceWithStatus: show
+                                     text: message];
 }
 ENDCLICOMMAND
 
index ac74a33aae1e44f23041bb4cf49886a4112a9691..c18f0074044b1dbd405d151981c78c88ef1e0fe9 100644 (file)
@@ -37,21 +37,11 @@ static void roster_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
 
 static void presence_changed(GtkComboBox *combo_box, gpointer data)
 {
-       XMPPPresence *pres;
-       XMPPConnection *connection = data;
+       JubChatClient *client = data;
        OFAutoreleasePool *pool = [OFAutoreleasePool new];
-
        const char *status = gtk_combo_box_get_active_id(combo_box);
 
-       if (!strcmp(status, "unavailable"))
-               pres = [XMPPPresence presenceWithType: @"unavailable"];
-       else {
-               pres = [XMPPPresence presence];
-               if (strcmp(status, "available"))
-                       [pres setShow: @(status)];
-       }
-
-       [connection sendStanza: pres];
+       [client sendPresenceWithStatus: @(status)];
 
        [pool release];
 }
@@ -118,7 +108,7 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
 
                _presence_combo_changed_handler_id =
                    g_signal_connect(_presence_combo, "changed",
-                       G_CALLBACK(presence_changed), client.connection);
+                       G_CALLBACK(presence_changed), client);
 
                g_object_unref(G_OBJECT(builder));
        } @catch (id e) {