changeset 383:a90f26e89a4a

share widget: fixed crash when a text content is shared without `text` in data: sometimes, text content is shared via a path and not directly the `text` key. This is the case with vCards. This patch fixes share widget to handle this case.
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2020 20:47:17 +0100
parents c7f1176cd2a9
children 3669a26ef7d9
files cagou/core/share_widget.py cagou/plugins/plugin_wid_file_sharing.py
diffstat 2 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/share_widget.py	Tue Feb 04 20:47:17 2020 +0100
+++ b/cagou/core/share_widget.py	Tue Feb 04 20:47:17 2020 +0100
@@ -102,7 +102,7 @@
 
     def on_kv_post(self, wid):
         self.type, self.subtype = self.media_type.split('/')
-        if self.type == 'text':
+        if self.type == 'text' and 'text' in self.data:
             self.preview_box.add_widget(TextPreview(text=self.data['text']))
         elif self.type == 'image':
             self.preview_box.add_widget(ImagePreview(path=self.data['path']))
@@ -126,7 +126,7 @@
         G.host.doAction('chat', contact_jid, [profile])
         chat_wid = G.host.selected_widget
 
-        if self.type == 'text':
+        if self.type == 'text' and 'text' in self.data:
             text = self.data['text']
             chat_wid.message_input.text += text
         else:
--- a/cagou/plugins/plugin_wid_file_sharing.py	Tue Feb 04 20:47:17 2020 +0100
+++ b/cagou/plugins/plugin_wid_file_sharing.py	Tue Feb 04 20:47:17 2020 +0100
@@ -17,9 +17,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+from functools import partial
+import os.path
+import json
 from sat.core import log as logging
 from sat.core import exceptions
-log = logging.getLogger(__name__)
 from sat.core.i18n import _
 from sat.tools.common import files_utils
 from sat_frontends.quick_frontend import quick_widgets
@@ -35,9 +37,8 @@
 from kivy.uix.label import Label
 from kivy.uix.button import Button
 from kivy import utils as kivy_utils
-from functools import partial
-import os.path
-import json
+
+log = logging.getLogger(__name__)
 
 
 PLUGIN_INFO = {