summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--src/connection-presence.c53
-rw-r--r--tests/twisted/constants.py1
-rw-r--r--tests/twisted/presence/presence.py13
4 files changed, 51 insertions, 22 deletions
diff --git a/NEWS b/NEWS
index 4226389..ea11e0f 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,12 @@ Internal changes:
• remove deprecated Capabilities and Presence interfaces (fd.o #69318;
Guillaume, Simon)
+Fixes:
+
+• Report contacts with unknown presence as 'unknown' rather than raising
+ an error, and don't crash if libpurple reports a "primitive status"
+ that we don't understand (fd.o #69474, Simon)
+
telepathy-haze 0.7.1 (2013-09-17)
=================================
diff --git a/src/connection-presence.c b/src/connection-presence.c
index 51d78e0..23c8764 100644
--- a/src/connection-presence.c
+++ b/src/connection-presence.c
@@ -38,10 +38,12 @@ typedef enum {
HAZE_STATUS_EXT_AWAY,
HAZE_STATUS_INVISIBLE,
HAZE_STATUS_OFFLINE,
+ HAZE_STATUS_UNKNOWN,
HAZE_NUM_STATUSES
} HazeStatusIndex;
+/* Indexed by HazeStatusIndex */
static const TpPresenceStatusSpec statuses[] = {
{ "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE,
arg_specs, NULL, NULL },
@@ -53,6 +55,7 @@ static const TpPresenceStatusSpec statuses[] = {
arg_specs, NULL, NULL },
{ "hidden", TP_CONNECTION_PRESENCE_TYPE_HIDDEN, TRUE, NULL, NULL, NULL },
{ "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, NULL, NULL, NULL },
+ { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, NULL, NULL, NULL },
{ NULL, TP_CONNECTION_PRESENCE_TYPE_UNSET, FALSE, NULL, NULL, NULL }
};
@@ -63,7 +66,7 @@ static const PurpleStatusPrimitive primitives[] = {
PURPLE_STATUS_AWAY,
PURPLE_STATUS_EXTENDED_AWAY,
PURPLE_STATUS_INVISIBLE,
- PURPLE_STATUS_OFFLINE
+ PURPLE_STATUS_UNSET,
};
/* Indexed by PurpleStatusPrimitive */
@@ -89,22 +92,36 @@ _get_tp_status (PurpleStatus *p_status)
gchar *message;
TpPresenceStatus *tp_status;
- g_assert (p_status != NULL);
+ if (p_status == NULL)
+ {
+ status_ix = HAZE_STATUS_UNKNOWN;
+ }
+ else
+ {
+ type = purple_status_get_type (p_status);
+ prim = purple_status_type_get_primitive (type);
- type = purple_status_get_type (p_status);
- prim = purple_status_type_get_primitive (type);
- status_ix = status_indices[prim];
+ if (prim <= 0 || prim >= G_N_ELEMENTS (status_indices))
+ {
+ /* guess wildly rather than crashing */
+ status_ix = HAZE_STATUS_AVAILABLE;
+ }
+ else
+ {
+ status_ix = status_indices[prim];
+ }
- xhtml_message = purple_status_get_attr_string (p_status, "message");
- if (xhtml_message)
- {
- GValue *message_v = g_slice_new0 (GValue);
+ xhtml_message = purple_status_get_attr_string (p_status, "message");
+ if (xhtml_message)
+ {
+ GValue *message_v = g_slice_new0 (GValue);
- message = purple_markup_strip_html (xhtml_message);
- g_value_init (message_v, G_TYPE_STRING);
- g_value_set_string (message_v, message);
- g_hash_table_insert (arguments, "message", message_v);
- g_free (message);
+ message = purple_markup_strip_html (xhtml_message);
+ g_value_init (message_v, G_TYPE_STRING);
+ g_value_set_string (message_v, message);
+ g_hash_table_insert (arguments, "message", message_v);
+ g_free (message);
+ }
}
tp_status = tp_presence_status_new (status_ix, arguments);
@@ -180,22 +197,18 @@ _get_contact_statuses (GObject *obj,
if (buddy)
{
PurplePresence *presence = purple_buddy_get_presence (buddy);
+
p_status = purple_presence_get_active_status (presence);
}
else
{
DEBUG ("[%s] %s isn't on the blist, ergo no status!",
conn->account->username, bname);
- g_set_error (error, TP_ERROR, TP_ERROR_NOT_AVAILABLE,
- "Presence for %u unknown; subscribe to them first", handle);
- g_hash_table_destroy (status_table);
- status_table = NULL;
- break;
+ p_status = NULL;
}
}
tp_status = _get_tp_status (p_status);
-
g_hash_table_insert (status_table, GINT_TO_POINTER (handle), tp_status);
}
diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py
index d541c75..37d6d52 100644
--- a/tests/twisted/constants.py
+++ b/tests/twisted/constants.py
@@ -195,6 +195,7 @@ CONN_IFACE_CONTACT_BLOCKING = CONN + '.Interface.ContactBlocking'
CONN_IFACE_ADDRESSING = CONN + '.Interface.Addressing1'
ATTR_CONTACT_CAPABILITIES = CONN_IFACE_CONTACT_CAPS + '/capabilities'
+ATTR_PRESENCE = CONN_IFACE_SIMPLE_PRESENCE + '/presence'
STREAM_HANDLER = 'org.freedesktop.Telepathy.Media.StreamHandler'
diff --git a/tests/twisted/presence/presence.py b/tests/twisted/presence/presence.py
index a3c5854..e35616e 100644
--- a/tests/twisted/presence/presence.py
+++ b/tests/twisted/presence/presence.py
@@ -1,7 +1,5 @@
"""
A simple smoke-test for C.I.SimplePresence
-
-FIXME: test C.I.Presence too
"""
import dbus
@@ -9,7 +7,9 @@ import dbus
from twisted.words.xish import domish, xpath
from twisted.words.protocols.jabber.client import IQ
+from servicetest import assertEquals
from hazetest import exec_test
+import constants as cs
def test(q, bus, conn, stream):
amy_handle = conn.RequestHandles(1, ['amy@foo.com'])[0]
@@ -48,6 +48,15 @@ def test(q, bus, conn, stream):
# produces.
assert event.args[0] == { amy_handle: (2, 'available', 'I may have been drinking') }
+ amy_handle, asv = conn.Contacts.GetContactByID('amy@foo.com',
+ [cs.CONN_IFACE_SIMPLE_PRESENCE])
+ assertEquals(event.args[0][amy_handle], asv.get(cs.ATTR_PRESENCE))
+
+ bob_handle, asv = conn.Contacts.GetContactByID('bob@foo.com',
+ [cs.CONN_IFACE_SIMPLE_PRESENCE])
+ assertEquals((cs.PRESENCE_UNKNOWN, 'unknown', ''),
+ asv.get(cs.ATTR_PRESENCE))
+
conn.Disconnect()
q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])