diff options
author | James Booth <boothj5@gmail.com> | 2014-09-28 01:55:24 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-09-28 01:55:24 +0100 |
commit | 41b49cb5d6507636070c4d65f0e3f006c1ac9952 (patch) | |
tree | b99b0190a148d8b297561e95695db7695339fdc0 /src/xmpp | |
parent | a4f7932ed7dc35aa1a706d1b889c26da079963bb (diff) | |
download | profani-tty-41b49cb5d6507636070c4d65f0e3f006c1ac9952.tar.gz |
Store room affiliation and role
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/presence.c | 36 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 12 |
2 files changed, 32 insertions, 16 deletions
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index adbb21fb..f63b3349 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -697,6 +697,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *new_nick = stanza_get_new_nick(stanza); + // self unavailable if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) { // leave room if not self nick change @@ -706,18 +707,33 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, handle_leave_room(from_room); } - // handle self nick change - } else if (muc_is_room_pending_nick_change(from_room)) { - muc_complete_room_nick_change(from_room, from_nick); - handle_room_nick_change(from_room, from_nick); + // self online + } else { + + // handle self nick change + if (muc_is_room_pending_nick_change(from_room)) { + handle_room_nick_change(from_room, from_nick); + + // handle roster complete + } else if (!muc_get_roster_received(from_room)) { + handle_room_roster_complete(from_room); - // handle roster complete - } else if (!muc_get_roster_received(from_room)) { - handle_room_roster_complete(from_room); + // room configuration required + if (stanza_muc_requires_config(stanza)) { + handle_room_requires_config(from_room); + } + } - // room configuration required - if (stanza_muc_requires_config(stanza)) { - handle_room_requires_config(from_room); + // set own affiliation and role + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); + if (x) { + xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM); + if (item) { + char *role = xmpp_stanza_get_attribute(item, "role"); + muc_set_role(from_room, role); + char *affiliation = xmpp_stanza_get_attribute(item, "affiliation"); + muc_set_affiliation(from_room, affiliation); + } } } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 2d99c0f0..045fea59 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -822,11 +822,11 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, // muc user namespaced x element xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - if (x != NULL) { + if (x) { // check for status child element with 110 code xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) { char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE); if (g_strcmp0(code, "110") == 0) { @@ -838,9 +838,9 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, // check for item child element with jid property xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, STANZA_NAME_ITEM); - if (item != NULL) { + if (item) { char *jid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); - if (jid != NULL) { + if (jid) { if (g_str_has_prefix(self_jid, jid)) { return TRUE; } @@ -849,7 +849,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, // check if 'from' attribute identifies this user char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (from != NULL) { + if (from) { Jid *from_jid = jid_create(from); if (muc_room_is_active(from_jid->barejid)) { char *nick = muc_get_room_nick(from_jid->barejid); @@ -861,7 +861,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza, // check if a new nickname maps to a pending nick change for this user if (muc_is_room_pending_nick_change(from_jid->barejid)) { char *new_nick = from_jid->resourcepart; - if (new_nick != NULL) { + if (new_nick) { char *nick = muc_get_room_nick(from_jid->barejid); char *old_nick = muc_get_old_nick(from_jid->barejid, new_nick); if (g_strcmp0(old_nick, nick) == 0) { |