summaryrefslogtreecommitdiff
path: root/src/text_buffer.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-02-27 22:09:14 +0100
committermathieui <mathieui@mathieui.net>2013-02-27 22:09:14 +0100
commitde11a00a8e6d448dbe909d5f96f04bdda9d8e8ec (patch)
treee47da2a0ac33ac591c7e5f550ab8a34dfa21a2e7 /src/text_buffer.py
parentf1831cc0ec51c6b09f43fab67f7f0940fb931039 (diff)
downloadpoezio-de11a00a8e6d448dbe909d5f96f04bdda9d8e8ec.tar.gz
poezio-de11a00a8e6d448dbe909d5f96f04bdda9d8e8ec.tar.bz2
poezio-de11a00a8e6d448dbe909d5f96f04bdda9d8e8ec.tar.xz
poezio-de11a00a8e6d448dbe909d5f96f04bdda9d8e8ec.zip
Improve XEP-0308 support
- Prevent correction of delayed messages - Prevent correction of messages by someone else in a MUC (and in a private tab) - Messages with unauthorized corrections (above) or wrong message id will be displayed as normal messages TODO: restrict the corrections to the same fullJID (only in direct "normal" conversations, because we can know in private an muc tabs, via the User object)
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r--src/text_buffer.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py
index 2aa80670..0b9fc319 100644
--- a/src/text_buffer.py
+++ b/src/text_buffer.py
@@ -21,6 +21,8 @@ from theming import get_theme
message_fields = 'txt nick_color time str_time nickname user identifier highlight me old_message revisions'
Message = collections.namedtuple('Message', message_fields)
+class CorrectionError(Exception): pass
+
def other_elems(self):
acc = ['Message(']
fields = message_fields.split()
@@ -103,16 +105,20 @@ class TextBuffer(object):
window.scroll_up(nb)
return ret_val or 1
- def modify_message(self, txt, old_id, new_id, highlight=False, time=None):
+ def modify_message(self, txt, old_id, new_id, highlight=False, time=None, user=None):
for i in range(len(self.messages) -1, -1, -1):
msg = self.messages[i]
if msg.identifier == old_id:
+ if msg.user and msg.user is not user:
+ raise CorrectionError("wrong user")
+ elif len(msg.str_time) > 8: # ugly
+ raise CorrectionError("delayed message")
message = self.make_message(txt, time if time else msg.time, msg.nickname, msg.nick_color, None, msg.user, new_id, highlight=highlight, old_message=msg, revisions=msg.revisions + 1)
self.messages[i] = message
log.debug('Replacing message %s with %s.', old_id, new_id)
return message
log.debug('Message %s not found in text_buffer, abort replacement.', old_id)
- return
+ raise CorrectionError("nothing to replace")
def del_window(self, win):
self.windows.remove(win)