From 8812915d4e956d607c45076cc1ad48a3f3e7027a Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 18 Feb 2020 18:17:18 +0100 Subject: [PATCH] quick frontends (chat): handle attachments in Message --- sat_frontends/quick_frontend/quick_chat.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sat_frontends/quick_frontend/quick_chat.py b/sat_frontends/quick_frontend/quick_chat.py index 82943a4a..9d7bbb31 100644 --- a/sat_frontends/quick_frontend/quick_chat.py +++ b/sat_frontends/quick_frontend/quick_chat.py @@ -85,6 +85,9 @@ class Message: nick=self.nick, message=self.main_message) + def __contains__(self, item): + return hasattr(self, item) or item in self.extra + @property def host(self): return self.parent.host @@ -120,7 +123,9 @@ class Message: self.selected_lang = lang return mess except StopIteration: - log.error("Can't find message for uid {}".format(self.uid)) + if not self.attachments: + # we may have empty messages if we have attachments + log.error("Can't find message for uid {}".format(self.uid)) return "" @property @@ -200,6 +205,10 @@ class Message: for lang, mess in self.message.items(): self.message[lang] = "* " + nick + mess[3:] + @property + def attachments(self): + return self.extra.get(C.MESS_KEY_ATTACHMENTS) + class MessageWidget(object): """Base classe for widgets""" @@ -708,7 +717,8 @@ class QuickChat(quick_widgets.QuickWidget): ) return - if not msg and not subject and type_ != C.MESS_TYPE_INFO: + if ((not msg and not subject and not extra[C.MESS_KEY_ATTACHMENTS] + and type_ != C.MESS_TYPE_INFO)): log.warning("Received an empty message for uid {}".format(uid)) return