services/presence/: Make Activities responsible for tracking their members.
Add a signal to notify the PS when all members have gone away.
This commit is contained in:
parent
9d812430bf
commit
6957446167
@ -48,8 +48,17 @@ class Activity(ExportedGObject):
|
||||
__gtype_name__ = "Activity"
|
||||
|
||||
__gsignals__ = {
|
||||
'validity-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([gobject.TYPE_BOOLEAN]))
|
||||
'validity-changed':
|
||||
# The activity's validity has changed.
|
||||
# An activity is valid if its name, color, type and ID have been
|
||||
# set.
|
||||
# Arguments:
|
||||
# validity: bool
|
||||
(gobject.SIGNAL_RUN_FIRST, None, [bool]),
|
||||
'disappeared':
|
||||
# Nobody is in this activity any more.
|
||||
# No arguments.
|
||||
(gobject.SIGNAL_RUN_FIRST, None, []),
|
||||
}
|
||||
|
||||
__gproperties__ = {
|
||||
@ -381,6 +390,7 @@ class Activity(ExportedGObject):
|
||||
"""
|
||||
if buddy not in self._buddies:
|
||||
self._buddies.append(buddy)
|
||||
buddy.add_activity(self)
|
||||
if self.props.valid:
|
||||
self.BuddyJoined(buddy.object_path())
|
||||
|
||||
@ -396,9 +406,13 @@ class Activity(ExportedGObject):
|
||||
"""
|
||||
if buddy in self._buddies:
|
||||
self._buddies.remove(buddy)
|
||||
buddy.remove_activity(self)
|
||||
if self.props.valid:
|
||||
self.BuddyLeft(buddy.object_path())
|
||||
|
||||
if not self._buddies:
|
||||
self.emit('disappeared')
|
||||
|
||||
def _handle_share_join(self, tp, text_channel):
|
||||
"""Called when a join to a network activity was successful.
|
||||
|
||||
|
@ -219,11 +219,12 @@ class PresenceService(ExportedGObject):
|
||||
|
||||
activity.connect("validity-changed",
|
||||
self._activity_validity_changed_cb)
|
||||
activity.connect("disappeared", self._activity_disappeared_cb)
|
||||
self._activities[activity_id] = activity
|
||||
return activity
|
||||
|
||||
def _remove_activity(self, activity):
|
||||
_logger.debug("remove activity %s" % activity.props.id)
|
||||
def _activity_disappeared_cb(self, activity):
|
||||
_logger.debug("activity %s disappeared" % activity.props.id)
|
||||
|
||||
self.ActivityDisappeared(activity.object_path())
|
||||
del self._activities[activity.props.id]
|
||||
@ -259,7 +260,6 @@ class PresenceService(ExportedGObject):
|
||||
|
||||
if activity is not None:
|
||||
activity.buddy_joined(buddy)
|
||||
buddy.add_activity(activity)
|
||||
|
||||
activities_left = old_activities - new_activities
|
||||
for act in activities_left:
|
||||
@ -269,10 +269,6 @@ class PresenceService(ExportedGObject):
|
||||
continue
|
||||
|
||||
activity.buddy_left(buddy)
|
||||
buddy.remove_activity(activity)
|
||||
|
||||
if not activity.get_joined_buddies():
|
||||
self._remove_activity(activity)
|
||||
|
||||
def _activity_invitation(self, tp, act_id):
|
||||
activity = self._activities.get(act_id)
|
||||
|
Loading…
Reference in New Issue
Block a user