degesch: store channel modes differently

This commit is contained in:
Přemysl Eric Janouch 2015-06-04 22:19:32 +02:00
parent b0753438c4
commit 9b1664f968
1 changed files with 37 additions and 5 deletions

View File

@ -852,9 +852,12 @@ struct channel
// TODO: eventually a reference to the server // TODO: eventually a reference to the server
char *name; ///< Channel name char *name; ///< Channel name
char *mode; ///< Channel mode
char *topic; ///< Channel topic char *topic; ///< Channel topic
// XXX: write something like an ordered set of characters object?
struct str no_param_modes; ///< No parameter channel modes
struct str_map param_modes; ///< Parametrized channel modes
struct channel_user *users; ///< Channel users struct channel_user *users; ///< Channel users
struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY
}; };
@ -864,6 +867,9 @@ channel_new (void)
{ {
struct channel *self = xcalloc (1, sizeof *self); struct channel *self = xcalloc (1, sizeof *self);
self->ref_count = 1; self->ref_count = 1;
str_init (&self->no_param_modes);
str_map_init (&self->param_modes);
self->param_modes.free = free;
str_vector_init (&self->names_buf); str_vector_init (&self->names_buf);
return self; return self;
} }
@ -872,8 +878,9 @@ static void
channel_destroy (struct channel *self) channel_destroy (struct channel *self)
{ {
free (self->name); free (self->name);
free (self->mode);
free (self->topic); free (self->topic);
str_free (&self->no_param_modes);
str_map_free (&self->param_modes);
// Owner has to make sure we have no users by now // Owner has to make sure we have no users by now
hard_assert (!self->users); hard_assert (!self->users);
str_vector_free (&self->names_buf); str_vector_free (&self->names_buf);
@ -2796,7 +2803,6 @@ irc_make_channel (struct server *s, char *name)
channel->on_destroy = irc_channel_on_destroy; channel->on_destroy = irc_channel_on_destroy;
channel->user_data = s; channel->user_data = s;
channel->name = name; channel->name = name;
channel->mode = xstrdup ("");
channel->topic = NULL; channel->topic = NULL;
str_map_set (&s->irc_channels, channel->name, channel); str_map_set (&s->irc_channels, channel->name, channel);
return channel; return channel;
@ -3604,6 +3610,27 @@ make_unseen_prefix (struct app_context *ctx)
return NULL; return NULL;
} }
static char *
make_chanmode_postfix (struct channel *channel)
{
struct str modes;
str_init (&modes);
if (channel->no_param_modes.len)
str_append (&modes, channel->no_param_modes.str);
struct str_map_iter iter;
str_map_iter_init (&iter, &channel->param_modes);
char *param;
while ((param = str_map_iter_next (&iter)))
str_append_c (&modes, iter.link->key[0]);
if (modes.len)
return str_steal (&modes);
str_free (&modes);
return NULL;
}
static void static void
make_prompt (struct app_context *ctx, struct str *output) make_prompt (struct app_context *ctx, struct str *output)
{ {
@ -3620,8 +3647,13 @@ make_prompt (struct app_context *ctx, struct str *output)
str_append_printf (output, "%d:%s", str_append_printf (output, "%d:%s",
buffer_get_index (ctx, buffer), buffer->name); buffer_get_index (ctx, buffer), buffer->name);
if (buffer->type == BUFFER_CHANNEL && *buffer->channel->mode) if (buffer->type == BUFFER_CHANNEL)
str_append_printf (output, "(%s)", buffer->channel->mode); {
char *modes = make_chanmode_postfix (buffer->channel);
if (modes)
str_append_printf (output, "(+%s)", modes);
free (modes);
}
if (buffer != ctx->global_buffer) if (buffer != ctx->global_buffer)
{ {