Use "available" presence type instead of "probe"

darcs-hash:20080528124630-86b55-0d0ee3b409a4c58cf4579c4ed894959b9f762cbd.gz
This commit is contained in:
David Rousselie
2008-05-28 14:46:30 +02:00
parent 2fd9bc173b
commit a43d0b9a3a
2 changed files with 38 additions and 31 deletions

View File

@@ -337,54 +337,51 @@ class AccountManager(object):
###### presence generic handlers ######
def get_presence_all(self, presence):
"""Send presence to all account. Optimized to use only one sql
request"""
"""Send presence to all account."""
result = []
model.db_connect()
for user in account.get_all_users():
result.extend(self.get_presence(self.component.jid,
result.append(self.get_presence(self.component.jid,
user.jid,
presence))
for _account in account.get_all_accounts():
result.extend(getattr(self, "get_account_presence_" +
presence)(_account))
model.db_disconnect()
return result
def get_root_presence(self, to_jid, presence_type,
show=None, status=None):
result = self.get_presence(self.component.jid, to_jid,
presence_type, show=show,
status=status)
result = [self.get_presence(self.component.jid, to_jid,
presence_type, show=show,
status=status)]
for legacy_jid in account.get_legacy_jids(unicode(to_jid.bare())):
result.append(Presence(from_jid=legacy_jid.jid,
to_jid=to_jid,
show=show,
status=status,
stanza_type=presence_type))
result.append(self.get_presence(from_jid=legacy_jid.jid,
to_jid=to_jid,
presence_type=presence_type,
status=status,
show=show))
return result
def get_presence(self, from_jid, to_jid, presence_type,
status=None, show=None):
"""Send presence stanza"""
return [Presence(from_jid=from_jid,
to_jid=to_jid,
status=status,
show=show,
stanza_type=presence_type)]
return Presence(from_jid=from_jid,
to_jid=to_jid,
status=status,
show=show,
stanza_type=presence_type)
def get_account_presence_probe(self, _account):
"""Send presence probe to account's user"""
return self.get_presence(from_jid=_account.jid,
to_jid=_account.user.jid,
presence_type="probe")
return [self.get_presence(from_jid=_account.jid,
to_jid=_account.user.jid,
presence_type="probe")]
def get_account_presence_unavailable(self, _account):
"""Send unavailable presence to account's user"""
_account.status = account.OFFLINE
return self.get_presence(from_jid=_account.jid,
to_jid=_account.user.jid,
presence_type="unavailable")
return [self.get_presence(from_jid=_account.jid,
to_jid=_account.user.jid,
presence_type="unavailable")]
def get_account_presence_available(self, _account, lang_class):
"""Send available presence to account's user and ask for password
@@ -397,7 +394,7 @@ class AccountManager(object):
elif not _account.enabled:
_account.status = account.XA
if old_status != _account.status:
result.extend(self.get_presence(from_jid=_account.jid,
result.append(self.get_presence(from_jid=_account.jid,
to_jid=_account.user.jid,
status=_account.status_msg,
show=_account.status,
@@ -412,7 +409,17 @@ class AccountManager(object):
def probe_all_accounts_presence(self):
"""Send presence probe to all registered accounts"""
return self.get_presence_all("probe")
result = [self.get_presence(self.component.jid,
user.jid,
"available")
for user in account.get_all_users()]
result += [self.get_presence(from_jid=_account.jid,
to_jid=_account.user.jid,
status=_account.status_msg,
show=_account.status,
presence_type="available")
for _account in account.get_all_accounts()]
return result
###### Utils methods ######
def list_accounts(self, bare_from_jid, account_class=None,

View File

@@ -418,27 +418,27 @@ class JCLComponent_TestCase(JCLTestCase):
self.assertTrue(isinstance(presence, Presence))
self.assertEquals(presence.get_from(), "jcl.test.com")
self.assertEquals(presence.get_to(), "test1@test.com")
self.assertEquals(presence.get_node().prop("type"), "probe")
self.assertEquals(presence.get_node().prop("type"), None)
presence = self.comp.stream.sent[1]
self.assertTrue(isinstance(presence, Presence))
self.assertEquals(presence.get_from(), "jcl.test.com")
self.assertEquals(presence.get_to(), "test2@test.com")
self.assertEquals(presence.get_node().prop("type"), "probe")
self.assertEquals(presence.get_node().prop("type"), None)
presence = self.comp.stream.sent[2]
self.assertTrue(isinstance(presence, Presence))
self.assertEquals(presence.get_from(), "account11@jcl.test.com")
self.assertEquals(presence.get_to(), "test1@test.com")
self.assertEquals(presence.get_node().prop("type"), "probe")
self.assertEquals(presence.get_node().prop("type"), None)
presence = self.comp.stream.sent[3]
self.assertTrue(isinstance(presence, Presence))
self.assertEquals(presence.get_from(), "account12@jcl.test.com")
self.assertEquals(presence.get_to(), "test1@test.com")
self.assertEquals(presence.get_node().prop("type"), "probe")
self.assertEquals(presence.get_node().prop("type"), None)
presence = self.comp.stream.sent[4]
self.assertTrue(isinstance(presence, Presence))
self.assertEquals(presence.get_from(), "account2@jcl.test.com")
self.assertEquals(presence.get_to(), "test2@test.com")
self.assertEquals(presence.get_node().prop("type"), "probe")
self.assertEquals(presence.get_node().prop("type"), None)
###########################################################################
# 'signal_handler' tests