From 953bc72e2b4696d4f89e8335426950a56a0b639f Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sun, 19 Apr 2015 22:19:52 +0200
Subject: degesch: implement PRIVMSG handling
---
degesch.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/degesch.c b/degesch.c
index 20e1ff7..1d7bf96 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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
--
cgit v1.2.3-70-g09d2