changeset 2736:df2bc2e704bc

core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
author Goffi <goffi@goffi.org>
date Wed, 02 Jan 2019 18:28:30 +0100
parents ba74914277cf
children 5c2ed8a5ae22
files sat/core/xmpp.py sat_frontends/primitivus/chat.py sat_frontends/quick_frontend/quick_chat.py
diffstat 3 files changed, 49 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/xmpp.py	Wed Jan 02 18:25:55 2019 +0100
+++ b/sat/core/xmpp.py	Wed Jan 02 18:28:30 2019 +0100
@@ -971,17 +971,21 @@
         if C.MESS_KEY_ENCRYPTION in data:
             data[u"extra"][u"encrypted"] = C.BOOL_TRUE
         if data is not None:
-            self.host.bridge.messageNew(
-                data["uid"],
-                data["timestamp"],
-                data["from"].full(),
-                data["to"].full(),
-                data["message"],
-                data["subject"],
-                data["type"],
-                data["extra"],
-                profile=self.parent.profile,
-            )
+            if data["message"] or data["subject"] or data["type"] == C.MESS_TYPE_INFO:
+                self.host.bridge.messageNew(
+                    data["uid"],
+                    data["timestamp"],
+                    data["from"].full(),
+                    data["to"].full(),
+                    data["message"],
+                    data["subject"],
+                    data["type"],
+                    data["extra"],
+                    profile=self.parent.profile,
+                )
+            else:
+                log.debug(u"Discarding bridge signal for empty message: {data}".format(
+                    data=data))
         return data
 
     def cancelErrorTrap(self, failure_):
--- a/sat_frontends/primitivus/chat.py	Wed Jan 02 18:25:55 2019 +0100
+++ b/sat_frontends/primitivus/chat.py	Wed Jan 02 18:28:30 2019 +0100
@@ -492,42 +492,39 @@
             if self.focus_marker_set:
                 self.focus_marker_set = False
 
-        if not message.message:
-            log.error(u"Received an empty message for uid {}".format(message.uid))
-        else:
-            wid = MessageWidget(message)
-            self.mess_walker.append(wid)
-            self._scrollDown()
-            if self._user_moved(message):
-                return  # no notification for moved messages
+        wid = MessageWidget(message)
+        self.mess_walker.append(wid)
+        self._scrollDown()
+        if self._user_moved(message):
+            return  # no notification for moved messages
 
-            # notifications
+        # notifications
 
-            if self._locked:
-                # we don't want notifications when locked
-                # because that's history messages
-                return
+        if self._locked:
+            # we don't want notifications when locked
+            # because that's history messages
+            return
 
-            if wid.mess_data.mention:
-                from_jid = wid.mess_data.from_jid
-                msg = _(
-                    u"You have been mentioned by {nick} in {room}".format(
-                        nick=wid.mess_data.nick, room=self.target
-                    )
-                )
-                self.host.notify(
-                    C.NOTIFY_MENTION, from_jid, msg, widget=self, profile=self.profile
+        if wid.mess_data.mention:
+            from_jid = wid.mess_data.from_jid
+            msg = _(
+                u"You have been mentioned by {nick} in {room}".format(
+                    nick=wid.mess_data.nick, room=self.target
                 )
-            elif self.type == C.CHAT_ONE2ONE:
-                from_jid = wid.mess_data.from_jid
-                msg = _(u"{entity} is talking to you".format(entity=from_jid))
-                self.host.notify(
-                    C.NOTIFY_MESSAGE, from_jid, msg, widget=self, profile=self.profile
-                )
-            else:
-                self.host.notify(
-                    C.NOTIFY_MESSAGE, self.target, widget=self, profile=self.profile
-                )
+            )
+            self.host.notify(
+                C.NOTIFY_MENTION, from_jid, msg, widget=self, profile=self.profile
+            )
+        elif self.type == C.CHAT_ONE2ONE:
+            from_jid = wid.mess_data.from_jid
+            msg = _(u"{entity} is talking to you".format(entity=from_jid))
+            self.host.notify(
+                C.NOTIFY_MESSAGE, from_jid, msg, widget=self, profile=self.profile
+            )
+        else:
+            self.host.notify(
+                C.NOTIFY_MESSAGE, self.target, widget=self, profile=self.profile
+            )
 
     def addUser(self, nick):
         occupant = super(Chat, self).addUser(nick)
--- a/sat_frontends/quick_frontend/quick_chat.py	Wed Jan 02 18:25:55 2019 +0100
+++ b/sat_frontends/quick_frontend/quick_chat.py	Wed Jan 02 18:28:30 2019 +0100
@@ -584,6 +584,11 @@
                 profile,
             )
             return
+
+        if not msg and not subject and type_ != C.MESS_TYPE_INFO:
+            log.warning(u"Received an empty message for uid {}".format(uid))
+            return
+
         if self.type == C.CHAT_GROUP:
             if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT:
                 # we have a private message, we forward it to a private conversation