summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2010-10-22 12:09:10 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2010-10-22 12:09:11 +0100
commit29ed25e0fdec53c7d294e09a8024b37d64694963 (patch)
tree96c6bc041d0013fb6f915ddd6f90405b5aaa89cb
parent54023e383523e20246fa8015f5cfdcf6f333c461 (diff)
parent4f66208343c29226bdb549c2b1d6d15cd2ab985e (diff)
Merge branch '0.10-xep0186-precedence' into telepathy-gabble-0.10
This is backported from master, where it was merged as 3be1240c7917e90de9818236d02b289ee1166a9f.
-rw-r--r--src/conn-presence.c59
-rw-r--r--tests/twisted/presence/initial-presence.py8
-rw-r--r--tests/twisted/presence/invisible_helper.py12
-rw-r--r--tests/twisted/presence/invisible_xep_0186.py11
-rw-r--r--tests/twisted/presence/plugins.py40
-rw-r--r--tests/twisted/presence/set-idempotence.py9
6 files changed, 101 insertions, 38 deletions
diff --git a/src/conn-presence.c b/src/conn-presence.c
index be7fe652e..617733f62 100644
--- a/src/conn-presence.c
+++ b/src/conn-presence.c
@@ -130,6 +130,9 @@ static void toggle_initial_presence_visibility_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data);
+static void activate_current_privacy_list (GabbleConnection *self,
+ GSimpleAsyncResult *result);
+
/* actual code! */
GQuark
@@ -256,6 +259,7 @@ set_xep0186_invisible (GabbleConnection *self,
GSimpleAsyncResult *result)
{
TpBaseConnection *base = (TpBaseConnection *) self;
+ GabbleConnectionPresencePrivate *priv = self->presence_priv;
GError *error = NULL;
const gchar *element = invisible ? "invisible" : "visible";
WockyStanza *iq = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ,
@@ -267,9 +271,18 @@ set_xep0186_invisible (GabbleConnection *self,
if (!invisible && base->status != TP_CONNECTION_STATUS_CONNECTED)
{
- conn_presence_signal_own_presence (self, NULL, &error);
- g_simple_async_result_complete_in_idle (result);
- g_object_unref (result);
+ if (priv->privacy_statuses != NULL)
+ {
+ /* A plugin might need to activate a privacy list */
+ activate_current_privacy_list (self, result);
+ g_object_unref (result);
+ }
+ else
+ {
+ conn_presence_signal_own_presence (self, NULL, &error);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+ }
}
else if (!_gabble_connection_send_with_reply (self, (LmMessage *) iq,
set_xep0186_invisible_cb, NULL, result, &error))
@@ -442,14 +455,17 @@ disable_invisible_privacy_list (GabbleConnection *self)
{
GabbleConnectionPresencePrivate *priv = self->presence_priv;
- if (self->features & GABBLE_CONNECTION_FEATURES_PRESENCE_INVISIBLE)
- priv->invisibility_method = INVISIBILITY_METHOD_PRESENCE_INVISIBLE;
- else
- priv->invisibility_method = INVISIBILITY_METHOD_NONE;
+ if (priv->invisibility_method == INVISIBILITY_METHOD_PRIVACY)
+ {
+ if (self->features & GABBLE_CONNECTION_FEATURES_PRESENCE_INVISIBLE)
+ priv->invisibility_method = INVISIBILITY_METHOD_PRESENCE_INVISIBLE;
+ else
+ priv->invisibility_method = INVISIBILITY_METHOD_NONE;
- DEBUG ("Set invisibility method to %s",
- (priv->invisibility_method == INVISIBILITY_METHOD_PRESENCE_INVISIBLE) ?
- "presence-invisible" : "none");
+ DEBUG ("Set invisibility method to %s",
+ (priv->invisibility_method == INVISIBILITY_METHOD_PRESENCE_INVISIBLE)
+ ? "presence-invisible" : "none");
+ }
}
static LmHandlerResult
@@ -955,28 +971,29 @@ privacy_lists_loaded_cb (GObject *source_object,
priv->invisible_list_name =
g_strdup (g_hash_table_lookup (priv->privacy_statuses, "hidden"));
- priv->invisibility_method = INVISIBILITY_METHOD_PRIVACY;
-
- setup_invisible_privacy_list_async (self, initial_presence_setup_cb,
- user_data);
+ if (priv->invisibility_method == INVISIBILITY_METHOD_NONE)
+ priv->invisibility_method = INVISIBILITY_METHOD_PRIVACY;
}
- else
- {
- if (self->features & GABBLE_CONNECTION_FEATURES_INVISIBLE)
- priv->invisibility_method = INVISIBILITY_METHOD_INVISIBLE_COMMAND;
- toggle_presence_visibility_async (self,
- toggle_initial_presence_visibility_cb, user_data);
- }
+ if (priv->invisibility_method == INVISIBILITY_METHOD_PRIVACY)
+ setup_invisible_privacy_list_async (self, initial_presence_setup_cb,
+ user_data);
+ else
+ toggle_presence_visibility_async (self,
+ toggle_initial_presence_visibility_cb, user_data);
}
void
conn_presence_set_initial_presence_async (GabbleConnection *self,
GAsyncReadyCallback callback, gpointer user_data)
{
+ GabbleConnectionPresencePrivate *priv = self->presence_priv;
GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (self),
callback, user_data, conn_presence_set_initial_presence_async);
+ if (self->features & GABBLE_CONNECTION_FEATURES_INVISIBLE)
+ priv->invisibility_method = INVISIBILITY_METHOD_INVISIBLE_COMMAND;
+
get_existing_privacy_lists_async (self, privacy_lists_loaded_cb, result);
}
diff --git a/tests/twisted/presence/initial-presence.py b/tests/twisted/presence/initial-presence.py
index 11e97a9aa..84a69534b 100644
--- a/tests/twisted/presence/initial-presence.py
+++ b/tests/twisted/presence/initial-presence.py
@@ -9,7 +9,8 @@ from gabbletest import exec_test
from servicetest import EventPattern, assertEquals, assertNotEquals
import ns
import constants as cs
-from invisible_helper import ValidInvisibleListStream, Xep0186XmlStream
+from invisible_helper import ValidInvisibleListStream, Xep0186Stream, \
+ Xep0186AndValidInvisibleListStream
def test(q, bus, conn, stream):
props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE)
@@ -31,5 +32,6 @@ def test(q, bus, conn, stream):
if __name__ == '__main__':
exec_test(test)
- exec_test(test, protocol=ValidInvisibleListStream)
- exec_test(test, protocol=Xep0186XmlStream)
+ for protocol in [ValidInvisibleListStream, Xep0186Stream,
+ Xep0186AndValidInvisibleListStream]:
+ exec_test(test, protocol=protocol)
diff --git a/tests/twisted/presence/invisible_helper.py b/tests/twisted/presence/invisible_helper.py
index 59da5c87d..58b5195fe 100644
--- a/tests/twisted/presence/invisible_helper.py
+++ b/tests/twisted/presence/invisible_helper.py
@@ -4,9 +4,6 @@ from gabbletest import (
import ns
from twisted.words.xish import xpath
-class Xep0186XmlStream(XmppXmlStream):
- disco_features = [ns.INVISIBLE]
-
class ManualPrivacyListStream(XmppXmlStream):
"""Unlike the base class, which automatically responds to privacy list
requests in the negative, this stream class does not automatically respond.
@@ -84,3 +81,12 @@ class ValidInvisibleListStream(ManualPrivacyListStream):
])
else:
send_error_reply(self, iq, elem(ns.STANZA, 'item-not-found'))
+
+class Xep0186Stream(XmppXmlStream):
+ disco_features = [ns.INVISIBLE]
+
+class Xep0186AndValidInvisibleListStream(ValidInvisibleListStream):
+ disco_features = [ns.INVISIBLE]
+
+class Xep0186AndManualPrivacyListStream(ManualPrivacyListStream):
+ disco_features = [ns.INVISIBLE]
diff --git a/tests/twisted/presence/invisible_xep_0186.py b/tests/twisted/presence/invisible_xep_0186.py
index d66131896..85337b015 100644
--- a/tests/twisted/presence/invisible_xep_0186.py
+++ b/tests/twisted/presence/invisible_xep_0186.py
@@ -9,7 +9,7 @@ from servicetest import (
)
import ns
import constants as cs
-from invisible_helper import Xep0186XmlStream
+from invisible_helper import Xep0186AndValidInvisibleListStream, Xep0186Stream
def test_invisible_on_connect(q, bus, conn, stream):
props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE)
@@ -113,7 +113,8 @@ def test_invisible_fails(q, bus, conn, stream):
if __name__ == '__main__':
- exec_test(test_invisible_on_connect, protocol=Xep0186XmlStream)
- exec_test(test_invisible_on_connect_fails, protocol=Xep0186XmlStream)
- exec_test(test_invisible, protocol=Xep0186XmlStream)
- exec_test(test_invisible_fails, protocol=Xep0186XmlStream)
+ for protocol in [Xep0186Stream, Xep0186AndValidInvisibleListStream]:
+ exec_test(test_invisible_on_connect, protocol=protocol)
+ exec_test(test_invisible_on_connect_fails, protocol=protocol)
+ exec_test(test_invisible, protocol=protocol)
+ exec_test(test_invisible_fails, protocol=protocol)
diff --git a/tests/twisted/presence/plugins.py b/tests/twisted/presence/plugins.py
index 7c5b66c86..f5b40db6f 100644
--- a/tests/twisted/presence/plugins.py
+++ b/tests/twisted/presence/plugins.py
@@ -14,7 +14,8 @@ import constants as cs
from twisted.words.xish import xpath, domish
-from invisible_helper import ManualPrivacyListStream
+from invisible_helper import Xep0186AndManualPrivacyListStream, \
+ ManualPrivacyListStream
def test(q, bus, conn, stream):
statuses = conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE,
@@ -71,11 +72,44 @@ def test(q, bus, conn, stream):
call_async(q, conn.SimplePresence, 'SetPresence', 'testaway', '')
q.expect('dbus-error', method='SetPresence', name=cs.INVALID_ARGUMENT)
- conn.Disconnect()
+def test_with_xep0186(q, bus, conn, stream):
+ statuses = conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE,
+ 'Statuses')
+
+ # testbusy and testaway are provided by test plugin
+ assertContains('testbusy', statuses)
+ assertContains('testaway', statuses)
+
+ assertEquals(statuses['testbusy'][0], cs.PRESENCE_BUSY)
+ assertEquals(statuses['testaway'][0], cs.PRESENCE_AWAY)
+
+ conn.SimplePresence.SetPresence('testbusy', '')
+
+ conn.Connect()
+
+ # ... gabble asks for all the available lists on the server ...
+ stream.handle_get_all_privacy_lists(q, bus, conn,
+ lists=["foo-list", "test-busy-list", "bar-list"])
+ get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
+ list_node = xpath.queryForNodes('//active', get_list.query)[0]
+
+ # ... and then activates the one linked with the requested status
+ # Note: testbusy status is linked to test-busy-list by test plugin
+ assertEquals('test-busy-list', list_node['name'])
+ acknowledge_iq(stream, get_list.stanza)
+
+ q.expect('dbus-signal', signal='PresenceUpdate',
+ args=[{1L: (0L, {u'testbusy': {}})}])
q.expect('dbus-signal', signal='StatusChanged',
- args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_REQUESTED])
+ args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+ # ... testaway is not supposed to be settable on us
+ call_async(q, conn.SimplePresence, 'SetPresence', 'testaway', '')
+ q.expect('dbus-error', method='SetPresence', name=cs.INVALID_ARGUMENT)
+
if __name__ == '__main__':
exec_test(test, protocol=ManualPrivacyListStream)
+ exec_test(test_with_xep0186, protocol=Xep0186AndManualPrivacyListStream)
diff --git a/tests/twisted/presence/set-idempotence.py b/tests/twisted/presence/set-idempotence.py
index 864ff9f66..98e6238e3 100644
--- a/tests/twisted/presence/set-idempotence.py
+++ b/tests/twisted/presence/set-idempotence.py
@@ -8,7 +8,8 @@ import dbus
from servicetest import EventPattern
from gabbletest import exec_test
import constants as cs
-from invisible_helper import Xep0186XmlStream, ValidInvisibleListStream
+from invisible_helper import Xep0186Stream, ValidInvisibleListStream, \
+ Xep0186AndValidInvisibleListStream
def test_presence(q, bus, conn, stream):
conn.Connect()
@@ -114,6 +115,8 @@ if __name__ == '__main__':
# <https://bugs.freedesktop.org/show_bug.cgi?id=30117>. It turned out that
# XEP-0126 support meant that our own presence changes were never
# signalled.
- exec_test(test_simple_presence, protocol=ValidInvisibleListStream)
- exec_test(test_simple_presence, protocol=Xep0186XmlStream)
+ for protocol in [Xep0186AndValidInvisibleListStream, Xep0186Stream,
+ ValidInvisibleListStream]:
+ exec_test(test_simple_presence, protocol=protocol)
+ exec_test(test_simple_presence, protocol=protocol)