Moved functions to xmpp_presence
This commit is contained in:
@@ -25,8 +25,10 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#include "preferences.h"
|
||||
#include "profanity.h"
|
||||
#include "xmpp.h"
|
||||
|
||||
@@ -87,6 +89,151 @@ presence_free_sub_requests(void)
|
||||
g_hash_table_remove_all(sub_requests);
|
||||
}
|
||||
|
||||
void
|
||||
presence_join_room(Jid *jid)
|
||||
{
|
||||
xmpp_ctx_t *ctx = jabber_get_ctx();
|
||||
xmpp_conn_t *conn = jabber_get_conn();
|
||||
xmpp_stanza_t *presence = stanza_create_room_join_presence(ctx, jid->fulljid);
|
||||
xmpp_send(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
muc_join_room(jid->barejid, jid->resourcepart);
|
||||
}
|
||||
|
||||
void
|
||||
presence_change_room_nick(const char * const room, const char * const nick)
|
||||
{
|
||||
xmpp_ctx_t *ctx = jabber_get_ctx();
|
||||
xmpp_conn_t *conn = jabber_get_conn();
|
||||
char *full_room_jid = create_fulljid(room, nick);
|
||||
xmpp_stanza_t *presence = stanza_create_room_newnick_presence(ctx, full_room_jid);
|
||||
xmpp_send(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
free(full_room_jid);
|
||||
}
|
||||
|
||||
void
|
||||
presence_leave_chat_room(const char * const room_jid)
|
||||
{
|
||||
xmpp_ctx_t *ctx = jabber_get_ctx();
|
||||
xmpp_conn_t *conn = jabber_get_conn();
|
||||
char *nick = muc_get_room_nick(room_jid);
|
||||
|
||||
xmpp_stanza_t *presence = stanza_create_room_leave_presence(ctx, room_jid,
|
||||
nick);
|
||||
xmpp_send(conn, presence);
|
||||
xmpp_stanza_release(presence);
|
||||
}
|
||||
|
||||
void
|
||||
presence_update(jabber_presence_t status, const char * const msg,
|
||||
int idle)
|
||||
{
|
||||
xmpp_ctx_t *ctx = jabber_get_ctx();
|
||||
xmpp_conn_t *conn = jabber_get_conn();
|
||||
int pri;
|
||||
char *show, *last;
|
||||
|
||||
// don't send presence when disconnected
|
||||
if (jabber_get_connection_status() != JABBER_CONNECTED)
|
||||
return;
|
||||
|
||||
pri = prefs_get_priority();
|
||||
if (pri < JABBER_PRIORITY_MIN || pri > JABBER_PRIORITY_MAX)
|
||||
pri = 0;
|
||||
|
||||
jabber_conn_set_presence(status);
|
||||
jabber_conn_set_priority(pri);
|
||||
|
||||
switch(status)
|
||||
{
|
||||
case PRESENCE_AWAY:
|
||||
show = STANZA_TEXT_AWAY;
|
||||
last = STANZA_TEXT_AWAY;
|
||||
break;
|
||||
case PRESENCE_DND:
|
||||
show = STANZA_TEXT_DND;
|
||||
last = STANZA_TEXT_DND;
|
||||
break;
|
||||
case PRESENCE_CHAT:
|
||||
show = STANZA_TEXT_CHAT;
|
||||
last = STANZA_TEXT_CHAT;
|
||||
break;
|
||||
case PRESENCE_XA:
|
||||
show = STANZA_TEXT_XA;
|
||||
last = STANZA_TEXT_XA;
|
||||
break;
|
||||
default: // PRESENCE_ONLINE
|
||||
show = NULL;
|
||||
last = STANZA_TEXT_ONLINE;
|
||||
break;
|
||||
}
|
||||
|
||||
jabber_conn_set_status(msg);
|
||||
|
||||
xmpp_stanza_t *presence = stanza_create_presence(ctx, show, msg);
|
||||
if (pri != 0) {
|
||||
xmpp_stanza_t *priority, *value;
|
||||
char pri_str[10];
|
||||
|
||||
snprintf(pri_str, sizeof(pri_str), "%d", pri);
|
||||
priority = xmpp_stanza_new(ctx);
|
||||
value = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(priority, STANZA_NAME_PRIORITY);
|
||||
xmpp_stanza_set_text(value, pri_str);
|
||||
xmpp_stanza_add_child(priority, value);
|
||||
xmpp_stanza_add_child(presence, priority);
|
||||
}
|
||||
|
||||
if (idle > 0) {
|
||||
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(query, STANZA_NS_LASTACTIVITY);
|
||||
char idle_str[10];
|
||||
snprintf(idle_str, sizeof(idle_str), "%d", idle);
|
||||
xmpp_stanza_set_attribute(query, STANZA_ATTR_SECONDS, idle_str);
|
||||
xmpp_stanza_add_child(presence, query);
|
||||
}
|
||||
|
||||
// add caps
|
||||
xmpp_stanza_t *caps = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(caps, STANZA_NAME_C);
|
||||
xmpp_stanza_set_ns(caps, STANZA_NS_CAPS);
|
||||
xmpp_stanza_t *query = caps_create_query_response_stanza(ctx);
|
||||
|
||||
char *sha1 = caps_create_sha1_str(query);
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_HASH, "sha-1");
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_NODE, "http://www.profanity.im");
|
||||
xmpp_stanza_set_attribute(caps, STANZA_ATTR_VER, sha1);
|
||||
xmpp_stanza_add_child(presence, caps);
|
||||
|
||||
xmpp_send(conn, presence);
|
||||
|
||||
// send presence for each room
|
||||
GList *rooms = muc_get_active_room_list();
|
||||
while (rooms != NULL) {
|
||||
char *room = rooms->data;
|
||||
char *nick = muc_get_room_nick(room);
|
||||
char *full_room_jid = create_fulljid(room, nick);
|
||||
|
||||
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
|
||||
xmpp_send(conn, presence);
|
||||
|
||||
rooms = g_list_next(rooms);
|
||||
}
|
||||
g_list_free(rooms);
|
||||
|
||||
xmpp_stanza_release(presence);
|
||||
|
||||
FREE_SET_NULL(sha1);
|
||||
|
||||
// set last presence for account
|
||||
accounts_set_last_presence(jabber_get_account_name(), last);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
presence_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata)
|
||||
|
||||
Reference in New Issue
Block a user