about summary refs log tree commit diff stats
path: root/src/room_chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/room_chat.c')
-rw-r--r--src/room_chat.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/room_chat.c b/src/room_chat.c
index cdadc529..22a3d555 100644
--- a/src/room_chat.c
+++ b/src/room_chat.c
@@ -31,6 +31,7 @@ typedef struct _muc_room_t {
     char *room;
     char *nick;
     GHashTable *roster;
+    GHashTable *nick_changes;
     gboolean roster_received;
 } muc_room;
 
@@ -51,6 +52,8 @@ room_join(const char * const room, const char * const nick)
     new_room->nick = strdup(nick);
     new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
         (GDestroyNotify)p_contact_free);
+    new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal,
+        g_free, g_free);
     new_room->roster_received = FALSE;
 
     g_hash_table_insert(rooms, strdup(room), new_room);
@@ -174,12 +177,13 @@ room_parse_room_jid(const char * const full_room_jid, char **room, char **nick)
 }
 
 void
-room_add_to_roster(const char * const room, const char * const nick)
+room_add_to_roster(const char * const room, const char * const nick,
+    const char * const show, const char * const status)
 {
     muc_room *chat_room = g_hash_table_lookup(rooms, room);
 
     if (chat_room != NULL) {
-        PContact contact = p_contact_new(nick, NULL, "online", NULL, NULL);
+        PContact contact = p_contact_new(nick, NULL, show, status, NULL);
         g_hash_table_replace(chat_room->roster, strdup(nick), contact);
     }
 }
@@ -228,6 +232,35 @@ room_get_roster_received(const char * const room)
     }
 }
 
+void
+room_add_pending_nick_change(const char * const room,
+    const char * const new_nick, const char * const old_nick)
+{
+    muc_room *chat_room = g_hash_table_lookup(rooms, room);
+
+    if (chat_room != NULL) {
+        g_hash_table_insert(chat_room->nick_changes, strdup(new_nick), strdup(old_nick));
+    }
+}
+
+char *
+room_complete_pending_nick_change(const char * const room,
+    const char * const nick)
+{
+    muc_room *chat_room = g_hash_table_lookup(rooms, room);
+
+    if (chat_room != NULL) {
+        char *old_nick =
+            strdup(g_hash_table_lookup(chat_room->nick_changes, nick));
+
+        if (old_nick != NULL) {
+            return old_nick;
+        }
+    }
+
+    return NULL;
+}
+
 static void
 _room_free(muc_room *room)
 {
@@ -244,6 +277,10 @@ _room_free(muc_room *room)
             g_hash_table_remove_all(room->roster);
             room->roster = NULL;
         }
+        if (room->nick_changes != NULL) {
+            g_hash_table_remove_all(room->nick_changes);
+            room->nick_changes = NULL;
+        }
         g_free(room);
     }
     room = NULL;
205'>205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239