degesch: implement PRIVMSG handling

This commit is contained in:
Přemysl Eric Janouch 2015-04-19 22:19:52 +02:00
parent 56ae38b19a
commit 953bc72e2b

View File

@ -1849,7 +1849,52 @@ irc_handle_ping (struct app_context *ctx, const struct irc_message *msg)
static void
irc_handle_privmsg (struct app_context *ctx, const struct irc_message *msg)
{
// TODO: log a message
if (!msg->prefix || msg->params.len < 2)
return;
const char *target = msg->params.vector[0];
const char *message = msg->params.vector[1];
struct buffer *buffer = str_map_find (&ctx->irc_buffer_map, target);
if (irc_is_channel (ctx, target))
{
struct channel *channel = str_map_find (&ctx->irc_channels, target);
hard_assert ((channel && buffer) ||
(channel && !buffer) || (!channel && !buffer));
// This is weird, ignoring
if (!channel)
return;
}
else if (!buffer)
{
// Get or make a user object
char *nickname = irc_cut_nickname (msg->prefix);
struct user *user = str_map_find (&ctx->irc_users, nickname);
if (!user)
{
user = user_new ();
user->nickname = xstrdup (nickname);
str_map_set (&ctx->irc_users, user->nickname, user);
}
// Open a new buffer for the user
buffer = buffer_new ();
buffer->type = BUFFER_PM;
buffer->name = xstrdup (nickname);
buffer->user = user_ref (user);
LIST_APPEND_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
str_map_set (&ctx->irc_buffer_map, user->nickname, buffer);
free (nickname);
}
if (buffer)
{
// TODO: handle CTCP messages
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
msg->prefix, NULL, "%s", message);
}
}
static void