From 8e7412eb970437541fc4b184e7429231a6384860 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Mon, 20 Apr 2015 00:08:18 +0200
Subject: [PATCH] degesch: halfplement NICK and QUIT handlers
---
degesch.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 89 insertions(+), 5 deletions(-)
diff --git a/degesch.c b/degesch.c
index 798344f..8ea9ad9 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1835,9 +1835,57 @@ irc_handle_mode (struct app_context *ctx, const struct irc_message *msg)
static void
irc_handle_nick (struct app_context *ctx, const struct irc_message *msg)
{
- // TODO: rename the user in all relevant channels
- // TODO: if it's us, rename ourselves
- // TODO: log a message in all relevant channels
+ if (!msg->prefix || msg->params.len < 1)
+ return;
+
+ // FIXME: make sure we have an associated user;
+ // we might be able to get rid of "irc_nickname" then
+ char *nickname = irc_cut_nickname (msg->prefix);
+ struct user *user = str_map_find (&ctx->irc_users, nickname);
+ free (nickname);
+ if (!user)
+ return;
+
+ const char *new_nickname = msg->params.vector[0];
+ if (irc_is_this_us (ctx, msg->prefix))
+ {
+ // Update user information
+ free (ctx->irc_nickname);
+ ctx->irc_nickname = xstrdup (new_nickname);
+ refresh_prompt (ctx);
+
+ // Log a message in all open buffers on this server
+ struct str_map_iter iter;
+ str_map_iter_init (&iter, &ctx->irc_buffer_map);
+ struct buffer *buffer;
+ while ((buffer = str_map_iter_next (&iter)))
+ {
+ // TODO: log a "You are now known as" message
+ }
+ }
+ else
+ {
+ // Log a message in any PM buffer
+ struct buffer *buffer =
+ str_map_find (&ctx->irc_buffer_map, user->nickname);
+ if (buffer)
+ {
+ // TODO: log a message in the buffer
+ // TODO: rename the buffer, and if it collides, merge them
+ }
+
+ // Log a message in all channels the user is in
+ LIST_FOR_EACH (struct user_channel, iter, user->channels)
+ {
+ buffer = str_map_find (&ctx->irc_buffer_map, iter->channel->name);
+ hard_assert (buffer != NULL);
+ // TODO: log a message in the buffer
+ }
+ }
+
+ // Finally rename the user
+ free (user->nickname);
+ user->nickname = xstrdup (new_nickname);
}
static void
@@ -1916,8 +1964,44 @@ irc_handle_privmsg (struct app_context *ctx, const struct irc_message *msg)
static void
irc_handle_quit (struct app_context *ctx, const struct irc_message *msg)
{
- // TODO: remove user from all channels
- // TODO: log a message
+ if (!msg->prefix)
+ return;
+
+ // What the fuck
+ if (irc_is_this_us (ctx, msg->prefix))
+ return;
+
+ char *nickname = irc_cut_nickname (msg->prefix);
+ struct user *user = str_map_find (&ctx->irc_users, nickname);
+ free (nickname);
+ if (!user)
+ return;
+
+ const char *message = NULL;
+ if (msg->params.len > 0)
+ message = msg->params.vector[0];
+
+ // Log a message in any PM buffer
+ struct buffer *buffer =
+ str_map_find (&ctx->irc_buffer_map, user->nickname);
+ if (buffer)
+ {
+ // TODO: log a message in the buffer
+ }
+
+ // Log a message in all channels the user is in
+ LIST_FOR_EACH (struct user_channel, iter, user->channels)
+ {
+ buffer = str_map_find (&ctx->irc_buffer_map, iter->channel->name);
+ hard_assert (buffer != NULL);
+ // TODO: log a message in the buffer
+
+ // TODO: remove the "channel_user" link from iter->channel
+ // TODO: remove the link from the list and free it
+ }
+
+ // TODO: check reference count on the user and if it's just one,
+ // remove him from "irc_users"
}
static void