Index: doc/user-guide/commands.xml
===================================================================
--- doc/user-guide/commands.xml (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ doc/user-guide/commands.xml (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -1404,4 +1404,31 @@
+
+ true
+ true, false, prefix, prefix_notice
+
+
+
+ Change this setting to customize how (or whether) to show self-messages, which are messages sent by yourself from other locations (for example, mobile clients), for IM protocols that support it.
+
+
+
+ When this is set to "true", it will send those messages in the "standard" way, which is a PRIVMSG with source and target fields swapped.
+
+
+
+ Since this isn't very well supported by some clients (the messages might appear in the wrong window), you can set it to "prefix" to show them as a normal message prefixed with "-> ", or use "prefix_notice" which is the same thing but with a NOTICE instead.
+
+
+
+ You can also set it to "false" to disable these messages completely.
+
+
+
+ This setting only applies to private messages. Self messages in groupchats are always shown, since they haven't caused issues in any clients so far.
+
+
+
+
Index: irc.c
===================================================================
--- irc.c (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ irc.c (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -129,4 +129,5 @@
s = set_add(&b->set, "show_offline", "false", set_eval_bw_compat, irc);
s->flags |= SET_HIDDEN;
+ s = set_add(&b->set, "self_messages", "true", set_eval_self_messages, irc);
s = set_add(&b->set, "simulate_netsplit", "true", set_eval_bool, irc);
s = set_add(&b->set, "timezone", "local", set_eval_timezone, irc);
Index: irc.h
===================================================================
--- irc.h (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ irc.h (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -354,4 +354,5 @@
char *set_eval_timezone(struct set *set, char *value);
char *irc_format_timestamp(irc_t *irc, time_t msg_ts);
+char *set_eval_self_messages(struct set *set, char *value);
/* irc_im.c */
Index: irc_im.c
===================================================================
--- irc_im.c (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ irc_im.c (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -201,12 +201,15 @@
}
-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;
@@ -216,7 +219,42 @@
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;
@@ -249,5 +287,5 @@
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);
@@ -260,5 +298,5 @@
}
-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;
@@ -617,8 +655,8 @@
}
-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;
Index: irc_util.c
===================================================================
--- irc_util.c (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ irc_util.c (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -119,2 +119,14 @@
}
}
+
+
+char *set_eval_self_messages(set_t *set, char *value)
+{
+ if (is_bool(value) ||
+ g_strcasecmp(value, "prefix") == 0 ||
+ g_strcasecmp(value, "prefix_notice") == 0) {
+ return value;
+ } else {
+ return SET_INVALID;
+ }
+}
Index: protocols/bee.h
===================================================================
--- protocols/bee.h (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ protocols/bee.h (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -105,5 +105,5 @@
gboolean (*user_status)(bee_t *bee, struct bee_user *bu, struct bee_user *old);
/* On every incoming message. sent_at = 0 means unknown. */
- gboolean (*user_msg)(bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at);
+ gboolean (*user_msg)(bee_t *bee, bee_user_t *bu, const char *msg, guint32 flags, time_t sent_at);
/* Flags currently defined (OPT_TYPING/THINKING) in nogaim.h. */
gboolean (*user_typing)(bee_t *bee, bee_user_t *bu, guint32 flags);
@@ -118,5 +118,5 @@
/* System messages of any kind. */
gboolean (*chat_log)(bee_t *bee, struct groupchat *c, const char *text);
- gboolean (*chat_msg)(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at);
+ gboolean (*chat_msg)(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, guint32 flags, time_t sent_at);
gboolean (*chat_add_user)(bee_t *bee, struct groupchat *c, bee_user_t *bu);
gboolean (*chat_remove_user)(bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *reason);
Index: protocols/bee_chat.c
===================================================================
--- protocols/bee_chat.c (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ protocols/bee_chat.c (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -95,14 +95,13 @@
}
-void imcb_chat_msg(struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at)
+void imcb_chat_msg(struct groupchat *c, const char *who, char *msg, guint32 flags, time_t sent_at)
{
struct im_connection *ic = c->ic;
bee_t *bee = ic->bee;
bee_user_t *bu;
- gboolean temp;
+ gboolean temp = FALSE;
char *s;
- /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */
- if (handle_is_self(ic, who)) {
+ if (handle_is_self(ic, who) && !(flags & OPT_SELFMESSAGE)) {
return;
}
@@ -122,5 +121,5 @@
if (bee->ui->chat_msg) {
- bee->ui->chat_msg(bee, c, bu, msg, sent_at);
+ bee->ui->chat_msg(bee, c, bu, msg, flags, sent_at);
}
Index: protocols/bee_user.c
===================================================================
--- protocols/bee_user.c (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ protocols/bee_user.c (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -247,5 +247,5 @@
}
-void imcb_buddy_msg(struct im_connection *ic, const char *handle, const char *msg, uint32_t flags, time_t sent_at)
+void imcb_buddy_msg(struct im_connection *ic, const char *handle, const char *msg, guint32 flags, time_t sent_at)
{
bee_t *bee = ic->bee;
@@ -265,5 +265,5 @@
if (bee->ui->user_msg && bu) {
- bee->ui->user_msg(bee, bu, msg, sent_at);
+ bee->ui->user_msg(bee, bu, msg, flags, sent_at);
} else {
imcb_log(ic, "Message from unknown handle %s:\n%s", handle, msg);
@@ -297,5 +297,5 @@
}
-void imcb_buddy_typing(struct im_connection *ic, const char *handle, uint32_t flags)
+void imcb_buddy_typing(struct im_connection *ic, const char *handle, guint32 flags)
{
bee_user_t *bu;
Index: protocols/nogaim.h
===================================================================
--- protocols/nogaim.h (revision 0db66186f49438ae9c2f73ca85b915e999896309)
+++ protocols/nogaim.h (revision 345577bc90da1d1fffa0df013426eab54fa2b1b2)
@@ -70,4 +70,5 @@
#define OPT_PONGS 0x00010000 /* Service sends us keep-alives */
#define OPT_PONGED 0x00020000 /* Received a keep-alive during last interval */
+#define OPT_SELFMESSAGE 0x00080000 /* A message sent by self from another location */
/* ok. now the fun begins. first we create a connection structure */
@@ -325,5 +326,5 @@
G_MODULE_EXPORT void imcb_buddy_action_response(bee_user_t *bu, const char *action, char * const args[], void *data);
-G_MODULE_EXPORT void imcb_buddy_typing(struct im_connection *ic, const char *handle, uint32_t flags);
+G_MODULE_EXPORT void imcb_buddy_typing(struct im_connection *ic, const char *handle, guint32 flags);
G_MODULE_EXPORT struct bee_user *imcb_buddy_by_handle(struct im_connection *ic, const char *handle);
G_MODULE_EXPORT void imcb_clean_handle(struct im_connection *ic, char *handle);