[telepathy-ashes/master] Made presence echoing a bit more resilliant.
David Laban
alsuren at korma.collabora.co.uk
Wed Oct 7 07:39:34 PDT 2009
Don't try to copy people with unknown presence.
Also fixed up the code to set initial status to online.
---
ashes/tools/presence.py | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/ashes/tools/presence.py b/ashes/tools/presence.py
index 69bf78a..415e118 100644
--- a/ashes/tools/presence.py
+++ b/ashes/tools/presence.py
@@ -6,16 +6,26 @@ import telepathy
from telepathy.constants import HANDLE_TYPE_CONTACT
from bases import ConnectionListener
+from helper_functions import printer
class Onlineifier(ConnectionListener):
"""
Sets presence to online on setup
"""
def finish_setup(self, *_args):
- print "Setting status to online"
super(Onlineifier, self).finish_setup(*_args)
+ print "Telling connection to connect."
self.connection.Connect()
- self.connection[self.SIMPLE_PRESENCE].SetPresence('available', '')
+ self.connection.GetStatus(reply_handler=self.StatusChanged,
+ error_handler=printer)
+
+ def StatusChanged(self, status, reason=0):
+ if status == 0: #Connected
+ print "Setting status to online"
+ self.connection[self.SIMPLE_PRESENCE].SetPresence('available', '')
+ # FIXME: if anyone else in the mixin implements this method, we should
+ # call super(Onlineifier, self).StatusChanged(status, reason)
+ # This will be fixed when we use single inheritance.
class PresenceEchoer(ConnectionListener):
@@ -43,7 +53,8 @@ class PresenceEchoer(ConnectionListener):
for handle, presence in presences.items():
type, status, message = presence
self_handle = self._get_self_handle()
- if (type > 1 and handle != self_handle):
+ # type between offline and unknown (exclusive)
+ if (7 > type > 1 and handle != self_handle):
(contact_string,) = self.connection.InspectHandles(HANDLE_TYPE_CONTACT, [handle])
if re.match(self.contact_regexp, contact_string):
@@ -64,9 +75,10 @@ class PresenceEchoer(ConnectionListener):
((status, parameters),) = statuses.items()
self_handle = self._get_self_handle()
- if (handle != self_handle and status != 'offline'):
+ if (handle != self_handle and status not in ['unknown', 'offline']):
(contact_string,) = self.connection.InspectHandles(HANDLE_TYPE_CONTACT, [handle])
if re.match(self.contact_regexp, contact_string):
message = parameters.get('message', '')
new_message = self.identify(contact_string, message)
- self.connection[self.PRESENCE].SetStatus({status: {'message': new_message}})
\ No newline at end of file
+ self.connection[self.PRESENCE].SetStatus({status: {'message': new_message}})
+
--
1.5.6.5
More information about the telepathy-commits
mailing list