pidgin/purple-plugin-pack

Parents 27f3e0ca2360
Children 3fa43343f2c5
splitter: Fix compatibility with OTR (and play nice with other plugins by hooking in last)
--- a/splitter/splitter.c Mon Dec 28 23:09:22 2009 -0800
+++ b/splitter/splitter.c Wed Dec 30 19:48:39 2009 -0800
@@ -75,6 +75,9 @@
gint end;
} message_slice;
+/* Global variable to block infinite loops. Single-threaded is nice */
+static gboolean splitter_injected_message = FALSE;
+
/* plugin preference variables */
static gint current_split_size;
@@ -123,7 +126,6 @@
PurpleAccount *account;
PurpleConnection *gc;
char *displayed = NULL, *sent = NULL;
- gint err = 0;
if (strlen(message) == 0)
return;
@@ -149,60 +151,18 @@
msgflags |= PURPLE_MESSAGE_SEND;
- if (type == PURPLE_CONV_TYPE_IM) {
- PurpleConvIm *im = PURPLE_CONV_IM(conv);
-
- if (sent != NULL && sent[0] != '\0') {
-
- err = serv_send_im(gc, purple_conversation_get_name(conv),
- sent, msgflags);
+ splitter_injected_message = TRUE;
- if ((err > 0) && (displayed != NULL))
- purple_conv_im_write(im, NULL, displayed, msgflags, time(NULL));
-
- purple_signal_emit(purple_conversations_get_handle(), "sent-im-msg",
- account,
- purple_conversation_get_name(conv), sent);
- }
+ if (type == PURPLE_CONV_TYPE_IM) {
+ if (sent != NULL && sent[0] != '\0')
+ purple_conv_im_send_with_flags(PURPLE_CONV_IM(conv), sent, msgflags);
}
else {
- if (sent != NULL && sent[0] != '\0') {
- err = serv_chat_send(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), sent, msgflags);
-
- purple_signal_emit(purple_conversations_get_handle(), "sent-chat-msg",
- account, sent,
- purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)));
- }
+ if (sent != NULL && sent[0] != '\0')
+ purple_conv_chat_send_with_flags(PURPLE_CONV_CHAT(conv), sent, msgflags);
}
- if (err < 0) {
- const char *who;
- const char *msg;
-
- who = purple_conversation_get_name(conv);
-
- if (err == -E2BIG) {
- msg = _("Unable to send message: The message is too large.");
-
- if (!purple_conv_present_error(who, account, msg)) {
- char *msg2 = g_strdup_printf(_("Unable to send message to %s."), who);
- purple_notify_error(gc, NULL, msg2, _("The message is too large."));
- g_free(msg2);
- }
- }
- else if (err == -ENOTCONN) {
- purple_debug_error("conversation", "Not yet connected.\n");
- }
- else {
- msg = _("Unable to send message.");
-
- if (!purple_conv_present_error(who, account, msg)) {
- char *msg2 = g_strdup_printf(_("Unable to send message to %s."), who);
- purple_notify_error(gc, NULL, msg2, NULL);
- g_free(msg2);
- }
- }
- }
+ splitter_injected_message = FALSE;
g_free(displayed);
g_free(sent);
@@ -443,6 +403,9 @@
sending_chat_msg_cb(PurpleAccount *account, const char **message, int id) {
message_to_conv *msg_to_conv;
+ if (splitter_injected_message)
+ return;
+
purple_debug_misc("purple-splitter", "splitter plugin invoked\n");
g_return_if_fail(account != NULL);
@@ -466,6 +429,9 @@
{
message_to_conv *msg_to_conv;
+ if (splitter_injected_message)
+ return;
+
purple_debug_misc("purple-splitter", "splitter plugin invoked\n");
g_return_if_fail(account != NULL);
@@ -473,6 +439,10 @@
g_return_if_fail(message != NULL);
g_return_if_fail(*message != NULL);
+ /* OTR compatibility hack */
+ if (0 == strncmp(*message, "?OTR", strlen("?OTR")))
+ return;
+
msg_to_conv = g_new0(message_to_conv, 1);
msg_to_conv->sender_username = g_strdup(account->username);
@@ -491,13 +461,13 @@
plugin,
PURPLE_CALLBACK(sending_im_msg_cb),
NULL,
- PURPLE_SIGNAL_PRIORITY_LOWEST);
+ PURPLE_SIGNAL_PRIORITY_HIGHEST);
purple_signal_connect_priority(purple_conversations_get_handle(),
"sending-chat-msg",
plugin,
PURPLE_CALLBACK(sending_chat_msg_cb),
NULL,
- PURPLE_SIGNAL_PRIORITY_LOWEST);
+ PURPLE_SIGNAL_PRIORITY_HIGHEST);
return TRUE;
}