/pidgin/main: 4aa7dfcc02a1: Fix writing_msg instances

Tomasz Wasilczyk <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 4aa7dfcc02a1bb5bb66f82f3914e6815302663f2
Author:	 Tomasz Wasilczyk <[email protected]>
Date:	 2014-06-12 21:33 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/4aa7dfcc02a1

Description:

Fix writing_msg instances

diffstat:

 finch/plugins/gnttinyurl.c |  19 ++++++++-----------
 pidgin/gtkconv.c           |  38 +++++++++++++++++++++++++++-----------
 2 files changed, 35 insertions(+), 22 deletions(-)

diffs (112 lines):

diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c
--- a/finch/plugins/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl.c
@@ -246,26 +246,24 @@ static void free_urls(gpointer data, gpo
 	g_free(data);
 }
 
-static gboolean writing_msg(PurpleAccount *account, char *sender, char **message,
-				PurpleConversation *conv, PurpleMessageFlags flags)
+static gboolean writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused)
 {
 	GString *t;
 	GList *iter, *urls, *next;
 	int c = 0;
 
-	if ((flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE)))
+	if (purple_message_get_flags(msg) & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE))
 		return FALSE;
 
 	urls = g_object_get_data(G_OBJECT(conv), "TinyURLs");
 	if (urls != NULL) /* message was cancelled somewhere? Reset. */
 		g_list_foreach(urls, free_urls, NULL);
 	g_list_free(urls);
-	urls = extract_urls(*message);
+	urls = extract_urls(purple_message_get_contents(msg));
 	if (!urls)
 		return FALSE;
 
-	t = g_string_new(*message);
-	g_free(*message);
+	t = g_string_new(g_strdup(purple_message_get_contents(msg)));
 	for (iter = urls; iter; iter = next) {
 		next = iter->next;
 		if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) {
@@ -289,11 +287,10 @@ static gboolean writing_msg(PurpleAccoun
 			urls = g_list_delete_link(urls, iter);
 		}
 	}
-	*message = t->str;
-	g_string_free(t, FALSE);
-	if (conv == NULL)
-		conv = PURPLE_CONVERSATION(purple_im_conversation_new(account, sender));
-	g_object_set_data(G_OBJECT(conv), "TinyURLs", urls);
+	purple_message_set_contents(msg, t->str);
+	g_string_free(t, TRUE);
+	if (conv != NULL)
+		g_object_set_data(G_OBJECT(conv), "TinyURLs", urls);
 	return FALSE;
 }
 
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -6654,6 +6654,29 @@ box_remote_images(PurpleConversation *co
 		box_remote_image_cb, conv, NULL);
 }
 
+static gboolean
+writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused)
+{
+	PidginConversation *gtkconv;
+
+	g_return_val_if_fail(msg != NULL, FALSE);
+
+	if (!(purple_message_get_flags(msg) & PURPLE_MESSAGE_ACTIVE_ONLY))
+		return FALSE;
+
+	g_return_val_if_fail(conv != NULL, FALSE);
+	gtkconv = PIDGIN_CONVERSATION(conv);
+	g_return_val_if_fail(gtkconv != NULL, FALSE);
+
+	if (conv == gtkconv->active_conv)
+		return FALSE;
+
+	purple_debug_info("gtkconv",
+		"Suppressing message for an inactive conversation");
+
+	return TRUE;
+}
+
 static void
 pidgin_conv_write_conv(PurpleConversation *conv, PurpleMessage *pmsg)
 {
@@ -6702,17 +6725,6 @@ pidgin_conv_write_conv(PurpleConversatio
 
 	if (conv != gtkconv->active_conv)
 	{
-		if (flags & PURPLE_MESSAGE_ACTIVE_ONLY)
-		{
-			/* Unless this had PURPLE_MESSAGE_NO_LOG, this message
-			 * was logged.  Plugin writers: if this isn't what
-			 * you wanted, call purple_im_conversation_write_message() instead of
-			 * purple_conversation_write(). */
-			purple_debug_info("gtkconv",
-			                "Suppressing message for an inactive conversation in pidgin_conv_write_conv()\n");
-			return;
-		}
-
 		/* Set the active conversation to the one that just messaged us. */
 		/* TODO: consider not doing this if the account is offline or something */
 		if (flags & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV))
@@ -8862,6 +8874,10 @@ pidgin_conversations_init(void)
 	purple_signal_connect(purple_connections_get_handle(), "signing-off", handle,
 						G_CALLBACK(account_signing_off), NULL);
 
+	purple_signal_connect(purple_conversations_get_handle(), "writing-im-msg",
+		handle, G_CALLBACK(writing_msg), NULL);
+	purple_signal_connect(purple_conversations_get_handle(), "writing-chat-msg",
+		handle, G_CALLBACK(writing_msg), NULL);
 	purple_signal_connect(purple_conversations_get_handle(), "received-im-msg",
 						handle, G_CALLBACK(received_im_msg_cb), NULL);
 	purple_signal_connect(purple_conversations_get_handle(), "cleared-message-history",
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.