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

Merge branch 'master' into nextdev

This commit is contained in:
James Booth 2013-08-05 23:18:19 +01:00
commit 6651b13bd0
4 changed files with 53 additions and 6 deletions

View File

@ -167,17 +167,30 @@ muc_room_is_active(Jid *jid)
} }
} }
char *
muc_get_old_nick(const char * const room, const char * const new_nick)
{
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if ((chat_room != NULL) && (chat_room->pending_nick_change)) {
return g_hash_table_lookup(chat_room->nick_changes, new_nick);
}
return NULL;
}
/* /*
* Flag that the user has sent a nick change to the service * Flag that the user has sent a nick change to the service
* and is awaiting the response * and is awaiting the response
*/ */
void void
muc_set_room_pending_nick_change(const char * const room) muc_set_room_pending_nick_change(const char * const room, const char * const new_nick)
{ {
ChatRoom *chat_room = g_hash_table_lookup(rooms, room); ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room != NULL) { if (chat_room != NULL) {
chat_room->pending_nick_change = TRUE; chat_room->pending_nick_change = TRUE;
g_hash_table_insert(chat_room->nick_changes, strdup(new_nick), strdup(chat_room->nick));
} }
} }
@ -210,6 +223,7 @@ muc_complete_room_nick_change(const char * const room, const char * const nick)
free(chat_room->nick); free(chat_room->nick);
chat_room->nick = strdup(nick); chat_room->nick = strdup(nick);
chat_room->pending_nick_change = FALSE; chat_room->pending_nick_change = FALSE;
g_hash_table_remove(chat_room->nick_changes, nick);
} }
} }

View File

@ -36,10 +36,11 @@ gboolean muc_room_is_active(Jid *jid);
GList* muc_get_active_room_list(void); GList* muc_get_active_room_list(void);
char * muc_get_room_nick(const char * const room); char * muc_get_room_nick(const char * const room);
void muc_set_room_pending_nick_change(const char * const room); void muc_set_room_pending_nick_change(const char * const room, const char * const new_nick);
gboolean muc_is_room_pending_nick_change(const char * const room); gboolean muc_is_room_pending_nick_change(const char * const room);
void muc_complete_room_nick_change(const char * const room, void muc_complete_room_nick_change(const char * const room,
const char * const nick); const char * const nick);
char * muc_get_old_nick(const char * const room, const char * const new_nick);
gboolean muc_add_to_roster(const char * const room, const char * const nick, gboolean muc_add_to_roster(const char * const room, const char * const nick,
const char * const show, const char * const status, const char * const show, const char * const status,

View File

@ -605,13 +605,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// handle self presence // handle self presence
if (stanza_is_muc_self_presence(stanza, jabber_get_fulljid())) { if (stanza_is_muc_self_presence(stanza, jabber_get_fulljid())) {
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
gboolean nick_change = stanza_is_room_nick_change(stanza); char *new_nick = stanza_get_new_nick(stanza);
if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) { if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) {
// leave room if not self nick change // leave room if not self nick change
if (nick_change) { if (new_nick != NULL) {
muc_set_room_pending_nick_change(room); muc_set_room_pending_nick_change(room, new_nick);
} else { } else {
prof_handle_leave_room(room); prof_handle_leave_room(room);
} }

View File

@ -31,6 +31,8 @@
#include "xmpp/stanza.h" #include "xmpp/stanza.h"
#include "xmpp/capabilities.h" #include "xmpp/capabilities.h"
#include "muc.h"
static int _field_compare(FormField *f1, FormField *f2); static int _field_compare(FormField *f1, FormField *f2);
#if 0 #if 0
@ -565,6 +567,37 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
x_children = xmpp_stanza_get_next(x_children); x_children = xmpp_stanza_get_next(x_children);
} }
// for servers that don't send status 110 or Jid property
// first check if 'from' attribute identifies this user
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (from != NULL) {
Jid *jidp = jid_create(from);
if (muc_room_is_active(jidp)) {
char *nick = muc_get_room_nick(jidp->barejid);
if (g_strcmp0(jidp->resourcepart, nick) == 0) {
return TRUE;
}
}
jid_destroy(jidp);
}
// secondly check if the new nickname maps to a pending nick change for this user
if (from != NULL) {
Jid *jidp = jid_create(from);
if (muc_is_room_pending_nick_change(jidp->barejid)) {
char *new_nick = jidp->resourcepart;
if (new_nick != NULL) {
char *nick = muc_get_room_nick(jidp->barejid);
char *old_nick = muc_get_old_nick(jidp->barejid, new_nick);
if (g_strcmp0(old_nick, nick) == 0) {
return TRUE;
}
}
}
jid_destroy(jidp);
}
return FALSE; return FALSE;
} }
@ -608,7 +641,6 @@ stanza_is_room_nick_change(xmpp_stanza_t * const stanza)
} }
return FALSE; return FALSE;
} }
char * char *