From 20d5ea90e7718e6931fd271715e8b9e2dc91a8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Fri, 3 Nov 2017 20:36:53 +0100 Subject: [PATCH] Store oob data into DB Right now oob data is merged into the message text and stored into the DB. If we load this message from the DB we cannot know anymore if and which parts of the text was oob data. Use the additional_data api to store oob data into the DB instead of altering the original message text. This lets us decide later on if and which data we want to display, even on history replays. Also plugins can use the data. --- gajim/common/connection_handlers_events.py | 23 ++++++++++------------ gajim/conversation_textview.py | 13 ++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index 0e10fa662..a2b93349b 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -1399,8 +1399,7 @@ class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): def generate(self): self.stanza = self.msg_obj.stanza - if not hasattr(self, 'additional_data'): - self.additional_data = self.msg_obj.additional_data + self.additional_data = self.msg_obj.additional_data self.id_ = self.msg_obj.id_ self.jid = self.msg_obj.jid self.fjid = self.msg_obj.fjid @@ -1453,18 +1452,13 @@ class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): self.get_chatstate() oob_node = self.stanza.getTag('x', namespace=nbxmpp.NS_X_OOB) - self.oob_url = None - self.oob_desc = None - if oob_node: + if oob_node is not None: self.oob_url = oob_node.getTagData('url') + if self.oob_url is not None: + self.additional_data['gajim'] = {'oob_url': self.oob_url} self.oob_desc = oob_node.getTagData('desc') - if self.oob_url: - self.msgtxt += '\n' - if self.oob_desc: - self.msgtxt += self.oob_desc - else: - self.msgtxt += _('URL:') - self.msgtxt += ' ' + self.oob_url + if self.oob_desc is not None: + self.additional_data['gajim'] = {'oob_desc': self.oob_desc} replace = self.stanza.getTag('replace', namespace=nbxmpp.NS_CORRECT) if replace: @@ -1506,7 +1500,10 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent): def generate(self): self.stanza = self.msg_obj.stanza - self.additional_data = self.msg_obj.additional_data + if not hasattr(self.msg_obj, 'additional_data'): + self.additional_data = {} + else: + self.additional_data = self.msg_obj.additional_data self.id_ = self.msg_obj.stanza.getID() self.fjid = self.msg_obj.fjid self.msgtxt = self.msg_obj.msgtxt diff --git a/gajim/conversation_textview.py b/gajim/conversation_textview.py index 685b4ff0c..28e71cb3e 100644 --- a/gajim/conversation_textview.py +++ b/gajim/conversation_textview.py @@ -844,6 +844,19 @@ class ConversationTextview(GObject.GObject): # We impose an arbitrary limit of 100 specials per message. specials_limit = 100 + # add oob text to the end + try: + gajim_data = additional_data['gajim'] + oob_url = gajim_data['oob_url'] + print(oob_url) + except KeyError: + pass + else: + oob_desc = additional_data['gajim'].get('oob_desc', None) + if oob_desc is None: + oob_desc = _('URL:') + otext += '\n{} {}'.format(oob_desc, oob_url) + # basic: links + mail + formatting is always checked (we like that) if app.config.get('emoticons_theme') and graphics: # search for emoticons & urls