diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2010-12-01 18:59:57 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2010-12-01 18:59:59 +0000 |
commit | fc8258409337a777b5249d37df5bc6b88573165c (patch) | |
tree | 9a2bb4e30a5ab4a69848e1283f65749cf2c98850 | |
parent | 4a2f68a1b2c84940b844652566710ca2706cfc63 (diff) | |
parent | 438826eb7970d706a8bcb6c6ed79590a885ff761 (diff) |
Merge branch 'fd.o-24779-CurrentPresence-incorrect' into telepathy-mission-control-5.6
Fixes: <https://bugs.freedesktop.org/show_bug.cgi?id=24779>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r-- | src/mcd-account.c | 62 | ||||
-rw-r--r-- | test/twisted/account-manager/request-online.py | 55 |
2 files changed, 80 insertions, 37 deletions
diff --git a/src/mcd-account.c b/src/mcd-account.c index 0a7f3efc..f113f267 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -2977,6 +2977,10 @@ mcd_account_init (McdAccount *account) priv->min_presence_status = NULL; priv->min_presence_message = NULL; + priv->curr_presence_type = TP_CONNECTION_PRESENCE_TYPE_OFFLINE; + priv->curr_presence_status = g_strdup ("offline"); + priv->curr_presence_status = g_strdup (""); + combine_presences (account); priv->always_on = FALSE; @@ -3208,18 +3212,14 @@ mcd_account_request_presence (McdAccount *account, } static void -on_conn_self_presence_changed (McdConnection *connection, - TpConnectionPresenceType presence, - const gchar *status, - const gchar *message, - gpointer user_data) +mcd_account_update_self_presence (McdAccount *account, + TpConnectionPresenceType presence, + const gchar *status, + const gchar *message) { - McdAccount *account = MCD_ACCOUNT (user_data); McdAccountPrivate *priv = account->priv; gboolean changed = FALSE; GValue value = { 0 }; - GType type; - GValueArray *va; if (priv->curr_presence_type != presence) { @@ -3239,24 +3239,39 @@ on_conn_self_presence_changed (McdConnection *connection, changed = TRUE; } - if (_mcd_connection_presence_info_is_ready (connection)) + if (_mcd_connection_presence_info_is_ready (priv->connection)) { _mcd_account_set_changing_presence (account, FALSE); } if (!changed) return; - type = TP_STRUCT_TYPE_SIMPLE_PRESENCE; - g_value_init (&value, type); - g_value_take_boxed (&value, dbus_g_type_specialized_construct (type)); - va = (GValueArray *) g_value_get_boxed (&value); - g_value_set_uint (va->values, presence); - g_value_set_static_string (va->values + 1, status); - g_value_set_static_string (va->values + 2, message); + g_value_init (&value, TP_STRUCT_TYPE_SIMPLE_PRESENCE); + g_value_take_boxed (&value, + tp_value_array_build (3, + G_TYPE_UINT, presence, + G_TYPE_STRING, status, + G_TYPE_STRING, message, + G_TYPE_INVALID)); mcd_account_changed_property (account, "CurrentPresence", &value); g_value_unset (&value); } + +static void +on_conn_self_presence_changed (McdConnection *connection, + TpConnectionPresenceType presence, + const gchar *status, + const gchar *message, + gpointer user_data) +{ + McdAccount *account = MCD_ACCOUNT (user_data); + McdAccountPrivate *priv = account->priv; + + g_assert (priv->connection == connection); + mcd_account_update_self_presence (account, presence, status, message); +} + /* TODO: remove when the relative members will become public */ void mcd_account_get_requested_presence (McdAccount *account, @@ -4080,6 +4095,21 @@ mcd_account_connection_ready_cb (McdAccount *account, } g_free (nickname); + + if (!tp_proxy_has_interface_by_id (tp_connection, + TP_IFACE_QUARK_CONNECTION_INTERFACE_SIMPLE_PRESENCE)) + { + /* This connection doesn't have SimplePresence, but it's online. + * TpConnection only emits connection-ready when the account is online + * and we've introspected it, so we know that if this interface isn't + * present now, it's not going to appear. + * + * So, the spec says that we should set CurrentPresence to Unset. + */ + mcd_account_update_self_presence (account, + TP_CONNECTION_PRESENCE_TYPE_UNSET, "", ""); + } + } void diff --git a/test/twisted/account-manager/request-online.py b/test/twisted/account-manager/request-online.py index 08be67aa..83f34f43 100644 --- a/test/twisted/account-manager/request-online.py +++ b/test/twisted/account-manager/request-online.py @@ -1,5 +1,6 @@ -# Copyright (C) 2009 Nokia Corporation -# Copyright (C) 2009 Collabora Ltd. +# Python is really rubbish. vim: set fileencoding=utf-8 : +# Copyright © 2009–2010 Nokia Corporation +# Copyright © 2009–2010 Collabora Ltd. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -19,9 +20,13 @@ import dbus import dbus.service -from servicetest import EventPattern, tp_name_prefix, tp_path_prefix -from mctest import exec_test, SimulatedConnection, create_fakecm_account,\ - SimulatedChannel, SimulatedClient, expect_client_setup +from servicetest import ( + EventPattern, tp_name_prefix, tp_path_prefix, assertEquals, +) +from mctest import ( + exec_test, SimulatedConnection, create_fakecm_account, + SimulatedChannel, SimulatedClient, expect_client_setup, +) import constants as cs def test(q, bus, mc): @@ -47,11 +52,14 @@ def test(q, bus, mc): "password": "secrecy"}, signature='sv') (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params) - # The account is initially valid but disabled - assert not account.Get(cs.ACCOUNT, 'Enabled', - dbus_interface=cs.PROPERTIES_IFACE) - assert account.Get(cs.ACCOUNT, 'Valid', - dbus_interface=cs.PROPERTIES_IFACE) + # The account is initially valid but disabled, and hence offline + props = account.GetAll(cs.ACCOUNT, dbus_interface=cs.PROPERTIES_IFACE) + assert not props['Enabled'] + assert props['Valid'] + # The spec says it should be (Offline, "", "") but I don't think the + # strings really matter. If anything, the second one should start out at + # "offline". + assertEquals(cs.PRESENCE_TYPE_OFFLINE, props['CurrentPresence'][0]) # Enable the account account.Set(cs.ACCOUNT, 'Enabled', True, @@ -61,10 +69,11 @@ def test(q, bus, mc): signal='AccountPropertyChanged', interface=cs.ACCOUNT) - assert account.Get(cs.ACCOUNT, 'Enabled', - dbus_interface=cs.PROPERTIES_IFACE) - assert account.Get(cs.ACCOUNT, 'Valid', - dbus_interface=cs.PROPERTIES_IFACE) + props = account.GetAll(cs.ACCOUNT, dbus_interface=cs.PROPERTIES_IFACE) + assert props['Enabled'] + assert props['Valid'] + # Ditto above re. string fields. + assertEquals(cs.PRESENCE_TYPE_OFFLINE, props['CurrentPresence'][0]) # Go online requested_presence = dbus.Struct((dbus.UInt32(2L), dbus.String(u'brb'), @@ -115,9 +124,13 @@ def test(q, bus, mc): properties = account.GetAll(cs.ACCOUNT, dbus_interface=cs.PROPERTIES_IFACE) assert properties is not None - assert properties.get('HasBeenOnline') == True - assert properties.get('RequestedPresence') == requested_presence, \ - properties.get('RequestedPresence') + assert properties.get('HasBeenOnline') + assertEquals(requested_presence, properties.get('RequestedPresence')) + + # Since this Connection doesn't support SimplePresence, but it's online, + # the spec says that CurrentPresence should be Unset. + assertEquals((cs.PRESENCE_TYPE_UNSET, "", ""), + properties.get('CurrentPresence')) new_channel = http_fixed_properties buddy_handle = conn.ensure_handle(cs.HT_CONTACT, "buddy") @@ -148,10 +161,10 @@ def test(q, bus, mc): # path=chan.object_path, handled=True) properties = account.GetAll(cs.ACCOUNT, dbus_interface=cs.PROPERTIES_IFACE) - assert properties['Connection'] == '/' - assert properties['ConnectionStatus'] == cs.CONN_STATUS_DISCONNECTED - assert properties['CurrentPresence'] == requested_presence - assert properties['RequestedPresence'] == requested_presence + assertEquals('/', properties['Connection']) + assertEquals(cs.CONN_STATUS_DISCONNECTED, properties['ConnectionStatus']) + assertEquals(requested_presence, properties['CurrentPresence']) + assertEquals(requested_presence, properties['RequestedPresence']) if __name__ == '__main__': exec_test(test, {}) |