Use Tox ID instead of peer number to index nicks in group chats.
This commit is contained in:
parent
a5c4023f9e
commit
b1d16a086d
@ -43,6 +43,25 @@ int
|
|||||||
twc_chat_buffer_close_callback(void *data,
|
twc_chat_buffer_close_callback(void *data,
|
||||||
struct t_gui_buffer *weechat_buffer);
|
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.
|
* 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,
|
chat->nicklist_group = weechat_nicklist_add_group(chat->buffer, NULL,
|
||||||
NULL, NULL, true);
|
NULL, NULL, true);
|
||||||
chat->nicks = weechat_hashtable_new(256,
|
chat->nicks = weechat_hashtable_new(32,
|
||||||
WEECHAT_HASHTABLE_INTEGER,
|
WEECHAT_HASHTABLE_BUFFER,
|
||||||
WEECHAT_HASHTABLE_POINTER,
|
WEECHAT_HASHTABLE_POINTER,
|
||||||
NULL, NULL);
|
twc_tox_id_hash_callback,
|
||||||
|
twc_tox_id_compare_callback);
|
||||||
|
|
||||||
weechat_buffer_set(chat->buffer, "nicklist", "1");
|
weechat_buffer_set(chat->buffer, "nicklist", "1");
|
||||||
}
|
}
|
||||||
|
@ -328,16 +328,21 @@ twc_group_namelist_change_callback(Tox *tox,
|
|||||||
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
||||||
char *prev_name = NULL;
|
char *prev_name = NULL;
|
||||||
|
|
||||||
|
uint8_t pubkey[TOX_CLIENT_ID_SIZE];
|
||||||
|
int pkrc = tox_group_peer_pubkey(profile->tox, group_number,
|
||||||
|
peer_number, pubkey);
|
||||||
|
if (pkrc == 0)
|
||||||
|
{
|
||||||
if (change_type == TOX_CHAT_CHANGE_PEER_DEL
|
if (change_type == TOX_CHAT_CHANGE_PEER_DEL
|
||||||
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
|
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
|
||||||
{
|
{
|
||||||
nick = weechat_hashtable_get(chat->nicks, &peer_number);
|
nick = weechat_hashtable_get(chat->nicks, pubkey);
|
||||||
if (nick)
|
if (nick)
|
||||||
{
|
{
|
||||||
prev_name = strdup(weechat_nicklist_nick_get_string(chat->buffer,
|
prev_name = strdup(weechat_nicklist_nick_get_string(chat->buffer,
|
||||||
nick, "name"));
|
nick, "name"));
|
||||||
weechat_nicklist_remove_nick(chat->buffer, nick);
|
weechat_nicklist_remove_nick(chat->buffer, nick);
|
||||||
weechat_hashtable_remove(chat->nicks, &peer_number);
|
weechat_hashtable_remove(chat->nicks, pubkey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +352,10 @@ twc_group_namelist_change_callback(Tox *tox,
|
|||||||
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
|
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
|
||||||
name, NULL, NULL, NULL, 1);
|
name, NULL, NULL, NULL, 1);
|
||||||
if (nick)
|
if (nick)
|
||||||
weechat_hashtable_set(chat->nicks, &peer_number, nick);
|
weechat_hashtable_set_with_size(chat->nicks,
|
||||||
|
pubkey, TOX_CLIENT_ID_SIZE,
|
||||||
|
nick, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (change_type)
|
switch (change_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user