[Telepathy-commits] [telepathy-haze/master] Move incoming message handling to IMChannel

Will Thompson will.thompson at collabora.co.uk
Sun Mar 22 04:10:52 PDT 2009


---
 src/im-channel-factory.c |   40 ++--------------------------------------
 src/im-channel.c         |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/im-channel.h         |    3 +++
 3 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/src/im-channel-factory.c b/src/im-channel-factory.c
index 23da76e..66906aa 100644
--- a/src/im-channel-factory.c
+++ b/src/im-channel-factory.c
@@ -391,49 +391,13 @@ haze_write_im (PurpleConversation *conv,
                time_t mtime)
 {
     PurpleAccount *account = purple_conversation_get_account (conv);
-
     HazeImChannelFactory *im_factory =
         ACCOUNT_GET_HAZE_CONNECTION (account)->im_factory;
-    TpChannelTextMessageType type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
-    HazeIMChannel *chan = NULL;
-    char *line_broken, *message;
-
     HazeConversationUiData *ui_data = PURPLE_CONV_GET_HAZE_UI_DATA (conv);
-
-    /* Replaces newline characters with <br>, which then get turned back into
-     * newlines by purple_markup_strip_html (which replaces "\n" with " ")...
-     */
-    line_broken = purple_strdup_withhtml (xhtml_message);
-    message = purple_markup_strip_html (line_broken);
-    g_free (line_broken);
-
-    if (flags & PURPLE_MESSAGE_AUTO_RESP)
-        type = TP_CHANNEL_TEXT_MESSAGE_TYPE_AUTO_REPLY;
-    else if (purple_message_meify(message, -1))
-        type = TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION;
-
-    chan = get_im_channel (im_factory, ui_data->contact_handle,
+    HazeIMChannel *chan = get_im_channel (im_factory, ui_data->contact_handle,
         ui_data->contact_handle, NULL, NULL);
 
-    if (flags & PURPLE_MESSAGE_RECV)
-        tp_text_mixin_receive (G_OBJECT (chan), type, ui_data->contact_handle,
-                               mtime, message);
-    else if (flags & PURPLE_MESSAGE_SEND)
-        tp_svc_channel_type_text_emit_sent (chan, mtime, type, message);
-    else if (flags & PURPLE_MESSAGE_ERROR)
-        /* This is wrong.  The mtime, type and message are of the error message
-         * (such as "Unable to send message: The message is too large.") not of
-         * the message causing the error, and the ChannelTextSendError parameter
-         * shouldn't always be unknown.  But this is the best that can be done
-         * until I fix libpurple.
-         */
-        tp_svc_channel_type_text_emit_send_error (chan,
-            TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN, mtime, type, message);
-    else
-        DEBUG ("channel %u: ignoring message %s with flags %u",
-            ui_data->contact_handle, message, flags);
-
-    g_free (message);
+    haze_im_channel_receive (chan, xhtml_message, flags, mtime);
 }
 
 static void
diff --git a/src/im-channel.c b/src/im-channel.c
index 010c22b..0b5c998 100644
--- a/src/im-channel.c
+++ b/src/im-channel.c
@@ -654,3 +654,45 @@ haze_im_channel_init (HazeIMChannel *self)
     self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, HAZE_TYPE_IM_CHANNEL,
                                               HazeIMChannelPrivate);
 }
+
+void
+haze_im_channel_receive (HazeIMChannel *self,
+                         const char *xhtml_message,
+                         PurpleMessageFlags flags,
+                         time_t mtime)
+{
+    TpChannelTextMessageType type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
+    char *line_broken, *message;
+
+    /* Replaces newline characters with <br>, which then get turned back into
+     * newlines by purple_markup_strip_html (which replaces "\n" with " ")...
+     */
+    line_broken = purple_strdup_withhtml (xhtml_message);
+    message = purple_markup_strip_html (line_broken);
+    g_free (line_broken);
+
+    if (flags & PURPLE_MESSAGE_AUTO_RESP)
+        type = TP_CHANNEL_TEXT_MESSAGE_TYPE_AUTO_REPLY;
+    else if (purple_message_meify (message, -1))
+        type = TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION;
+
+    if (flags & PURPLE_MESSAGE_RECV)
+        tp_text_mixin_receive (G_OBJECT (self), type, self->priv->handle,
+                               mtime, message);
+    else if (flags & PURPLE_MESSAGE_SEND)
+        tp_svc_channel_type_text_emit_sent (self, mtime, type, message);
+    else if (flags & PURPLE_MESSAGE_ERROR)
+        /* This is wrong.  The mtime, type and message are of the error message
+         * (such as "Unable to send message: The message is too large.") not of
+         * the message causing the error, and the ChannelTextSendError parameter
+         * shouldn't always be unknown.  But this is the best that can be done
+         * until I fix libpurple.
+         */
+        tp_svc_channel_type_text_emit_send_error (self,
+            TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN, mtime, type, message);
+    else
+        DEBUG ("channel %u: ignoring message %s with flags %u",
+            self->priv->handle, message, flags);
+
+    g_free (message);
+}
diff --git a/src/im-channel.h b/src/im-channel.h
index f23881b..abe0502 100644
--- a/src/im-channel.h
+++ b/src/im-channel.h
@@ -81,6 +81,9 @@ struct _HazeConversationUiData
 #define PURPLE_CONV_GET_HAZE_UI_DATA(conv) \
     ((HazeConversationUiData *) conv->ui_data)
 
+void haze_im_channel_receive (HazeIMChannel *self, const char *xhtml_message,
+    PurpleMessageFlags flags, time_t mtime);
+
 G_END_DECLS
 
 #endif /* #ifndef __HAZE_IM_CHANNEL_H__*/
-- 
1.5.6.5




More information about the telepathy-commits mailing list