aboutsummaryrefslogtreecommitdiffstats
path: root/irc_im.c
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2018-04-19 10:23:08 +0200
committerMarius Halden <marius.h@lden.org>2018-04-19 10:23:08 +0200
commitdb02ac8971379f9fee2f3a618bb08b8076d1a83d (patch)
tree0e7d46bad6162509300aa73ae6d77e571a5b26d0 /irc_im.c
parent6dc54671e368d03ed447d0fbd2d662af6c36b7fd (diff)
parent246b98bbdf221448fd7a638fea04373ed1612de5 (diff)
Merge branch 'master' into patched-master
Diffstat (limited to 'irc_im.c')
-rw-r--r--irc_im.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/irc_im.c b/irc_im.c
index dd56165c..f8b50853 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -458,6 +458,35 @@ void bee_irc_user_nick_reset(irc_user_t *iu)
}
+#define PASTEBUF_LONG_SPACELESS_LINE_LENGTH 350
+
+/* Returns FALSE if the last line of the message is near the typical irc length
+ * limit and the message has no spaces, indicating that it's probably desirable
+ * to join messages without the newline.
+ *
+ * The main use case for this is pasting long URLs and not breaking them */
+static gboolean bee_irc_pastebuf_should_start_with_newline(const char *msg)
+{
+ int i;
+ const char *last_line = strrchr(msg, '\n') ? : msg;
+
+ if (*last_line == '\n') {
+ last_line++;
+ }
+
+ for (i = 0; last_line[i]; i++) {
+ if (g_ascii_isspace(last_line[i])) {
+ return TRUE;
+ }
+ }
+
+ if (i < PASTEBUF_LONG_SPACELESS_LINE_LENGTH) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/* IRC->IM calls */
static gboolean bee_irc_user_privmsg_cb(gpointer data, gint fd, b_input_condition cond);
@@ -482,7 +511,10 @@ static gboolean bee_irc_user_privmsg(irc_user_t *iu, const char *msg)
iu->pastebuf = g_string_new(msg);
} else {
b_event_remove(iu->pastebuf_timer);
- g_string_append_printf(iu->pastebuf, "\n%s", msg);
+ if (bee_irc_pastebuf_should_start_with_newline(iu->pastebuf->str)) {
+ g_string_append_c(iu->pastebuf, '\n');
+ }
+ g_string_append(iu->pastebuf, msg);
}
if (set_getbool(&iu->irc->b->set, "paste_buffer")) {