aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-12-27 01:39:17 -0300
committerdequis <dx@dxzone.com.ar>2015-12-27 01:39:17 -0300
commitba7618d607898050db6e7c380e70c77116100d5f (patch)
treecf37d71046df3534ff45874a8c1ccbc96a423c87
parent98d46d52222e7c4faf352614f354ef80dc414fba (diff)
purple: Show self-messages for private messages only
Those are purple_conversation_write with PURPLE_MESSAGE_SEND flag set, received through the write_conv UI op. write_chat and write_im still receive and filter PURPLE_MESSAGE_SEND. In the case of write_chat it *could* show some of those, but it seems there's no decent way to tell echoes apart from remote self-messages. So just keep those hidden for now.
-rw-r--r--protocols/purple/purple.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c
index a3b997cd..40415067 100644
--- a/protocols/purple/purple.c
+++ b/protocols/purple/purple.c
@@ -963,42 +963,43 @@ void prplcb_conv_del_users(PurpleConversation *conv, GList *cbuddies)
}
}
-void prplcb_conv_chat_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags,
- time_t mtime)
+/* Generic handler for IM or chat messages, covers write_chat, write_im and write_conv */
+static void handle_conv_msg(PurpleConversation *conv, const char *who, const char *message, guint32 bee_flags, time_t mtime)
{
+ struct im_connection *ic = purple_ic_by_pa(conv->account);
struct groupchat *gc = conv->ui_data;
PurpleBuddy *buddy;
- /* ..._SEND means it's an outgoing message, no need to echo those. */
- if (flags & PURPLE_MESSAGE_SEND) {
- return;
- }
-
buddy = purple_find_buddy(conv->account, who);
if (buddy != NULL) {
who = purple_buddy_get_name(buddy);
}
- imcb_chat_msg(gc, who, (char *) message, 0, mtime);
+ if (conv->type == PURPLE_CONV_TYPE_IM) {
+ imcb_buddy_msg(ic, (char *) who, (char *) message, bee_flags, mtime);
+ } else if (gc) {
+ imcb_chat_msg(gc, who, (char *) message, bee_flags, mtime);
+ }
}
-static void prplcb_conv_im(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags,
- time_t mtime)
+/* Handles write_im and write_chat. Removes echoes of locally sent messages */
+static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime)
{
- struct im_connection *ic = purple_ic_by_pa(conv->account);
- PurpleBuddy *buddy;
-
- /* ..._SEND means it's an outgoing message, no need to echo those. */
- if (flags & PURPLE_MESSAGE_SEND) {
- return;
+ if (!(flags & PURPLE_MESSAGE_SEND)) {
+ handle_conv_msg(conv, who, message, 0, mtime);
}
+}
- buddy = purple_find_buddy(conv->account, who);
- if (buddy != NULL) {
- who = purple_buddy_get_name(buddy);
+/* Handles write_conv. Only passes self messages from other locations through.
+ * That is, only writes of PURPLE_MESSAGE_SEND.
+ * There are more events which might be handled in the future, but some are tricky.
+ * (images look like <img id="123">, what do i do with that?) */
+static void prplcb_conv_write(PurpleConversation *conv, const char *who, const char *alias, const char *message,
+ PurpleMessageFlags flags, time_t mtime)
+{
+ if (flags & PURPLE_MESSAGE_SEND) {
+ handle_conv_msg(conv, who, message, OPT_SELFMESSAGE, mtime);
}
-
- imcb_buddy_msg(ic, (char *) who, (char *) message, 0, mtime);
}
/* No, this is not a ui_op but a signal. */
@@ -1031,9 +1032,9 @@ static PurpleConversationUiOps bee_conv_uiops =
{
prplcb_conv_new, /* create_conversation */
prplcb_conv_free, /* destroy_conversation */
- prplcb_conv_chat_msg, /* write_chat */
- prplcb_conv_im, /* write_im */
- NULL, /* write_conv */
+ prplcb_conv_msg, /* write_chat */
+ prplcb_conv_msg, /* write_im */
+ prplcb_conv_write, /* write_conv */
prplcb_conv_add_users, /* chat_add_users */
NULL, /* chat_rename_user */
prplcb_conv_del_users, /* chat_remove_users */