aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-20 21:49:46 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-20 21:49:46 +0200
commitb8bfcfde7c54e32c7d5d521325bf43d98efa17b4 (patch)
treea3d2695881790f90842dac39889efb709da0da3d
parent8e7412eb970437541fc4b184e7429231a6384860 (diff)
downloadxK-b8bfcfde7c54e32c7d5d521325bf43d98efa17b4.tar.gz
xK-b8bfcfde7c54e32c7d5d521325bf43d98efa17b4.tar.xz
xK-b8bfcfde7c54e32c7d5d521325bf43d98efa17b4.zip
degesch: finish QUIT handling
-rw-r--r--degesch.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/degesch.c b/degesch.c
index 8ea9ad9..dc80fb1 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1986,7 +1986,13 @@ irc_handle_quit (struct app_context *ctx, const struct irc_message *msg)
str_map_find (&ctx->irc_buffer_map, user->nickname);
if (buffer)
{
- // TODO: log a message in the buffer
+ buffer_send (ctx, buffer, BUFFER_LINE_QUIT, 0,
+ msg->prefix, message, "");
+
+ // TODO: set some kind of a flag in the buffer and when the user
+ // reappers on a channel (JOIN), log a "is back online" message.
+ // Also set this flag when we receive a "no such nick" numeric
+ // and reset it when we send something to the buffer.
}
// Log a message in all channels the user is in
@@ -1994,14 +2000,30 @@ irc_handle_quit (struct app_context *ctx, const struct irc_message *msg)
{
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
+ buffer_send (ctx, buffer, BUFFER_LINE_QUIT, 0,
+ msg->prefix, message, "");
+
+ // Unlink the user from the channel
+ struct channel *channel = iter->channel;
+ LIST_FOR_EACH (struct channel_user, iter, channel->users)
+ if (iter->user == user)
+ {
+ LIST_UNLINK (channel->users, iter);
+ channel_user_destroy (iter);
+ }
+
+ LIST_UNLINK (user->channels, iter);
+ user_channel_destroy (iter);
}
- // TODO: check reference count on the user and if it's just one,
- // remove him from "irc_users"
+ // If it's the last reference, there's no reason for the user to stay.
+ // Note that when the user has their own buffer, it still keeps a reference
+ // and we don't have to care about removing them from "irc_buffer_map".
+ if (user->ref_count == 1)
+ {
+ hard_assert (!user->channels);
+ str_map_set (&ctx->irc_users, user->nickname, NULL);
+ }
}
static void