Use Tox ID instead of peer number to index nicks in group chats.

This commit is contained in:
Håvard Pettersson 2014-11-22 22:32:32 +01:00
parent a5c4023f9e
commit b1d16a086d
2 changed files with 47 additions and 19 deletions

View File

@ -43,6 +43,25 @@ int
twc_chat_buffer_close_callback(void *data,
struct t_gui_buffer *weechat_buffer);
/**
* Hash a Tox ID for the nicklist hashtable in group chat objects.
*/
unsigned long long
twc_tox_id_hash_callback(struct t_hashtable *hashtable, const void *key)
{
return twc_hash_tox_id(key);
}
/**
* Compare two Tox IDs for the nicklist hashtable in group chat objects.
*/
int
twc_tox_id_compare_callback(struct t_hashtable *hashtable,
const void *id1, const void *id2)
{
return memcmp(id1, id2, TOX_CLIENT_ID_SIZE);
}
/**
* Create a new chat.
*/
@ -112,10 +131,11 @@ twc_chat_new_group(struct t_twc_profile *profile, int32_t group_number)
chat->nicklist_group = weechat_nicklist_add_group(chat->buffer, NULL,
NULL, NULL, true);
chat->nicks = weechat_hashtable_new(256,
WEECHAT_HASHTABLE_INTEGER,
chat->nicks = weechat_hashtable_new(32,
WEECHAT_HASHTABLE_BUFFER,
WEECHAT_HASHTABLE_POINTER,
NULL, NULL);
twc_tox_id_hash_callback,
twc_tox_id_compare_callback);
weechat_buffer_set(chat->buffer, "nicklist", "1");
}

View File

@ -328,26 +328,34 @@ twc_group_namelist_change_callback(Tox *tox,
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
char *prev_name = NULL;
if (change_type == TOX_CHAT_CHANGE_PEER_DEL
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
uint8_t pubkey[TOX_CLIENT_ID_SIZE];
int pkrc = tox_group_peer_pubkey(profile->tox, group_number,
peer_number, pubkey);
if (pkrc == 0)
{
nick = weechat_hashtable_get(chat->nicks, &peer_number);
if (nick)
if (change_type == TOX_CHAT_CHANGE_PEER_DEL
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
{
prev_name = strdup(weechat_nicklist_nick_get_string(chat->buffer,
nick, "name"));
weechat_nicklist_remove_nick(chat->buffer, nick);
weechat_hashtable_remove(chat->nicks, &peer_number);
nick = weechat_hashtable_get(chat->nicks, pubkey);
if (nick)
{
prev_name = strdup(weechat_nicklist_nick_get_string(chat->buffer,
nick, "name"));
weechat_nicklist_remove_nick(chat->buffer, nick);
weechat_hashtable_remove(chat->nicks, pubkey);
}
}
}
if (change_type == TOX_CHAT_CHANGE_PEER_ADD
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
{
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
name, NULL, NULL, NULL, 1);
if (nick)
weechat_hashtable_set(chat->nicks, &peer_number, nick);
if (change_type == TOX_CHAT_CHANGE_PEER_ADD
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
{
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
name, NULL, NULL, NULL, 1);
if (nick)
weechat_hashtable_set_with_size(chat->nicks,
pubkey, TOX_CLIENT_ID_SIZE,
nick, 0);
}
}
switch (change_type)