degesch: implement TOPIC handling

This commit is contained in:
Přemysl Eric Janouch 2015-04-21 21:47:34 +02:00
parent 9c0f0c0e33
commit d0b7545f1e

View File

@ -277,6 +277,7 @@ enum buffer_line_type
BUFFER_LINE_PART, ///< PART
BUFFER_LINE_KICK, ///< KICK
BUFFER_LINE_NICK, ///< NICK
BUFFER_LINE_TOPIC, ///< TOPIC
BUFFER_LINE_QUIT, ///< QUIT
BUFFER_LINE_STATUS, ///< Whatever status messages
BUFFER_LINE_ERROR ///< Whatever error messages
@ -926,6 +927,14 @@ buffer_line_display (struct app_context *ctx, struct buffer_line *line)
else
str_append_printf (&text, " - You are now known as %s", object);
break;
case BUFFER_LINE_TOPIC:
if (*who)
str_append_printf (&text,
" - %s has changed the topic to: %s", nick, object);
else
str_append_printf (&text,
" - You have changed the topic to: %s", object);
break;
case BUFFER_LINE_QUIT:
if (*who)
str_append_printf (&text, "<-- %s (%s) has quit (%s)",
@ -2189,7 +2198,31 @@ irc_handle_quit (struct app_context *ctx, const struct irc_message *msg)
static void
irc_handle_topic (struct app_context *ctx, const struct irc_message *msg)
{
// TODO: log a message
if (!msg->prefix || msg->params.len < 2)
return;
const char *channel_name = msg->params.vector[0];
const char *topic = msg->params.vector[1];
if (!irc_is_channel (ctx, channel_name))
return;
struct channel *channel = str_map_find (&ctx->irc_channels, channel_name);
struct buffer *buffer = str_map_find (&ctx->irc_buffer_map, channel_name);
hard_assert ((channel && buffer) ||
(channel && !buffer) || (!channel && !buffer));
// It would be is weird for this to be false
if (channel)
{
free (channel->topic);
channel->topic = xstrdup (topic);
}
if (buffer)
{
buffer_send (ctx, buffer, BUFFER_LINE_TOPIC, 0,
msg->prefix, NULL, "%s", topic);
}
}
static struct irc_handler