comparison src/core/xmpp.py @ 2136:cc3a6aea9508

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
author Goffi <goffi@goffi.org>
date Sun, 05 Feb 2017 14:55:54 +0100
parents c0577837680a
children f8401024ab28
comparison
equal deleted inserted replaced
2135:4e67d6ffea66 2136:cc3a6aea9508
102 # is it is intended for things like end 2 end encryption. 102 # is it is intended for things like end 2 end encryption.
103 # *DO NOT* cancel (i.e. return False) without very good reason 103 # *DO NOT* cancel (i.e. return False) without very good reason
104 # (out of band transmission for instance). 104 # (out of band transmission for instance).
105 # e2e should have a priority of 0 here, and out of band transmission 105 # e2e should have a priority of 0 here, and out of band transmission
106 # a lower priority 106 # a lower priority
107 if not self.host_app.trigger.point("send", self, obj): 107 # FIXME: trigger not used yet, can be uncommented when e2e full stanza encryption is implemented
108 return 108 # if not self.host_app.trigger.point("send", self, obj):
109 return super(SatXMPPClient, self).send(obj) 109 #  return
110 110 super(SatXMPPClient, self).send(obj)
111
112 def sendMessage(self, mess_data):
113 """Convenient method to send message data to stream
114
115 This method will send mess_data[u'xml'] to stream, but a trigger is there
116 The trigger can't be cancelled, it's a good place for e2e encryption which
117 don't handle full stanza encryption
118 @param mess_data(dict): message data as constructed by onMessage workflow
119 @return (dict): mess_data (so it can be used in a deferred chain)
120 """
121 # XXX: This is the last trigger before u"send" (last but one globally) for sending message.
122 # This is intented for e2e encryption which doesn't do full stanza encryption (e.g. OTR)
123 # This trigger point can't cancel the method
124 self.host_app.trigger.point("sendMessageFinish", self, mess_data)
125 self.send(mess_data[u'xml'])
126 return mess_data
127
128 def feedback(self, to_jid, message):
129 """Send message to frontends
130
131 This message will be an info message, not recorded in history.
132 It can be used to give feedback of a command
133 @param to_jid(jid.Jid): destinee jid
134 @param message(unicode): message to send to frontends
135 """
136 self.host_app.bridge.messageNew(uid=unicode(uuid.uuid4()),
137 timestamp=time.time(),
138 from_jid=self.jid.full(),
139 to_jid=to_jid.full(),
140 message={u'': message},
141 subject={},
142 mess_type=C.MESS_TYPE_INFO,
143 extra={},
144 profile=self.profile)
111 145
112 def _authd(self, xmlstream): 146 def _authd(self, xmlstream):
113 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): 147 if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile):
114 return 148 return
115 wokkel_client.XMPPClient._authd(self, xmlstream) 149 wokkel_client.XMPPClient._authd(self, xmlstream)