degesch: start with lexically ordered chanusers

This makes nick autocompletion start in a non-arbitrary state.
This commit is contained in:
Přemysl Eric Janouch 2021-07-23 19:00:25 +02:00
parent 3cb93d24e8
commit 7c7e12d8d5
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -7606,6 +7606,25 @@ channel_user_sort_entry_cmp (const void *entry_a, const void *entry_b)
b->channel_user->user->nickname); b->channel_user->user->nickname);
} }
static void
irc_sort_channel_users (struct channel *channel)
{
size_t n_users = channel->users_len;
struct channel_user_sort_entry entries[n_users], *p = entries;
LIST_FOR_EACH (struct channel_user, iter, channel->users)
{
p->s = channel->s;
p->channel_user = iter;
p++;
}
qsort (entries, n_users, sizeof *entries, channel_user_sort_entry_cmp);
channel->users = NULL;
while (p-- != entries)
LIST_PREPEND (channel->users, p->channel_user);
}
static char * static char *
make_channel_users_list (struct channel *channel) make_channel_users_list (struct channel *channel)
{ {
@ -7676,6 +7695,9 @@ irc_process_names (struct channel *channel)
struct str_map present = str_map_make (NULL); struct str_map present = str_map_make (NULL);
present.key_xfrm = channel->s->irc_strxfrm; present.key_xfrm = channel->s->irc_strxfrm;
// Either that, or there is no other inhabitant, and sorting does nothing
bool we_have_just_joined = channel->users_len == 1;
struct strv *updates = &channel->names_buf; struct strv *updates = &channel->names_buf;
for (size_t i = 0; i < updates->len; i++) for (size_t i = 0; i < updates->len; i++)
{ {
@ -7699,6 +7721,8 @@ irc_process_names (struct channel *channel)
str_map_free (&present); str_map_free (&present);
strv_reset (&channel->names_buf); strv_reset (&channel->names_buf);
if (we_have_just_joined)
irc_sort_channel_users (channel);
if (!channel->show_names_after_who) if (!channel->show_names_after_who)
irc_process_names_finish (channel); irc_process_names_finish (channel);
} }