aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-23 16:29:55 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-23 17:14:24 +0200
commitc0f4b554effb1513ceca9d32162dab977aa45cf1 (patch)
tree3b74c96dca57f06c38dd61fcd32a56a392a99085
parent639da7a9a76e78e35c65c9991b739de8247e341c (diff)
downloadxK-c0f4b554effb1513ceca9d32162dab977aa45cf1.tar.gz
xK-c0f4b554effb1513ceca9d32162dab977aa45cf1.tar.xz
xK-c0f4b554effb1513ceca9d32162dab977aa45cf1.zip
degesch: show channel user count in the status
-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 ---------------------------------------------