Mercurial > libervia-desktop-kivy
comparison src/cagou/plugins/plugin_wid_chat.py @ 111:c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 15 Jan 2017 23:52:28 +0100 |
parents | 7631325e11f4 |
children | f0291755b07c |
comparison
equal
deleted
inserted
replaced
110:34dfe0e32064 | 111:c3952922ca56 |
---|---|
33 from cagou.core import cagou_widget | 33 from cagou.core import cagou_widget |
34 from cagou.core.image import Image | 34 from cagou.core.image import Image |
35 from cagou.core.common import JidWidget | 35 from cagou.core.common import JidWidget |
36 from kivy.uix.dropdown import DropDown | 36 from kivy.uix.dropdown import DropDown |
37 from cagou import G | 37 from cagou import G |
38 import mimetypes | |
38 | 39 |
39 | 40 |
40 PLUGIN_INFO = { | 41 PLUGIN_INFO = { |
41 "name": _(u"chat"), | 42 "name": _(u"chat"), |
42 "main": "Chat", | 43 "main": "Chat", |
287 # TODO: display message to user | 288 # TODO: display message to user |
288 log.warning(u"Can't transfer file: {}".format(err_msg)) | 289 log.warning(u"Can't transfer file: {}".format(err_msg)) |
289 | 290 |
290 def fileTransferDone(self, metadata, profile): | 291 def fileTransferDone(self, metadata, profile): |
291 log.debug("file transfered: {}".format(metadata)) | 292 log.debug("file transfered: {}".format(metadata)) |
293 extra = {} | |
294 | |
295 # FIXME: Q&D way of getting file type, upload plugins shouls give it | |
296 mime_type = mimetypes.guess_type(metadata['url'])[0] | |
297 if mime_type is not None: | |
298 if mime_type.split(u'/')[0] == 'image': | |
299 # we generate url ourselves, so this formatting is safe | |
300 extra['xhtml'] = u"<img src='{url}' />".format(**metadata) | |
301 | |
292 G.host.messageSend( | 302 G.host.messageSend( |
293 self.target, | 303 self.target, |
294 {'': metadata['url']}, | 304 {'': metadata['url']}, |
295 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, | 305 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, |
306 extra = extra, | |
296 profile_key=profile | 307 profile_key=profile |
297 ) | 308 ) |
298 | 309 |
299 def fileTransferCb(self, progress_data, cleaning_cb): | 310 def fileTransferCb(self, progress_data, cleaning_cb): |
300 try: | 311 try: |