comparison src/core/xmpp.py @ 2460:feaacc462fef

core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage
author Goffi <goffi@goffi.org>
date Wed, 03 Jan 2018 00:13:48 +0100
parents 8b37a62336c3
children 0046283a285d
comparison
equal deleted inserted replaced
2459:a9c092bf4ee9 2460:feaacc462fef
354 """ 354 """
355 if subject is None: 355 if subject is None:
356 subject = {} 356 subject = {}
357 if extra is None: 357 if extra is None:
358 extra = {} 358 extra = {}
359
360 assert mess_type in C.MESS_TYPE_ALL
361
359 data = { # dict is similar to the one used in client.onMessage 362 data = { # dict is similar to the one used in client.onMessage
360 "from": self.jid, 363 "from": self.jid,
361 "to": to_jid, 364 "to": to_jid,
362 "uid": uid or unicode(uuid.uuid4()), 365 "uid": uid or unicode(uuid.uuid4()),
363 "message": message, 366 "message": message,
367 "timestamp": time.time(), 370 "timestamp": time.time(),
368 } 371 }
369 pre_xml_treatments = defer.Deferred() # XXX: plugin can add their pre XML treatments to this deferred 372 pre_xml_treatments = defer.Deferred() # XXX: plugin can add their pre XML treatments to this deferred
370 post_xml_treatments = defer.Deferred() # XXX: plugin can add their post XML treatments to this deferred 373 post_xml_treatments = defer.Deferred() # XXX: plugin can add their post XML treatments to this deferred
371 374
372 if data["type"] == "auto": 375 if data["type"] == C.MESS_TYPE_AUTO:
373 # we try to guess the type 376 # we try to guess the type
374 if data["subject"]: 377 if data["subject"]:
375 data["type"] = 'normal' 378 data["type"] = C.MESS_TYPE_NORMAL
376 elif not data["to"].resource: # if to JID has a resource, the type is not 'groupchat' 379 elif not data["to"].resource: # if to JID has a resource, the type is not 'groupchat'
377 # we may have a groupchat message, we check if the we know this jid 380 # we may have a groupchat message, we check if the we know this jid
378 try: 381 try:
379 entity_type = self.host_app.memory.getEntityData(data["to"], ['type'], self.profile)["type"] 382 entity_type = self.host_app.memory.getEntityData(data["to"], ['type'], self.profile)["type"]
380 #FIXME: should entity_type manage resources ? 383 #FIXME: should entity_type manage resources ?
381 except (exceptions.UnknownEntityError, KeyError): 384 except (exceptions.UnknownEntityError, KeyError):
382 entity_type = "contact" 385 entity_type = "contact"
383 386
384 if entity_type == "chatroom": 387 if entity_type == "chatroom":
385 data["type"] = 'groupchat' 388 data["type"] = C.MESS_TYPE_GROUPCHAT
386 else: 389 else:
387 data["type"] = 'chat' 390 data["type"] = C.MESS_TYPE_CHAT
388 else: 391 else:
389 data["type"] == 'chat' 392 data["type"] == C.MESS_TYPE_CHAT
390 data["type"] == "chat" if data["subject"] else "normal" 393 data["type"] == C.MESS_TYPE_CHAT if data["subject"] else C.MESS_TYPE_NORMAL
391 394
392 # FIXME: send_only is used by libervia's OTR plugin to avoid 395 # FIXME: send_only is used by libervia's OTR plugin to avoid
393 # the triggers from frontend, and no_trigger do the same 396 # the triggers from frontend, and no_trigger do the same
394 # thing internally, this could be unified 397 # thing internally, this could be unified
395 send_only = data['extra'].get('send_only', False) 398 send_only = data['extra'].get('send_only', False)