summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/degesch.c b/degesch.c
index 413c6f0..8385f83 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1342,6 +1342,7 @@ struct channel
struct channel_user *users; ///< Channel users
struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY
+ size_t users_len; ///< User count
bool left_manually; ///< Don't rejoin on reconnect
};
@@ -1366,7 +1367,7 @@ channel_destroy (struct channel *self)
str_free (&self->no_param_modes);
str_map_free (&self->param_modes);
// Owner has to make sure we have no users by now
- hard_assert (!self->users);
+ hard_assert (!self->users && !self->users_len);
str_vector_free (&self->names_buf);
free (self);
}
@@ -4362,7 +4363,7 @@ static bool
irc_channel_is_joined (struct channel *channel)
{
// TODO: find a better way of checking if we're on a channel
- return !!channel->users;
+ return !!channel->users_len;
}
// Note that this eats the user reference
@@ -4378,6 +4379,7 @@ irc_channel_link_user (struct channel *channel, struct user *user,
channel_user->user = user;
str_append (&channel_user->prefixes, prefixes);
LIST_PREPEND (channel->users, channel_user);
+ channel->users_len++;
}
static void
@@ -4396,6 +4398,7 @@ irc_channel_unlink_user
// Then just unlink the user from the channel
LIST_UNLINK (channel->users, channel_user);
channel_user_destroy (channel_user);
+ channel->users_len--;
}
static void
@@ -5819,6 +5822,9 @@ make_prompt (struct app_context *ctx, struct str *output)
if (modes.len)
str_append_printf (output, "(+%s)", modes.str);
str_free (&modes);
+
+ if (buffer->channel->users_len)
+ str_append_printf (output, "{%zu}", buffer->channel->users_len);
}
if (buffer != ctx->global_buffer)
@@ -5838,6 +5844,7 @@ input_maybe_set_prompt (struct input *self, char *new_prompt)
CALL_ (self, set_prompt, new_prompt);
}
+// TODO: do this in an idle task so as to not call this unnecessarily
static void
refresh_prompt (struct app_context *ctx)
{
@@ -6528,9 +6535,6 @@ irc_handle_mode (struct server *s, const struct irc_message *msg)
}
free (modes);
-
- // Our own modes might have changed
- refresh_prompt (s->ctx);
}
static void
@@ -6646,9 +6650,6 @@ irc_handle_nick (struct server *s, const struct irc_message *msg)
free (user->nickname);
user->nickname = xstrdup (new_nickname);
-
- // We might have renamed ourselves
- refresh_prompt (s->ctx);
}
static void
@@ -7117,7 +7118,6 @@ irc_handle_rpl_umodeis (struct server *s, const struct irc_message *msg)
irc_handle_mode_user (s, msg->params.vector + 1);
// XXX: do we want to log a message?
- refresh_prompt (s->ctx);
}
static void
@@ -7335,7 +7335,6 @@ irc_handle_rpl_channelmodeis (struct server *s, const struct irc_message *msg)
}
// XXX: do we want to log a message?
- refresh_prompt (s->ctx);
}
static char *
@@ -7697,6 +7696,10 @@ irc_process_message (const struct irc_message *msg, struct server *s)
unsigned long numeric;
if (xstrtoul (&numeric, msg->command, 10))
irc_process_numeric (s, msg, numeric);
+
+ // Better always make sure everything is in sync rather than care about
+ // each case explicitly whether anything might have changed
+ refresh_prompt (s->ctx);
}
// --- Message autosplitting magic ---------------------------------------------