diff options
| -rw-r--r-- | degesch.c | 87 | 
1 files changed, 69 insertions, 18 deletions
| @@ -5778,6 +5778,73 @@ irc_handle_rpl_namreply (struct server *s, const struct irc_message *msg)  		cstr_split_ignore_empty (nicks, ' ', &channel->names_buf);  } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +struct channel_user_sort_entry +{ +	struct server *s;                   ///< Server +	struct channel_user *channel_user;  ///< Channel user +}; + +static int +channel_user_sort_entry_cmp (const void *entry_a, const void *entry_b) +{ +	const struct channel_user_sort_entry *a = entry_a; +	const struct channel_user_sort_entry *b = entry_b; +	struct server *s = a->s; + +	// First order by the most significant channel user prefix +	const char *prio_a = strchr (s->irc_chanuser_prefixes, +		*a->channel_user->prefixes.str); +	const char *prio_b = strchr (s->irc_chanuser_prefixes, +		*b->channel_user->prefixes.str); + +	// Put unrecognized prefixes at the end of the list +	if (prio_a || prio_b) +	{ +		if (!prio_a) return  1; +		if (!prio_b) return -1; + +		if (prio_a != prio_b) +			return prio_a - prio_b; +	} + +	return irc_server_strcmp (s, +		a->channel_user->user->nickname, +		b->channel_user->user->nickname); +} + +static char * +make_channel_users_list (struct server *s, struct channel *channel) +{ +	size_t n_users = 0; +	LIST_FOR_EACH (struct channel_user, iter, channel->users) +		n_users++; + +	struct channel_user_sort_entry entries[n_users]; +	size_t i = 0; +	LIST_FOR_EACH (struct channel_user, iter, channel->users) +	{ +		entries[i].s = s; +		entries[i].channel_user = iter; +		i++; +	} + +	qsort (entries, n_users, sizeof *entries, channel_user_sort_entry_cmp); + +	struct str list; +	str_init (&list); +	for (i = 0; i < n_users; i++) +	{ +		irc_get_channel_user_prefix (s, entries[i].channel_user, &list); +		str_append (&list, entries[i].channel_user->user->nickname); +		str_append_c (&list, ' '); +	} +	if (list.len) +		list.str[--list.len] = '\0'; +	return str_steal (&list); +} +  static void  irc_sync_channel_user (struct server *s, struct channel *channel,  	const char *nickname, const char *prefixes) @@ -5802,24 +5869,6 @@ irc_sync_channel_user (struct server *s, struct channel *channel,  	}  } -static char * -make_channel_users_list (struct server *s, struct channel *channel) -{ -	struct str_vector v; -	str_vector_init (&v); -	LIST_FOR_EACH (struct channel_user, iter, channel->users) -	{ -		struct str item; -		str_init (&item); -		irc_get_channel_user_prefix (s, iter, &item); -		str_append (&item, iter->user->nickname); -		str_vector_add_owned (&v, str_steal (&item)); -	} -	char *result = join_str_vector (&v, ' '); -	str_vector_free (&v); -	return result; -} -  static void  irc_process_names (struct server *s, struct channel *channel)  { @@ -5861,6 +5910,8 @@ irc_process_names (struct server *s, struct channel *channel)  	free (all_users);  } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  static void  irc_handle_rpl_endofnames (struct server *s, const struct irc_message *msg)  { | 
