pidgin/pidgin

Fix writing_msg instances

2014-06-12, Tomasz Wasilczyk
4aa7dfcc02a1
Parents f72e153dd417
Children 4c9faa80e58b
Fix writing_msg instances
--- a/finch/plugins/gnttinyurl.c Thu Jun 12 21:18:56 2014 +0200
+++ b/finch/plugins/gnttinyurl.c Thu Jun 12 21:33:01 2014 +0200
@@ -246,26 +246,24 @@
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 @@
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;
}
--- a/pidgin/gtkconv.c Thu Jun 12 21:18:56 2014 +0200
+++ b/pidgin/gtkconv.c Thu Jun 12 21:33:01 2014 +0200
@@ -6654,6 +6654,29 @@
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 @@
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 @@
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",