From be992586b1e0d849a732b44eed7047dd8be62501 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 22 Jun 2006 18:37:34 +0000 Subject: Don't create more than one activity chat, and join a published chat when it appears --- (limited to 'sugar/chat') diff --git a/sugar/chat/ActivityChat.py b/sugar/chat/ActivityChat.py index f24269b..a7a6516 100644 --- a/sugar/chat/ActivityChat.py +++ b/sugar/chat/ActivityChat.py @@ -4,23 +4,41 @@ from sugar.chat.GroupChat import GroupChat class ActivityChat(GroupChat): SERVICE_TYPE = "_olpc_activity_chat._udp" - SERVICE_PORT = 6200 def __init__(self, activity): GroupChat.__init__(self) + self._chat_service = None + self._activity = activity self._pservice.connect('service-appeared', self._service_appeared_cb) self._pservice.track_service_type(ActivityChat.SERVICE_TYPE) + + # Find an existing activity chat to latch onto service = self._pservice.get_activity_service(activity, ActivityChat.SERVICE_TYPE) if service is not None: self._service_appeared_cb(self._pservice, None, service) def _service_appeared_cb(self, pservice, buddy, service): - if service.get_activity_id() == self._activity.get_id(): - if service.get_type() == ActivityChat.SERVICE_TYPE: - logging.debug('Group chat service appeared, setup the stream.') - self._setup_stream(service) + if service.get_activity_id() != self._activity.get_id(): + return + if service.get_type() != ActivityChat.SERVICE_TYPE: + return + if buddy and buddy.is_owner(): + return + if self._chat_service: + return + + logging.debug('Activity chat service appeared, setup the stream.') + # Ok, there's an existing chat service that we copy + # parameters and such from + addr = service.get_address() + port = service.get_port() + self._chat_service = self._pservice.share_activity(self._activity, + stype=ActivityChat.SERVICE_TYPE, properties=None, + address=addr, port=port) + self._setup_stream(self._chat_service) def publish(self): - service = self._pservice.share_activity(self._activity, - stype = ActivityChat.SERVICE_TYPE, port = ActivityChat.SERVICE_PORT) + """Only called when we publish the activity this chat is tied to.""" + self._chat_service = self._pservice.share_activity(self._activity, + stype=ActivityChat.SERVICE_TYPE) -- cgit v0.9.1