Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/chat
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-06-22 20:01:14 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-06-22 20:01:14 (GMT)
commitc234b7b4a396ce523692d5516c3cc4fb159d9d0c (patch)
tree47f1ce749cdf31abc7b06ba6ad1b3fb493d465b5 /sugar/chat
parent0a305004b08cab01c1ae42a069d77b1517491f99 (diff)
parentbe992586b1e0d849a732b44eed7047dd8be62501 (diff)
Merge branch 'master' of git+ssh://crank.laptop.org/git/sugar
Conflicts: sugar/presence/Buddy.py
Diffstat (limited to 'sugar/chat')
-rw-r--r--sugar/chat/ActivityChat.py32
-rw-r--r--sugar/chat/Chat.py12
2 files changed, 33 insertions, 11 deletions
diff --git a/sugar/chat/ActivityChat.py b/sugar/chat/ActivityChat.py
index 6e3c71c..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_uid() == 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)
diff --git a/sugar/chat/Chat.py b/sugar/chat/Chat.py
index 0894428..ec51f2f 100644
--- a/sugar/chat/Chat.py
+++ b/sugar/chat/Chat.py
@@ -216,17 +216,21 @@ class Chat(gtk.VBox):
def send_sketch(self, svgdata):
if not svgdata or not len(svgdata):
return
- self._stream_writer.write(self.serialize_message(svgdata))
+ if self._stream_writer:
+ self._stream_writer.write(self.serialize_message(svgdata))
owner = PresenceService.get_instance().get_owner()
- self._insert_sketch(owner, svgdata)
+ if owner:
+ self._insert_sketch(owner, svgdata)
def send_text_message(self, text):
"""Send a chat message and insert it into the local buffer."""
if len(text) <= 0:
return
- self._stream_writer.write(self.serialize_message(text))
+ if self._stream_writer:
+ self._stream_writer.write(self.serialize_message(text))
owner = PresenceService.get_instance().get_owner()
- self._insert_rich_message(owner, text)
+ if owner:
+ self._insert_rich_message(owner, text)
def serialize_message(self, message):
owner = PresenceService.get_instance().get_owner()