core (xmpp): new message key to handle attachments
This commit is contained in:
parent
3b64263f3b
commit
5b0e084a5d
2 changed files with 22 additions and 6 deletions
|
|
@ -133,6 +133,9 @@ class Const(object):
|
|||
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"
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import sys
|
|||
import time
|
||||
import calendar
|
||||
import uuid
|
||||
import mimetypes
|
||||
from functools import partial
|
||||
import shortuuid
|
||||
from sat.core.i18n import _
|
||||
|
|
@ -656,6 +657,14 @@ class SatXMPPEntity:
|
|||
"""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 @@ class SatXMPPEntity:
|
|||
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 @@ class SatXMPPEntity:
|
|||
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 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
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 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
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 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
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"],
|
||||
|
|
|
|||
Loading…
Reference in a new issue