diff options
Diffstat (limited to 'src/text_buffer.py')
-rw-r--r-- | src/text_buffer.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/text_buffer.py b/src/text_buffer.py index 59aa96e1..6bc3ee23 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -24,6 +24,9 @@ Message = collections.namedtuple('Message', message_fields) class CorrectionError(Exception): pass +class AckError(Exception): + pass + def other_elems(self): "Helper for the repr_message function" acc = ['Message('] @@ -84,7 +87,7 @@ class TextBuffer(object): @staticmethod def make_message(txt, time, nickname, nick_color, history, user, identifier, str_time=None, highlight=False, - old_message=None, revisions=0, jid=None, ack=None): + old_message=None, revisions=0, jid=None, ack=0): """ Create a new Message object with parameters, check for /me messages, and delayed messages @@ -125,7 +128,7 @@ class TextBuffer(object): def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None, highlight=False, - identifier=None, str_time=None, jid=None, ack=None): + identifier=None, str_time=None, jid=None, ack=0): """ Create a message and add it to the text buffer """ @@ -161,16 +164,31 @@ class TextBuffer(object): return i return -1 - def ack_message(self, old_id): + def ack_message(self, old_id, jid): + """Mark a message as acked""" + return self.edit_ack(1, old_id, jid) + + def nack_message(self, error, old_id, jid): + """Mark a message as errored""" + return self.edit_ack(-1, old_id, jid, append=error) + + def edit_ack(self, value, old_id, jid, append=''): """ - Ack a message + Edit the ack status of a message, and optionally + append some text. """ i = self._find_message(old_id) if i == -1: return msg = self.messages[i] + if msg.jid != jid: + raise AckError('Wrong JID for message id %s (was %s, expected %s)' % + (old_id, msg.jid, jid)) + new_msg = list(msg) - new_msg[12] = True + new_msg[12] = value + if append: + new_msg[0] = new_msg[0] + append new_msg = Message(*new_msg) self.messages[i] = new_msg return new_msg |