summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.py12
-rw-r--r--src/tabs.py27
-rw-r--r--src/text_buffer.py17
3 files changed, 33 insertions, 23 deletions
diff --git a/src/core.py b/src/core.py
index 4c1566bd..dc19038a 100644
--- a/src/core.py
+++ b/src/core.py
@@ -2717,7 +2717,7 @@ class Core(object):
if replaced_id is not '' and (config.get_by_tabname(
'group_corrections', 'true', jid.bare).lower() != 'false'):
try:
- conversation.modify_message(body, replaced_id, message['id'])
+ conversation.modify_message(body, replaced_id, message['id'], jid=message['from'])
replaced = True
except CorrectionError:
pass
@@ -2726,7 +2726,8 @@ class Core(object):
nickname=remote_nick,
nick_color=get_theme().COLOR_REMOTE_USER,
history=delayed,
- identifier=message['id'])
+ identifier=message['id'],
+ jid=message['from'])
if conversation.remote_wants_chatstates is None and not delayed:
if message['chat_state']:
conversation.remote_wants_chatstates = True
@@ -2925,7 +2926,7 @@ class Core(object):
replaced = True
except CorrectionError:
pass
- if not replaced and tab.add_message(body, date, nick_from, history=delayed, identifier=message['id']):
+ if not replaced and tab.add_message(body, date, nick_from, history=delayed, identifier=message['id'], jid=message['from']):
self.events.trigger('highlight', message, tab)
if tab is self.current_tab():
@@ -2971,14 +2972,15 @@ class Core(object):
if replaced_id is not '' and (config.get_by_tabname(
'group_corrections', 'true', room_from).lower() != 'false'):
try:
- tab.modify_message(body, replaced_id, message['id'], user=user)
+ tab.modify_message(body, replaced_id, message['id'], user=user, jid=message['from'])
replaced = True
except CorrectionError:
pass
if not replaced:
tab.add_message(body, time=None, nickname=nick_from,
forced_user=user,
- identifier=message['id'])
+ identifier=message['id'],
+ jid=message['from'])
if tab.remote_wants_chatstates is None:
if message['chat_state']:
tab.remote_wants_chatstates = True
diff --git a/src/tabs.py b/src/tabs.py
index 318f90b3..4ea64171 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -484,17 +484,18 @@ class ChatTab(Tab):
if not logger.log_message(self.name, nickname, txt, date=time):
self.core.information(_('Unable to write in the log file'), 'Error')
- def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, identifier=None):
+ def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, identifier=None, jid=None):
self._text_buffer.add_message(txt, time=time,
nickname=nickname,
nick_color=nick_color,
history=None,
user=forced_user,
- identifier=identifier)
+ identifier=identifier,
+ jid=jid)
- def modify_message(self, txt, old_id, new_id, user=None):
+ def modify_message(self, txt, old_id, new_id, user=None, jid=None):
self.log_message(txt, self.name)
- message = self._text_buffer.modify_message(txt, old_id, new_id, time=time, user=user)
+ message = self._text_buffer.modify_message(txt, old_id, new_id, time=time, user=user, jid=jid)
if message:
self.text_win.modify_message(old_id, message)
self.core.refresh_window()
@@ -1748,7 +1749,7 @@ class MucTab(ChatTab):
return user
return None
- def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, history=None, identifier=None):
+ def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, history=None, identifier=None, jid=None):
"""
Note that user can be None even if nickname is not None. It happens
when we receive an history message said by someone who is not
@@ -1774,13 +1775,13 @@ class MucTab(ChatTab):
else: # TODO
highlight = self.do_highlight(txt, time, nickname)
time = time or datetime.now()
- self._text_buffer.add_message(txt, time, nickname, nick_color, history, user, highlight=highlight, identifier=identifier)
+ self._text_buffer.add_message(txt, time, nickname, nick_color, history, user, highlight=highlight, identifier=identifier, jid=jid)
return highlight
- def modify_message(self, txt, old_id, new_id, time=None, nickname=None, user=None):
+ def modify_message(self, txt, old_id, new_id, time=None, nickname=None, user=None, jid=None):
self.log_message(txt, nickname, time=time)
highlight = self.do_highlight(txt, time, nickname)
- message = self._text_buffer.modify_message(txt, old_id, new_id, highlight=highlight, time=time, user=user)
+ message = self._text_buffer.modify_message(txt, old_id, new_id, highlight=highlight, time=time, user=user, jid=jid)
if message:
self.text_win.modify_message(old_id, message)
self.core.refresh_window()
@@ -1872,7 +1873,7 @@ class PrivateTab(ChatTab):
msg['replace']['id'] = self.last_sent_message['id']
if config.get_by_tabname('group_corrections', 'true', self.get_name()).lower() != 'false':
try:
- self.modify_message(line, self.last_sent_message['id'], msg['id'], user=user)
+ self.modify_message(line, self.last_sent_message['id'], msg['id'], user=user, jid=self.core.xmpp.boundjid)
replaced = True
except:
pass
@@ -1882,7 +1883,8 @@ class PrivateTab(ChatTab):
nickname=self.core.own_nick or self.own_nick,
forced_user=user,
nick_color=get_theme().COLOR_OWN_NICK,
- identifier=msg['id'])
+ identifier=msg['id'],
+ jid=self.core.xmpp.boundjid)
if msg['body'].find('\x19') != -1:
msg.enable('html')
msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
@@ -3043,7 +3045,7 @@ class ConversationTab(ChatTab):
msg['replace']['id'] = self.last_sent_message['id']
if config.get_by_tabname('group_corrections', 'true', self.get_name()).lower() != 'false':
try:
- self.modify_message(line, self.last_sent_message['id'], msg['id'])
+ self.modify_message(line, self.last_sent_message['id'], msg['id'], jid=self.core.xmpp.boundjid)
replaced = True
except:
pass
@@ -3051,7 +3053,8 @@ class ConversationTab(ChatTab):
self.add_message(msg['body'],
nickname=self.core.own_nick,
nick_color=get_theme().COLOR_OWN_NICK,
- identifier=msg['id'])
+ identifier=msg['id'],
+ jid=self.core.xmpp.boundjid)
if msg['body'].find('\x19') != -1:
msg.enable('html')
msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
diff --git a/src/text_buffer.py b/src/text_buffer.py
index 62489af8..91b0b57f 100644
--- a/src/text_buffer.py
+++ b/src/text_buffer.py
@@ -18,7 +18,7 @@ from datetime import datetime
from config import config
from theming import get_theme
-message_fields = 'txt nick_color time str_time nickname user identifier highlight me old_message revisions'
+message_fields = 'txt nick_color time str_time nickname user identifier highlight me old_message revisions jid'
Message = collections.namedtuple('Message', message_fields)
class CorrectionError(Exception): pass
@@ -69,7 +69,7 @@ class TextBuffer(object):
return self.messages[-1] if self.messages else None
- def make_message(self, txt, time, nickname, nick_color, history, user, identifier, str_time=None, highlight=False, old_message=None, revisions=0):
+ def make_message(self, txt, time, nickname, nick_color, history, user, identifier, str_time=None, highlight=False, old_message=None, revisions=0, jid=None):
time = time or datetime.now()
me = False
if txt.startswith('/me '):
@@ -86,12 +86,13 @@ class TextBuffer(object):
highlight=highlight,
me=me,
old_message=old_message,
- revisions=revisions)
+ revisions=revisions,
+ jid=jid)
log.debug('Set message %s with %s.', identifier, msg)
return msg
- def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None, highlight=False, identifier=None, str_time=None):
- msg = self.make_message(txt, time, nickname, nick_color, history, user, identifier, str_time=str_time, highlight=highlight)
+ 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):
+ msg = self.make_message(txt, time, nickname, nick_color, history, user, identifier, str_time=str_time, highlight=highlight, jid=jid)
self.messages.append(msg)
while len(self.messages) > self.messages_nb_limit:
self.messages.pop(0)
@@ -105,7 +106,7 @@ 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, user=None):
+ def modify_message(self, txt, old_id, new_id, highlight=False, time=None, user=None, jid=None):
for i in range(len(self.messages) -1, -1, -1):
msg = self.messages[i]
if msg.identifier == old_id:
@@ -113,6 +114,10 @@ class TextBuffer(object):
raise CorrectionError("Different users")
elif len(msg.str_time) > 8: # ugly
raise CorrectionError("Delayed message")
+ elif not msg.user and (msg.jid is None or jid is None):
+ raise CorrectionError('Could not check the identity of the sender')
+ elif not msg.user and msg.jid.full != jid.full:
+ raise CorrectionError('Messages %s and %s have not been sent by the same fullJID' % (old_id, new_id))
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)