annotate libervia/frontends/quick_frontend/quick_chat.py @ 4272:89a0999884ac default tip @

cli (list/set): add "--comments" argument.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:46:55 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
3 # helper class for making a SàT frontend
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3254
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
5
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
6 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
9 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
10
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
11 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
14 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
15
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 588
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
18
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
19 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core import exceptions
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 from libervia.frontends.quick_frontend import quick_widgets
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
24 from libervia.frontends.quick_frontend.constants import Const as C
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
25 from collections import OrderedDict
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
26 from libervia.frontends.tools import jid
2029
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
27 import time
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
28
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
29
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
30 log = getLogger(__name__)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
31
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
32
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
33 ROOM_USER_JOINED = "ROOM_USER_JOINED"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
34 ROOM_USER_LEFT = "ROOM_USER_LEFT"
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
35 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
36
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
37 # from datetime import datetime
0
goffi@necton2
parents:
diff changeset
38
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
39 # FIXME: day_format need to be settable (i18n)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
40
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
41
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
42 class Message:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
43 """Message metadata"""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
44
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
45 def __init__(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
46 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
47 parent,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
48 uid,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
49 timestamp,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
50 from_jid,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
51 to_jid,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
52 msg,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
53 subject,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
54 type_,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
55 extra,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
56 profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
57 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
58 self.parent = parent
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
59 self.profile = profile
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
60 self.uid = uid
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
61 self.timestamp = timestamp
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
62 self.from_jid = from_jid
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
63 self.to_jid = to_jid
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
64 self.message = msg
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
65 self.subject = subject
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
66 self.type = type_
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
67 self.extra = extra
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
68 self.nick = self.get_nick(from_jid)
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
69 self._status = None
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
70 # own_mess is True if message was sent by profile's jid
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
71 self.own_mess = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
72 (from_jid.resource == self.parent.nick)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
73 if self.parent.type == C.CHAT_GROUP
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
74 else (from_jid.bare == self.host.profiles[profile].whoami.bare)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
75 )
1973
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
76 # is user mentioned here ?
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
77 if self.parent.type == C.CHAT_GROUP and not self.own_mess:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
78 for m in msg.values():
1973
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
79 if self.parent.nick.lower() in m.lower():
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
80 self._mention = True
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
81 break
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
82 self.handle_me()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
83 self.widgets = set() # widgets linked to this message
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
84
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
85 def __str__(self):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
86 return "Message<{mess_type}> [{time}]{nick}> {message}".format(
2847
c055a3a4ecb0 quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 2839
diff changeset
87 mess_type=self.type,
c055a3a4ecb0 quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 2839
diff changeset
88 time=self.time_text,
c055a3a4ecb0 quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 2839
diff changeset
89 nick=self.nick,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
90 message=self.main_message,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
91 )
2847
c055a3a4ecb0 quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 2839
diff changeset
92
3176
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
93 def __contains__(self, item):
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
94 return hasattr(self, item) or item in self.extra
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
95
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
96 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
97 def host(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
98 return self.parent.host
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
99
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
100 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
101 def info_type(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
102 return self.extra.get("info_type")
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
103
1973
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
104 @property
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
105 def mention(self):
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
106 try:
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
107 return self._mention
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
108 except AttributeError:
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
109 return False
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
110
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
111 @property
2580
5e54afd17321 quick frontend (chat): added a property to Message which is True when message comes from history
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 def history(self):
5e54afd17321 quick frontend (chat): added a property to Message which is True when message comes from history
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 """True if message come from history"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
114 return self.extra.get("history", False)
2580
5e54afd17321 quick frontend (chat): added a property to Message which is True when message comes from history
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115
5e54afd17321 quick frontend (chat): added a property to Message which is True when message comes from history
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 @property
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
117 def main_message(self):
2078
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
118 """currently displayed message"""
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
119 if self.parent.lang in self.message:
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
120 self.selected_lang = self.parent.lang
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
121 return self.message[self.parent.lang]
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
122 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
123 self.selected_lang = ""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
124 return self.message[""]
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
125 except KeyError:
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
126 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
127 lang, mess = next(iter(self.message.items()))
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
128 self.selected_lang = lang
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
129 return mess
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
130 except StopIteration:
3176
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
131 if not self.attachments:
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
132 # we may have empty messages if we have attachments
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
133 log.error("Can't find message for uid {}".format(self.uid))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
134 return ""
1993
981e2abbb56c quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
135
2029
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
136 @property
2078
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
137 def main_message_xhtml(self):
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
138 """rich message"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
139 xhtml = {k: v for k, v in self.extra.items() if "html" in k}
2078
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
140 if xhtml:
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
141 # FIXME: we only return first found value for now
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
142 return next(iter(xhtml.values()))
2078
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
143
3a0a7e5cef49 quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents: 2076
diff changeset
144 @property
2029
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
145 def time_text(self):
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
146 """Return timestamp in a nicely formatted way"""
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
147 # if the message was sent before today, we print the full date
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
148 timestamp = time.localtime(self.timestamp)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
149 time_format = "%c" if timestamp < self.parent.day_change else "%H:%M"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
150 return time.strftime(time_format, timestamp)
2029
62a99c214b57 primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents: 2026
diff changeset
151
2057
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
152 @property
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
153 def avatar(self):
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
154 """avatar data or None if no avatar is found"""
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
155 entity = self.from_jid
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
156 contact_list = self.host.contact_lists[self.profile]
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
157 try:
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
158 return contact_list.getCache(entity, "avatar")
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
159 except (exceptions.NotFound, KeyError):
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
160 # we don't check the result as the avatar listener will be called
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
161 self.host.bridge.avatar_get(entity, True, self.profile)
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
162 return None
2057
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
163
3229
2556eb576aed quick frontend (chat): added `encrypted` property
Goffi <goffi@goffi.org>
parents: 3176
diff changeset
164 @property
2556eb576aed quick frontend (chat): added `encrypted` property
Goffi <goffi@goffi.org>
parents: 3176
diff changeset
165 def encrypted(self):
2556eb576aed quick frontend (chat): added `encrypted` property
Goffi <goffi@goffi.org>
parents: 3176
diff changeset
166 return self.extra.get("encrypted", False)
2556eb576aed quick frontend (chat): added `encrypted` property
Goffi <goffi@goffi.org>
parents: 3176
diff changeset
167
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
168 def get_nick(self, entity):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
169 """Return nick of an entity when possible"""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
170 contact_list = self.host.contact_lists[self.profile]
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
171 if self.type == C.MESS_TYPE_INFO and self.info_type in ROOM_USER_MOVED:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
172 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
173 return self.extra["user_nick"]
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
174 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
175 log.error("extra data is missing user nick for uid {}".format(self.uid))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
176 return ""
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
177 # FIXME: converted get_specials to list for pyjamas
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
178 if self.parent.type == C.CHAT_GROUP or entity in list(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
179 contact_list.get_specials(C.CONTACT_SPECIAL_GROUP)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
180 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
181 return entity.resource or ""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
182 if entity.bare in contact_list:
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
183
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
184 try:
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
185 nicknames = contact_list.getCache(entity, "nicknames")
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
186 except (exceptions.NotFound, KeyError):
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
187 # we check result as listener will be called
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
188 self.host.bridge.identity_get(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
189 entity.bare, ["nicknames"], True, self.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
190 )
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
191 return entity.node or entity
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
192
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
193 if nicknames:
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
194 return nicknames[0]
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
195 else:
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
196 return (
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
197 contact_list.getCache(entity, "name", default=None)
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
198 or entity.node
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
199 or entity
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
200 )
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
201
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
202 return entity.node or entity
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
203
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
204 @property
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
205 def status(self):
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
206 return self._status
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
207
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
208 @status.setter
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
209 def status(self, status):
2115
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
210 if status != self._status:
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
211 self._status = status
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
212 for w in self.widgets:
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
213 w.update({"status": status})
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
214
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
215 def handle_me(self):
2055
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
216 """Check if messages starts with "/me " and change them if it is the case
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
217
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
218 if several messages (different languages) are presents, they all need to start with "/me "
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
219 """
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
220 # TODO: XHTML-IM /me are not handled
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
221 me = False
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
222 # we need to check /me for every message
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
223 for m in self.message.values():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
224 if m.startswith("/me "):
2055
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
225 me = True
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
226 else:
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
227 me = False
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
228 break
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
229 if me:
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
230 self.type = C.MESS_TYPE_INFO
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
231 self.extra["info_type"] = "me"
2055
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
232 nick = self.nick
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
233 for lang, mess in self.message.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
234 self.message[lang] = "* " + nick + mess[3:]
2055
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
235
3176
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
236 @property
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
237 def attachments(self):
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
238 return self.extra.get(C.KEY_ATTACHMENTS)
3176
4b5c77673015 quick frontends (chat): handle attachments in Message
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
239
2055
ed33cd382bf9 plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents: 2051
diff changeset
240
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
241 class MessageWidget:
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
242 """Base classe for widgets"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
243
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
244 # This class does nothing and is only used to have a common ancestor
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
245
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
246 pass
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
247
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
248
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
249 class Occupant:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
250 """Occupant metadata"""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
251
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
252 def __init__(self, parent, data, profile):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
253 self.parent = parent
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
254 self.profile = profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
255 self.nick = data["nick"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
256 self._entity = data.get("entity")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
257 self.affiliation = data["affiliation"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
258 self.role = data["role"]
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
259 self.widgets = set() # widgets linked to this occupant
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
260 self._state = None
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
261
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
262 @property
2063
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
263 def data(self):
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
264 """reconstruct data dict from attributes"""
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
265 data = {}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
266 data["nick"] = self.nick
2063
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
267 if self._entity is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
268 data["entity"] = self._entity
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
269 data["affiliation"] = self.affiliation
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
270 data["role"] = self.role
2063
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
271 return data
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
272
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
273 @property
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
274 def jid(self):
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
275 """jid in the room"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
276 return jid.JID("{}/{}".format(self.parent.target.bare, self.nick))
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
277
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
278 @property
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
279 def real_jid(self):
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
280 """real jid if known else None"""
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
281 return self._entity
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
282
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
283 @property
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
284 def host(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
285 return self.parent.host
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
286
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
287 @property
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
288 def state(self):
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
289 return self._state
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
290
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
291 @state.setter
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
292 def state(self, new_state):
2115
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
293 if new_state != self._state:
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
294 self._state = new_state
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
295 for w in self.widgets:
3435e8d2e8e4 quick frontends (chat): send actual value instead of None on status and state updates
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
296 w.update({"state": new_state})
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
297
2075
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
298 def update(self, update_dict=None):
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
299 for w in self.widgets:
2075
4f3ebf786fbc quick_frontend, primitivus (chat): renamed updated to update, using a dict as argument + fixed Primitivus group chat
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
300 w.update(update_dict)
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
301
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
302
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
303 class QuickChat(quick_widgets.QuickWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
304 visible_states = ["chat_state"] # FIXME: to be removed, used only in quick_games
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
305
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
306 def __init__(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
307 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
308 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
309 target,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
310 type_=C.CHAT_ONE2ONE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
311 nick=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
312 occupants=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
313 subject=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
314 statuses=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
315 profiles=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
316 ):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
317 """
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
318 @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
319 chat à la IRC
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
320 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
321 self.lang = "" # default language to use for messages
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
322 quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
323 assert type_ in (C.CHAT_ONE2ONE, C.CHAT_GROUP)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
324 self.current_target = target
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
325 self.type = type_
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
326 self.encrypted = False # True if this session is currently encrypted
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
327 self._locked = False
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
328 # True when resync is in progress, avoid resynchronising twice when resync is called
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
329 # and history is still being updated. For internal use only
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
330 self._resync_lock = False
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
331 self.set_locked()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
332 if type_ == C.CHAT_GROUP:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
333 if target.resource:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
334 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
335 "a group chat entity can't have a resource"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
336 )
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
337 if nick is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
338 raise exceptions.InternalError("nick must not be None for group chat")
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
339
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
340 self.nick = nick
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
341 self.occupants = {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
342 self.set_occupants(occupants)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
343 else:
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
344 if occupants is not None or nick is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
345 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
346 "only group chat can have occupants or nick"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
347 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
348 self.messages = OrderedDict() # key: uid, value: Message instance
1379
da2ea16fabc6 quick_frontend: display MUC games symbols
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
349 self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
350 self.subject = subject
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3078
diff changeset
351 self.statuses = set(statuses or [])
2033
e3f1bd9dd009 quick frontend (chat): added a getlocale method and changed self.day_change calculation for pyjamas compatibility
Goffi <goffi@goffi.org>
parents: 2029
diff changeset
352 lt = time.localtime()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
353 self.day_change = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
354 lt.tm_year,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
355 lt.tm_mon,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
356 lt.tm_mday,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
357 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
358 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
359 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
360 lt.tm_wday,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
361 lt.tm_yday,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
362 lt.tm_isdst,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
363 ) # struct_time of day changing time
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
364 if self.host.AVATARS_HANDLER:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
365 self.host.addListener("avatar", self.on_avatar, profiles)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
366
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
367 def set_locked(self):
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
368 """Set locked flag
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
369
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
370 To be set when we are waiting for history/search
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
371 """
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
372 # FIXME: we don't use getter/setter here because of pyjamas
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
373 # TODO: use proper getter/setter once we get rid of pyjamas
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
374 if self._locked:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
375 log.warning("{wid} is already locked!".format(wid=self))
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
376 return
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
377 self._locked = True
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
378 # message_new signals are cached when locked
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
379 self._cache = OrderedDict()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
380 log.debug("{wid} is now locked".format(wid=self))
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
381
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
382 def set_unlocked(self):
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
383 if not self._locked:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
384 log.debug("{wid} was already unlocked".format(wid=self))
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
385 return
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
386 self._locked = False
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
387 for uid, data in self._cache.items():
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
388 if uid not in self.messages:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
389 self.message_new(*data)
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
390 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
391 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
392 "discarding message already in history: {data}, ".format(data=data)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
393 )
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
394 del self._cache
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
395 log.debug("{wid} is now unlocked".format(wid=self))
2849
c2858e63cd82 quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents: 2847
diff changeset
396
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
397 def post_init(self):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
398 """Method to be called by frontend after widget is initialised
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
399
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
400 handle the display of history and subject
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
401 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
402 self.history_print(profile=self.profile)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
403 if self.subject is not None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
404 self.set_subject(self.subject)
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
405 if self.host.ENCRYPTION_HANDLERS:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
406 self.get_encryption_state()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
407
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
408 def on_delete(self):
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
409 if self.host.AVATARS_HANDLER:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
410 self.host.removeListener("avatar", self.on_avatar)
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
411
2057
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
412 @property
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
413 def contact_list(self):
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
414 return self.host.contact_lists[self.profile]
a52a6ed7d48f quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents: 2055
diff changeset
415
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
416 @property
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
417 def message_widgets_rev(self):
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
418 """Return the history of MessageWidget in reverse chronological order
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
419
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
420 Must be implemented by frontend
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
421 """
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
422 raise NotImplementedError
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
423
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
424 ## synchornisation handling ##
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
425
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
426 @quick_widgets.QuickWidget.sync.setter
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
427 def sync(self, state):
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
428 quick_widgets.QuickWidget.sync.fset(self, state)
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
429 if not state:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
430 self.set_locked()
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
431
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
432 def _resync_complete(self):
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
433 self.sync = True
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
434 self._resync_lock = False
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
435
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
436 def occupants_clear(self):
2988
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2976
diff changeset
437 """Remove all occupants
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2976
diff changeset
438
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2976
diff changeset
439 Must be overridden by frontends to clear their own representations of occupants
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2976
diff changeset
440 """
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2976
diff changeset
441 self.occupants.clear()
b5f8cb26ef6f quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents: 2976
diff changeset
442
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
443 def resync(self):
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
444 if self._resync_lock:
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
445 return
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
446 self._resync_lock = True
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
447 log.debug("resynchronising {self}".format(self=self))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
448 for mess in reversed(list(self.messages.values())):
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
449 if mess.type == C.MESS_TYPE_INFO:
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
450 continue
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
451 last_message = mess
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
452 break
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
453 else:
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
454 # we have no message yet, we can get normal history
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
455 self.history_print(callback=self._resync_complete, profile=self.profile)
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
456 return
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
457 if self.type == C.CHAT_GROUP:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
458 self.occupants_clear()
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
459 self.host.bridge.muc_occupants_get(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
460 str(self.target),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
461 self.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
462 callback=self.update_occupants,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
463 errback=log.error,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
464 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
465 self.history_print(
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
466 size=C.HISTORY_LIMIT_NONE,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
467 filters={"timestamp_start": last_message.timestamp},
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
468 callback=self._resync_complete,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
469 profile=self.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
470 )
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
471
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
472 ## Widget management ##
1764
33c815c17fe6 quick_frontend (chat): temporary fix for bug 12:
souliane <souliane@mailoo.org>
parents: 1763
diff changeset
473
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
474 def __str__(self):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
475 return "Chat Widget [target: {}, type: {}, profile: {}]".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
476 self.target, self.type, self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
477 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
478
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
479 @staticmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
480 def get_widget_hash(target, profiles):
2048
aff318d4a786 quick frontend (chat): fixed getWidgetHash
Goffi <goffi@goffi.org>
parents: 2040
diff changeset
481 profile = list(profiles)[0]
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
482 return profile + "\n" + str(target.bare)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
483
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
484 @staticmethod
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
485 def get_private_hash(target, profile):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
486 """Get unique hash for private conversations
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
487
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
488 This method should be used with force_hash to get unique widget for private MUC conversations
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
489 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
490 return (str(profile), target)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
491
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
492 def add_target(self, target):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
493 super(QuickChat, self).add_target(target)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
494 if target.resource:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
495 self.current_target = target # FIXME: tmp, must use resource priority throught contactList instead
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
496
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
497 def recreate_args(self, args, kwargs):
2063
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
498 """copy important attribute for a new widget"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
499 kwargs["type_"] = self.type
2063
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
500 if self.type == C.CHAT_GROUP:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
501 kwargs["occupants"] = {o.nick: o.data for o in self.occupants.values()}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
502 kwargs["subject"] = self.subject
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
503 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
504 kwargs["nick"] = self.nick
2066
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
505 except AttributeError:
09c18fcd8225 plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents: 2063
diff changeset
506 pass
2063
8fa0d95c2142 quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents: 2057
diff changeset
507
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
508 def on_private_created(self, widget):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
509 """Method called when a new widget for private conversation (MUC) is created"""
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
510 raise NotImplementedError
0
goffi@necton2
parents:
diff changeset
511
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
512 def get_or_create_private_widget(self, entity):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
513 """Create a widget for private conversation, or get it if it already exists
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
514
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
515 @param entity: full jid of the target
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
516 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
517 return self.host.widgets.get_or_create_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
518 QuickChat,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
519 entity,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
520 type_=C.CHAT_ONE2ONE,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
521 force_hash=self.get_private_hash(self.profile, entity),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
522 on_new_widget=self.on_private_created,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
523 profile=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
524 ) # we force hash to have a new widget, not this one again
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
525
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
526 @property
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
527 def target(self):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
528 if self.type == C.CHAT_GROUP:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
529 return self.current_target.bare
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
530 return self.current_target
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
531
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
532 ## occupants ##
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
533
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
534 def set_occupants(self, occupants):
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
535 """Set the whole list of occupants"""
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
536 assert len(self.occupants) == 0
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
537 for nick, data in occupants.items():
2976
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2896
diff changeset
538 # XXX: this log is disabled because it's really too verbose
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2896
diff changeset
539 # but kept commented as it may be useful for debugging
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2896
diff changeset
540 # log.debug(u"adding occupant {nick} to {room}".format(
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2896
diff changeset
541 # nick=nick, room=self.target))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
542 self.occupants[nick] = Occupant(self, data, self.profile)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
543
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
544 def update_occupants(self, occupants):
2850
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
545 """Update occupants list
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
546
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
547 In opposition to set_occupants, this only add missing occupants and remove
2850
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
548 occupants who have left
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
549 """
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
550 # FIXME: occupants with modified status are not handled
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
551 local_occupants = set(self.occupants)
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
552 updated_occupants = set(occupants)
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
553 left_occupants = local_occupants - updated_occupants
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
554 joined_occupants = updated_occupants - local_occupants
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
555 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
556 "updating occupants for {room}:\n"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
557 "left: {left_occupants}\n"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
558 "joined: {joined_occupants}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
559 room=self.target,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
560 left_occupants=", ".join(left_occupants),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
561 joined_occupants=", ".join(joined_occupants),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
562 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
563 )
2850
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
564 for nick in left_occupants:
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
565 self.removeUser(occupants[nick])
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
566 for nick in joined_occupants:
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
567 self.addUser(occupants[nick])
272dc905ff20 quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
Goffi <goffi@goffi.org>
parents: 2849
diff changeset
568
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
569 def addUser(self, occupant_data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
570 """Add user if it is not in the group list"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
571 occupant = Occupant(self, occupant_data, self.profile)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
572 self.occupants[occupant.nick] = occupant
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
573 return occupant
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
574
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
575 def removeUser(self, occupant_data):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
576 """Remove a user from the group list"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
577 nick = occupant_data["nick"]
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
578 try:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
579 occupant = self.occupants.pop(nick)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
580 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
581 log.warning("Trying to remove an unknown occupant: {}".format(nick))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
582 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
583 return occupant
1764
33c815c17fe6 quick_frontend (chat): temporary fix for bug 12:
souliane <souliane@mailoo.org>
parents: 1763
diff changeset
584
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
585 def set_user_nick(self, nick):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
586 """Set the nick of the user, usefull for e.g. change the color of the user"""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
587 self.nick = nick
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
588
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
589 def change_user_nick(self, old_nick, new_nick):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
590 """Change nick of a user in group list"""
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
591 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
592 "{old} is now known as {new} in room {room_jid}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
593 old=old_nick, new=new_nick, room_jid=self.target
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
594 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
595 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
596
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
597 ## Messages ##
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
598
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
599 def manage_message(self, entity, mess_type):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
600 """Tell if this chat widget manage an entity and message type couple
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
601
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
602 @param entity (jid.JID): (full) jid of the sending entity
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
603 @param mess_type (str): message type as given by message_new
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
604 @return (bool): True if this Chat Widget manage this couple
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
605 """
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
606 if self.type == C.CHAT_GROUP:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
607 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
608 mess_type in (C.MESS_TYPE_GROUPCHAT, C.MESS_TYPE_INFO)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
609 and self.target == entity.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
610 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
611 return True
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
612 else:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
613 if mess_type != C.MESS_TYPE_GROUPCHAT and entity in self.targets:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
614 return True
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
615 return False
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
616
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
617 def update_history(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
618 self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile="@NONE@"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
619 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
620 """Called when history need to be recreated
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
621
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
622 Remove all message from history then call history_print
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
623 Must probably be overriden by frontend to clear widget
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
624 @param size (int): number of messages
2013
b536dd121da1 backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents: 2007
diff changeset
625 @param filters (str): patterns to filter the history results
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
626 @param profile (str): %(doc_profile)s
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
627 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
628 self.set_locked()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
629 self.messages.clear()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
630 self.history_print(size, filters, profile=profile)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
631
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
632 def _on_history_printed(self):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
633 """Method called when history is printed (or failed)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
634
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
635 unlock the widget, and can be used to refresh or scroll down
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
636 the focus after the history is printed
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
637 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
638 self.set_unlocked()
1748
3a6cd1c14974 frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents: 1462
diff changeset
639
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
640 def history_print(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
641 self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, callback=None, profile="@NONE@"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
642 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
643 """Print the current history
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
644
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
645 Note: self.set_unlocked will be called once history is printed
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
646 @param size (int): number of messages
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
647 @param search (str): pattern to filter the history results
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
648 @param callback(callable, None): method to call when history has been printed
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
649 @param profile (str): %(doc_profile)s
1748
3a6cd1c14974 frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents: 1462
diff changeset
650 """
2013
b536dd121da1 backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents: 2007
diff changeset
651 if filters is None:
b536dd121da1 backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents: 2007
diff changeset
652 filters = {}
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
653 if size == 0:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
654 log.debug("Empty history requested, skipping")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
655 self._on_history_printed()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
656 return
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
657 log_msg = _("now we print the history")
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
658 if size != C.HISTORY_LIMIT_DEFAULT:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
659 log_msg += _(" ({} messages)".format(size))
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
660 log.debug(log_msg)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
661
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
662 if self.type == C.CHAT_ONE2ONE:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
663 special = self.host.contact_lists[self.profile].getCache(
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
664 self.target, C.CONTACT_SPECIAL, create_if_not_found=True, default=None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
665 )
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
666 if special == C.CONTACT_SPECIAL_GROUP:
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
667 # we have a private conversation
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
668 # so we need full jid for the history
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
669 # (else we would get history from group itself)
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
670 # and to filter out groupchat message
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
671 target = self.target
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
672 filters["not_types"] = C.MESS_TYPE_GROUPCHAT
2020
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
673 else:
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
674 target = self.target.bare
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
675 else:
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
676 # groupchat
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
677 target = self.target.bare
f67da1cab6d3 quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents: 2019
diff changeset
678 # FIXME: info not handled correctly
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
679 filters["types"] = C.MESS_TYPE_GROUPCHAT
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
680
3078
95c94d94872d quick frontend(chat): store filters used with initial historyGet
Goffi <goffi@goffi.org>
parents: 3070
diff changeset
681 self.history_filters = filters
95c94d94872d quick frontend(chat): store filters used with initial historyGet
Goffi <goffi@goffi.org>
parents: 3070
diff changeset
682
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
683 def _history_get_cb(history):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
684 # day_format = "%A, %d %b %Y" # to display the day change
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
685 # previous_day = datetime.now().strftime(day_format)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
686 # message_day = datetime.fromtimestamp(timestamp).strftime(self.day_format)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
687 # if previous_day != message_day:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
688 # self.print_day_change(message_day)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
689 # previous_day = message_day
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
690 for data in history:
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
691 uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
692 from_jid = jid.JID(from_jid)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
693 to_jid = jid.JID(to_jid)
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
694 extra = data_format.deserialise(extra_s)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
695 # if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
696 # (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)):
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
697 # continue
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
698 extra["history"] = True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
699 self.messages[uid] = Message(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
700 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
701 uid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
702 timestamp,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
703 from_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
704 to_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
705 message,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
706 subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
707 type_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
708 extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
709 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
710 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
711 self._on_history_printed()
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
712 if callback is not None:
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
713 callback()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
714
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
715 def _history_get_eb(err):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
716 log.error(_("Can't get history: {}").format(err))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
717 self._on_history_printed()
2851
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
718 if callback is not None:
7764383a968c quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents: 2850
diff changeset
719 callback()
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
720
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
721 self.host.bridge.history_get(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
722 str(self.host.profiles[profile].whoami.bare),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
723 str(target),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
724 size,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
725 True,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
726 {k: str(v) for k, v in filters.items()},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
727 profile,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
728 callback=_history_get_cb,
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
729 errback=_history_get_eb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
730 )
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 144
diff changeset
731
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
732 def message_encryption_get_cb(self, session_data):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
733 if session_data:
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
734 session_data = data_format.deserialise(session_data)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
735 self.message_encryption_started(session_data)
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
736
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
737 def message_encryption_get_eb(self, failure_):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
738 log.error(_("Can't get encryption state: {reason}").format(reason=failure_))
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
739
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
740 def get_encryption_state(self):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
741 """Retrieve encryption state with current target.
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
742
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
743 Once state is retrieved, default message_encryption_started will be called if
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
744 suitable
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
745 """
2839
76f714b12d21 quick frontend(chat): use bare jid for getEncryptionState, and skip if for group chat
Goffi <goffi@goffi.org>
parents: 2788
diff changeset
746 if self.type == C.CHAT_GROUP:
76f714b12d21 quick frontend(chat): use bare jid for getEncryptionState, and skip if for group chat
Goffi <goffi@goffi.org>
parents: 2788
diff changeset
747 return
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
748 self.host.bridge.message_encryption_get(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
749 str(self.target.bare),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
750 self.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
751 callback=self.message_encryption_get_cb,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
752 errback=self.message_encryption_get_eb,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
753 )
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
754
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
755 def message_new(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
756 self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
757 ):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
758 if self._locked:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
759 self._cache[uid] = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
760 uid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
761 timestamp,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
762 from_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
763 to_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
764 msg,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
765 subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
766 type_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
767 extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
768 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
769 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
770 return
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2730
diff changeset
771
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
772 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
773 not msg
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
774 and not subject
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
775 and not extra[C.KEY_ATTACHMENTS]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
776 and type_ != C.MESS_TYPE_INFO
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
777 ):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
778 log.warning("Received an empty message for uid {}".format(uid))
2736
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2730
diff changeset
779 return
df2bc2e704bc core (xmpp): don't send message without message or subject to bridge (and log a warning in frontends if such a message is received)
Goffi <goffi@goffi.org>
parents: 2730
diff changeset
780
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
781 if self.type == C.CHAT_GROUP:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
782 if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT:
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
783 # we have a private message, we forward it to a private conversation
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
784 # widget
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
785 chat_widget = self.get_or_create_private_widget(to_jid)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
786 chat_widget.message_new(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
787 uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
788 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
789 return
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
790 if type_ == C.MESS_TYPE_INFO:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
791 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
792 info_type = extra["info_type"]
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
793 except KeyError:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
794 pass
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
795 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
796 user_data = {
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
797 k[5:]: v for k, v in extra.items() if k.startswith("user_")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
798 }
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
799 if info_type == ROOM_USER_JOINED:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
800 self.addUser(user_data)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
801 elif info_type == ROOM_USER_LEFT:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
802 self.removeUser(user_data)
1748
3a6cd1c14974 frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents: 1462
diff changeset
803
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
804 message = Message(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
805 self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
806 )
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
807 self.messages[uid] = message
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
808
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
809 if "received_timestamp" in extra:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
810 log.warning("Delayed message received after history, this should not happen")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
811 self.create_message(message)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
812
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
813 def message_encryption_started(self, session_data):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
814 self.encrypted = True
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
815 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
816 _("message encryption started with {target} using {encryption}").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
817 target=self.target, encryption=session_data["name"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
818 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
819 )
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
820
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
821 def message_encryption_stopped(self, session_data):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
822 self.encrypted = False
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
823 log.debug(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
824 _("message encryption stopped with {target} (was using {encryption})").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
825 target=self.target, encryption=session_data["name"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
826 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
827 )
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2632
diff changeset
828
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
829 def create_message(self, message, append=False):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
830 """Must be implemented by frontend to create and show a new message widget
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
831
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
832 This is only called on message_new, not on history.
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
833 You need to override history_print to handle the later
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
834 @param message(Message): message data
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 144
diff changeset
835 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
836 raise NotImplementedError
1786
104874018ab0 quick_frontend, primitivus (chat): move notification command to quick_frontend
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
837
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
838 def is_user_moved(self, message):
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
839 """Return True if message is a user left/joined message
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
840
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
841 @param message(Message): message to check
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
842 @return (bool): True is message is user moved info message
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
843 """
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
844 if message.type != C.MESS_TYPE_INFO:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
845 return False
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
846 try:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
847 info_type = message.extra["info_type"]
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
848 except KeyError:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
849 return False
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
850 else:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
851 return info_type in ROOM_USER_MOVED
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
852
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
853 def handle_user_moved(self, message):
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
854 """Check if this message is a UserMoved one, and merge it when possible
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
855
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
856 "merge it" means that info message indicating a user joined/left will be
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
857 grouped if no other non-info messages has been sent since
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
858 @param message(Message): message to check
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
859 @return (bool): True if this message has been merged
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
860 if True, a new MessageWidget must not be created and appended to history
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
861 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
862 if self.is_user_moved(message):
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
863 for wid in self.message_widgets_rev:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
864 # we merge in/out messages if no message was sent meanwhile
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
865 if not isinstance(wid, MessageWidget):
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
866 continue
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
867 elif wid.mess_data.type != C.MESS_TYPE_INFO:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
868 return False
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
869 elif (
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
870 wid.info_type in ROOM_USER_MOVED
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
871 and wid.mess_data.nick == message.nick
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
872 ):
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
873 try:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
874 count = wid.reentered_count
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
875 except AttributeError:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
876 count = wid.reentered_count = 1
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
877 nick = wid.mess_data.nick
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
878 if message.info_type == ROOM_USER_LEFT:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
879 wid.message = _("<= {nick} has left the room ({count})").format(
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
880 nick=nick, count=count
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
881 )
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
882 else:
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
883 wid.message = _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
884 "<=> {nick} re-entered the room ({count})"
2880
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
885 ).format(nick=nick, count=count)
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
886 wid.reentered_count += 1
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
887 return True
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
888 return False
dd650f3e070f quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents: 2864
diff changeset
889
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
890 def print_day_change(self, day):
1749
d047535e3ed5 quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents: 1748
diff changeset
891 """Display the day on a new line.
d047535e3ed5 quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents: 1748
diff changeset
892
d047535e3ed5 quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents: 1748
diff changeset
893 @param day(unicode): day to display (or not if this method is not overwritten)
d047535e3ed5 quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents: 1748
diff changeset
894 """
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
895 # FIXME: not called anymore after refactoring
1749
d047535e3ed5 quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents: 1748
diff changeset
896 pass
d047535e3ed5 quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents: 1748
diff changeset
897
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
898 ## Room ##
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
899
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
900 def set_subject(self, subject):
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
901 """Set title for a group chat"""
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
902 if self.type != C.CHAT_GROUP:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
903 raise exceptions.InternalError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
904 "trying to set subject for a non group chat window"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
905 )
2022
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
906 self.subject = subject
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
907
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
908 def change_subject(self, new_subject):
2022
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
909 """Change the subject of the room
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
910
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
911 This change the subject on the room itself (i.e. via XMPP),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
912 while set_subject change the subject of this widget
2022
88c41a195728 primitivus (chat): added :topic (and :subject and :title aliases) to change subject with a dialog (/!\ urwid SàText need to be updated)
Goffi <goffi@goffi.org>
parents: 2020
diff changeset
913 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
914 self.host.bridge.muc_subject(str(self.target), new_subject, self.profile)
907
cd02f5ef30df primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 812
diff changeset
915
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
916 def add_game_panel(self, widget):
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
917 """Insert a game panel to this Chat dialog.
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
918
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
919 @param widget (Widget): the game panel
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
920 """
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
921 raise NotImplementedError
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
922
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
923 def remove_game_panel(self, widget):
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
924 """Remove the game panel from this Chat dialog.
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
925
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
926 @param widget (Widget): the game panel
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
927 """
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
928 raise NotImplementedError
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
929
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
930 def update(self, entity=None):
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
931 """Update one or all entities.
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
932
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
933 @param entity (jid.JID): entity to update
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
934 """
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
935 # FIXME: to remove ?
1388
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
936 raise NotImplementedError
a025242bebe7 quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents: 1386
diff changeset
937
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
938 ## events ##
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
939
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
940 def on_chat_state(self, from_jid, state, profile):
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
941 """A chat state has been received"""
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
942 if self.type == C.CHAT_GROUP:
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
943 nick = from_jid.resource
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
944 try:
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
945 self.occupants[nick].state = state
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
946 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
947 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
948 "{nick} not found in {room}, ignoring new chat state".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
949 nick=nick, room=self.target.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
950 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
951 )
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1993
diff changeset
952
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
953 def on_message_state(self, uid, status, profile):
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
954 try:
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
955 mess_data = self.messages[uid]
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
956 except KeyError:
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
957 pass
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
958 else:
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
959 mess_data.status = status
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2022
diff changeset
960
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
961 def on_avatar(self, entity, avatar_data, profile):
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
962 if self.type == C.CHAT_GROUP:
2123
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
963 if entity.bare == self.target:
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
964 try:
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
965 self.occupants[entity.resource].update({"avatar": avatar_data})
2123
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
966 except KeyError:
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
967 # can happen for a message in history where the
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
968 # entity is not here anymore
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
969 pass
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
970
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
971 for m in list(self.messages.values()):
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
972 if m.nick == entity.resource:
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
973 for w in m.widgets:
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
974 w.update({"avatar": avatar_data})
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
975 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
976 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
977 entity.bare == self.target.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
978 or entity.bare == self.host.profiles[profile].whoami.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2580
diff changeset
979 ):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
980 log.info("avatar updated for {}".format(entity))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2988
diff changeset
981 for m in list(self.messages.values()):
2123
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
982 if m.from_jid.bare == entity.bare:
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2115
diff changeset
983 for w in m.widgets:
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3229
diff changeset
984 w.update({"avatar": avatar_data})
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
985
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1296
diff changeset
986
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1224
diff changeset
987 quick_widgets.register(QuickChat)