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; jabber_conn.presence = status;
xmpp_stanza_t *pres, *show; char *show = NULL;
switch(status)
pres = xmpp_stanza_new(jabber_conn.ctx); {
xmpp_stanza_set_name(pres, STANZA_NAME_PRESENCE); case PRESENCE_AWAY:
show = STANZA_TEXT_AWAY;
if (status != PRESENCE_ONLINE) { break;
show = xmpp_stanza_new(jabber_conn.ctx); case PRESENCE_DND:
xmpp_stanza_set_name(show, STANZA_NAME_SHOW); show = STANZA_TEXT_DND;
xmpp_stanza_t *text = xmpp_stanza_new(jabber_conn.ctx); break;
case PRESENCE_CHAT:
if (status == PRESENCE_AWAY) show = STANZA_TEXT_CHAT;
xmpp_stanza_set_text(text, STANZA_TEXT_AWAY); break;
else if (status == PRESENCE_DND) case PRESENCE_XA:
xmpp_stanza_set_text(text, STANZA_TEXT_DND); show = STANZA_TEXT_XA;
else if (status == PRESENCE_CHAT) break;
xmpp_stanza_set_text(text, STANZA_TEXT_CHAT); default:
else if (status == PRESENCE_XA) show = STANZA_TEXT_ONLINE;
xmpp_stanza_set_text(text, STANZA_TEXT_XA); break;
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);
} }
if (msg != NULL) { xmpp_stanza_t *presence = stanza_create_presence(jabber_conn.ctx, show, msg);
xmpp_stanza_t *status = xmpp_stanza_new(jabber_conn.ctx); xmpp_send(jabber_conn.conn, presence);
xmpp_stanza_set_name(status, STANZA_NAME_STATUS); xmpp_stanza_release(presence);
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);
} }
jabber_conn_status_t jabber_conn_status_t

View File

@ -20,6 +20,8 @@
* *
*/ */
#include <string.h>
#include <strophe.h> #include <strophe.h>
#include "common.h" #include "common.h"
@ -116,3 +118,35 @@ stanza_create_room_leave(xmpp_ctx_t *ctx, const char * const room,
return presence; 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, xmpp_stanza_t* stanza_create_room_leave(xmpp_ctx_t *ctx,
const char * const room, const char * const nick); 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 #endif