Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2007-06-11 14:46:52 (GMT)
committer Simon McVittie <simon.mcvittie@collabora.co.uk>2007-06-11 14:46:52 (GMT)
commitb1598f4ba7adc553eecb687b284288d0998909e6 (patch)
tree4d4ae9bd351903859793f59f8b91f2d5ad60d8b3
parent8dbe02b14e7af74d81fae40dc1a612bccb4028e9 (diff)
Move responsibility for tracking claimed buddy activities from ServerPlugin to PresenceService
-rw-r--r--src/presenceservice.py26
-rw-r--r--src/server_plugin.py41
2 files changed, 24 insertions, 43 deletions
diff --git a/src/presenceservice.py b/src/presenceservice.py
index 818692e..5a57a3c 100644
--- a/src/presenceservice.py
+++ b/src/presenceservice.py
@@ -38,6 +38,7 @@ from buddy import Buddy, ShellOwner
from activity import Activity
from psutils import pubkey_to_keyid
+CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
_PRESENCE_SERVICE = "org.laptop.Sugar.Presence"
@@ -114,8 +115,6 @@ class PresenceService(ExportedGObject):
self._server_plugin.connect('avatar-updated', self._avatar_updated)
self._server_plugin.connect('buddy-properties-changed',
self._buddy_properties_changed)
- self._server_plugin.connect('buddy-activities-changed',
- self._buddy_activities_changed)
self._server_plugin.connect('activity-invitation',
self._activity_invitation)
self._server_plugin.connect('private-invitation',
@@ -172,6 +171,12 @@ class PresenceService(ExportedGObject):
activity_properties_changed)
self._conn_matches[conn].append(m)
+ def buddy_activities_changed(contact, activities):
+ self._buddy_activities_changed(tp, contact, activities)
+ m = conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal(
+ 'ActivitiesChanged', buddy_activities_changed)
+ self._conn_matches[conn].append(m)
+
def _tp_disconnected(self, tp):
if tp.self_handle is not None:
self._handles_buddies.setdefault(tp, {}).pop(
@@ -208,6 +213,17 @@ class PresenceService(ExportedGObject):
buddy.add_telepathy_handle(tp, handle)
buddy.set_properties(props)
+ # kick off a request for their current activities
+ # FIXME: move this to the Buddy?
+ conn = tp.get_connection()
+
+ def got_activities(activities):
+ self._buddy_activities_changed(tp, handle, activities)
+ conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle,
+ reply_handler=got_activities,
+ error_handler=lambda e: _logger.warning('%r: Error getting '
+ 'activities: %s', buddy, e))
+
def _buddy_validity_changed_cb(self, buddy, valid):
if valid:
self.BuddyAppeared(buddy.object_path())
@@ -287,11 +303,17 @@ class PresenceService(ExportedGObject):
pass
def _buddy_activities_changed(self, tp, contact_handle, activities):
+ activities = dict(activities)
_logger.debug("Handle %s activities changed: %s", contact_handle,
activities)
buddies = self._handles_buddies[tp]
buddy = buddies.get(contact_handle)
+ if buddy is self._owner:
+ # ignore network events for Owner activity changes since those
+ # are handled locally
+ return
+
if not buddy:
# We don't know this buddy
# FIXME: What should we do here?
diff --git a/src/server_plugin.py b/src/server_plugin.py
index 10d5731..e48df8d 100644
--- a/src/server_plugin.py
+++ b/src/server_plugin.py
@@ -96,12 +96,6 @@ class ServerPlugin(gobject.GObject):
# properties: dict {name: str => property: object}
# FIXME: are these all the properties or just those that changed?
(gobject.SIGNAL_RUN_FIRST, None, [object, object]),
- 'buddy-activities-changed':
- # OLPC activities changed
- # args:
- # contact handle: int
- # activities: dict {activity_id: str => room: int or long}
- (gobject.SIGNAL_RUN_FIRST, None, [object, object]),
'activity-invitation':
# We were invited to join an activity
# args:
@@ -338,9 +332,6 @@ class ServerPlugin(gobject.GObject):
'PropertiesChanged', self._buddy_properties_changed_cb)
self._matches.append(m)
m = self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal(
- 'ActivitiesChanged', self._buddy_activities_changed_cb)
- self._matches.append(m)
- m = self._conn[CONN_INTERFACE_BUDDY_INFO].connect_to_signal(
'CurrentActivityChanged',
self._buddy_current_activity_changed_cb)
self._matches.append(m)
@@ -465,17 +456,6 @@ class ServerPlugin(gobject.GObject):
self.emit("contact-offline", handle)
del self._online_contacts[handle]
- def _contact_online_activities_cb(self, handle, activities):
- """Handle contact's activity list update"""
- self._buddy_activities_changed_cb(handle, activities)
-
- def _contact_online_activities_error_cb(self, handle, err):
- """Handle contact's activity list being unavailable"""
- _logger.debug("Handle %s - Error getting activities: %s",
- handle, err)
- # Don't drop the buddy if we can't get their activities, for now
- #self._contact_offline(handle)
-
def _contact_online_aliases_cb(self, handle, props, aliases):
"""Handle contact's alias being received (do further queries)"""
if not self._conn or not aliases or not len(aliases):
@@ -492,12 +472,6 @@ class ServerPlugin(gobject.GObject):
self.emit("contact-online", objid, handle, props)
- self._conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle,
- reply_handler=lambda *args: self._contact_online_activities_cb(
- handle, *args),
- error_handler=lambda e: self._contact_online_activities_error_cb(
- handle, e))
-
def _contact_online_aliases_error_cb(self, handle, props, retry, err):
"""Handle failure to retrieve given user's alias/information"""
if retry:
@@ -695,21 +669,6 @@ class ServerPlugin(gobject.GObject):
self._online_contacts[handle]):
self.emit("buddy-properties-changed", handle, properties)
- def _buddy_activities_changed_cb(self, handle, activities):
- """Handle update of given user (handle)'s activities"""
- if handle == self._conn[CONN_INTERFACE].GetSelfHandle():
- # ignore network events for Owner activity changes since those
- # are handled locally
- return
- if (not self._online_contacts.has_key(handle) or
- not self._online_contacts[handle]):
- return
-
- activities_dict = {}
- for act_id, act_handle in activities:
- activities_dict[act_id] = act_handle
- self.emit("buddy-activities-changed", handle, activities_dict)
-
def _buddy_current_activity_changed_cb(self, handle, activity, channel):
"""Handle update of given user (handle)'s current activity"""