summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-07-23 19:00:25 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-07-23 19:14:57 +0200
commit7c7e12d8d5e08cc5938b9d3bb8883048b6e2fd35 (patch)
treea6c2e0874cbe268814b9cfe1f70b41a00bc8bd72
parent3cb93d24e8ced647a0af656e10919d45cd6eef25 (diff)
downloadxK-7c7e12d8d5e08cc5938b9d3bb8883048b6e2fd35.tar.gz
xK-7c7e12d8d5e08cc5938b9d3bb8883048b6e2fd35.tar.xz
xK-7c7e12d8d5e08cc5938b9d3bb8883048b6e2fd35.zip
degesch: start with lexically ordered chanusers
This makes nick autocompletion start in a non-arbitrary state.
-rw-r--r--degesch.c24
1 files changed, 24 insertions, 0 deletions
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);
}