From 3ab7f9285604474bc1d87db6604b3d84c25edd5c Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sun, 23 Sep 2018 22:45:05 +0200
Subject: [PATCH] handle error message from MUC correctly. Fixes #9280

---
 gajim/common/modules/message.py | 18 ++++++++++++------
 gajim/common/modules/muc.py     |  3 +++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/gajim/common/modules/message.py b/gajim/common/modules/message.py
index 1bee6875b9..946bc70690 100644
--- a/gajim/common/modules/message.py
+++ b/gajim/common/modules/message.py
@@ -82,7 +82,7 @@ class Message:
             return
 
         muc_user = stanza.getTag('x', namespace=nbxmpp.NS_MUC_USER)
-        if muc_user is not None:
+        if muc_user is not None and (stanza.getType() != 'error'):
             if muc_user.getChildren():
                 # Not a PM, handled by MUC module
                 return
@@ -155,8 +155,11 @@ class Message:
 
         if gc_control and jid == fjid:
             if type_ == 'error':
-                msgtxt = _('error while sending %(message)s ( %(error)s )') % {
-                    'message': msgtxt, 'error': stanza.getErrorMsg()}
+                if msgtxt:
+                    msgtxt = _('error while sending %(message)s ( %(error)s )') % {
+                        'message': msgtxt, 'error': stanza.getErrorMsg()}
+                else:
+                    msgtxt = _('error: %s') % stanza.getErrorMsg()
                 # TODO: why is this here?
                 if stanza.getTag('html'):
                     stanza.delChild('html')
@@ -245,9 +248,12 @@ class Message:
         if event.mtype == 'error':
             if not event.msgtxt:
                 event.msgtxt = _('message')
-            self._con.dispatch_error_message(
-                event.stanza, event.msgtxt,
-                event.session, event.fjid, timestamp)
+            if event.gc_control:
+                event.gc_control.print_conversation(event.msgtxt)
+            else:
+                self._con.dispatch_error_message(
+                    event.stanza, event.msgtxt,
+                    event.session, event.fjid, timestamp)
             return
 
         if event.mtype == 'groupchat':
diff --git a/gajim/common/modules/muc.py b/gajim/common/modules/muc.py
index 6a6f012fdf..9e43092293 100644
--- a/gajim/common/modules/muc.py
+++ b/gajim/common/modules/muc.py
@@ -253,6 +253,9 @@ class MUC:
         if muc_user is None:
             return
 
+        if stanza.getType() == 'error':
+            return
+
         decline = muc_user.getTag('decline')
         if decline is not None:
 
-- 
GitLab