Reducing the timeout for closing the channel and cleaning up some code
[theonering] / src / presence.py
1 import logging
2
3 import tp
4 import util.misc as misc_utils
5 import simple_presence
6
7
8 _moduleLogger = logging.getLogger(__name__)
9
10
11 class PresenceMixin(tp.ConnectionInterfacePresence, simple_presence.TheOneRingPresence):
12
13         def __init__(self):
14                 tp.ConnectionInterfacePresence.__init__(self)
15                 simple_presence.TheOneRingPresence.__init__(self)
16
17         @misc_utils.log_exception(_moduleLogger)
18         def GetStatuses(self):
19                 # the arguments are in common to all on-line presences
20                 arguments = {}
21
22                 return dict(
23                         (localType, (telepathyType, True, True, arguments))
24                         for (localType, telepathyType) in self.TO_PRESENCE_TYPE.iteritems()
25                 )
26
27         @misc_utils.log_exception(_moduleLogger)
28         def RequestPresence(self, contactIds):
29                 presences = self.__get_presences(contactIds)
30                 self.PresenceUpdate(presences)
31
32         @misc_utils.log_exception(_moduleLogger)
33         def GetPresence(self, contactIds):
34                 return self.__get_presences(contactIds)
35
36         @misc_utils.log_exception(_moduleLogger)
37         def SetStatus(self, statuses):
38                 assert len(statuses) == 1
39                 status, arguments = statuses.items()[0]
40                 assert len(arguments) == 0
41                 self.set_presence(status)
42
43         def __get_presences(self, contacts):
44                 arguments = {}
45                 return dict(
46                         (h, (0, {presence: arguments}))
47                         for (h, (presenceType, presence)) in self.get_presences(contacts).iteritems()
48                 )