From 7c7e12d8d5e08cc5938b9d3bb8883048b6e2fd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Fri, 23 Jul 2021 19:00:25 +0200 Subject: [PATCH] degesch: start with lexically ordered chanusers This makes nick autocompletion start in a non-arbitrary state. --- degesch.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/degesch.c b/degesch.c index 76b8b16..c61fab6 100644 --- a/degesch.c +++ b/degesch.c @@ -7606,6 +7606,25 @@ channel_user_sort_entry_cmp (const void *entry_a, const void *entry_b) 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 * 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); 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; for (size_t i = 0; i < updates->len; i++) { @@ -7699,6 +7721,8 @@ irc_process_names (struct channel *channel) str_map_free (&present); strv_reset (&channel->names_buf); + if (we_have_just_joined) + irc_sort_channel_users (channel); if (!channel->show_names_after_who) irc_process_names_finish (channel); }