- initWithConfig: (JubConfig*)config;
- (id<JubChatUI>)chatForContact: (XMPPContact*)contact;
+- (void)sendPresenceWithStatus: (OFString*)status;
+- (void)sendPresenceWithStatus: (OFString*)status
+ text: (OFString*)text;
@end
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
{
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
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];
}
_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) {