comparison src/core/xmpp.py @ 2132:c0577837680a

core: replaced SkipHistory exception by a key in mess_data: SkipHistory was skipping all remaining triggers just to skip history, which is not the intented behaviour. Now history can be skipped by setting mess_data[u'history'] = C.HISTORY_SKIP, this way we won't skip importants triggers. When history is skipped, mess_data[u'extra'][u'history'] will be set to C.HISTORY_SKIP for frontends, so they can inform user that the message is not stored locally.
author Goffi <goffi@goffi.org>
date Sun, 05 Feb 2017 14:55:21 +0100
parents f0bc29dc8157
children cc3a6aea9508
comparison
equal deleted inserted replaced
2131:628c1c95f442 2132:c0577837680a
232 232
233 data = self.parseMessage(message_elt, client) 233 data = self.parseMessage(message_elt, client)
234 234
235 post_treat.addCallback(self.skipEmptyMessage) 235 post_treat.addCallback(self.skipEmptyMessage)
236 post_treat.addCallback(self.addToHistory, client) 236 post_treat.addCallback(self.addToHistory, client)
237 post_treat.addErrback(self.treatmentsEb)
238 post_treat.addCallback(self.bridgeSignal, client, data) 237 post_treat.addCallback(self.bridgeSignal, client, data)
239 post_treat.addErrback(self.cancelErrorTrap) 238 post_treat.addErrback(self.cancelErrorTrap)
240 post_treat.callback(data) 239 post_treat.callback(data)
241 240
242 def skipEmptyMessage(self, data): 241 def skipEmptyMessage(self, data):
243 if not data['message'] and not data['extra'] and not data['subject']: 242 if not data['message'] and not data['extra'] and not data['subject']:
244 raise failure.Failure(exceptions.CancelError("Cancelled empty message")) 243 raise failure.Failure(exceptions.CancelError("Cancelled empty message"))
245 return data 244 return data
246 245
247 def addToHistory(self, data, client): 246 def addToHistory(self, data, client):
248 return self.host.memory.addToHistory(client, data) 247 if data.pop(u'history', None) == C.HISTORY_SKIP:
249 248 log.info(u'history is skipped as requested')
250 def treatmentsEb(self, failure_): 249 data[u'extra'][u'history'] = C.HISTORY_SKIP
251 failure_.trap(exceptions.SkipHistory) 250 else:
251 return self.host.memory.addToHistory(client, data)
252 252
253 def bridgeSignal(self, dummy, client, data): 253 def bridgeSignal(self, dummy, client, data):
254 try: 254 try:
255 data['extra']['received_timestamp'] = data['received_timestamp'] 255 data['extra']['received_timestamp'] = data['received_timestamp']
256 data['extra']['delay_sender'] = data['delay_sender'] 256 data['extra']['delay_sender'] = data['delay_sender']