From 15032f9ce7b8eec42e74428acca12dd7f0e6247a Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Thu, 23 Apr 2015 03:00:19 +0200 Subject: degesch: fix /query --- degesch.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/degesch.c b/degesch.c index 8bf40ad..765fdd7 100644 --- a/degesch.c +++ b/degesch.c @@ -1299,6 +1299,27 @@ irc_make_user (struct app_context *ctx, char *nickname) return user; } +static struct buffer * +irc_get_user_buffer (struct app_context *ctx, const char *nickname) +{ + struct buffer *buffer = str_map_find (&ctx->irc_buffer_map, nickname); + if (buffer) + return buffer; + + struct user *user = str_map_find (&ctx->irc_users, nickname); + if (!user) + user = irc_make_user (ctx, xstrdup (nickname)); + + // 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); + return buffer; +} + static void irc_channel_on_destroy (void *object, void *user_data) { @@ -2116,20 +2137,8 @@ irc_handle_privmsg (struct app_context *ctx, const struct irc_message *msg) } 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 = irc_make_user (ctx, xstrdup (nickname)); - - // 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); - + buffer = irc_get_user_buffer (ctx, nickname); free (nickname); } @@ -2707,13 +2716,7 @@ handle_command_query (struct app_context *ctx, char *arguments) buffer_send_error (ctx, ctx->server_buffer, "No text to send"); else { - struct buffer *buffer = str_map_find (&ctx->irc_buffer_map, target); - if (!buffer) - { - // TODO: create a buffer for this user - // TODO: see irc_handle_privmsg - } - buffer_activate (ctx, buffer); + buffer_activate (ctx, irc_get_user_buffer (ctx, target)); SEND_AUTOSPLIT_PRIVMSG (ctx, target, arguments); } } -- cgit v1.2.3-70-g09d2