summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDafydd Harries <dafydd.harries@collabora.co.uk>2007-09-27 15:03:28 +0000
committerDafydd Harries <dafydd.harries@collabora.co.uk>2007-09-27 15:03:28 +0000
commit3a4df2954becfbc195fadfc325a5c6f3d2eefbcf (patch)
tree9344084796de1a42bbb0cb914a8122cffd8f15be
parent22083c7a6f9dbf64c6d405310cf2ba130921f90a (diff)
use MessageTypeNormal for offline messages without type attribute that Google server sends
-rw-r--r--src/text-mixin.c12
-rw-r--r--tests/test-parse-message.c38
2 files changed, 49 insertions, 1 deletions
diff --git a/src/text-mixin.c b/src/text-mixin.c
index 34ef51e43..ddb72adeb 100644
--- a/src/text-mixin.c
+++ b/src/text-mixin.c
@@ -315,7 +315,17 @@ gabble_text_mixin_parse_incoming_message (LmMessage *message,
if (body != NULL)
{
- if (0 == strncmp (body, "/me ", 4))
+ if (type == NULL &&
+ lm_message_node_get_child_with_namespace (message->node,
+ "time", "google:timestamp") != NULL &&
+ lm_message_node_get_child_with_namespace (message->node,
+ "x", "jabber:x:delay") != NULL)
+ {
+ /* Google servers send offline messages without a type. Work around
+ * this. */
+ *msgtype = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
+ }
+ else if (0 == strncmp (body, "/me ", 4))
{
*msgtype = TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION;
*body_ret = body + 4;
diff --git a/tests/test-parse-message.c b/tests/test-parse-message.c
index e3d0545e6..48da1623b 100644
--- a/tests/test-parse-message.c
+++ b/tests/test-parse-message.c
@@ -126,6 +126,43 @@ test_error (void)
return TRUE;
}
+static gboolean
+test_google_offline (void)
+{
+ LmMessage *msg;
+ gboolean ret;
+ const gchar *from;
+ time_t stamp;
+ TpChannelTextMessageType type;
+ TpChannelTextSendError send_error;
+ const gchar *body;
+ gint state;
+
+ msg = lm_message_build (NULL, LM_MESSAGE_TYPE_MESSAGE,
+ '@', "from", "foo@bar.com",
+ '(', "body", "hello", ')',
+ '(', "x", "",
+ '@', "xmlns", "jabber:x:delay",
+ '@', "stamp", "20070927T13:24:14",
+ ')',
+ '(', "time", "",
+ '@', "xmlns", "google:timestamp",
+ '@', "ms", "1190899454656",
+ ')',
+ NULL);
+ ret = gabble_text_mixin_parse_incoming_message (
+ msg, &from, &stamp, &type, &body, &state, &send_error);
+ g_assert (ret == TRUE);
+ g_assert (0 == strcmp (from, "foo@bar.com"));
+ g_assert (stamp == 1190899454);
+ g_assert (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL);
+ g_assert (0 == strcmp(body, "hello"));
+ g_assert (state == -1);
+ g_assert (send_error == GABBLE_TEXT_CHANNEL_SEND_NO_ERROR);
+ lm_message_unref (msg);
+ return TRUE;
+}
+
int
main (void)
{
@@ -133,6 +170,7 @@ main (void)
g_assert (test2 ());
g_assert (test3 ());
g_assert (test_error ());
+ g_assert (test_google_offline ());
return 0;
}