Mercurial > libervia-desktop-kivy
annotate libervia/desktop_kivy/plugins/plugin_wid_chat.py @ 518:196483685a63 default tip
Use Font-Awesome instead of Fontello, following change in Libervia Media.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:44:37 +0200 |
parents | b3cedbee561d |
children |
rev | line source |
---|---|
379 | 1 #!/usr/bin/env python3 |
22 | 2 |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
3 #Libervia Desktop-Kivy |
461 | 4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) |
22 | 5 |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 | |
276 | 20 from functools import partial |
412 | 21 from pathlib import Path |
276 | 22 import sys |
412 | 23 import uuid |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
24 import mimetypes |
425 | 25 from urllib.parse import urlparse |
78 | 26 from kivy.uix.boxlayout import BoxLayout |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
27 from kivy.uix.gridlayout import GridLayout |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
28 from kivy.uix.screenmanager import Screen, NoTransition |
22 | 29 from kivy.uix.textinput import TextInput |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
30 from kivy.uix.label import Label |
354 | 31 from kivy.uix import screenmanager |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
32 from kivy.uix.behaviors import ButtonBehavior |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
33 from kivy.metrics import sp, dp |
276 | 34 from kivy.clock import Clock |
22 | 35 from kivy import properties |
411
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
36 from kivy.uix.stacklayout import StackLayout |
325 | 37 from kivy.uix.dropdown import DropDown |
38 from kivy.core.window import Window | |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
39 from libervia.backend.core import log as logging |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
40 from libervia.backend.core.i18n import _ |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
41 from libervia.backend.core import exceptions |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
42 from libervia.backend.tools.common import data_format |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
43 from libervia.frontends.quick_frontend import quick_widgets |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
44 from libervia.frontends.quick_frontend import quick_chat |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
45 from libervia.frontends.tools import jid |
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
46 from libervia.desktop_kivy import G |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
47 from ..core.constants import Const as C |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
48 from ..core import cagou_widget |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
49 from ..core import xmlui |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
50 from ..core.image import Image, AsyncImage |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
51 from ..core.common import Symbol, SymbolButton, JidButton, ContactButton |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
52 from ..core.behaviors import FilterBehavior |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
53 from ..core import menu |
425 | 54 from ..core.common_widgets import ImagesGallery |
22 | 55 |
276 | 56 log = logging.getLogger(__name__) |
22 | 57 |
58 PLUGIN_INFO = { | |
312 | 59 "name": _("chat"), |
22 | 60 "main": "Chat", |
312 | 61 "description": _("instant messaging with one person or a group"), |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
62 "icon_symbol": "comments", |
22 | 63 } |
64 | |
244
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
65 # FIXME: OTR specific code is legacy, and only used nowadays for lock color |
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
66 # we can probably get rid of them. |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
67 OTR_STATE_UNTRUSTED = 'untrusted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
68 OTR_STATE_TRUSTED = 'trusted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
69 OTR_STATE_TRUST = (OTR_STATE_UNTRUSTED, OTR_STATE_TRUSTED) |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
70 OTR_STATE_UNENCRYPTED = 'unencrypted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
71 OTR_STATE_ENCRYPTED = 'encrypted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
72 OTR_STATE_ENCRYPTION = (OTR_STATE_UNENCRYPTED, OTR_STATE_ENCRYPTED) |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
73 |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
74 SYMBOL_UNENCRYPTED = 'unlock' |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
75 SYMBOL_ENCRYPTED = 'lock' |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
76 SYMBOL_ENCRYPTED_TRUSTED = 'lock' |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
77 COLOR_UNENCRYPTED = (0.4, 0.4, 0.4, 1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
78 COLOR_ENCRYPTED = (0.4, 0.4, 0.4, 1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
79 COLOR_ENCRYPTED_TRUSTED = (0.29,0.87,0.0,1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
80 |
326 | 81 # below this limit, new messages will be prepended |
82 INFINITE_SCROLL_LIMIT = dp(600) | |
83 | |
412 | 84 # File sending progress |
85 PROGRESS_UPDATE = 0.2 # number of seconds before next progress update | |
86 | |
22 | 87 |
411
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
88 # FIXME: a ScrollLayout was supposed to be used here, but due |
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
89 # to https://github.com/kivy/kivy/issues/6745, a StackLayout is used for now |
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
90 class AttachmentsLayout(StackLayout): |
412 | 91 """Layout for attachments in a received message""" |
92 padding = properties.VariableListProperty([dp(5), dp(5), 0, dp(5)]) | |
93 attachments = properties.ObjectProperty() | |
94 | |
95 | |
96 class AttachmentsToSend(BoxLayout): | |
97 """Layout for attachments to be sent with current message""" | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
98 attachments = properties.ObjectProperty() |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
99 reduce_checkbox = properties.ObjectProperty() |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
100 show_resize = properties.BooleanProperty(False) |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
101 |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
102 def on_kv_post(self, __): |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
103 self.attachments.bind(children=self.on_attachment) |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
104 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
105 def on_attachment(self, __, attachments): |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
106 if len(attachments) == 0: |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
107 self.show_resize = False |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
108 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
109 |
425 | 110 class BaseAttachmentItem(BoxLayout): |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
111 data = properties.DictProperty() |
412 | 112 progress = properties.NumericProperty(0) |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
113 |
425 | 114 |
115 class AttachmentItem(BaseAttachmentItem): | |
116 | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
117 def get_symbol(self, data): |
490
962d17c4078c
chat: changed KEY_ATTACHEMENTS* name following backend change
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
118 media_type = data.get(C.KEY_ATTACHMENTS_MEDIA_TYPE, '') |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
119 main_type = media_type.split('/', 1)[0] |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
120 if main_type == 'image': |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
121 return "regular file-image" |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
122 elif main_type == 'video': |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
123 return "regular file-video" |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
124 elif main_type == 'audio': |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
125 return "regular file-audio" |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
126 else: |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
127 return "regular file" |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
128 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
129 def on_press(self): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
130 url = self.data.get('url') |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
131 if url: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
132 G.local_platform.open_url(url, self) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
133 else: |
412 | 134 log.warning(f"can't find URL in {self.data}") |
135 | |
136 | |
425 | 137 class AttachmentImageItem(ButtonBehavior, BaseAttachmentItem): |
138 image = properties.ObjectProperty() | |
139 | |
140 def on_press(self): | |
433 | 141 full_size_source = self.data.get('path', self.data.get('url')) |
142 gallery = ImagesGallery(sources=[full_size_source]) | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
143 G.host.show_extra_ui(gallery) |
425 | 144 |
446
ffdf2390ea56
chat: fixed `source` assignment for `AttachmentImageItem`
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
145 def on_kv_post(self, __): |
ffdf2390ea56
chat: fixed `source` assignment for `AttachmentImageItem`
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
146 self.on_data(None, self.data) |
ffdf2390ea56
chat: fixed `source` assignment for `AttachmentImageItem`
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
147 |
437
b5e6d36fbf9c
chat: set AttachmentImageItem in python instead of kv:
Goffi <goffi@goffi.org>
parents:
435
diff
changeset
|
148 def on_data(self, __, data): |
446
ffdf2390ea56
chat: fixed `source` assignment for `AttachmentImageItem`
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
149 if self.image is None: |
ffdf2390ea56
chat: fixed `source` assignment for `AttachmentImageItem`
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
150 return |
437
b5e6d36fbf9c
chat: set AttachmentImageItem in python instead of kv:
Goffi <goffi@goffi.org>
parents:
435
diff
changeset
|
151 source = data.get('preview') or data.get('path') or data.get('url') |
b5e6d36fbf9c
chat: set AttachmentImageItem in python instead of kv:
Goffi <goffi@goffi.org>
parents:
435
diff
changeset
|
152 if source: |
446
ffdf2390ea56
chat: fixed `source` assignment for `AttachmentImageItem`
Goffi <goffi@goffi.org>
parents:
443
diff
changeset
|
153 self.image.source = source |
437
b5e6d36fbf9c
chat: set AttachmentImageItem in python instead of kv:
Goffi <goffi@goffi.org>
parents:
435
diff
changeset
|
154 |
425 | 155 |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
156 class AttachmentImagesCollectionItem(ButtonBehavior, GridLayout): |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
157 attachments = properties.ListProperty([]) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
158 chat = properties.ObjectProperty() |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
159 mess_data = properties.ObjectProperty() |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
160 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
161 def _set_preview(self, attachment, wid, preview_path): |
433 | 162 attachment['preview'] = preview_path |
163 wid.source = preview_path | |
164 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
165 def _set_path(self, attachment, wid, path): |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
166 attachment['path'] = path |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
167 if wid is not None: |
433 | 168 # we also need a preview for the widget |
169 if 'preview' in attachment: | |
170 wid.source = attachment['preview'] | |
171 else: | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
172 G.host.bridge.image_generate_preview( |
433 | 173 path, |
174 self.chat.profile, | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
175 callback=partial(self._set_preview, attachment, wid), |
433 | 176 ) |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
177 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
178 def on_kv_post(self, __): |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
179 attachments = self.attachments |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
180 self.clear_widgets() |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
181 for idx, attachment in enumerate(attachments): |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
182 try: |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
183 url = attachment['url'] |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
184 except KeyError: |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
185 url = None |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
186 to_download = False |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
187 else: |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
188 if url.startswith("aesgcm:"): |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
189 del attachment['url'] |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
190 # if the file is encrypted, we need to download it for decryption |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
191 to_download = True |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
192 else: |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
193 to_download = False |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
194 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
195 if idx < 3 or len(attachments) <= 4: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
196 if ((self.mess_data.own_mess |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
197 or self.chat.contact_list.is_in_roster(self.mess_data.from_jid))): |
441
ff548846df91
chat: use `image-loading` as source by default:
Goffi <goffi@goffi.org>
parents:
437
diff
changeset
|
198 wid = AsyncImage(size_hint=(1, 1), source="data/images/image-loading.gif") |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
199 if 'preview' in attachment: |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
200 wid.source = attachment["preview"] |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
201 elif 'path' in attachment: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
202 G.host.bridge.image_generate_preview( |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
203 attachment['path'], |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
204 self.chat.profile, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
205 callback=partial(self._set_preview, attachment, wid), |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
206 ) |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
207 elif url is None: |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
208 log.warning(f"Can't find any source for {attachment}") |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
209 else: |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
210 # we'll download the file, the preview will then be generated |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
211 to_download = True |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
212 else: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
213 # we don't download automatically the image if the contact is not |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
214 # in roster, to avoid leaking the ip |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
215 wid = Symbol(symbol="regular file-image") |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
216 self.add_widget(wid) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
217 else: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
218 wid = None |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
219 |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
220 if to_download: |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
221 # the file needs to be downloaded, the widget source, |
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
222 # attachment path, and preview will then be completed |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
223 G.host.download_url( |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
224 url, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
225 callback=partial(self._set_path, attachment, wid), |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
226 dest=C.FILE_DEST_CACHE, |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
227 profile=self.chat.profile, |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
228 ) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
229 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
230 if len(attachments) > 4: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
231 counter = Label( |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
232 bold=True, |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
233 text=f"+{len(attachments) - 3}", |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
234 ) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
235 self.add_widget(counter) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
236 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
237 def on_press(self): |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
238 sources = [] |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
239 for attachment in self.attachments: |
435
53bb3886b408
chat: generate preview if there is not one already for non encrypted attachments
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
240 source = attachment.get('path') or attachment.get('url') |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
241 if not source: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
242 log.warning(f"no source for {attachment}") |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
243 else: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
244 sources.append(source) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
245 gallery = ImagesGallery(sources=sources) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
246 G.host.show_extra_ui(gallery) |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
247 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
248 |
412 | 249 class AttachmentToSendItem(AttachmentItem): |
250 # True when the item is being sent | |
251 sending = properties.BooleanProperty(False) | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
252 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
253 |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
254 class MessAvatar(ButtonBehavior, Image): |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
255 pass |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
256 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
257 |
325 | 258 class MessageWidget(quick_chat.MessageWidget, BoxLayout): |
22 | 259 mess_data = properties.ObjectProperty() |
57 | 260 mess_xhtml = properties.ObjectProperty() |
45 | 261 mess_padding = (dp(5), dp(5)) |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
262 avatar = properties.ObjectProperty() |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
263 delivery = properties.ObjectProperty() |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
264 font_size = properties.NumericProperty(sp(12)) |
325 | 265 right_part = properties.ObjectProperty() |
266 header_box = properties.ObjectProperty() | |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
267 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
268 def on_kv_post(self, __): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
269 if not self.mess_data: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
270 raise exceptions.InternalError( |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
271 "mess_data must always be set in MessageWidget") |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
272 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
273 self.mess_data.widgets.add(self) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
274 self.add_attachments() |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
275 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
276 @property |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
277 def chat(self): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
278 """return parent Chat instance""" |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
279 return self.mess_data.parent |
22 | 280 |
325 | 281 def _get_from_mess_data(self, name, default): |
282 if self.mess_data is None: | |
283 return default | |
284 return getattr(self.mess_data, name) | |
285 | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
286 def _get_message(self): |
22 | 287 """Return currently displayed message""" |
325 | 288 if self.mess_data is None: |
289 return "" | |
22 | 290 return self.mess_data.main_message |
291 | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
292 def _set_message(self, message): |
325 | 293 if self.mess_data is None: |
294 return False | |
312 | 295 if message == self.mess_data.message.get(""): |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
296 return False |
312 | 297 self.mess_data.message = {"": message} |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
298 return True |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
299 |
325 | 300 message = properties.AliasProperty( |
301 partial(_get_from_mess_data, name="main_message", default=""), | |
302 _set_message, | |
303 bind=['mess_data'], | |
304 ) | |
305 message_xhtml = properties.AliasProperty( | |
306 partial(_get_from_mess_data, name="main_message_xhtml", default=""), | |
307 bind=['mess_data']) | |
308 mess_type = properties.AliasProperty( | |
309 partial(_get_from_mess_data, name="type", default=""), bind=['mess_data']) | |
310 own_mess = properties.AliasProperty( | |
311 partial(_get_from_mess_data, name="own_mess", default=False), bind=['mess_data']) | |
312 nick = properties.AliasProperty( | |
313 partial(_get_from_mess_data, name="nick", default=""), bind=['mess_data']) | |
314 time_text = properties.AliasProperty( | |
315 partial(_get_from_mess_data, name="time_text", default=""), bind=['mess_data']) | |
57 | 316 |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
317 @property |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
318 def info_type(self): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
319 return self.mess_data.info_type |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
320 |
54
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
321 def update(self, update_dict): |
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
322 if 'avatar' in update_dict: |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
455
diff
changeset
|
323 avatar_data = update_dict['avatar'] |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
455
diff
changeset
|
324 if avatar_data is None: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
325 source = G.host.get_default_avatar() |
458
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
455
diff
changeset
|
326 else: |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
455
diff
changeset
|
327 source = avatar_data['path'] |
1dd6db69406a
core: update avatar handling following backend changes:
Goffi <goffi@goffi.org>
parents:
455
diff
changeset
|
328 self.avatar.source = source |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
329 if 'status' in update_dict: |
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
330 status = update_dict['status'] |
312 | 331 self.delivery.text = '\u2714' if status == 'delivered' else '' |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
332 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
333 def _set_path(self, data, path): |
425 | 334 """Set path of decrypted file to an item""" |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
335 data['path'] = path |
425 | 336 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
337 def add_attachments(self): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
338 """Add attachments layout + attachments item""" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
339 attachments = self.mess_data.attachments |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
340 if not attachments: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
341 return |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
342 root_layout = AttachmentsLayout() |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
343 self.right_part.add_widget(root_layout) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
344 layout = root_layout.attachments |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
345 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
346 image_attachments = [] |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
347 other_attachments = [] |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
348 # we first separate images and other attachments, so we know if we need |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
349 # to use an image collection |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
350 for attachment in attachments: |
490
962d17c4078c
chat: changed KEY_ATTACHEMENTS* name following backend change
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
351 media_type = attachment.get(C.KEY_ATTACHMENTS_MEDIA_TYPE, '') |
425 | 352 main_type = media_type.split('/', 1)[0] |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
353 # GIF images are really badly handled by Kivy, the memory |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
354 # consumption explode, and the images frequencies are not handled |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
355 # correctly, thus we can't display them and we consider them as |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
356 # other attachment, so user can open the item with appropriate |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
357 # software. |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
358 if main_type == 'image' and media_type != "image/gif": |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
359 image_attachments.append(attachment) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
360 else: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
361 other_attachments.append(attachment) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
362 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
363 if len(image_attachments) > 1: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
364 collection = AttachmentImagesCollectionItem( |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
365 attachments=image_attachments, |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
366 chat=self.chat, |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
367 mess_data=self.mess_data, |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
368 ) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
369 layout.add_widget(collection) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
370 elif image_attachments: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
371 attachment = image_attachments[0] |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
372 # to avoid leaking IP address, we only display image if the contact is in |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
373 # roster |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
374 if ((self.mess_data.own_mess |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
375 or self.chat.contact_list.is_in_roster(self.mess_data.from_jid))): |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
376 try: |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
377 url = urlparse(attachment['url']) |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
378 except KeyError: |
425 | 379 item = AttachmentImageItem(data=attachment) |
380 else: | |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
381 if url.scheme == "aesgcm": |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
382 # we remove the URL now, we'll replace it by |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
383 # the local decrypted version |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
384 del attachment['url'] |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
385 item = AttachmentImageItem(data=attachment) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
386 G.host.download_url( |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
387 url.geturl(), |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
388 callback=partial(self._set_path, item.data), |
443
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
389 dest=C.FILE_DEST_CACHE, |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
390 profile=self.chat.profile, |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
391 ) |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
392 else: |
61322ff8090b
chat: fixed handling of attachments without URL
Goffi <goffi@goffi.org>
parents:
442
diff
changeset
|
393 item = AttachmentImageItem(data=attachment) |
425 | 394 else: |
395 item = AttachmentItem(data=attachment) | |
426
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
396 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
397 layout.add_widget(item) |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
398 |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
399 for attachment in other_attachments: |
d3a6ae859556
chat: image attachments collection, first draft:
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
400 item = AttachmentItem(data=attachment) |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
401 layout.add_widget(item) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
402 |
22 | 403 |
78 | 404 class MessageInputBox(BoxLayout): |
276 | 405 message_input = properties.ObjectProperty() |
406 | |
407 def send_text(self): | |
408 self.message_input.send_text() | |
78 | 409 |
410 | |
22 | 411 class MessageInputWidget(TextInput): |
412 | |
276 | 413 def keyboard_on_key_down(self, window, keycode, text, modifiers): |
414 # We don't send text when shift is pressed to be able to add line feeds | |
415 # (i.e. multi-lines messages). We don't send on Android either as the | |
416 # send button appears on this platform. | |
417 if (keycode[-1] == "enter" | |
418 and "shift" not in modifiers | |
419 and sys.platform != 'android'): | |
420 self.send_text() | |
22 | 421 else: |
276 | 422 return super(MessageInputWidget, self).keyboard_on_key_down( |
423 window, keycode, text, modifiers) | |
424 | |
425 def send_text(self): | |
426 self.dispatch('on_text_validate') | |
22 | 427 |
428 | |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
429 class TransferButton(SymbolButton): |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
430 chat = properties.ObjectProperty() |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
431 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
432 def on_release(self, *args): |
417
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
433 menu.TransferMenu( |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
434 encrypted=self.chat.encrypted, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
435 callback=self.chat.transfer_file, |
417
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
414
diff
changeset
|
436 ).show(self) |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
437 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
438 |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
439 class ExtraMenu(DropDown): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
440 chat = properties.ObjectProperty() |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
441 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
442 def on_select(self, menu): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
443 if menu == 'bookmark': |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
444 G.host.bridge.menu_launch(C.MENU_GLOBAL, ("groups", "bookmarks"), |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
445 {}, C.NO_SECURITY_LIMIT, self.chat.profile, |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
446 callback=partial( |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
447 G.host.action_manager, profile=self.chat.profile), |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
448 errback=G.host.errback) |
393
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
449 elif menu == 'close': |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
450 if self.chat.type == C.CHAT_GROUP: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
451 # for MUC, we have to indicate the backend that we've left |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
452 G.host.bridge.muc_leave(self.chat.target, self.chat.profile) |
393
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
453 else: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
454 # for one2one, backend doesn't keep any state, so we just delete the |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
455 # widget here in the frontend |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
456 G.host.widgets.delete_widget( |
393
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
457 self.chat, all_instances=True, explicit_close=True) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
458 else: |
312 | 459 raise exceptions.InternalError("Unknown menu: {}".format(menu)) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
460 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
461 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
462 class ExtraButton(SymbolButton): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
463 chat = properties.ObjectProperty() |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
464 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
465 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
466 class EncryptionMainButton(SymbolButton): |
117 | 467 |
468 def __init__(self, chat, **kwargs): | |
469 """ | |
470 @param chat(Chat): Chat instance | |
471 """ | |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
472 self.chat = chat |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
473 self.encryption_menu = EncryptionMenu(chat) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
474 super(EncryptionMainButton, self).__init__(**kwargs) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
475 self.bind(on_release=self.encryption_menu.open) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
476 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
477 def select_algo(self, name): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
478 """Mark an encryption algorithm as selected. |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
479 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
480 This will also deselect all other button |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
481 @param name(unicode, None): encryption plugin name |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
482 None for plain text |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
483 """ |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
484 buttons = self.encryption_menu.container.children |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
485 buttons[-1].selected = name is None |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
486 for button in buttons[:-1]: |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
487 button.selected = button.text == name |
117 | 488 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
489 def get_color(self): |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
490 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
491 return (0.4, 0.4, 0.4, 1) |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
492 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
493 return (0.29,0.87,0.0,1) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
494 else: |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
495 return (0.4, 0.4, 0.4, 1) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
496 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
497 def get_symbol(self): |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
498 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
499 return 'unlock' |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
500 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
501 # FIXME: Used to be "lock-filled" before transition to font-awesome. |
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
502 return 'lock' |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
503 else: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
504 return 'lock' |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
505 |
117 | 506 |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
507 class TrustManagementButton(SymbolButton): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
508 pass |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
509 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
510 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
511 class EncryptionButton(BoxLayout): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
512 selected = properties.BooleanProperty(False) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
513 text = properties.StringProperty() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
514 trust_button = properties.BooleanProperty(False) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
515 best_width = properties.NumericProperty(0) |
312 | 516 bold = properties.BooleanProperty(True) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
517 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
518 def __init__(self, **kwargs): |
312 | 519 super(EncryptionButton, self).__init__(**kwargs) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
520 self.register_event_type('on_release') |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
521 self.register_event_type('on_trust_release') |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
522 if self.trust_button: |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
523 self.add_widget(TrustManagementButton()) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
524 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
525 def on_release(self): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
526 pass |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
527 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
528 def on_trust_release(self): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
529 pass |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
530 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
531 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
532 class EncryptionMenu(DropDown): |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
533 # best with to display all algorithms buttons + trust buttons |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
534 best_width = properties.NumericProperty(0) |
117 | 535 |
536 def __init__(self, chat, **kwargs): | |
537 """ | |
538 @param chat(Chat): Chat instance | |
539 """ | |
540 self.chat = chat | |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
541 super(EncryptionMenu, self).__init__(**kwargs) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
542 btn = EncryptionButton( |
312 | 543 text=_("unencrypted (plain text)"), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
544 on_release=self.unencrypted, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
545 selected=True, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
546 bold=False, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
547 ) |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
548 btn.bind( |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
549 on_release=self.unencrypted, |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
550 ) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
551 self.add_widget(btn) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
552 for plugin in G.host.encryption_plugins: |
339
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
553 if chat.type == C.CHAT_GROUP and plugin["directed"]: |
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
554 # directed plugins can't work with group chat |
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
555 continue |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
556 btn = EncryptionButton( |
312 | 557 text=plugin['name'], |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
558 trust_button=True, |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
559 ) |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
560 btn.bind( |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
561 on_release=partial(self.start_encryption, plugin=plugin), |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
562 on_trust_release=partial(self.get_trust_ui, plugin=plugin), |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
563 ) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
564 self.add_widget(btn) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
565 log.info("added encryption: {}".format(plugin['name'])) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
566 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
567 def message_encryption_stop_cb(self): |
312 | 568 log.info(_("Session with {destinee} is now in plain text").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
569 destinee = self.chat.target)) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
570 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
571 def message_encryption_stop_eb(self, failure_): |
312 | 572 msg = _("Error while stopping encryption with {destinee}: {reason}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
573 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
574 reason = failure_) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
575 log.warning(msg) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
576 G.host.add_note(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
577 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
578 def unencrypted(self, button): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
579 self.dismiss() |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
580 G.host.bridge.message_encryption_stop( |
312 | 581 str(self.chat.target), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
582 self.chat.profile, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
583 callback=self.message_encryption_stop_cb, |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
584 errback=self.message_encryption_stop_eb) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
585 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
586 def message_encryption_start_cb(self, plugin): |
312 | 587 log.info(_("Session with {destinee} is now encrypted with {encr_name}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
588 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
589 encr_name = plugin['name'])) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
590 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
591 def message_encryption_start_eb(self, failure_): |
312 | 592 msg = _("Session can't be encrypted with {destinee}: {reason}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
593 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
594 reason = failure_) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
595 log.warning(msg) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
596 G.host.add_note(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
597 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
598 def start_encryption(self, button, plugin): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
599 """Request encryption with given plugin for this session |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
600 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
601 @param button(EncryptionButton): button which has been pressed |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
602 @param plugin(dict): plugin data |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
603 """ |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
604 self.dismiss() |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
605 G.host.bridge.message_encryption_start( |
312 | 606 str(self.chat.target), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
607 plugin['namespace'], |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
608 True, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
609 self.chat.profile, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
610 callback=partial(self.message_encryption_start_cb, plugin=plugin), |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
611 errback=self.message_encryption_start_eb) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
612 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
613 def encryption_trust_ui_get_cb(self, xmlui_raw): |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
614 xml_ui = xmlui.create( |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
615 G.host, xmlui_raw, profile=self.chat.profile) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
616 xml_ui.show() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
617 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
618 def encryption_trust_ui_get_eb(self, failure_): |
312 | 619 msg = _("Trust manager interface can't be retrieved: {reason}").format( |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
620 reason = failure_) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
621 log.warning(msg) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
622 G.host.add_note(_("encryption trust management problem"), msg, |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
623 C.XMLUI_DATA_LVL_ERROR) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
624 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
625 def get_trust_ui(self, button, plugin): |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
626 """Request and display trust management UI |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
627 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
628 @param button(EncryptionButton): button which has been pressed |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
629 @param plugin(dict): plugin data |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
630 """ |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
631 self.dismiss() |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
632 G.host.bridge.encryption_trust_ui_get( |
312 | 633 str(self.chat.target), |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
634 plugin['namespace'], |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
635 self.chat.profile, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
636 callback=self.encryption_trust_ui_get_cb, |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
637 errback=self.encryption_trust_ui_get_eb) |
117 | 638 |
639 | |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
640 class Chat(quick_chat.QuickChat, cagou_widget.LiberviaDesktopKivyWidget): |
78 | 641 message_input = properties.ObjectProperty() |
86 | 642 messages_widget = properties.ObjectProperty() |
326 | 643 history_scroll = properties.ObjectProperty() |
412 | 644 attachments_to_send = properties.ObjectProperty() |
413
c466678c57b2
chat: control send button visibility in core.platform_, and show it when there are attachments
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
645 send_button_visible = properties.BooleanProperty() |
387
d61bbbac4160
cagou widget: don't add header_input systematically anymore:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
646 use_header_input = True |
354 | 647 global_screen_manager = True |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
648 collection_carousel = True |
22 | 649 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
650 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
651 subject=None, statuses=None, profiles=None): |
354 | 652 self.show_chat_selector = False |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
653 if statuses is None: |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
654 statuses = {} |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
655 quick_chat.QuickChat.__init__( |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
656 self, host, target, type_, nick, occupants, subject, statuses, |
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
657 profiles=profiles) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
658 self.otr_state_encryption = OTR_STATE_UNENCRYPTED |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
659 self.otr_state_trust = OTR_STATE_UNTRUSTED |
225
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
660 # completion attributes |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
661 self._hi_comp_data = None |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
662 self._hi_comp_last = None |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
663 self._hi_comp_dropdown = DropDown() |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
664 self._hi_comp_allowed = True |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
665 cagou_widget.LiberviaDesktopKivyWidget.__init__(self) |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
666 transfer_btn = TransferButton(chat=self) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
667 self.header_input_add_extra(transfer_btn) |
339
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
668 if (type_ == C.CHAT_ONE2ONE or "REALJID_PUBLIC" in statuses): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
669 self.encryption_btn = EncryptionMainButton(self) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
670 self.header_input_add_extra(self.encryption_btn) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
671 self.extra_menu = ExtraMenu(chat=self) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
672 extra_btn = ExtraButton(chat=self) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
673 self.header_input_add_extra(extra_btn) |
325 | 674 self.header_input.hint_text = target |
326 | 675 self._history_prepend_lock = False |
676 self.history_count = 0 | |
22 | 677 |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
678 def on_kv_post(self, __): |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
679 self.post_init() |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
680 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
681 def screen_manager_init(self, screen_manager): |
354 | 682 screen_manager.transition = screenmanager.SlideTransition(direction='down') |
683 sel_screen = Screen(name='chat_selector') | |
684 chat_selector = ChatSelector(profile=self.profile) | |
685 sel_screen.add_widget(chat_selector) | |
686 screen_manager.add_widget(sel_screen) | |
687 if self.show_chat_selector: | |
688 transition = screen_manager.transition | |
689 screen_manager.transition = NoTransition() | |
690 screen_manager.current = 'chat_selector' | |
691 screen_manager.transition = transition | |
692 | |
156
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
693 def __str__(self): |
312 | 694 return "Chat({})".format(self.target) |
156
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
695 |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
696 def __repr__(self): |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
697 return self.__str__() |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
698 |
22 | 699 @classmethod |
700 def factory(cls, plugin_info, target, profiles): | |
701 profiles = list(profiles) | |
702 if len(profiles) > 1: | |
312 | 703 raise NotImplementedError("Multi-profiles is not available yet for chat") |
22 | 704 if target is None: |
354 | 705 show_chat_selector = True |
22 | 706 target = G.host.profiles[profiles[0]].whoami |
354 | 707 else: |
708 show_chat_selector = False | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
709 wid = G.host.widgets.get_or_create_widget(cls, target, on_new_widget=None, |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
710 on_existing_widget=G.host.get_or_clone, |
354 | 711 profiles=profiles) |
712 wid.show_chat_selector = show_chat_selector | |
713 return wid | |
22 | 714 |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
715 @property |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
716 def message_widgets_rev(self): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
717 return self.messages_widget.children |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
718 |
354 | 719 ## keyboard ## |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
720 |
354 | 721 def key_input(self, window, key, scancode, codepoint, modifier): |
722 if key == 27: | |
723 screen_manager = self.screen_manager | |
724 screen_manager.transition.direction = 'down' | |
725 screen_manager.current = 'chat_selector' | |
726 return True | |
727 | |
414 | 728 ## drop ## |
729 | |
730 def on_drop_file(self, path): | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
731 self.add_attachment(path) |
354 | 732 |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
733 ## header ## |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
734 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
735 def change_widget(self, jid_): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
736 """change current widget for a new one with given jid |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
737 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
738 @param jid_(jid.JID): jid of the widget to create |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
739 """ |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
740 plugin_info = G.host.get_plugin_info(main=Chat) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
741 factory = plugin_info['factory'] |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
742 G.host.switch_widget(self, factory(plugin_info, jid_, profiles=[self.profile])) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
743 self.header_input.text = '' |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
744 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
745 def on_header_wid_input(self): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
746 text = self.header_input.text.strip() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
747 try: |
312 | 748 if text.count('@') != 1 or text.count(' '): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
749 raise ValueError |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
750 jid_ = jid.JID(text) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
751 except ValueError: |
312 | 752 log.info("entered text is not a jid") |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
753 return |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
754 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
755 def disco_cb(disco): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
756 # TODO: check if plugin XEP-0045 is activated |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
757 if "conference" in [i[0] for i in disco[1]]: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
758 G.host.bridge.muc_join(str(jid_), "", "", self.profile, |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
759 callback=self._muc_join_cb, errback=self._muc_join_eb) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
760 else: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
761 self.change_widget(jid_) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
762 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
763 def disco_eb(failure): |
312 | 764 log.warning("Disco failure, ignore this text: {}".format(failure)) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
765 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
766 G.host.bridge.disco_infos( |
442 | 767 jid_.domain, |
768 profile_key=self.profile, | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
769 callback=disco_cb, |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
770 errback=disco_eb) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
771 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
772 def on_header_wid_input_completed(self, input_wid, completed_text): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
773 self._hi_comp_allowed = False |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
774 input_wid.text = completed_text |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
775 self._hi_comp_allowed = True |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
776 self._hi_comp_dropdown.dismiss() |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
777 self.on_header_wid_input() |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
778 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
779 def on_header_wid_input_complete(self, wid, text): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
780 if not self._hi_comp_allowed: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
781 return |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
782 text = text.lstrip() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
783 if not text: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
784 self._hi_comp_data = None |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
785 self._hi_comp_last = None |
144 | 786 self._hi_comp_dropdown.dismiss() |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
787 return |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
788 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
789 profile = list(self.profiles)[0] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
790 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
791 if self._hi_comp_data is None: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
792 # first completion, we build the initial list |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
793 comp_data = self._hi_comp_data = [] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
794 self._hi_comp_last = '' |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
795 for jid_, jid_data in G.host.contact_lists[profile].all_iter: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
796 comp_data.append((jid_, jid_data)) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
797 comp_data.sort(key=lambda datum: datum[0]) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
798 else: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
799 comp_data = self._hi_comp_data |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
800 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
801 # XXX: dropdown is rebuilt each time backspace is pressed or if the text is changed, |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
802 # it works OK, but some optimisation may be done here |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
803 dropdown = self._hi_comp_dropdown |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
804 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
805 if not text.startswith(self._hi_comp_last) or not self._hi_comp_last: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
806 # text has changed or backspace has been pressed, we restart |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
807 dropdown.clear_widgets() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
808 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
809 for jid_, jid_data in comp_data: |
312 | 810 nick = jid_data.get('nick', '') |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
811 if text in jid_.bare or text in nick.lower(): |
193
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
186
diff
changeset
|
812 btn = JidButton( |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
813 jid = jid_.bare, |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
814 profile = profile, |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
815 size_hint = (0.5, None), |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
816 nick = nick, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
817 on_release=lambda __, txt=jid_.bare: self.on_header_wid_input_completed(wid, txt) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
818 ) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
819 dropdown.add_widget(btn) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
820 else: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
821 # more chars, we continue completion by removing unwanted widgets |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
822 to_remove = [] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
823 for c in dropdown.children[0].children: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
824 if text not in c.jid and text not in (c.nick or ''): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
825 to_remove.append(c) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
826 for c in to_remove: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
827 dropdown.remove_widget(c) |
144 | 828 if dropdown.attach_to is None: |
829 dropdown.open(wid) | |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
830 self._hi_comp_last = text |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
831 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
832 def message_data_converter(self, idx, mess_id): |
22 | 833 return {"mess_data": self.messages[mess_id]} |
834 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
835 def _on_history_printed(self): |
22 | 836 """Refresh or scroll down the focus after the history is printed""" |
837 # self.adapter.data = self.messages | |
312 | 838 for mess_data in self.messages.values(): |
22 | 839 self.appendMessage(mess_data) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
840 super(Chat, self)._on_history_printed() |
22 | 841 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
842 def create_message(self, message): |
22 | 843 self.appendMessage(message) |
329
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
844 # we need to render immediatly next 2 layouts to avoid an unpleasant flickering |
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
845 # when sending or receiving a message |
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
846 self.messages_widget.dont_delay_next_layouts = 2 |
22 | 847 |
848 def appendMessage(self, mess_data): | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
849 """Append a message Widget to the history |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
850 |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
851 @param mess_data(quick_chat.Message): message data |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
852 """ |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
853 if self.handle_user_moved(mess_data): |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
854 return |
22 | 855 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
856 self.notify(mess_data) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
857 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
858 def prepend_message(self, mess_data): |
326 | 859 """Prepend a message Widget to the history |
860 | |
861 @param mess_data(quick_chat.Message): message data | |
862 """ | |
863 mess_wid = self.messages_widget | |
864 last_idx = len(mess_wid.children) | |
865 mess_wid.add_widget(MessageWidget(mess_data=mess_data), index=last_idx) | |
866 | |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
867 def _get_notif_msg(self, mess_data): |
312 | 868 return _("{nick}: {message}").format( |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
869 nick=mess_data.nick, |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
870 message=mess_data.main_message) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
871 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
872 def notify(self, mess_data): |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
873 """Notify user when suitable |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
874 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
875 For one2one chat, notification will happen when window has not focus |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
876 or when one2one chat is not visible. A note is also there when widget |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
877 is not visible. |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
878 For group chat, note will be added on mention, with a desktop notification if |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
879 window has not focus or is not visible. |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
880 """ |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
881 visible_clones = [w for w in G.host.get_visible_list(self.__class__) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
882 if w.target == self.target] |
186
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
883 if len(visible_clones) > 1 and visible_clones.index(self) > 0: |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
884 # to avoid multiple notifications in case of multiple cloned widgets |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
885 # we only handle first clone |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
886 return |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
887 is_visible = bool(visible_clones) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
888 if self.type == C.CHAT_ONE2ONE: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
889 if (not Window.focus or not is_visible) and not mess_data.history: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
890 notif_msg = self._get_notif_msg(mess_data) |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
891 G.host.notify( |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
892 type_=C.NOTIFY_MESSAGE, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
893 entity=mess_data.from_jid, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
894 message=notif_msg, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
895 subject=_("private message"), |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
896 widget=self, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
897 profile=self.profile |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
898 ) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
899 if not is_visible: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
900 G.host.add_note( |
312 | 901 _("private message"), |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
902 notif_msg, |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
903 symbol = "comments", |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
904 action = { |
312 | 905 "action": 'chat', |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
906 "target": self.target, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
907 "profiles": self.profiles} |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
908 ) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
909 else: |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
910 if mess_data.mention: |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
911 notif_msg = self._get_notif_msg(mess_data) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
912 G.host.add_note( |
312 | 913 _("mention"), |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
914 notif_msg, |
518
196483685a63
Use Font-Awesome instead of Fontello, following change in Libervia Media.
Goffi <goffi@goffi.org>
parents:
493
diff
changeset
|
915 symbol = "comments", |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
916 action = { |
312 | 917 "action": 'chat', |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
918 "target": self.target, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
919 "profiles": self.profiles} |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
920 ) |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
921 if not is_visible or not Window.focus: |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
922 subject=_("mention ({room_jid})").format(room_jid=self.target) |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
923 G.host.notify( |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
924 type_=C.NOTIFY_MENTION, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
925 entity=self.target, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
926 message=notif_msg, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
927 subject=subject, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
928 widget=self, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
929 profile=self.profile |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
930 ) |
22 | 931 |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
932 # message input |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
933 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
934 def _attachment_progress_cb(self, item, metadata, profile): |
412 | 935 item.parent.remove_widget(item) |
936 log.info(f"item {item.data.get('path')} uploaded successfully") | |
937 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
938 def _attachment_progress_eb(self, item, err_msg, profile): |
412 | 939 item.parent.remove_widget(item) |
940 path = item.data.get('path') | |
941 msg = _("item {path} could not be uploaded: {err_msg}").format( | |
942 path=path, err_msg=err_msg) | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
943 G.host.add_note(_("can't upload file"), msg, C.XMLUI_DATA_LVL_WARNING) |
412 | 944 log.warning(msg) |
945 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
946 def _progress_get_cb(self, item, metadata): |
412 | 947 try: |
948 position = int(metadata["position"]) | |
949 size = int(metadata["size"]) | |
950 except KeyError: | |
951 # we got empty metadata, the progression is either not yet started or | |
952 # finished | |
953 if item.progress: | |
954 # if progress is already started, receiving empty metadata means | |
955 # that progression is finished | |
956 item.progress = 100 | |
957 return | |
958 else: | |
959 item.progress = position/size*100 | |
960 | |
961 if item.parent is not None: | |
962 # the item is not yet fully received, we reschedule an update | |
963 Clock.schedule_once( | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
964 partial(self._attachment_progress_update, item), |
412 | 965 PROGRESS_UPDATE) |
966 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
967 def _attachment_progress_update(self, item, __): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
968 G.host.bridge.progress_get( |
412 | 969 item.data["progress_id"], |
970 self.profile, | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
971 callback=partial(self._progress_get_cb, item), |
412 | 972 errback=G.host.errback, |
973 ) | |
974 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
975 def add_nick(self, nick): |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
976 """Add a nickname to message_input if suitable""" |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
977 if (self.type == C.CHAT_GROUP and not self.message_input.text.startswith(nick)): |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
978 self.message_input.text = f'{nick}: {self.message_input.text}' |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
979 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
980 def on_send(self, input_widget): |
412 | 981 extra = {} |
982 for item in self.attachments_to_send.attachments.children: | |
983 if item.sending: | |
984 # the item is already being sent | |
985 continue | |
986 item.sending = True | |
987 progress_id = item.data["progress_id"] = str(uuid.uuid4()) | |
490
962d17c4078c
chat: changed KEY_ATTACHEMENTS* name following backend change
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
988 attachments = extra.setdefault(C.KEY_ATTACHMENTS, []) |
412 | 989 attachment = { |
990 "path": str(item.data["path"]), | |
991 "progress_id": progress_id, | |
992 } | |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
993 if 'media_type' in item.data: |
490
962d17c4078c
chat: changed KEY_ATTACHEMENTS* name following backend change
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
994 attachment[C.KEY_ATTACHMENTS_MEDIA_TYPE] = item.data['media_type'] |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
995 |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
996 if ((self.attachments_to_send.reduce_checkbox.active |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
997 and attachment.get('media_type', '').split('/')[0] == 'image')): |
490
962d17c4078c
chat: changed KEY_ATTACHEMENTS* name following backend change
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
998 attachment[C.KEY_ATTACHMENTS_RESIZE] = True |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
999 |
412 | 1000 attachments.append(attachment) |
1001 | |
1002 Clock.schedule_once( | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1003 partial(self._attachment_progress_update, item), |
412 | 1004 PROGRESS_UPDATE) |
1005 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1006 G.host.register_progress_cbs( |
412 | 1007 progress_id, |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1008 callback=partial(self._attachment_progress_cb, item), |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1009 errback=partial(self._attachment_progress_eb, item) |
412 | 1010 ) |
1011 | |
1012 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1013 G.host.message_send( |
22 | 1014 self.target, |
412 | 1015 # TODO: handle language |
1016 {'': input_widget.text}, | |
1017 # TODO: put this in QuickChat | |
1018 mess_type= | |
1019 C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, | |
1020 extra=extra, | |
22 | 1021 profile_key=self.profile |
1022 ) | |
1023 input_widget.text = '' | |
1024 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1025 def _image_check_cb(self, report_raw): |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1026 report = data_format.deserialise(report_raw) |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1027 if report['too_large']: |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1028 self.attachments_to_send.show_resize=True |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1029 self.attachments_to_send.reduce_checkbox.active=True |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1030 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1031 def add_attachment(self, file_path, media_type=None): |
412 | 1032 file_path = Path(file_path) |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1033 if media_type is None: |
455
642cd2435e26
chat: fixed media_type guessing when Path is used for attachment
Goffi <goffi@goffi.org>
parents:
448
diff
changeset
|
1034 media_type = mimetypes.guess_type(str(file_path), strict=False)[0] |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1035 if not self.attachments_to_send.show_resize and media_type is not None: |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1036 # we check if the attachment is an image and if it's too large. |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1037 # If too large, the reduce size check box will be displayed, and checked by |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1038 # default. |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1039 main_type = media_type.split('/')[0] |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1040 if main_type == "image": |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1041 G.host.bridge.image_check( |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1042 str(file_path), |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1043 callback=self._image_check_cb, |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1044 errback=partial( |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1045 G.host.errback, |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1046 title=_("Can't check image size"), |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1047 message=_("Can't check image at {path}: {{msg}}").format( |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1048 path=file_path), |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1049 ) |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1050 ) |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1051 |
412 | 1052 data = { |
1053 "path": file_path, | |
1054 "name": file_path.name, | |
1055 } | |
448
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1056 |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1057 if media_type is not None: |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1058 data['media_type'] = media_type |
20a807443c3f
chat: resize attachments (images only for now):
Goffi <goffi@goffi.org>
parents:
446
diff
changeset
|
1059 |
412 | 1060 self.attachments_to_send.attachments.add_widget( |
1061 AttachmentToSendItem(data=data) | |
1062 ) | |
283
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
1063 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1064 def transfer_file(self, file_path, transfer_type=C.TRANSFER_UPLOAD, cleaning_cb=None): |
412 | 1065 # FIXME: cleaning_cb is not managed |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
1066 if transfer_type == C.TRANSFER_UPLOAD: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1067 self.add_attachment(file_path) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1068 elif transfer_type == C.TRANSFER_SEND: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1069 if self.type == C.CHAT_GROUP: |
312 | 1070 log.warning("P2P transfer is not possible for group chat") |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1071 # TODO: show an error dialog to user, or better hide the send button for |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1072 # MUC |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1073 else: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1074 jid_ = self.target |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1075 if not jid_.resource: |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1076 jid_ = G.host.contact_lists[self.profile].get_full_jid(jid_) |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1077 G.host.bridge.file_send(str(jid_), str(file_path), "", "", "", |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1078 profile=self.profile) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1079 # TODO: notification of sending/failing |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1080 else: |
312 | 1081 raise log.error("transfer of type {} are not handled".format(transfer_type)) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1082 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1083 def message_encryption_started(self, plugin_data): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1084 quick_chat.QuickChat.message_encryption_started(self, plugin_data) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1085 self.encryption_btn.symbol = SYMBOL_ENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1086 self.encryption_btn.color = COLOR_ENCRYPTED |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1087 self.encryption_btn.select_algo(plugin_data['name']) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1088 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1089 def message_encryption_stopped(self, plugin_data): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1090 quick_chat.QuickChat.message_encryption_stopped(self, plugin_data) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1091 self.encryption_btn.symbol = SYMBOL_UNENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
1092 self.encryption_btn.color = COLOR_UNENCRYPTED |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1093 self.encryption_btn.select_algo(None) |
78 | 1094 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1095 def _muc_join_cb(self, joined_data): |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
1096 joined, room_jid_s, occupants, user_nick, subject, statuses, profile = joined_data |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1097 self.host.muc_room_joined_handler(*joined_data[1:]) |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
1098 jid_ = jid.JID(room_jid_s) |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1099 self.change_widget(jid_) |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
1100 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1101 def _muc_join_eb(self, failure): |
312 | 1102 log.warning("Can't join room: {}".format(failure)) |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
1103 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1104 def on_otr_state(self, state, dest_jid, profile): |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1105 assert profile in self.profiles |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1106 if state in OTR_STATE_ENCRYPTION: |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1107 self.otr_state_encryption = state |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1108 elif state in OTR_STATE_TRUST: |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1109 self.otr_state_trust = state |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1110 else: |
312 | 1111 log.error(_("Unknown OTR state received: {}".format(state))) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1112 return |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1113 self.encryption_btn.symbol = self.encryption_btn.get_symbol() |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1114 self.encryption_btn.color = self.encryption_btn.get_color() |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
1115 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1116 def on_visible(self): |
265
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
1117 if not self.sync: |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
1118 self.resync() |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
1119 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1120 def on_selected(self): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1121 G.host.clear_notifs(self.target, profile=self.profile) |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
1122 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1123 def on_delete(self, **kwargs): |
393
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1124 if kwargs.get('explicit_close', False): |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1125 wrapper = self.whwrapper |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1126 if wrapper is not None: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1127 if len(wrapper.carousel.slides) == 1: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1128 # if we delete the last opened chat, we need to show the selector |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1129 screen_manager = self.screen_manager |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1130 screen_manager.transition.direction = 'down' |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1131 screen_manager.current = 'chat_selector' |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1132 wrapper.carousel.remove_widget(self) |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
1133 return True |
261
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
1134 # we always keep one widget, so it's available when swiping |
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
1135 # TODO: delete all widgets when chat is closed |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1136 nb_instances = sum(1 for _ in self.host.widgets.get_widget_instances(self)) |
356
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
1137 # we want to keep at least one instance of Chat by WHWrapper |
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
1138 nb_to_keep = len(G.host.widgets_handler.children) |
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
1139 if nb_instances <= nb_to_keep: |
261
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
1140 return False |
22 | 1141 |
326 | 1142 def _history_unlock(self, __): |
1143 self._history_prepend_lock = False | |
1144 log.debug("history prepend unlocked") | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1145 # we call manually on_scroll, to check if we are still in the scrolling zone |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1146 self.on_scroll(self.history_scroll, self.history_scroll.scroll_y) |
326 | 1147 |
1148 def _history_scroll_adjust(self, __, scroll_start_height): | |
1149 # history scroll position must correspond to where it was before new messages | |
1150 # have been appended | |
1151 self.history_scroll.scroll_y = ( | |
1152 scroll_start_height / self.messages_widget.height | |
1153 ) | |
1154 | |
1155 # we want a small delay before unlocking, to avoid re-fetching history | |
1156 # again | |
1157 Clock.schedule_once(self._history_unlock, 1.5) | |
1158 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1159 def _back_history_get_cb_post(self, __, history, scroll_start_height): |
326 | 1160 if len(history) == 0: |
1161 # we don't unlock self._history_prepend_lock if there is no history, as there | |
1162 # is no sense to try to retrieve more in this case. | |
1163 log.debug(f"we've reached top of history for {self.target.bare} chat") | |
1164 else: | |
1165 # we have to schedule again for _history_scroll_adjust, else messages_widget | |
1166 # is not resized (self.messages_widget.height is not yet updated) | |
1167 # as a result, the scroll_to can't work correctly | |
1168 Clock.schedule_once(partial( | |
1169 self._history_scroll_adjust, | |
1170 scroll_start_height=scroll_start_height)) | |
1171 log.debug( | |
1172 f"{len(history)} messages prepended to history (last: {history[0][0]})") | |
1173 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1174 def _back_history_get_cb(self, history): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1175 # TODO: factorise with QuickChat._history_get_cb |
326 | 1176 scroll_start_height = self.messages_widget.height * self.history_scroll.scroll_y |
1177 for data in reversed(history): | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
1178 uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data |
326 | 1179 from_jid = jid.JID(from_jid) |
1180 to_jid = jid.JID(to_jid) | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
1181 extra = data_format.deserialise(extra_s) |
326 | 1182 extra["history"] = True |
1183 self.messages[uid] = message = quick_chat.Message( | |
1184 self, | |
1185 uid, | |
1186 timestamp, | |
1187 from_jid, | |
1188 to_jid, | |
1189 message, | |
1190 subject, | |
1191 type_, | |
1192 extra, | |
1193 self.profile, | |
1194 ) | |
1195 self.messages.move_to_end(uid, last=False) | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1196 self.prepend_message(message) |
326 | 1197 Clock.schedule_once(partial( |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1198 self._back_history_get_cb_post, |
326 | 1199 history=history, |
1200 scroll_start_height=scroll_start_height)) | |
1201 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1202 def _back_history_get_eb(self, failure_): |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1203 G.host.add_note( |
326 | 1204 _("Problem while getting back history"), |
1205 _("Can't back history for {target}: {problem}").format( | |
1206 target=self.target, problem=failure_), | |
1207 C.XMLUI_DATA_LVL_ERROR) | |
1208 # we don't unlock self._history_prepend_lock on purpose, no need | |
1209 # to try to get more history if something is wrong | |
1210 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1211 def on_scroll(self, scroll_view, scroll_y): |
326 | 1212 if self._history_prepend_lock: |
1213 return | |
1214 if (1-scroll_y) * self.messages_widget.height < INFINITE_SCROLL_LIMIT: | |
1215 self._history_prepend_lock = True | |
1216 log.debug(f"Retrieving back history for {self} [{self.history_count}]") | |
1217 self.history_count += 1 | |
1218 first_uid = next(iter(self.messages.keys())) | |
1219 filters = self.history_filters.copy() | |
1220 filters['before_uid'] = first_uid | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1221 self.host.bridge.history_get( |
326 | 1222 str(self.host.profiles[self.profile].whoami.bare), |
1223 str(self.target), | |
1224 30, | |
1225 True, | |
1226 {k: str(v) for k,v in filters.items()}, | |
1227 self.profile, | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1228 callback=self._back_history_get_cb, |
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1229 errback=self._back_history_get_eb, |
326 | 1230 ) |
1231 | |
22 | 1232 |
493
b3cedbee561d
refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents:
491
diff
changeset
|
1233 class ChatSelector(cagou_widget.LiberviaDesktopKivyWidget, FilterBehavior): |
394
d15828ca9d86
chat: use the new "implicit_update" and "to_show" properties for ChatSelector.jid_selector:
Goffi <goffi@goffi.org>
parents:
393
diff
changeset
|
1234 jid_selector = properties.ObjectProperty() |
354 | 1235 profile = properties.StringProperty() |
1236 plugin_info_class = Chat | |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1237 use_header_input = True |
354 | 1238 |
1239 def on_select(self, contact_button): | |
1240 contact_jid = jid.JID(contact_button.jid) | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1241 plugin_info = G.host.get_plugin_info(main=Chat) |
354 | 1242 factory = plugin_info['factory'] |
1243 self.screen_manager.transition.direction = 'up' | |
1244 carousel = self.whwrapper.carousel | |
1245 current_slides = {w.target: w for w in carousel.slides} | |
1246 if contact_jid in current_slides: | |
1247 slide = current_slides[contact_jid] | |
1248 idx = carousel.slides.index(slide) | |
1249 carousel.index = idx | |
1250 self.screen_manager.current = '' | |
1251 else: | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1252 G.host.switch_widget( |
354 | 1253 self, factory(plugin_info, contact_jid, profiles=[self.profile])) |
1254 | |
1255 | |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1256 def on_header_wid_input(self): |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1257 text = self.header_input.text.strip() |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1258 try: |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1259 if text.count('@') != 1 or text.count(' '): |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1260 raise ValueError |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1261 jid_ = jid.JID(text) |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1262 except ValueError: |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1263 log.info("entered text is not a jid") |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1264 return |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1265 G.host.do_action("chat", jid_, [self.profile]) |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1266 |
491
203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
490
diff
changeset
|
1267 def on_header_wid_input_complete(self, wid, text, **kwargs): |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1268 """we filter items when text is entered in input box""" |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1269 for layout in self.jid_selector.items_layouts: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1270 self.do_filter( |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1271 layout, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1272 text, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1273 # we append nick to jid to filter on both |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1274 lambda c: c.jid + c.data.get('nick', ''), |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1275 width_cb=lambda c: c.base_width, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1276 height_cb=lambda c: c.minimum_height, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1277 continue_tests=[lambda c: not isinstance(c, ContactButton)]) |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1278 |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1279 |
22 | 1280 PLUGIN_INFO["factory"] = Chat.factory |
1281 quick_widgets.register(quick_chat.QuickChat, Chat) |