backend, frontend: messages refactoring (huge commit, not finished):

/!\ database schema has been modified, do a backup before updating

    message have been refactored, here are the main changes:

    - languages are now handled
    - all messages have an uid (internal to SàT)
    - message updating is anticipated
    - subject is now first class
    - new naming scheme is used newMessage => messageNew, getHistory => historyGet, sendMessage => messageSend
    - minimal compatibility refactoring in quick_frontend/Primitivus, better refactoring should follow
    - threads handling
    - delayed messages are saved into history
    - info messages may also be saved in history (e.g. to keep track of people joining/leaving a room)
    - duplicate messages should be avoided
    - historyGet return messages in right order, no need to sort again
    - plugins have been updated to follow new features, some of them need to be reworked (e.g. OTR)
    - XEP-0203 (Delayed Delivery) is now fully handled in core, the plugin just handle disco and creation of a delay element
    - /!\ jp and Libervia are currently broken, as some features of Primitivus

    It has been put in one huge commit to avoid breaking messaging between changes.
    This is the main part of message refactoring, other commits will follow to take profit of the new features/behaviour.
This commit is contained in:
Goffi 2016-05-24 22:11:04 +02:00
commit f12803fa65

View file

@ -22,7 +22,6 @@ from sat.core.i18n import _
from sat.core.log import getLogger
log = getLogger(__name__)
from calendar import timegm
from wokkel import disco, iwokkel, delay
try:
from twisted.words.protocols.xmlstream import XMPPHandler
@ -49,8 +48,6 @@ class XEP_0203(object):
def __init__(self, host):
log.info(_("Delayed Delivery plugin initialization"))
self.host = host
host.trigger.add("MessageReceived", self.messageReceivedTrigger)
def getHandler(self, profile):
return XEP_0203_handler(self, profile)
@ -71,30 +68,6 @@ class XEP_0203(object):
parent.addChild(elt)
return elt
def messagePostTreat(self, data, timestamp):
"""Set the timestamp of a received message.
@param data (dict): data send by MessageReceived trigger through post_treat deferred
@param timestamp (int): original timestamp of a delayed message
@return: dict
"""
data['extra']['timestamp'] = unicode(timestamp)
return data
def messageReceivedTrigger(self, message, post_treat, profile):
"""Process a delay element from incoming message.
@param message (domish.Element): message element
@param post_treat (Deferred): deferred instance to add post treatments
"""
try:
delay_ = delay.Delay.fromElement([elm for elm in message.elements() if elm.name == 'delay'][0])
except IndexError:
return True
else:
timestamp = timegm(delay_.stamp.utctimetuple())
post_treat.addCallback(self.messagePostTreat, timestamp)
return True
class XEP_0203_handler(XMPPHandler):
implements(iwokkel.IDisco)