1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Moved update presence handler creation to stanza module

This commit is contained in:
James Booth 2012-11-10 00:16:56 +00:00
parent ca75c1c231
commit 34c21c0a2e
3 changed files with 59 additions and 40 deletions

View File

@ -260,48 +260,29 @@ jabber_update_presence(jabber_presence_t status, const char * const msg)
{
jabber_conn.presence = status;
xmpp_stanza_t *pres, *show;
pres = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(pres, STANZA_NAME_PRESENCE);
if (status != PRESENCE_ONLINE) {
show = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(show, STANZA_NAME_SHOW);
xmpp_stanza_t *text = xmpp_stanza_new(jabber_conn.ctx);
if (status == PRESENCE_AWAY)
xmpp_stanza_set_text(text, STANZA_TEXT_AWAY);
else if (status == PRESENCE_DND)
xmpp_stanza_set_text(text, STANZA_TEXT_DND);
else if (status == PRESENCE_CHAT)
xmpp_stanza_set_text(text, STANZA_TEXT_CHAT);
else if (status == PRESENCE_XA)
xmpp_stanza_set_text(text, STANZA_TEXT_XA);
else
xmpp_stanza_set_text(text, STANZA_TEXT_ONLINE);
xmpp_stanza_add_child(show, text);
xmpp_stanza_add_child(pres, show);
xmpp_stanza_release(text);
xmpp_stanza_release(show);
char *show = NULL;
switch(status)
{
case PRESENCE_AWAY:
show = STANZA_TEXT_AWAY;
break;
case PRESENCE_DND:
show = STANZA_TEXT_DND;
break;
case PRESENCE_CHAT:
show = STANZA_TEXT_CHAT;
break;
case PRESENCE_XA:
show = STANZA_TEXT_XA;
break;
default:
show = STANZA_TEXT_ONLINE;
break;
}
if (msg != NULL) {
xmpp_stanza_t *status = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(status, STANZA_NAME_STATUS);
xmpp_stanza_t *text = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_text(text, msg);
xmpp_stanza_add_child(status, text);
xmpp_stanza_add_child(pres, status);
xmpp_stanza_release(text);
xmpp_stanza_release(status);
}
xmpp_send(jabber_conn.conn, pres);
xmpp_stanza_release(pres);
xmpp_stanza_t *presence = stanza_create_presence(jabber_conn.ctx, show, msg);
xmpp_send(jabber_conn.conn, presence);
xmpp_stanza_release(presence);
}
jabber_conn_status_t

View File

@ -20,6 +20,8 @@
*
*/
#include <string.h>
#include <strophe.h>
#include "common.h"
@ -116,3 +118,35 @@ stanza_create_room_leave(xmpp_ctx_t *ctx, const char * const room,
return presence;
}
xmpp_stanza_t *
stanza_create_presence(xmpp_ctx_t *ctx, const char * const show,
const char * const status)
{
xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
if (strcmp(show, STANZA_TEXT_ONLINE) != 0) {
xmpp_stanza_t *show_stanza = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(show_stanza, STANZA_NAME_SHOW);
xmpp_stanza_t *text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(text, show);
xmpp_stanza_add_child(show_stanza, text);
xmpp_stanza_add_child(presence, show_stanza);
xmpp_stanza_release(text);
xmpp_stanza_release(show_stanza);
}
if (status != NULL) {
xmpp_stanza_t *status_stanza = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(status_stanza, STANZA_NAME_STATUS);
xmpp_stanza_t *text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(text, status);
xmpp_stanza_add_child(status_stanza, text);
xmpp_stanza_add_child(presence, status_stanza);
xmpp_stanza_release(text);
xmpp_stanza_release(status_stanza);
}
return presence;
}

View File

@ -81,4 +81,8 @@ xmpp_stanza_t* stanza_create_room_presence(xmpp_ctx_t *ctx,
xmpp_stanza_t* stanza_create_room_leave(xmpp_ctx_t *ctx,
const char * const room, const char * const nick);
xmpp_stanza_t *
stanza_create_presence(xmpp_ctx_t *ctx, const char * const show,
const char * const status);
#endif