Echo messages back to ourselves now that we ignore ourselves in the buddy list

This commit is contained in:
Dan Williams 2006-04-24 15:17:03 -04:00
parent 68ffc82c46
commit fdbb82c00e

View File

@ -32,17 +32,16 @@ class Chat(object):
self._view = view self._view = view
self._label = label self._label = label
def error_message(self, msg):
aniter = self._buffer.get_end_iter()
self._buffer.insert(aniter, "Error: %s\n" % msg)
def activate(self, label): def activate(self, label):
self._view.set_buffer(self._buffer) self._view.set_buffer(self._buffer)
self._label.set_text(label) self._label.set_text(label)
def recv_message(self, buddy, msg): def recv_message(self, buddy, msg):
self._insert_rich_message(buddy.nick(), msg)
def _insert_rich_message(self, nick, msg):
aniter = self._buffer.get_end_iter() aniter = self._buffer.get_end_iter()
self._buffer.insert(aniter, buddy.nick() + ": ") self._buffer.insert(aniter, nick + ": ")
serializer = richtext.RichTextSerializer() serializer = richtext.RichTextSerializer()
serializer.deserialize(msg, self._buffer) serializer.deserialize(msg, self._buffer)
@ -50,6 +49,15 @@ class Chat(object):
aniter = self._buffer.get_end_iter() aniter = self._buffer.get_end_iter()
self._buffer.insert(aniter, "\n") self._buffer.insert(aniter, "\n")
def _local_message(self, success, text):
if not success:
message = "Error: %s\n" % text
aniter = self._buffer.get_end_iter()
self._buffer.insert(aniter, message)
else:
(nick, realname) = self._parent.local_name()
self._insert_rich_message(nick, text)
class BuddyChat(Chat): class BuddyChat(Chat):
def __init__(self, parent, buddy, view, label): def __init__(self, parent, buddy, view, label):
self._buddy = buddy self._buddy = buddy
@ -66,14 +74,14 @@ class BuddyChat(Chat):
return return
addr = "http://%s:%d" % (self._buddy.address(), self._buddy.port()) addr = "http://%s:%d" % (self._buddy.address(), self._buddy.port())
peer = xmlrpclib.ServerProxy(addr) peer = xmlrpclib.ServerProxy(addr)
msg = None msg = text
success = True success = True
try: try:
peer.message(text) peer.message(text)
except socket.error, e: except socket.error, e:
msg = str(e) msg = str(e)
success = False success = False
return (success, msg) self._local_message(success, msg)
class GroupChat(Chat): class GroupChat(Chat):
def __init__(self, parent, view, label): def __init__(self, parent, view, label):
@ -87,7 +95,7 @@ class GroupChat(Chat):
def send_message(self, text): def send_message(self, text):
if len(text) > 0: if len(text) > 0:
self._gc_controller.send_msg(text) self._gc_controller.send_msg(text)
return (True, None) self._local_message(True, text)
def _recv_group_message(self, msg): def _recv_group_message(self, msg):
buddy = self._parent.find_buddy_by_address(msg['addr']) buddy = self._parent.find_buddy_by_address(msg['addr'])
@ -237,9 +245,7 @@ class ChatActivity(activity.Activity):
serializer = richtext.RichTextSerializer() serializer = richtext.RichTextSerializer()
text = serializer.serialize(buf) text = serializer.serialize(buf)
(success, msg) = chat.send_message(text) chat.send_message(text)
if not success:
chat.error_message(msg)
buf.set_text("") buf.set_text("")
buf.place_cursor(buf.get_start_iter()) buf.place_cursor(buf.get_start_iter())
@ -328,6 +334,9 @@ class ChatActivity(activity.Activity):
def find_buddy_by_address(self, address): def find_buddy_by_address(self, address):
return self._buddy_list.find_buddy_by_address(address) return self._buddy_list.find_buddy_by_address(address)
def local_name(self):
return (self._nick, self._realname)
def _on_main_window_delete(self, widget, *args): def _on_main_window_delete(self, widget, *args):
self.quit() self.quit()