group nicklist handling fixed

This commit is contained in:
Gordon Quad 2017-01-03 12:41:35 +00:00
parent cc9d370105
commit 4021d9da0e
3 changed files with 52 additions and 41 deletions

View File

@ -133,11 +133,7 @@ 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(32, chat->nicks = weechat_list_new();
WEECHAT_HASHTABLE_INTEGER,
WEECHAT_HASHTABLE_POINTER,
NULL,
NULL);
weechat_buffer_set(chat->buffer, "nicklist", "1"); weechat_buffer_set(chat->buffer, "nicklist", "1");
} }
@ -401,7 +397,10 @@ twc_chat_free(struct t_twc_chat *chat)
{ {
weechat_nicklist_remove_all(chat->buffer); weechat_nicklist_remove_all(chat->buffer);
if (chat->nicks) if (chat->nicks)
weechat_hashtable_free(chat->nicks); {
weechat_list_remove_all(chat->nicks);
weechat_list_free(chat->nicks);
}
free(chat); free(chat);
} }

View File

@ -38,7 +38,7 @@ struct t_twc_chat
int32_t group_number; int32_t group_number;
struct t_gui_nick_group *nicklist_group; struct t_gui_nick_group *nicklist_group;
struct t_hashtable *nicks; struct t_weelist *nicks;
}; };
struct t_twc_chat * struct t_twc_chat *

View File

@ -435,52 +435,64 @@ twc_group_namelist_change_callback(Tox *tox,
true); true);
struct t_gui_nick *nick = NULL; struct t_gui_nick *nick = NULL;
char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number); int i, npeers;
char *prev_name = NULL; TOX_ERR_CONFERENCE_PEER_QUERY err = TOX_ERR_CONFERENCE_PEER_QUERY_OK;
if (change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT struct t_weelist *new_nicks;
|| change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE) struct t_weelist_item *n;
npeers = tox_conference_peer_count(profile->tox, group_number, &err);
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK)
{ {
nick = weechat_hashtable_get(chat->nicks, &peer_number); new_nicks = weechat_list_new();
if (nick) for (i = 0; i < npeers; i++)
{ {
prev_name = strdup(weechat_nicklist_nick_get_string(chat->buffer, char *name = twc_get_peer_name_nt(profile->tox, group_number, i);
nick, "name")); weechat_list_add(new_nicks, name, WEECHAT_LIST_POS_SORT, NULL);
weechat_nicklist_remove_nick(chat->buffer, nick); free(name);
weechat_hashtable_remove(chat->nicks, &peer_number);
} }
} }
else
return;
if (change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN // searching for exits
|| change_type == TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE) n = weechat_list_get(chat->nicks, 0);
while (n)
{ {
nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, const char *name = weechat_list_string(n);
name, NULL, NULL, NULL, 1); if (!weechat_list_search(new_nicks, name))
if (nick) {
weechat_hashtable_set(chat->nicks, &peer_number, nick); weechat_printf(chat->buffer, "%s%s just left the group chat",
weechat_prefix("quit"), name);
nick = weechat_nicklist_search_nick(chat->buffer,
chat->nicklist_group,
name);
weechat_nicklist_remove_nick(chat->buffer, nick);
}
n = weechat_list_next(n);
} }
switch (change_type) // searching for joins
n = weechat_list_get(new_nicks, 0);
while (n)
{ {
case TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE: const char *name = weechat_list_string(n);
if (prev_name && name) if (!weechat_list_search(chat->nicks, name))
weechat_printf(chat->buffer, "%s%s is now known as %s", {
weechat_prefix("network"), prev_name, name); weechat_printf(chat->buffer, "%s%s just joined the group chat",
break; weechat_prefix("join"), name);
case TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN: weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group,
if (name) name, NULL, NULL, NULL, 1);
weechat_printf(chat->buffer, "%s%s just joined the group chat", }
weechat_prefix("join"), name); n = weechat_list_next(n);
break;
case TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT:
if (prev_name)
weechat_printf(chat->buffer, "%s%s just left the group chat",
weechat_prefix("quit"), prev_name);
break;
} }
if (prev_name) weechat_list_remove_all(chat->nicks);
free(prev_name); weechat_list_free(chat->nicks);
chat->nicks = new_nicks;
} }
void void