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