Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_chat.py @ 409:2caea63ae2ab
chat: show attachments as clickable icons
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Feb 2020 09:49:21 +0100 |
parents | 03554ad70846 |
children | b018386653c2 |
rev | line source |
---|---|
379 | 1 #!/usr/bin/env python3 |
22 | 2 |
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
378 | 4 # Copyright (C) 2016-2020 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 |
21 import mimetypes | |
22 import sys | |
78 | 23 from kivy.uix.boxlayout import BoxLayout |
22 | 24 from kivy.uix.textinput import TextInput |
354 | 25 from kivy.uix.screenmanager import Screen, NoTransition |
26 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
|
27 from kivy.uix.behaviors import ButtonBehavior |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
28 from kivy.metrics import sp, dp |
276 | 29 from kivy.clock import Clock |
22 | 30 from kivy import properties |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
31 from kivy.uix.scrollview import ScrollView |
325 | 32 from kivy.uix.dropdown import DropDown |
33 from kivy.core.window import Window | |
34 from sat.core import log as logging | |
35 from sat.core.i18n import _ | |
36 from sat.core import exceptions | |
333
69d2a96ce26f
chat: serialise `options` in `fileUpload` following change in backend
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
37 from sat.tools.common import data_format |
22 | 38 from sat_frontends.quick_frontend import quick_widgets |
39 from sat_frontends.quick_frontend import quick_chat | |
106
9909ed7a7a20
moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
40 from sat_frontends.tools import jid |
325 | 41 from cagou import G |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
42 from ..core.constants import Const as C |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
43 from ..core import cagou_widget |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
44 from ..core import xmlui |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
45 from ..core.image import Image |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
46 from ..core.common import SymbolButton, JidButton |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
47 from ..core.behaviors import FilterBehavior |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
48 from ..core import menu |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
49 from ..core.common import ContactButton |
22 | 50 |
276 | 51 log = logging.getLogger(__name__) |
22 | 52 |
53 PLUGIN_INFO = { | |
312 | 54 "name": _("chat"), |
22 | 55 "main": "Chat", |
312 | 56 "description": _("instant messaging with one person or a group"), |
57 "icon_symbol": "chat", | |
22 | 58 } |
59 | |
244
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
60 # 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
|
61 # 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
|
62 OTR_STATE_UNTRUSTED = 'untrusted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
63 OTR_STATE_TRUSTED = 'trusted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
64 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
|
65 OTR_STATE_UNENCRYPTED = 'unencrypted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
66 OTR_STATE_ENCRYPTED = 'encrypted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
67 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
|
68 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
69 SYMBOL_UNENCRYPTED = 'lock-open' |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
70 SYMBOL_ENCRYPTED = 'lock' |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
71 SYMBOL_ENCRYPTED_TRUSTED = 'lock-filled' |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
72 COLOR_UNENCRYPTED = (0.4, 0.4, 0.4, 1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
73 COLOR_ENCRYPTED = (0.4, 0.4, 0.4, 1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
74 COLOR_ENCRYPTED_TRUSTED = (0.29,0.87,0.0,1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
75 |
326 | 76 # below this limit, new messages will be prepended |
77 INFINITE_SCROLL_LIMIT = dp(600) | |
78 | |
22 | 79 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
80 class AttachmentsLayout(ScrollView): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
81 attachments = properties.ObjectProperty() |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
82 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
83 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
84 class AttachmentItem(BoxLayout): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
85 data = properties.DictProperty() |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
86 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
87 def get_symbol(self, data): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
88 media_type = data.get('media_type', '') |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
89 main_type = media_type.split('/', 1)[0] |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
90 if main_type == 'image': |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
91 return "file-image" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
92 elif main_type == 'video': |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
93 return "file-video" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
94 elif main_type == 'audio': |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
95 return "file-audio" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
96 else: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
97 return "doc" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
98 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
99 def on_press(self): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
100 url = self.data.get('url') |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
101 if url: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
102 G.local_platform.open_url(url, self) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
103 else: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
104 log.warning("can't find URL in {self.data}") |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
105 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
106 |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
107 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
|
108 pass |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
109 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
110 |
325 | 111 class MessageWidget(quick_chat.MessageWidget, BoxLayout): |
22 | 112 mess_data = properties.ObjectProperty() |
57 | 113 mess_xhtml = properties.ObjectProperty() |
45 | 114 mess_padding = (dp(5), dp(5)) |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
115 avatar = properties.ObjectProperty() |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
116 delivery = properties.ObjectProperty() |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
117 font_size = properties.NumericProperty(sp(12)) |
325 | 118 right_part = properties.ObjectProperty() |
119 header_box = properties.ObjectProperty() | |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
120 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
121 def on_kv_post(self, __): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
122 if not self.mess_data: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
123 raise exceptions.InternalError( |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
124 "mess_data must always be set in MessageWidget") |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
125 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
126 self.mess_data.widgets.add(self) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
127 self.add_attachments() |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
128 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
129 @property |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
130 def chat(self): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
131 """return parent Chat instance""" |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
132 return self.mess_data.parent |
22 | 133 |
325 | 134 def _get_from_mess_data(self, name, default): |
135 if self.mess_data is None: | |
136 return default | |
137 return getattr(self.mess_data, name) | |
138 | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
139 def _get_message(self): |
22 | 140 """Return currently displayed message""" |
325 | 141 if self.mess_data is None: |
142 return "" | |
22 | 143 return self.mess_data.main_message |
144 | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
145 def _set_message(self, message): |
325 | 146 if self.mess_data is None: |
147 return False | |
312 | 148 if message == self.mess_data.message.get(""): |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
149 return False |
312 | 150 self.mess_data.message = {"": message} |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
151 return True |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
152 |
325 | 153 message = properties.AliasProperty( |
154 partial(_get_from_mess_data, name="main_message", default=""), | |
155 _set_message, | |
156 bind=['mess_data'], | |
157 ) | |
158 message_xhtml = properties.AliasProperty( | |
159 partial(_get_from_mess_data, name="main_message_xhtml", default=""), | |
160 bind=['mess_data']) | |
161 mess_type = properties.AliasProperty( | |
162 partial(_get_from_mess_data, name="type", default=""), bind=['mess_data']) | |
163 own_mess = properties.AliasProperty( | |
164 partial(_get_from_mess_data, name="own_mess", default=False), bind=['mess_data']) | |
165 nick = properties.AliasProperty( | |
166 partial(_get_from_mess_data, name="nick", default=""), bind=['mess_data']) | |
167 time_text = properties.AliasProperty( | |
168 partial(_get_from_mess_data, name="time_text", default=""), bind=['mess_data']) | |
57 | 169 |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
170 @property |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
171 def info_type(self): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
172 return self.mess_data.info_type |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
173 |
54
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
174 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
|
175 if 'avatar' in update_dict: |
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
176 self.avatar.source = update_dict['avatar'] |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
177 if 'status' in update_dict: |
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
178 status = update_dict['status'] |
312 | 179 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
|
180 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
181 def add_attachments(self): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
182 """Add attachments layout + attachments item""" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
183 attachments = self.mess_data.attachments |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
184 if not attachments: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
185 return |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
186 root_layout = AttachmentsLayout() |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
187 self.right_part.add_widget(root_layout) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
188 layout = root_layout.attachments |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
189 for attachment in attachments: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
190 item = AttachmentItem(data=attachment) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
191 layout.add_widget(item) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
192 |
22 | 193 |
276 | 194 class SendButton(SymbolButton): |
195 message_input_box = properties.ObjectProperty() | |
196 | |
197 | |
78 | 198 class MessageInputBox(BoxLayout): |
276 | 199 message_input = properties.ObjectProperty() |
200 | |
201 def __init__(self, *args, **kwargs): | |
202 super(MessageInputBox, self).__init__(*args, **kwargs) | |
203 Clock.schedule_once(self.post_init, 0) | |
204 | |
205 def post_init(self, *args): | |
206 if sys.platform == 'android': | |
207 self.add_widget(SendButton(message_input_box=self), 0) | |
208 | |
209 def send_text(self): | |
210 self.message_input.send_text() | |
78 | 211 |
212 | |
22 | 213 class MessageInputWidget(TextInput): |
214 | |
276 | 215 def keyboard_on_key_down(self, window, keycode, text, modifiers): |
216 # We don't send text when shift is pressed to be able to add line feeds | |
217 # (i.e. multi-lines messages). We don't send on Android either as the | |
218 # send button appears on this platform. | |
219 if (keycode[-1] == "enter" | |
220 and "shift" not in modifiers | |
221 and sys.platform != 'android'): | |
222 self.send_text() | |
22 | 223 else: |
276 | 224 return super(MessageInputWidget, self).keyboard_on_key_down( |
225 window, keycode, text, modifiers) | |
226 | |
227 def send_text(self): | |
228 self.dispatch('on_text_validate') | |
22 | 229 |
230 | |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
231 class TransferButton(SymbolButton): |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
232 chat = properties.ObjectProperty() |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
233 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
234 def on_release(self, *args): |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
235 menu.TransferMenu(callback=self.chat.transferFile).show(self) |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
236 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
237 |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
238 class ExtraMenu(DropDown): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
239 chat = properties.ObjectProperty() |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
240 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
241 def on_select(self, menu): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
242 if menu == 'bookmark': |
312 | 243 G.host.bridge.menuLaunch(C.MENU_GLOBAL, ("groups", "bookmarks"), |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
244 {}, C.NO_SECURITY_LIMIT, self.chat.profile, |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
245 callback=partial( |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
246 G.host.actionManager, profile=self.chat.profile), |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 # for MUC, we have to indicate the backend that we've left |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
251 G.host.bridge.mucLeave(self.chat.target, self.chat.profile) |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
252 else: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
253 # 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
|
254 # widget here in the frontend |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
255 G.host.widgets.deleteWidget( |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
256 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
|
257 else: |
312 | 258 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
|
259 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
260 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
261 class ExtraButton(SymbolButton): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
262 chat = properties.ObjectProperty() |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
263 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
264 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
265 class EncryptionMainButton(SymbolButton): |
117 | 266 |
267 def __init__(self, chat, **kwargs): | |
268 """ | |
269 @param chat(Chat): Chat instance | |
270 """ | |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
271 self.chat = chat |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
272 self.encryption_menu = EncryptionMenu(chat) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
273 super(EncryptionMainButton, self).__init__(**kwargs) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
274 self.bind(on_release=self.encryption_menu.open) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
275 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
276 def selectAlgo(self, name): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
277 """Mark an encryption algorithm as selected. |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
278 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
279 This will also deselect all other button |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
280 @param name(unicode, None): encryption plugin name |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
281 None for plain text |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
282 """ |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
283 buttons = self.encryption_menu.container.children |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
284 buttons[-1].selected = name is None |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
285 for button in buttons[:-1]: |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
286 button.selected = button.text == name |
117 | 287 |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
288 def getColor(self): |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 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
|
293 else: |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
294 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
|
295 |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
296 def getSymbol(self): |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
297 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
298 return 'lock-open' |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
299 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
|
300 return 'lock-filled' |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
301 else: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
302 return 'lock' |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
303 |
117 | 304 |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
305 class TrustManagementButton(SymbolButton): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
306 pass |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
307 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
308 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
309 class EncryptionButton(BoxLayout): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
310 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
|
311 text = properties.StringProperty() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
312 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
|
313 best_width = properties.NumericProperty(0) |
312 | 314 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
|
315 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
316 def __init__(self, **kwargs): |
312 | 317 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
|
318 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
|
319 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
|
320 if self.trust_button: |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
321 self.add_widget(TrustManagementButton()) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
322 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
323 def on_release(self): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
324 pass |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
325 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
326 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
|
327 pass |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
328 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
329 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
330 class EncryptionMenu(DropDown): |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
331 # 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
|
332 best_width = properties.NumericProperty(0) |
117 | 333 |
334 def __init__(self, chat, **kwargs): | |
335 """ | |
336 @param chat(Chat): Chat instance | |
337 """ | |
338 self.chat = chat | |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
339 super(EncryptionMenu, self).__init__(**kwargs) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
340 btn = EncryptionButton( |
312 | 341 text=_("unencrypted (plain text)"), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
342 on_release=self.unencrypted, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
343 selected=True, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
344 bold=False, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
345 ) |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
346 btn.bind( |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
347 on_release=self.unencrypted, |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
348 ) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
349 self.add_widget(btn) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
350 for plugin in G.host.encryption_plugins: |
339
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
351 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
|
352 # directed plugins can't work with group chat |
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
353 continue |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
354 btn = EncryptionButton( |
312 | 355 text=plugin['name'], |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
356 trust_button=True, |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
357 ) |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
358 btn.bind( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
359 on_release=partial(self.startEncryption, plugin=plugin), |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
360 on_trust_release=partial(self.getTrustUI, plugin=plugin), |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
361 ) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
362 self.add_widget(btn) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
363 log.info("added encryption: {}".format(plugin['name'])) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
364 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
365 def messageEncryptionStopCb(self): |
312 | 366 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
|
367 destinee = self.chat.target)) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
368 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
369 def messageEncryptionStopEb(self, failure_): |
312 | 370 msg = _("Error while stopping encryption with {destinee}: {reason}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
371 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
372 reason = failure_) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
373 log.warning(msg) |
312 | 374 G.host.addNote(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
375 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
376 def unencrypted(self, button): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
377 self.dismiss() |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
378 G.host.bridge.messageEncryptionStop( |
312 | 379 str(self.chat.target), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
380 self.chat.profile, |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
381 callback=self.messageEncryptionStopCb, |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
382 errback=self.messageEncryptionStopEb) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
383 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
384 def messageEncryptionStartCb(self, plugin): |
312 | 385 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
|
386 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
387 encr_name = plugin['name'])) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
388 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
389 def messageEncryptionStartEb(self, failure_): |
312 | 390 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
|
391 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
392 reason = failure_) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
393 log.warning(msg) |
312 | 394 G.host.addNote(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
395 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
396 def startEncryption(self, button, plugin): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
397 """Request encryption with given plugin for this session |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
398 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
399 @param button(EncryptionButton): button which has been pressed |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
400 @param plugin(dict): plugin data |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
401 """ |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
402 self.dismiss() |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
403 G.host.bridge.messageEncryptionStart( |
312 | 404 str(self.chat.target), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
405 plugin['namespace'], |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
406 True, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
407 self.chat.profile, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
408 callback=partial(self.messageEncryptionStartCb, plugin=plugin), |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
409 errback=self.messageEncryptionStartEb) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
410 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
411 def encryptionTrustUIGetCb(self, xmlui_raw): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
412 xml_ui = xmlui.create( |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
413 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
|
414 xml_ui.show() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
415 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
416 def encryptionTrustUIGetEb(self, failure_): |
312 | 417 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
|
418 reason = failure_) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
419 log.warning(msg) |
312 | 420 G.host.addNote(_("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
|
421 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
|
422 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
423 def getTrustUI(self, button, plugin): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
424 """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
|
425 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
426 @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
|
427 @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
|
428 """ |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
429 self.dismiss() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
430 G.host.bridge.encryptionTrustUIGet( |
312 | 431 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
|
432 plugin['namespace'], |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
433 self.chat.profile, |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
434 callback=self.encryptionTrustUIGetCb, |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
435 errback=self.encryptionTrustUIGetEb) |
117 | 436 |
437 | |
22 | 438 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): |
78 | 439 message_input = properties.ObjectProperty() |
86 | 440 messages_widget = properties.ObjectProperty() |
326 | 441 history_scroll = properties.ObjectProperty() |
387
d61bbbac4160
cagou widget: don't add header_input systematically anymore:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
442 use_header_input = True |
354 | 443 global_screen_manager = True |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
444 collection_carousel = True |
22 | 445 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
446 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
|
447 subject=None, statuses=None, profiles=None): |
354 | 448 self.show_chat_selector = False |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
449 if statuses is None: |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
450 statuses = {} |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
451 quick_chat.QuickChat.__init__( |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
452 self, host, target, type_, nick, occupants, subject, statuses, |
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
453 profiles=profiles) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
454 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
|
455 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
|
456 # 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
|
457 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
|
458 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
|
459 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
|
460 self._hi_comp_allowed = True |
22 | 461 cagou_widget.CagouWidget.__init__(self) |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
462 transfer_btn = TransferButton(chat=self) |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
463 self.headerInputAddExtra(transfer_btn) |
339
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
464 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
|
465 self.encryption_btn = EncryptionMainButton(self) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
466 self.headerInputAddExtra(self.encryption_btn) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
467 self.extra_menu = ExtraMenu(chat=self) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
468 extra_btn = ExtraButton(chat=self) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
469 self.headerInputAddExtra(extra_btn) |
325 | 470 self.header_input.hint_text = target |
326 | 471 self._history_prepend_lock = False |
472 self.history_count = 0 | |
22 | 473 |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
474 def on_kv_post(self, __): |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
475 self.postInit() |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
476 |
354 | 477 def screenManagerInit(self, screen_manager): |
478 screen_manager.transition = screenmanager.SlideTransition(direction='down') | |
479 sel_screen = Screen(name='chat_selector') | |
480 chat_selector = ChatSelector(profile=self.profile) | |
481 sel_screen.add_widget(chat_selector) | |
482 screen_manager.add_widget(sel_screen) | |
483 if self.show_chat_selector: | |
484 transition = screen_manager.transition | |
485 screen_manager.transition = NoTransition() | |
486 screen_manager.current = 'chat_selector' | |
487 screen_manager.transition = transition | |
488 | |
156
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
489 def __str__(self): |
312 | 490 return "Chat({})".format(self.target) |
156
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
491 |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
492 def __repr__(self): |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
493 return self.__str__() |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
494 |
22 | 495 @classmethod |
496 def factory(cls, plugin_info, target, profiles): | |
497 profiles = list(profiles) | |
498 if len(profiles) > 1: | |
312 | 499 raise NotImplementedError("Multi-profiles is not available yet for chat") |
22 | 500 if target is None: |
354 | 501 show_chat_selector = True |
22 | 502 target = G.host.profiles[profiles[0]].whoami |
354 | 503 else: |
504 show_chat_selector = False | |
505 wid = G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, | |
506 on_existing_widget=G.host.getOrClone, | |
507 profiles=profiles) | |
508 wid.show_chat_selector = show_chat_selector | |
509 return wid | |
22 | 510 |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
511 @property |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
512 def message_widgets_rev(self): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
513 return self.messages_widget.children |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
514 |
354 | 515 ## 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
|
516 |
354 | 517 def key_input(self, window, key, scancode, codepoint, modifier): |
518 if key == 27: | |
519 screen_manager = self.screen_manager | |
520 screen_manager.transition.direction = 'down' | |
521 screen_manager.current = 'chat_selector' | |
522 return True | |
523 | |
524 | |
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
|
525 ## 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
|
526 |
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
|
527 def changeWidget(self, 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
|
528 """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
|
529 |
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
|
530 @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
|
531 """ |
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
|
532 plugin_info = G.host.getPluginInfo(main=Chat) |
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
|
533 factory = plugin_info['factory'] |
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
|
534 G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.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
|
535 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
|
536 |
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
|
537 def onHeaderInput(self): |
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
|
538 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
|
539 try: |
312 | 540 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
|
541 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
|
542 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
|
543 except ValueError: |
312 | 544 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
|
545 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
|
546 |
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
|
547 def discoCb(disco): |
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
|
548 # 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
|
549 if "conference" in [i[0] for i in disco[1]]: |
312 | 550 G.host.bridge.mucJoin(str(jid_), "", "", self.profile, |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
551 callback=self._mucJoinCb, errback=self._mucJoinEb) |
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
|
552 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
|
553 self.changeWidget(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
|
554 |
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
|
555 def discoEb(failure): |
312 | 556 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
|
557 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
558 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
559 errback=discoEb) |
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
|
560 |
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
|
561 def onHeaderInputCompleted(self, input_wid, 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
|
562 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
|
563 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
|
564 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
|
565 self._hi_comp_dropdown.dismiss() |
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
|
566 self.onHeaderInput() |
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
|
567 |
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
|
568 def onHeaderInputComplete(self, wid, 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 self._hi_comp_last = None |
144 | 575 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
|
576 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
|
577 |
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
|
578 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
|
579 |
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
|
580 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
|
581 # 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
|
582 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
|
583 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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 |
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
|
590 # 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
|
591 # 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
|
592 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
|
593 |
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
|
594 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
|
595 # 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
|
596 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
|
597 |
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
|
598 for jid_, jid_data in comp_data: |
312 | 599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 nick = nick, |
284 | 606 on_release=lambda __, txt=jid_.bare: self.onHeaderInputCompleted(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
|
607 ) |
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
|
608 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
|
609 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
|
610 # 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 dropdown.remove_widget(c) |
144 | 617 if dropdown.attach_to is None: |
618 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
|
619 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
|
620 |
22 | 621 def messageDataConverter(self, idx, mess_id): |
622 return {"mess_data": self.messages[mess_id]} | |
623 | |
624 def _onHistoryPrinted(self): | |
625 """Refresh or scroll down the focus after the history is printed""" | |
626 # self.adapter.data = self.messages | |
312 | 627 for mess_data in self.messages.values(): |
22 | 628 self.appendMessage(mess_data) |
629 super(Chat, self)._onHistoryPrinted() | |
630 | |
631 def createMessage(self, message): | |
632 self.appendMessage(message) | |
329
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
633 # 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
|
634 # 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
|
635 self.messages_widget.dont_delay_next_layouts = 2 |
22 | 636 |
637 def appendMessage(self, mess_data): | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
638 """Append a message Widget to the history |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
639 |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
640 @param mess_data(quick_chat.Message): message data |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
641 """ |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
642 if self.handleUserMoved(mess_data): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
643 return |
22 | 644 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
|
645 self.notify(mess_data) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
646 |
326 | 647 def prependMessage(self, mess_data): |
648 """Prepend a message Widget to the history | |
649 | |
650 @param mess_data(quick_chat.Message): message data | |
651 """ | |
652 mess_wid = self.messages_widget | |
653 last_idx = len(mess_wid.children) | |
654 mess_wid.add_widget(MessageWidget(mess_data=mess_data), index=last_idx) | |
655 | |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
656 def _get_notif_msg(self, mess_data): |
312 | 657 return _("{nick}: {message}").format( |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
658 nick=mess_data.nick, |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
659 message=mess_data.main_message) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
660 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
661 def notify(self, mess_data): |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
662 """Notify user when suitable |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
663 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
664 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
|
665 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
|
666 is not visible. |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
667 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
|
668 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
|
669 """ |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
670 visible_clones = [w for w in G.host.getVisibleList(self.__class__) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
671 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
|
672 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
|
673 # 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
|
674 # 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
|
675 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
|
676 is_visible = bool(visible_clones) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
677 if self.type == C.CHAT_ONE2ONE: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
678 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
|
679 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
|
680 G.host.notify( |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
681 type_=C.NOTIFY_MESSAGE, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
682 entity=mess_data.from_jid, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
683 message=notif_msg, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
684 subject=_("private message"), |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
685 widget=self, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
686 profile=self.profile |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
687 ) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
688 if not is_visible: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
689 G.host.addNote( |
312 | 690 _("private message"), |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
691 notif_msg, |
312 | 692 symbol = "chat", |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
693 action = { |
312 | 694 "action": 'chat', |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
695 "target": self.target, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
696 "profiles": self.profiles} |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
697 ) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
698 else: |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
699 if mess_data.mention: |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
700 notif_msg = self._get_notif_msg(mess_data) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
701 G.host.addNote( |
312 | 702 _("mention"), |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
703 notif_msg, |
312 | 704 symbol = "chat", |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
705 action = { |
312 | 706 "action": 'chat', |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
707 "target": self.target, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
708 "profiles": self.profiles} |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
709 ) |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
710 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
|
711 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
|
712 G.host.notify( |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
713 type_=C.NOTIFY_MENTION, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
714 entity=self.target, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
715 message=notif_msg, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
716 subject=subject, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
717 widget=self, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
718 profile=self.profile |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
719 ) |
22 | 720 |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
721 # 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
|
722 |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
723 def addNick(self, nick): |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
724 """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
|
725 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
|
726 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
|
727 |
22 | 728 def onSend(self, input_widget): |
729 G.host.messageSend( | |
730 self.target, | |
731 {'': input_widget.text}, # TODO: handle language | |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
732 mess_type = (C.MESS_TYPE_GROUPCHAT |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
733 if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT), # TODO: put this in QuickChat |
22 | 734 profile_key=self.profile |
735 ) | |
736 input_widget.text = '' | |
737 | |
277
f5302d57fb09
chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
738 def fileTransferEb(self, err_msg, cleaning_cb, profile): |
88
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
739 if cleaning_cb is not None: |
3dc526bb4a5a
upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
740 cleaning_cb() |
312 | 741 msg = _("can't transfer file: {reason}").format(reason=err_msg) |
283
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
742 log.warning(msg) |
312 | 743 G.host.addNote(_("File transfer error"), |
295 | 744 msg, |
745 level=C.XMLUI_DATA_LVL_WARNING) | |
78 | 746 |
277
f5302d57fb09
chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
747 def fileTransferCb(self, metadata, cleaning_cb, profile): |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
748 log.debug("file transfered: {}".format(metadata)) |
111
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
749 extra = {} |
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
750 |
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
751 # FIXME: Q&D way of getting file type, upload plugins shouls give it |
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
752 mime_type = mimetypes.guess_type(metadata['url'])[0] |
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
753 if mime_type is not None: |
312 | 754 if mime_type.split('/')[0] == 'image': |
111
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
755 # we generate url ourselves, so this formatting is safe |
312 | 756 extra['xhtml'] = "<img src='{url}' />".format(**metadata) |
111
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
757 |
78 | 758 G.host.messageSend( |
759 self.target, | |
760 {'': metadata['url']}, | |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
761 mess_type = (C.MESS_TYPE_GROUPCHAT |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
762 if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT), |
111
c3952922ca56
chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
763 extra = extra, |
78 | 764 profile_key=profile |
765 ) | |
766 | |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
767 if cleaning_cb is not None: |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
768 cleaning_cb() |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
769 |
283
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
770 |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
771 def transferFile(self, file_path, transfer_type=C.TRANSFER_UPLOAD, cleaning_cb=None): |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
772 if transfer_type == C.TRANSFER_UPLOAD: |
333
69d2a96ce26f
chat: serialise `options` in `fileUpload` following change in backend
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
773 options = { |
69d2a96ce26f
chat: serialise `options` in `fileUpload` following change in backend
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
774 "ignore_tls_errors": not G.host.tls_validation, |
69d2a96ce26f
chat: serialise `options` in `fileUpload` following change in backend
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
775 } |
334
36d6763af547
chat: encrypt uploaded file if the session is encrypted
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
776 if self.encrypted: |
36d6763af547
chat: encrypt uploaded file if the session is encrypted
Goffi <goffi@goffi.org>
parents:
333
diff
changeset
|
777 options['encryption'] = C.ENC_AES_GCM |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
778 G.host.bridge.fileUpload( |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
779 str(file_path), |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
780 "", |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
781 "", |
333
69d2a96ce26f
chat: serialise `options` in `fileUpload` following change in backend
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
782 data_format.serialise(options), |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
783 self.profile, |
277
f5302d57fb09
chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
784 callback = partial( |
f5302d57fb09
chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
785 G.host.actionManager, |
f5302d57fb09
chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
786 progress_cb = partial(self.fileTransferCb, cleaning_cb=cleaning_cb), |
281
ef77423ce500
core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents:
278
diff
changeset
|
787 progress_eb = partial(self.fileTransferEb, cleaning_cb=cleaning_cb), |
283
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
788 profile = self.profile, |
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
789 ), |
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
790 errback = partial(G.host.errback, |
312 | 791 message=_("can't upload file: {msg}")) |
277
f5302d57fb09
chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
792 ) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
793 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
|
794 if self.type == C.CHAT_GROUP: |
312 | 795 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
|
796 # 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
|
797 # MUC |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
798 else: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
799 jid_ = self.target |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
800 if not jid_.resource: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
801 jid_ = G.host.contact_lists[self.profile].getFullJid(jid_) |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
802 G.host.bridge.fileSend(str(jid_), str(file_path), "", "", {}, |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
803 profile=self.profile) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
804 # 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
|
805 else: |
312 | 806 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
|
807 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
808 def messageEncryptionStarted(self, plugin_data): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
809 quick_chat.QuickChat.messageEncryptionStarted(self, plugin_data) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
810 self.encryption_btn.symbol = SYMBOL_ENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
811 self.encryption_btn.color = COLOR_ENCRYPTED |
312 | 812 self.encryption_btn.selectAlgo(plugin_data['name']) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
813 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
814 def messageEncryptionStopped(self, plugin_data): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
815 quick_chat.QuickChat.messageEncryptionStopped(self, plugin_data) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
816 self.encryption_btn.symbol = SYMBOL_UNENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
817 self.encryption_btn.color = COLOR_UNENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
818 self.encryption_btn.selectAlgo(None) |
78 | 819 |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
820 def _mucJoinCb(self, joined_data): |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
821 joined, room_jid_s, occupants, user_nick, subject, statuses, profile = joined_data |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
822 self.host.mucRoomJoinedHandler(*joined_data[1:]) |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
823 jid_ = jid.JID(room_jid_s) |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
824 self.changeWidget(jid_) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
825 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
826 def _mucJoinEb(self, failure): |
312 | 827 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
|
828 |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
829 def onOTRState(self, state, dest_jid, profile): |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 else: |
312 | 836 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
|
837 return |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
838 self.encryption_btn.symbol = self.encryption_btn.getSymbol() |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
839 self.encryption_btn.color = self.encryption_btn.getColor() |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
840 |
265
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
841 def onVisible(self): |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
842 if not self.sync: |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
843 self.resync() |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
844 |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
845 def onSelected(self): |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
846 G.host.clearNotifs(self.target, profile=self.profile) |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
847 |
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
|
848 def onDelete(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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 # 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 return True |
261
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
859 # 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
|
860 # TODO: delete all widgets when chat is closed |
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
861 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(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
|
862 # 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
|
863 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
|
864 if nb_instances <= nb_to_keep: |
261
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
865 return False |
22 | 866 |
326 | 867 def _history_unlock(self, __): |
868 self._history_prepend_lock = False | |
869 log.debug("history prepend unlocked") | |
870 # we call manually onScroll, to check if we are still in the scrolling zone | |
871 self.onScroll(self.history_scroll, self.history_scroll.scroll_y) | |
872 | |
873 def _history_scroll_adjust(self, __, scroll_start_height): | |
874 # history scroll position must correspond to where it was before new messages | |
875 # have been appended | |
876 self.history_scroll.scroll_y = ( | |
877 scroll_start_height / self.messages_widget.height | |
878 ) | |
879 | |
880 # we want a small delay before unlocking, to avoid re-fetching history | |
881 # again | |
882 Clock.schedule_once(self._history_unlock, 1.5) | |
883 | |
884 def _backHistoryGetCb_post(self, __, history, scroll_start_height): | |
885 if len(history) == 0: | |
886 # we don't unlock self._history_prepend_lock if there is no history, as there | |
887 # is no sense to try to retrieve more in this case. | |
888 log.debug(f"we've reached top of history for {self.target.bare} chat") | |
889 else: | |
890 # we have to schedule again for _history_scroll_adjust, else messages_widget | |
891 # is not resized (self.messages_widget.height is not yet updated) | |
892 # as a result, the scroll_to can't work correctly | |
893 Clock.schedule_once(partial( | |
894 self._history_scroll_adjust, | |
895 scroll_start_height=scroll_start_height)) | |
896 log.debug( | |
897 f"{len(history)} messages prepended to history (last: {history[0][0]})") | |
898 | |
899 def _backHistoryGetCb(self, history): | |
900 # TODO: factorise with QuickChat._historyGetCb | |
901 scroll_start_height = self.messages_widget.height * self.history_scroll.scroll_y | |
902 for data in reversed(history): | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
903 uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data |
326 | 904 from_jid = jid.JID(from_jid) |
905 to_jid = jid.JID(to_jid) | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
906 extra = data_format.deserialise(extra_s) |
326 | 907 extra["history"] = True |
908 self.messages[uid] = message = quick_chat.Message( | |
909 self, | |
910 uid, | |
911 timestamp, | |
912 from_jid, | |
913 to_jid, | |
914 message, | |
915 subject, | |
916 type_, | |
917 extra, | |
918 self.profile, | |
919 ) | |
920 self.messages.move_to_end(uid, last=False) | |
921 self.prependMessage(message) | |
922 Clock.schedule_once(partial( | |
923 self._backHistoryGetCb_post, | |
924 history=history, | |
925 scroll_start_height=scroll_start_height)) | |
926 | |
927 def _backHistoryGetEb(self, failure_): | |
928 G.host.addNote( | |
929 _("Problem while getting back history"), | |
930 _("Can't back history for {target}: {problem}").format( | |
931 target=self.target, problem=failure_), | |
932 C.XMLUI_DATA_LVL_ERROR) | |
933 # we don't unlock self._history_prepend_lock on purpose, no need | |
934 # to try to get more history if something is wrong | |
935 | |
936 def onScroll(self, scroll_view, scroll_y): | |
937 if self._history_prepend_lock: | |
938 return | |
939 if (1-scroll_y) * self.messages_widget.height < INFINITE_SCROLL_LIMIT: | |
940 self._history_prepend_lock = True | |
941 log.debug(f"Retrieving back history for {self} [{self.history_count}]") | |
942 self.history_count += 1 | |
943 first_uid = next(iter(self.messages.keys())) | |
944 filters = self.history_filters.copy() | |
945 filters['before_uid'] = first_uid | |
946 self.host.bridge.historyGet( | |
947 str(self.host.profiles[self.profile].whoami.bare), | |
948 str(self.target), | |
949 30, | |
950 True, | |
951 {k: str(v) for k,v in filters.items()}, | |
952 self.profile, | |
953 callback=self._backHistoryGetCb, | |
954 errback=self._backHistoryGetEb, | |
955 ) | |
956 | |
22 | 957 |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
958 class ChatSelector(cagou_widget.CagouWidget, 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
|
959 jid_selector = properties.ObjectProperty() |
354 | 960 profile = properties.StringProperty() |
961 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
|
962 use_header_input = True |
354 | 963 |
964 def on_select(self, contact_button): | |
965 contact_jid = jid.JID(contact_button.jid) | |
966 plugin_info = G.host.getPluginInfo(main=Chat) | |
967 factory = plugin_info['factory'] | |
968 self.screen_manager.transition.direction = 'up' | |
969 carousel = self.whwrapper.carousel | |
970 current_slides = {w.target: w for w in carousel.slides} | |
971 if contact_jid in current_slides: | |
972 slide = current_slides[contact_jid] | |
973 idx = carousel.slides.index(slide) | |
974 carousel.index = idx | |
975 self.screen_manager.current = '' | |
976 else: | |
977 G.host.switchWidget( | |
978 self, factory(plugin_info, contact_jid, profiles=[self.profile])) | |
979 | |
980 | |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
981 def onHeaderInput(self): |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
982 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
|
983 try: |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
984 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
|
985 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
|
986 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
|
987 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
|
988 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
|
989 return |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
990 G.host.doAction("chat", jid_, [self.profile]) |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
991 |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
992 def onHeaderInputComplete(self, wid, text, **kwargs): |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
993 """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
|
994 for layout in self.jid_selector.items_layouts: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
995 self.do_filter( |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
996 layout, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
997 text, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
998 # we append nick to jid to filter on both |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
999 lambda c: c.jid + c.data.get('nick', ''), |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1000 width_cb=lambda c: c.base_width, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1001 height_cb=lambda c: c.minimum_height, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1002 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
|
1003 |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1004 |
22 | 1005 PLUGIN_INFO["factory"] = Chat.factory |
1006 quick_widgets.register(quick_chat.QuickChat, Chat) |