diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-09 22:54:54 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-09 22:54:54 (GMT) |
commit | 9b12b11534a007c46e626b2b7b17265f4bddee5d (patch) | |
tree | 85f399dd4e536cfda01fbc80ccc2331e4e0bdda8 /shell/ChatController.py | |
parent | f5587ac7995feb4af14f23dd0f2dd389787758a6 (diff) |
Get one-to-one chat back to work
Diffstat (limited to 'shell/ChatController.py')
-rw-r--r-- | shell/ChatController.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/shell/ChatController.py b/shell/ChatController.py index 65bd8c6..96d2fd0 100644 --- a/shell/ChatController.py +++ b/shell/ChatController.py @@ -3,10 +3,21 @@ from sugar.chat.BuddyChat import BuddyChat from sugar.activity import ActivityFactory from sugar.presence.PresenceService import PresenceService from sugar.p2p.Stream import Stream +from sugar.chat.Chat import Chat class ChatController: def __init__(self, shell): self._shell = shell + self._id_to_name = {} + self._name_to_chat = {} + + self._shell.connect('activity-closed', self.__activity_closed_cb) + + def __activity_closed_cb(self, shell, activity_id): + if self._id_to_name.has_key(activity_id): + name = self._id_to_name[activity_id] + del self._name_to_chat[name] + del self._id_to_name[activity_id] def listen(self): self._pservice = PresenceService() @@ -18,11 +29,24 @@ class ChatController: self._buddy_stream = Stream.new_from_service(self._service) self._buddy_stream.set_data_listener(self._recv_message) + def open_chat_activity(self, buddy): + service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE) + if service: + activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity') + activity.execute('connect', [service.object_path()]) + self._name_to_chat[buddy.get_name()] = activity + self._id_to_name[activity.get_id()] = buddy.get_name() + + def _get_chat_activity(self, buddy): + nick = buddy.get_name() + if not self._name_to_chat.has_key(nick): + self.open_chat_activity(buddy) + return self._name_to_chat[nick] + def _recv_message(self, address, message): [nick, msg] = Chat.deserialize_message(message) buddy = self._pservice.get_buddy_by_name(nick) if buddy: - activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity') - service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE) - activity.execute('start', service.object_path()) - activity.execute('message', message) + activity = self._get_chat_activity(buddy) + if activity: + activity.execute('message', [message]) |