1
0
Fork 0
forked from murx/irc9

Sort channels and private chats in the tree

This commit is contained in:
Johannes Findeisen 2026-11-29 05:14:08 +01:00
commit 38dca11cf8
2 changed files with 26 additions and 5 deletions

28
irc9.c
View file

@ -290,17 +290,25 @@ static Window *reply_window(Server *s)
/* ------------------------------------------------------------------ */
/* windows and scrollback */
static void window_insert(Server *s, Window *w)
{
Window **link = &s->windows;
while (*link && ((*link)->type < w->type ||
((*link)->type == w->type && strcmp((*link)->name, w->name) <= 0)))
link = &(*link)->next;
w->next = *link;
*link = w;
}
static Window *window_new(Server *s, const char *name, Wintype type)
{
Window *w = xmalloc(sizeof *w);
Window **tail = &s->windows;
memset(w, 0, sizeof *w);
snprintf(w->name, sizeof w->name, "%s", name);
w->type = type;
w->srv = s;
w->lines = xalloc_array(MAXSCROLL, sizeof *w->lines);
while (*tail) tail = &(*tail)->next;
*tail = w;
window_insert(s, w);
return w;
}
@ -1316,14 +1324,26 @@ static void handle_line(Server *s, char *line)
if (strcasecmp(cmd, "NICK") == 0) {
if (narg < 1) return;
int in_channel = 0;
for (Window *w = s->windows; w; w = w->next) {
Window *renamed = NULL;
for (Window **link = &s->windows; *link; ) {
Window *w = *link;
if (w->type == W_CHANNEL && member_find(w, nick)) {
member_rename(w, nick, arg[0]);
if (!silent) append_nickf(w, "* ", nick, " ", "is now known as %s", arg[0]);
in_channel = 1;
} else if (w->type == W_QUERY && strcasecmp(w->name, nick) == 0) {
snprintf(w->name, sizeof w->name, "%s", arg[0]);
*link = w->next;
w->next = renamed;
renamed = w;
continue;
}
link = &w->next;
}
while (renamed) {
Window *w = renamed;
renamed = w->next;
window_insert(s, w);
}
if (strcasecmp(nick, s->nick) == 0)
snprintf(s->nick, sizeof s->nick, "%s", arg[0]);