1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added nickname autocompleter to chat rooms

This commit is contained in:
James Booth 2013-01-11 00:02:05 +00:00
parent 96b7b6bc71
commit ce8faa8d34

View File

@ -25,13 +25,15 @@
#include <glib.h> #include <glib.h>
#include <contact.h> #include "contact.h"
#include "prof_autocomplete.h"
typedef struct _muc_room_t { typedef struct _muc_room_t {
char *room; char *room;
char *nick; char *nick;
gboolean pending_nick_change; gboolean pending_nick_change;
GHashTable *roster; GHashTable *roster;
PAutocomplete nick_ac;
GHashTable *nick_changes; GHashTable *nick_changes;
gboolean roster_received; gboolean roster_received;
} muc_room; } muc_room;
@ -53,6 +55,7 @@ room_join(const char * const room, const char * const nick)
new_room->nick = strdup(nick); new_room->nick = strdup(nick);
new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, new_room->roster = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
(GDestroyNotify)p_contact_free); (GDestroyNotify)p_contact_free);
new_room->nick_ac = p_autocomplete_new();
new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal, new_room->nick_changes = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, g_free); g_free, g_free);
new_room->roster_received = FALSE; new_room->roster_received = FALSE;
@ -247,6 +250,7 @@ room_add_to_roster(const char * const room, const char * const nick,
if (old == NULL) { if (old == NULL) {
updated = TRUE; updated = TRUE;
p_autocomplete_add(chat_room->nick_ac, strdup(nick));
} else if ((g_strcmp0(p_contact_presence(old), show) != 0) || } else if ((g_strcmp0(p_contact_presence(old), show) != 0) ||
(g_strcmp0(p_contact_status(old), status) != 0)) { (g_strcmp0(p_contact_status(old), status) != 0)) {
updated = TRUE; updated = TRUE;
@ -266,6 +270,7 @@ room_remove_from_roster(const char * const room, const char * const nick)
if (chat_room != NULL) { if (chat_room != NULL) {
g_hash_table_remove(chat_room->roster, nick); g_hash_table_remove(chat_room->roster, nick);
p_autocomplete_remove(chat_room->nick_ac, nick);
} }
} }
@ -352,6 +357,9 @@ _room_free(muc_room *room)
g_hash_table_remove_all(room->roster); g_hash_table_remove_all(room->roster);
room->roster = NULL; room->roster = NULL;
} }
if (room->nick_ac != NULL) {
p_autocomplete_clear(room->nick_ac);
}
if (room->nick_changes != NULL) { if (room->nick_changes != NULL) {
g_hash_table_remove_all(room->nick_changes); g_hash_table_remove_all(room->nick_changes);
room->nick_changes = NULL; room->nick_changes = NULL;