From a9fb2e568eb8bc4ec6af50a48f527326efc7831e Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 3 Jan 2018 00:13:48 +0100 Subject: [PATCH] core: moved CHAT_* constants from frontends to core constants + uses constants for MESS_TYPE_* in sendMessage --- frontends/src/quick_frontend/constants.py | 2 -- src/core/constants.py | 5 +++++ src/core/xmpp.py | 15 +++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/frontends/src/quick_frontend/constants.py b/frontends/src/quick_frontend/constants.py index c038a774..47db4037 100644 --- a/frontends/src/quick_frontend/constants.py +++ b/frontends/src/quick_frontend/constants.py @@ -53,8 +53,6 @@ class Const(constants.Const): CONTACT_DATA_FORBIDDEN = {CONTACT_GROUPS, CONTACT_RESOURCES, CONTACT_MAIN_RESOURCE, CONTACT_SELECTED, CONTACT_PROFILE} # set of forbidden names for contact data # Chats - CHAT_ONE2ONE = 'one2one' - CHAT_GROUP = 'group' CHAT_STATE_ICON = { "": u" ", "active": u'✔', diff --git a/src/core/constants.py b/src/core/constants.py index 5f527418..a62f9646 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -119,6 +119,11 @@ class Const(object): MESS_EXTRA_INFO = "info_type" + ## Chat ## + CHAT_ONE2ONE = 'one2one' + CHAT_GROUP = 'group' + + ## Presence ## PRESENCE_UNAVAILABLE = 'unavailable' PRESENCE_SHOW_AWAY = 'away' diff --git a/src/core/xmpp.py b/src/core/xmpp.py index 55a5c124..2dbf00b6 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -356,6 +356,9 @@ class SatXMPPEntity(object): subject = {} if extra is None: extra = {} + + assert mess_type in C.MESS_TYPE_ALL + data = { # dict is similar to the one used in client.onMessage "from": self.jid, "to": to_jid, @@ -369,10 +372,10 @@ class SatXMPPEntity(object): pre_xml_treatments = defer.Deferred() # XXX: plugin can add their pre XML treatments to this deferred post_xml_treatments = defer.Deferred() # XXX: plugin can add their post XML treatments to this deferred - if data["type"] == "auto": + if data["type"] == C.MESS_TYPE_AUTO: # we try to guess the type if data["subject"]: - data["type"] = 'normal' + data["type"] = C.MESS_TYPE_NORMAL elif not data["to"].resource: # if to JID has a resource, the type is not 'groupchat' # we may have a groupchat message, we check if the we know this jid try: @@ -382,12 +385,12 @@ class SatXMPPEntity(object): entity_type = "contact" if entity_type == "chatroom": - data["type"] = 'groupchat' + data["type"] = C.MESS_TYPE_GROUPCHAT else: - data["type"] = 'chat' + data["type"] = C.MESS_TYPE_CHAT else: - data["type"] == 'chat' - data["type"] == "chat" if data["subject"] else "normal" + data["type"] == C.MESS_TYPE_CHAT + data["type"] == C.MESS_TYPE_CHAT if data["subject"] else C.MESS_TYPE_NORMAL # FIXME: send_only is used by libervia's OTR plugin to avoid # the triggers from frontend, and no_trigger do the same