degesch: factor out send_message_to_target()

And check that we're actually connected.
This commit is contained in:
Přemysl Eric Janouch 2015-04-19 22:20:03 +02:00
parent 953bc72e2b
commit 51415c1db6

View File

@ -2329,6 +2329,22 @@ process_user_command (struct app_context *ctx, char *command)
"%s: %s", "No such command", name);
}
static void
send_message_to_target (struct app_context *ctx,
const char *target, char *message, struct buffer *buffer)
{
if (ctx->irc_fd == -1)
{
buffer_send_error (ctx, buffer, "Not connected");
return;
}
// TODO: autosplit
irc_send (ctx, "PRIVMSG %s :%s", target, message);
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
ctx->irc_nickname, NULL, "%s", message);
}
static void
send_message_to_current_buffer (struct app_context *ctx, char *message)
{
@ -2342,16 +2358,10 @@ send_message_to_current_buffer (struct app_context *ctx, char *message)
buffer_send_error (ctx, buffer, "This buffer is not a channel");
break;
case BUFFER_CHANNEL:
// TODO: autosplit
irc_send (ctx, "PRIVMSG %s :%s", buffer->channel->name, message);
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
ctx->irc_nickname, NULL, "%s", message);
send_message_to_target (ctx, buffer->channel->name, message, buffer);
break;
case BUFFER_PM:
// TODO: autosplit
irc_send (ctx, "PRIVMSG %s :%s", buffer->user->nickname, message);
buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
ctx->irc_nickname, NULL, "%s", message);
send_message_to_target (ctx, buffer->user->nickname, message, buffer);
break;
}
}