Mercurial > libervia-backend
changeset 3173:343b8076e967
core (xmpp): new message key to handle attachments
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Feb 2020 18:17:14 +0100 (2020-02-18) |
parents | dcebc585c29f |
children | c90f27ce52b0 |
files | sat/core/constants.py sat/core/xmpp.py |
diffstat | 2 files changed, 22 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/core/constants.py Tue Feb 18 18:13:19 2020 +0100 +++ b/sat/core/constants.py Tue Feb 18 18:17:14 2020 +0100 @@ -133,6 +133,9 @@ MESS_KEY_ENCRYPTED = "encrypted" MESS_KEY_TRUSTED = "trusted" + MESS_KEY_ATTACHMENTS = "attachments" + MESS_KEY_MEDIA_TYPE = "media_type" + # File encryption algorithms ENC_AES_GCM = "AES-GCM"
--- a/sat/core/xmpp.py Tue Feb 18 18:13:19 2020 +0100 +++ b/sat/core/xmpp.py Tue Feb 18 18:17:14 2020 +0100 @@ -20,6 +20,7 @@ import time import calendar import uuid +import mimetypes from functools import partial import shortuuid from sat.core.i18n import _ @@ -656,6 +657,14 @@ """A message sending can be cancelled by a plugin treatment""" failure.trap(exceptions.CancelError) + def isMessagePrintable(self, mess_data): + """Return True if a message contain payload to show in frontends""" + return ( + mess_data["message"] or mess_data["subject"] + or mess_data["extra"].get(C.MESS_KEY_ATTACHMENTS) + or mess_data["type"] == C.MESS_TYPE_INFO + ) + def messageAddToHistory(self, data): """Store message into database (for local history) @@ -665,7 +674,9 @@ if data["type"] != C.MESS_TYPE_GROUPCHAT: # we don't add groupchat message to history, as we get them back # and they will be added then - if data["message"] or data["subject"]: # we need a message to store + + # we need a message to store + if self.isMessagePrintable(data): self.host_app.memory.addToHistory(self, data) else: log.warning( @@ -689,8 +700,9 @@ if data["type"] != C.MESS_TYPE_GROUPCHAT: # we don't send groupchat message to bridge, as we get them back # and they will be added the - if (data["message"] or data["subject"]): # we need a message to send - # something + + # we need a message to send something + if self.isMessagePrintable(data): # We send back the message, so all frontends are aware of it self.host_app.bridge.messageNew( @@ -995,7 +1007,7 @@ self.host = host def parseMessage(self, message_elt): - """parse a message XML and return message_data + """Parse a message XML and return message_data @param message_elt(domish.Element): raw <message> xml @param client(SatXMPPClient, None): client to map message id to uid @@ -1123,7 +1135,8 @@ log.debug("history is skipped as requested") data["extra"]["history"] = C.HISTORY_SKIP else: - if data["message"] or data["subject"]: # we need a message to store + # we need a message to store + if self.parent.isMessagePrintable(data): return self.host.memory.addToHistory(self.parent, data) else: log.debug("not storing empty message to history: {data}" @@ -1138,7 +1151,7 @@ if C.MESS_KEY_ENCRYPTION in data: data["extra"]["encrypted"] = C.BOOL_TRUE if data is not None: - if data["message"] or data["subject"] or data["type"] == C.MESS_TYPE_INFO: + if self.parent.isMessagePrintable(data): self.host.bridge.messageNew( data["uid"], data["timestamp"],