annotate cagou/plugins/plugin_wid_chat.py @ 443:61322ff8090b

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