comparison sat_frontends/quick_frontend/quick_chat.py @ 3176:4b5c77673015

quick frontends (chat): handle attachments in Message
author Goffi <goffi@goffi.org>
date Tue, 18 Feb 2020 18:17:18 +0100
parents 39d7327583e1
children 2556eb576aed
comparison
equal deleted inserted replaced
3175:b9a2dd4d750a 3176:4b5c77673015
83 mess_type=self.type, 83 mess_type=self.type,
84 time=self.time_text, 84 time=self.time_text,
85 nick=self.nick, 85 nick=self.nick,
86 message=self.main_message) 86 message=self.main_message)
87 87
88 def __contains__(self, item):
89 return hasattr(self, item) or item in self.extra
90
88 @property 91 @property
89 def host(self): 92 def host(self):
90 return self.parent.host 93 return self.parent.host
91 94
92 @property 95 @property
118 try: 121 try:
119 lang, mess = next(iter(self.message.items())) 122 lang, mess = next(iter(self.message.items()))
120 self.selected_lang = lang 123 self.selected_lang = lang
121 return mess 124 return mess
122 except StopIteration: 125 except StopIteration:
123 log.error("Can't find message for uid {}".format(self.uid)) 126 if not self.attachments:
127 # we may have empty messages if we have attachments
128 log.error("Can't find message for uid {}".format(self.uid))
124 return "" 129 return ""
125 130
126 @property 131 @property
127 def main_message_xhtml(self): 132 def main_message_xhtml(self):
128 """rich message""" 133 """rich message"""
197 self.type = C.MESS_TYPE_INFO 202 self.type = C.MESS_TYPE_INFO
198 self.extra["info_type"] = "me" 203 self.extra["info_type"] = "me"
199 nick = self.nick 204 nick = self.nick
200 for lang, mess in self.message.items(): 205 for lang, mess in self.message.items():
201 self.message[lang] = "* " + nick + mess[3:] 206 self.message[lang] = "* " + nick + mess[3:]
207
208 @property
209 def attachments(self):
210 return self.extra.get(C.MESS_KEY_ATTACHMENTS)
202 211
203 212
204 class MessageWidget(object): 213 class MessageWidget(object):
205 """Base classe for widgets""" 214 """Base classe for widgets"""
206 # This class does nothing and is only used to have a common ancestor 215 # This class does nothing and is only used to have a common ancestor
706 extra, 715 extra,
707 profile, 716 profile,
708 ) 717 )
709 return 718 return
710 719
711 if not msg and not subject and type_ != C.MESS_TYPE_INFO: 720 if ((not msg and not subject and not extra[C.MESS_KEY_ATTACHMENTS]
721 and type_ != C.MESS_TYPE_INFO)):
712 log.warning("Received an empty message for uid {}".format(uid)) 722 log.warning("Received an empty message for uid {}".format(uid))
713 return 723 return
714 724
715 if self.type == C.CHAT_GROUP: 725 if self.type == C.CHAT_GROUP:
716 if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT: 726 if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT: