diff options
author | dequis <dx@dxzone.com.ar> | 2015-09-13 01:17:14 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-10-30 07:27:20 -0300 |
commit | 345577bc90da1d1fffa0df013426eab54fa2b1b2 (patch) | |
tree | 2c07626bdaceb7bd5070eebd2c4a89b24d82db0b /irc_im.c | |
parent | 0db66186f49438ae9c2f73ca85b915e999896309 (diff) |
IRC self-message support (messages sent by yourself from other clients)
This adds an OPT_SELFMESSAGE flag that can be passed to imcb_buddy_msg()
or imcb_chat_msg() to indicate that the protocol knows that the message
being sent is a self message.
This needs to be explicit since the old behavior is to silently drop
these messages, which also removed server echoes.
This commit doesn't break API/ABI, the flags parameters that were added
are all internal (between protocols and UI code)
On the irc protocol side, the situation isn't very nice, since some
clients put these messages in the wrong window. Irssi, hexchat and mirc
get this wrong. Irssi 0.8.18 has a fix for it, and the others have
scripts to patch it.
But meanwhile, there's a "self_messages" global setting that lets users
disable this, or get them as normal messages / notices with a "->"
prefix, which loosely imitates the workaround used by the ZNC
"privmsg_prefix" module.
Diffstat (limited to 'irc_im.c')
-rw-r--r-- | irc_im.c | 54 |
1 files changed, 46 insertions, 8 deletions
@@ -200,14 +200,17 @@ void bee_irc_channel_update(irc_t *irc, irc_channel_t *ic, irc_user_t *iu) } } -static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, time_t sent_at) +static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, guint32 flags, time_t sent_at) { irc_t *irc = bee->ui_data; irc_user_t *iu = (irc_user_t *) bu->ui_data; + irc_user_t *src_iu = iu; + irc_user_t *dst_iu = irc->user; const char *dst; char *prefix = NULL; char *wrapped, *ts = NULL; char *msg = g_strdup(msg_); + char *message_type = "PRIVMSG"; GSList *l; if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) { @@ -215,9 +218,44 @@ static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, t } dst = irc_user_msgdest(iu); - if (dst != irc->user->nick) { - /* if not messaging directly, call user by name */ - prefix = g_strdup_printf("%s%s%s", irc->user->nick, set_getstr(&bee->set, "to_char"), ts ? : ""); + + if (flags & OPT_SELFMESSAGE) { + char *setting = set_getstr(&irc->b->set, "self_messages"); + + if (is_bool(setting)) { + if (bool2int(setting)) { + /* set to true, send it with src/dst flipped */ + + dst_iu = iu; + src_iu = irc->user; + + if (dst == irc->user->nick) { + dst = dst_iu->nick; + } + } else { + /* set to false, skip the message completely */ + goto cleanup; + } + } else if (g_strncasecmp(setting, "prefix", 6) == 0) { + /* third state, prefix, loosely imitates the znc privmsg_prefix module */ + + g_free(msg); + if (g_strncasecmp(msg_, "/me ", 4) == 0) { + msg = g_strdup_printf("/me -> %s", msg_ + 4); + } else { + msg = g_strdup_printf("-> %s", msg_); + } + + if (g_strcasecmp(setting, "prefix_notice") == 0) { + message_type = "NOTICE"; + } + } + + } + + if (dst != dst_iu->nick) { + /* if not messaging directly (control channel), call user by name */ + prefix = g_strdup_printf("%s%s%s", dst_iu->nick, set_getstr(&bee->set, "to_char"), ts ? : ""); } else { prefix = ts; ts = NULL; /* don't double-free */ @@ -248,7 +286,7 @@ static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, t } wrapped = word_wrap(msg, 425); - irc_send_msg(iu, "PRIVMSG", dst, wrapped, prefix); + irc_send_msg(src_iu, message_type, dst, wrapped, prefix); g_free(wrapped); cleanup: @@ -259,7 +297,7 @@ cleanup: return TRUE; } -static gboolean bee_irc_user_typing(bee_t *bee, bee_user_t *bu, uint32_t flags) +static gboolean bee_irc_user_typing(bee_t *bee, bee_user_t *bu, guint32 flags) { irc_t *irc = (irc_t *) bee->ui_data; @@ -616,10 +654,10 @@ static gboolean bee_irc_chat_log(bee_t *bee, struct groupchat *c, const char *te return TRUE; } -static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at) +static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, guint32 flags, time_t sent_at) { irc_t *irc = bee->ui_data; - irc_user_t *iu = bu->ui_data; + irc_user_t *iu = flags & OPT_SELFMESSAGE ? irc->user : bu->ui_data; irc_channel_t *ic = c->ui_data; char *wrapped, *ts = NULL; |