summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}