From 51415c1db6550534a4aefb8ec8405b21599819e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Sun, 19 Apr 2015 22:20:03 +0200
Subject: [PATCH] degesch: factor out send_message_to_target()
And check that we're actually connected.
---
degesch.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/degesch.c b/degesch.c
index 1d7bf96..34ee64c 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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;
}
}