core (client): added feedback and sendMessage methods:

- feedback method is a helper method to quickly display an info message to user
    - sendMessage is the method used to send a message in the stream, using message data dictionary.
    It inclure a trigger point which can't be cancelled, it is intended for e2e encryption method which don't do full stanza encryption.
    - "send" trigger point is disabled as it is not used at the moment
This commit is contained in:
Goffi 2017-02-05 14:55:54 +01:00
commit a8bd66d31d

View file

@ -104,10 +104,44 @@ class SatXMPPClient(wokkel_client.XMPPClient):
# (out of band transmission for instance).
# e2e should have a priority of 0 here, and out of band transmission
# a lower priority
if not self.host_app.trigger.point("send", self, obj):
return
return super(SatXMPPClient, self).send(obj)
# FIXME: trigger not used yet, can be uncommented when e2e full stanza encryption is implemented
# if not self.host_app.trigger.point("send", self, obj):
#  return
super(SatXMPPClient, self).send(obj)
def sendMessage(self, mess_data):
"""Convenient method to send message data to stream
This method will send mess_data[u'xml'] to stream, but a trigger is there
The trigger can't be cancelled, it's a good place for e2e encryption which
don't handle full stanza encryption
@param mess_data(dict): message data as constructed by onMessage workflow
@return (dict): mess_data (so it can be used in a deferred chain)
"""
# XXX: This is the last trigger before u"send" (last but one globally) for sending message.
# This is intented for e2e encryption which doesn't do full stanza encryption (e.g. OTR)
# This trigger point can't cancel the method
self.host_app.trigger.point("sendMessageFinish", self, mess_data)
self.send(mess_data[u'xml'])
return mess_data
def feedback(self, to_jid, message):
"""Send message to frontends
This message will be an info message, not recorded in history.
It can be used to give feedback of a command
@param to_jid(jid.Jid): destinee jid
@param message(unicode): message to send to frontends
"""
self.host_app.bridge.messageNew(uid=unicode(uuid.uuid4()),
timestamp=time.time(),
from_jid=self.jid.full(),
to_jid=to_jid.full(),
message={u'': message},
subject={},
mess_type=C.MESS_TYPE_INFO,
extra={},
profile=self.profile)
def _authd(self, xmlstream):
if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):