nicks hash moved to peer_number keys
This commit is contained in:
parent
ad2a727a91
commit
56c0c924ac
@ -45,25 +45,6 @@ twc_chat_buffer_close_callback(const void *pointer,
|
||||
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_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new chat.
|
||||
*/
|
||||
@ -137,10 +118,10 @@ 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(32,
|
||||
WEECHAT_HASHTABLE_BUFFER,
|
||||
WEECHAT_HASHTABLE_INTEGER,
|
||||
WEECHAT_HASHTABLE_POINTER,
|
||||
twc_tox_id_hash_callback,
|
||||
twc_tox_id_compare_callback);
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
weechat_buffer_set(chat->buffer, "nicklist", "1");
|
||||
}
|
||||
|
@ -84,6 +84,9 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
||||
{
|
||||
struct t_twc_profile *profile = data;
|
||||
char *name = twc_get_name_nt(profile->tox, friend_number);
|
||||
struct t_twc_chat *chat = twc_chat_search_friend(profile,
|
||||
friend_number,
|
||||
false);
|
||||
|
||||
// TODO: print in friend's buffer if it exists
|
||||
if (status == 0)
|
||||
@ -92,6 +95,13 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
||||
"%s%s just went offline.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
if (chat)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%s just went offline.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
}
|
||||
}
|
||||
else if (status == 1)
|
||||
{
|
||||
@ -99,6 +109,13 @@ twc_connection_status_callback(Tox *tox, uint32_t friend_number,
|
||||
"%s%s just came online.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
if (chat)
|
||||
{
|
||||
weechat_printf(chat->buffer,
|
||||
"%s%s just came online.",
|
||||
weechat_prefix("network"),
|
||||
name);
|
||||
}
|
||||
twc_message_queue_flush_friend(profile, friend_number);
|
||||
}
|
||||
free(name);
|
||||
@ -365,34 +382,26 @@ twc_group_namelist_change_callback(Tox *tox,
|
||||
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number);
|
||||
char *prev_name = NULL;
|
||||
|
||||
uint8_t pubkey[TOX_PUBLIC_KEY_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
|
||||
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
|
||||
{
|
||||
if (change_type == TOX_CHAT_CHANGE_PEER_DEL
|
||||
|| change_type == TOX_CHAT_CHANGE_PEER_NAME)
|
||||
nick = weechat_hashtable_get(chat->nicks, &peer_number);
|
||||
if (nick)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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_PUBLIC_KEY_SIZE,
|
||||
nick, 0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
switch (change_type)
|
||||
|
@ -123,7 +123,7 @@ twc_get_status_message_nt(Tox *tox, int32_t friend_number)
|
||||
char *
|
||||
twc_get_peer_name_nt(Tox *tox, int32_t group_number, int32_t peer_number)
|
||||
{
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH] = {0};
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH+1] = {0};
|
||||
|
||||
int length = tox_group_peername(tox, group_number, peer_number, name);
|
||||
if (length >= 0)
|
||||
@ -185,20 +185,6 @@ twc_uint32_reverse_bytes(uint32_t num)
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash a Tox ID of size TOX_PUBLIC_KEY_SIZE bytes using a modified djb2 hash.
|
||||
*/
|
||||
unsigned long long
|
||||
twc_hash_tox_id(const uint8_t *tox_id)
|
||||
{
|
||||
unsigned long long hash = 5381;
|
||||
|
||||
for (size_t i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i)
|
||||
hash ^= (hash << 5) + (hash >> 2) + tox_id[i];
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fit correct unicode string into max chars. Return number of bytes
|
||||
*/
|
||||
|
@ -51,9 +51,6 @@ twc_get_friend_id_short(Tox *tox, int32_t friend_number);
|
||||
uint32_t
|
||||
twc_uint32_reverse_bytes(uint32_t num);
|
||||
|
||||
unsigned long long
|
||||
twc_hash_tox_id(const uint8_t *tox_id);
|
||||
|
||||
int
|
||||
twc_fit_utf8(const char *str, int max);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user