degesch: halfplement NICK and QUIT handlers
This commit is contained in:
parent
8b279dde81
commit
8e7412eb97
94
degesch.c
94
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
|
||||
|
Loading…
Reference in New Issue
Block a user