From: Florian Zeitz Date: Wed, 27 Feb 2013 23:26:05 +0000 (+0100) Subject: Move presence changing to JubChatClient X-Git-Url: https://cgit.babelmonkeys.de/?a=commitdiff_plain;h=f2f00a4fdcbee2543ba4621faa86b24d53153f14;p=jubjub.git Move presence changing to JubChatClient --- diff --git a/src/core/JubChatClient.h b/src/core/JubChatClient.h index 95bda42..cacb72d 100644 --- a/src/core/JubChatClient.h +++ b/src/core/JubChatClient.h @@ -24,4 +24,7 @@ - initWithConfig: (JubConfig*)config; - (id)chatForContact: (XMPPContact*)contact; +- (void)sendPresenceWithStatus: (OFString*)status; +- (void)sendPresenceWithStatus: (OFString*)status + text: (OFString*)text; @end diff --git a/src/core/JubChatClient.m b/src/core/JubChatClient.m index b46c14c..eea1b8a 100644 --- a/src/core/JubChatClient.m +++ b/src/core/JubChatClient.m @@ -88,6 +88,32 @@ 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 { diff --git a/src/gui/cli/JubCLIUI.m b/src/gui/cli/JubCLIUI.m index e44a3f3..16083c0 100644 --- a/src/gui/cli/JubCLIUI.m +++ b/src/gui/cli/JubCLIUI.m @@ -77,34 +77,26 @@ BEGINCLICOMMAND(JubCLIPresenceCommand, @":t", @" []", return; } - XMPPPresence *presence; OFString *show = parameters[0]; if (![@[ @"available", @"away", @"dnd", @"xa", @"chat", @"unavailable" ] containsObject: show]) { - [of_stdout writeLine: @" must be one of:" + [of_stdout writeLine: @" 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 diff --git a/src/gui/gtk/JubGtkRosterUI.m b/src/gui/gtk/JubGtkRosterUI.m index ac74a33..c18f007 100644 --- a/src/gui/gtk/JubGtkRosterUI.m +++ b/src/gui/gtk/JubGtkRosterUI.m @@ -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) {