diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-23 03:00:19 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-23 03:00:19 +0200 |
commit | 15032f9ce7b8eec42e74428acca12dd7f0e6247a (patch) | |
tree | 42c2669a3db8692e3d640ece16cf442e2a212f9a | |
parent | 20c36b4b36987658d682694295140f5afbf405eb (diff) | |
download | xK-15032f9ce7b8eec42e74428acca12dd7f0e6247a.tar.gz xK-15032f9ce7b8eec42e74428acca12dd7f0e6247a.tar.xz xK-15032f9ce7b8eec42e74428acca12dd7f0e6247a.zip |
degesch: fix /query
-rw-r--r-- | degesch.c | 43 |
1 files changed, 23 insertions, 20 deletions
@@ -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); } } |