From f2f00a4fdcbee2543ba4621faa86b24d53153f14 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Thu, 28 Feb 2013 00:26:05 +0100 Subject: [PATCH] Move presence changing to JubChatClient --- src/core/JubChatClient.h | 3 +++ src/core/JubChatClient.m | 26 ++++++++++++++++++++++++++ src/gui/cli/JubCLIUI.m | 22 +++++++--------------- src/gui/gtk/JubGtkRosterUI.m | 16 +++------------- 4 files changed, 39 insertions(+), 28 deletions(-) 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) { -- 2.39.2