diff --git a/chat/chat.py b/chat/chat.py index 20842297..bb5bb34b 100755 --- a/chat/chat.py +++ b/chat/chat.py @@ -10,7 +10,6 @@ pygtk.require('2.0') import gtk, gobject import sys -import socket try: import activity @@ -21,7 +20,6 @@ except ImportError: import BuddyList import richtext -import xmlrpclib import p2p class Chat(activity.Activity): @@ -173,23 +171,22 @@ class BuddyChat(Chat): def _start(self): group = p2p.Group.get_instance() - input_pipe = InputPipe(group, "buddy-chat") - input_pipe.listen(self.recv_message) - self._output_pipe = OutputPipe(group, "buddy-chat") + self._output_pipe = p2p.OutputPipe(group, self._buddy, "buddy-chat") def activity_on_connected_to_shell(self): Chat.activity_on_connected_to_shell(self) self.activity_set_can_close(True) self.activity_set_tab_icon_name("im") self.activity_show_icon(True) + self._start() def recv_message(self, sender, msg): Chat.recv_message(self, self._buddy, msg) def send_message(self, text): if len(text) > 0: - self._output_pipe.send(self._buddy, text) - self._local_message(success, msg) + success = self._output_pipe.send(text) + self._local_message(success, text) def activity_on_close_from_user(self): Chat.activity_on_close_from_user(self) @@ -220,6 +217,9 @@ class GroupChat(Chat): input_pipe.listen(self.recv_message) self._output_pipe = p2p.BroadcastOutputPipe(group, "group-chat") + input_pipe = p2p.InputPipe(group, "buddy-chat") + input_pipe.listen(self._buddy_recv_message) + def _create_sidebar(self): vbox = gtk.VBox(False, 6) @@ -338,6 +338,14 @@ class GroupChat(Chat): self._insert_rich_message(buddy.nick(), msg) self._controller.notify_new_message(self, None) + def _buddy_recv_message(self, sender, msg): + chat = buddy.chat() + if not chat: + chat = BuddyChat(self._parent, buddy) + buddy.set_chat(chat) + chat.activity_connect_to_shell() + chat.recv_message(message) + def run(self): try: gtk.main() diff --git a/chat/p2p.py b/chat/p2p.py index 25607a61..fb21eb94 100644 --- a/chat/p2p.py +++ b/chat/p2p.py @@ -1,5 +1,7 @@ import os import pwd +import xmlrpclib +import socket import presence import BuddyList @@ -88,12 +90,11 @@ class Group: def send(self, buddy, pipe_id, msg): addr = "http://%s:%d" % (buddy.address(), buddy.port()) peer = xmlrpclib.ServerProxy(addr) - msg = text success = True try: peer.message(self._serialize_msg(pipe_id, msg)) except (socket.error, xmlrpclib.Fault), e: - msg = str(e) + print str(e) success = False return success @@ -137,14 +138,14 @@ class OutputPipe(AbstractOutputPipe): self._buddy = buddy def send(self, msg): - self._group.send(self._buddy, self._pipe_id, msg) + return self._group.send(self._buddy, self._pipe_id, msg) class BroadcastOutputPipe(AbstractOutputPipe): def __init__(self, group, pipe_id=None): AbstractOutputPipe.__init__(self, group, pipe_id) def send(self, msg): - self._group.broadcast(self._pipe_id, msg) + return self._group.broadcast(self._pipe_id, msg) class InputPipe(AbstractPipe): def __init__(self, group, pipe_id=None):