diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-21 21:47:34 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-21 21:47:34 +0200 |
commit | d0b7545f1e516db4362442a3d0f69d337f2e3e59 (patch) | |
tree | 7fb588e743c8ca896038db27bf45ea537a894c4a /degesch.c | |
parent | 9c0f0c0e33d583c7b7404c8318fda0c42b35997e (diff) | |
download | xK-d0b7545f1e516db4362442a3d0f69d337f2e3e59.tar.gz xK-d0b7545f1e516db4362442a3d0f69d337f2e3e59.tar.xz xK-d0b7545f1e516db4362442a3d0f69d337f2e3e59.zip |
degesch: implement TOPIC handling
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -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 |