Mercurial > libervia-backend
annotate sat_frontends/quick_frontend/quick_chat.py @ 3080:16925f494820
plugin XEP-0045: don't fail on `item-not-found` with MAM:
Some servers don't store permanently the whole history of MUC with MAM. As a result, an
"item-not-found" stanza error can be received when message id used as reference doesn't exist
anymore on the server.
When this case happens, the history is retrieved in the same way as for a newly joined room
(i.e. last 50 messages are requested).
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 05 Dec 2019 23:05:16 +0100 |
parents | 95c94d94872d |
children | ab7e8ade848a |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1786
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 2 # -*- coding: utf-8 -*- |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
4 # helper class for making a SAT frontend |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
12 # 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
|
13 # 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
|
14 # 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
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
588
diff
changeset
|
17 # 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
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
771 | 20 from sat.core.i18n import _ |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
907
diff
changeset
|
21 from sat.core.log import getLogger |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
22 from sat.tools.common import data_format |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
23 from sat.core import exceptions |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
24 from sat_frontends.quick_frontend import quick_widgets |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1139
diff
changeset
|
25 from sat_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
|
26 from collections import OrderedDict |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
27 from sat_frontends.tools import jid |
2029
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
28 import time |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
29 log = getLogger(__name__) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
30 |
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
|
31 try: |
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
|
32 from locale import getlocale |
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
|
33 except ImportError: |
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
|
34 # FIXME: pyjamas workaround |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
35 getlocale = lambda x: (None, "utf-8") |
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
|
36 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
37 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
38 ROOM_USER_JOINED = "ROOM_USER_JOINED" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
39 ROOM_USER_LEFT = "ROOM_USER_LEFT" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
40 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
41 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
42 # from datetime import datetime |
0 | 43 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
44 # FIXME: day_format need to be settable (i18n) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
45 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
46 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
47 class Message(object): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
48 """Message metadata""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
49 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
50 def __init__(self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
51 extra, profile): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
52 self.parent = parent |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
53 self.profile = profile |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
54 self.uid = uid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
55 self.timestamp = timestamp |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
56 self.from_jid = from_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
57 self.to_jid = to_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
58 self.message = msg |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
59 self.subject = subject |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
60 self.type = type_ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
61 self.extra = extra |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
62 self.nick = self.getNick(from_jid) |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
63 self._status = None |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
64 # 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
|
65 self.own_mess = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
66 (from_jid.resource == self.parent.nick) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
67 if self.parent.type == C.CHAT_GROUP |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
68 else (from_jid.bare == self.host.profiles[profile].whoami.bare) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
69 ) |
1973
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
70 # 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
|
71 if self.parent.type == C.CHAT_GROUP and not self.own_mess: |
3028 | 72 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
|
73 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
|
74 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
|
75 break |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
76 self.handleMe() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
77 self.widgets = set() # widgets linked to this message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
78 |
3028 | 79 def __str__(self): |
80 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
|
81 mess_type=self.type, |
c055a3a4ecb0
quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
2839
diff
changeset
|
82 time=self.time_text, |
c055a3a4ecb0
quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
2839
diff
changeset
|
83 nick=self.nick, |
c055a3a4ecb0
quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
2839
diff
changeset
|
84 message=self.main_message) |
c055a3a4ecb0
quick frontend(chat): display a useful message with __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
2839
diff
changeset
|
85 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
86 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
87 def host(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
88 return self.parent.host |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
89 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
90 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
91 def info_type(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
92 return self.extra.get("info_type") |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
93 |
1973
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
94 @property |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
95 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
|
96 try: |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
97 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
|
98 except AttributeError: |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
99 return False |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
100 |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
101 @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
|
102 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
|
103 """True if message come from history""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
104 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
|
105 |
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
|
106 @property |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
107 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
|
108 """currently displayed message""" |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
113 self.selected_lang = "" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
114 return self.message[""] |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
115 except KeyError: |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
116 try: |
3028 | 117 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
|
118 self.selected_lang = lang |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
119 return mess |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
120 except StopIteration: |
3028 | 121 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
|
122 return "" |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
123 |
2029
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
124 @property |
2078
3a0a7e5cef49
quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents:
2076
diff
changeset
|
125 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
|
126 """rich message""" |
3028 | 127 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
|
128 if xhtml: |
3a0a7e5cef49
quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents:
2076
diff
changeset
|
129 # FIXME: we only return first found value for now |
3028 | 130 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
|
131 |
3a0a7e5cef49
quick frontend (chat): added Message.main_message_xhtml property to get XHTML content
Goffi <goffi@goffi.org>
parents:
2076
diff
changeset
|
132 @property |
2029
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
133 def time_text(self): |
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
134 """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
|
135 # 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
|
136 timestamp = time.localtime(self.timestamp) |
3028 | 137 time_format = "%c" if timestamp < self.parent.day_change else "%H:%M" |
138 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
|
139 |
2057
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
140 @property |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
141 def avatar(self): |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
142 """avatar full path or None if no avatar is found""" |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
143 ret = self.host.getAvatar(self.from_jid, profile=self.profile) |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
144 return ret |
2057
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
145 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
146 def getNick(self, entity): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
147 """Return nick of an entity when possible""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
148 contact_list = self.host.contact_lists[self.profile] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
149 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
|
150 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
151 return self.extra["user_nick"] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
152 except KeyError: |
3028 | 153 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
|
154 return "" |
2167
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2123
diff
changeset
|
155 # FIXME: converted getSpecials to list for pyjamas |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
156 if self.parent.type == C.CHAT_GROUP or entity in list( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
157 contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
158 ): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
159 return entity.resource or "" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
160 if entity.bare in contact_list: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
161 return ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
162 contact_list.getCache(entity, "nick") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
163 or contact_list.getCache(entity, "name") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
164 or entity.node |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
165 or entity |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
166 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
167 return entity.node or entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
168 |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
169 @property |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
170 def status(self): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
171 return self._status |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
172 |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
173 @status.setter |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 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
|
178 w.update({"status": status}) |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
179 |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
180 def handleMe(self): |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
181 """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
|
182 |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
183 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
|
184 """ |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
185 # TODO: XHTML-IM /me are not handled |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
186 me = False |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
187 # we need to check /me for every message |
3028 | 188 for m in self.message.values(): |
189 if m.startswith("/me "): | |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
190 me = True |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
191 else: |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
192 me = False |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
193 break |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
194 if me: |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
195 self.type = C.MESS_TYPE_INFO |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
196 self.extra["info_type"] = "me" |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
197 nick = self.nick |
3028 | 198 for lang, mess in self.message.items(): |
199 self.message[lang] = "* " + nick + mess[3:] | |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
200 |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
201 |
2880
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
202 class MessageWidget(object): |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
203 """Base classe for widgets""" |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
204 # 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
|
205 |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
206 pass |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
207 |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
208 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
209 class Occupant(object): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
210 """Occupant metadata""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
211 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
212 def __init__(self, parent, data, profile): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
213 self.parent = parent |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
214 self.profile = profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
215 self.nick = data["nick"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
216 self._entity = data.get("entity") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
217 self.affiliation = data["affiliation"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
218 self.role = data["role"] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
219 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
|
220 self._state = None |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
221 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
222 @property |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
223 def data(self): |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
224 """reconstruct data dict from attributes""" |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
225 data = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
226 data["nick"] = self.nick |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
227 if self._entity is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
228 data["entity"] = self._entity |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
229 data["affiliation"] = self.affiliation |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
230 data["role"] = self.role |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
231 return data |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
232 |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
233 @property |
2020
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
234 def jid(self): |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
235 """jid in the room""" |
3028 | 236 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
|
237 |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
238 @property |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
239 def real_jid(self): |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
240 """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
|
241 return self._entity |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
242 |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
243 @property |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
244 def host(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
245 return self.parent.host |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
246 |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
247 @property |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
248 def state(self): |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
249 return self._state |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
250 |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
251 @state.setter |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 |
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
|
258 def update(self, update_dict=None): |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
259 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
|
260 w.update(update_dict) |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
261 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
262 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
263 class QuickChat(quick_widgets.QuickWidget): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
264 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
|
265 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
266 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
267 subject=None, profiles=None): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
268 """ |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
269 @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
|
270 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
|
271 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 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
|
276 self.type = type_ |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
277 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
|
278 self._locked = False |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
279 # 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
|
280 # 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
|
281 self._resync_lock = False |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
282 self.setLocked() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
283 if type_ == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
284 if target.resource: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
285 raise exceptions.InternalError( |
3028 | 286 "a group chat entity can't have a resource" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
287 ) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
288 if nick is None: |
3028 | 289 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
|
290 |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
291 self.nick = nick |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
292 self.occupants = {} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
293 self.setOccupants(occupants) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
294 else: |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
295 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
|
296 raise exceptions.InternalError( |
3028 | 297 "only group chat can have occupants or nick" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
298 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
299 self.messages = OrderedDict() # key: uid, value: Message instance |
1379
da2ea16fabc6
quick_frontend: display MUC games symbols
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
300 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
|
301 self.subject = subject |
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
|
302 lt = time.localtime() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
303 self.day_change = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
304 lt.tm_year, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
305 lt.tm_mon, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
306 lt.tm_mday, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
307 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
308 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
309 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
310 lt.tm_wday, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
311 lt.tm_yday, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
312 lt.tm_isdst, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
313 ) # struct_time of day changing time |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
314 if self.host.AVATARS_HANDLER: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
315 self.host.addListener("avatar", self.onAvatar, profiles) |
72 | 316 |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
317 def setLocked(self): |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
318 """Set locked flag |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
319 |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
320 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
|
321 """ |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
322 # 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
|
323 # 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
|
324 if self._locked: |
3028 | 325 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
|
326 return |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
327 self._locked = True |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
328 # messageNew signals are cached when locked |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
329 self._cache = OrderedDict() |
3028 | 330 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
|
331 |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
332 def setUnlocked(self): |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
333 if not self._locked: |
3028 | 334 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
|
335 return |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
336 self._locked = False |
3028 | 337 for uid, data in self._cache.items(): |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
338 if uid not in self.messages: |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
339 self.messageNew(*data) |
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
340 else: |
3028 | 341 log.debug("discarding message already in history: {data}, ".format(data=data)) |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
342 del self._cache |
3028 | 343 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
|
344 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
345 def postInit(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
346 """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
|
347 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
348 handle the display of history and subject |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
349 """ |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
350 self.historyPrint(profile=self.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
351 if self.subject is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
352 self.setSubject(self.subject) |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
353 if self.host.ENCRYPTION_HANDLERS: |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
354 self.getEncryptionState() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
355 |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
356 def onDelete(self): |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
357 if self.host.AVATARS_HANDLER: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
358 self.host.removeListener("avatar", self.onAvatar) |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
359 |
2057
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
360 @property |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
361 def contact_list(self): |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
362 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
|
363 |
2880
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
364 @property |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
365 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
|
366 """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
|
367 |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
368 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
|
369 """ |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
370 raise NotImplementedError |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
371 |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
372 ## synchornisation handling ## |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
373 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
374 @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
|
375 def sync(self, state): |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
376 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
|
377 if not state: |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
378 self.setLocked() |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
379 |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
380 def _resyncComplete(self): |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
381 self.sync = True |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
382 self._resync_lock = False |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
383 |
2988
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
384 def occupantsClear(self): |
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
385 """Remove all occupants |
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
386 |
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
387 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
|
388 """ |
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
389 self.occupants.clear() |
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
390 |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
391 def resync(self): |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
392 if self._resync_lock: |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
393 return |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
394 self._resync_lock = True |
3028 | 395 log.debug("resynchronising {self}".format(self=self)) |
396 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
|
397 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
|
398 continue |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
399 last_message = mess |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
400 break |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
401 else: |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
402 # we have no message yet, we can get normal history |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
403 self.historyPrint(callback=self._resyncComplete, profile=self.profile) |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
404 return |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
405 if self.type == C.CHAT_GROUP: |
2988
b5f8cb26ef6f
quick frontend (chat), primitivus(chat): properly clear occupants on resync:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
406 self.occupantsClear() |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
407 self.host.bridge.mucOccupantsGet( |
3028 | 408 str(self.target), self.profile, callback=self.updateOccupants, |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
409 errback=log.error) |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
410 self.historyPrint( |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
411 size=C.HISTORY_LIMIT_NONE, |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
412 filters={'timestamp_start': last_message.timestamp}, |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
413 callback=self._resyncComplete, |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
414 profile=self.profile) |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
415 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
416 ## Widget management ## |
1764
33c815c17fe6
quick_frontend (chat): temporary fix for bug 12:
souliane <souliane@mailoo.org>
parents:
1763
diff
changeset
|
417 |
3028 | 418 def __str__(self): |
419 return "Chat Widget [target: {}, type: {}, profile: {}]".format( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
420 self.target, self.type, self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
421 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
422 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
423 @staticmethod |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
424 def getWidgetHash(target, profiles): |
2048
aff318d4a786
quick frontend (chat): fixed getWidgetHash
Goffi <goffi@goffi.org>
parents:
2040
diff
changeset
|
425 profile = list(profiles)[0] |
3028 | 426 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
|
427 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
428 @staticmethod |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
429 def getPrivateHash(target, profile): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
430 """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
|
431 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
432 This method should be used with force_hash to get unique widget for private MUC conversations |
72 | 433 """ |
3028 | 434 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
|
435 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
436 def addTarget(self, target): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
437 super(QuickChat, self).addTarget(target) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
438 if target.resource: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
439 self.current_target = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
440 target |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
441 ) # 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
|
442 |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
443 def recreateArgs(self, args, kwargs): |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
444 """copy important attribute for a new widget""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
445 kwargs["type_"] = self.type |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
446 if self.type == C.CHAT_GROUP: |
3028 | 447 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
|
448 kwargs["subject"] = self.subject |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
449 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
450 kwargs["nick"] = self.nick |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
451 except AttributeError: |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
452 pass |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
453 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
454 def onPrivateCreated(self, widget): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
455 """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
|
456 raise NotImplementedError |
0 | 457 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
458 def getOrCreatePrivateWidget(self, entity): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
459 """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
|
460 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
461 @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
|
462 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
463 return self.host.widgets.getOrCreateWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
464 QuickChat, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
465 entity, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
466 type_=C.CHAT_ONE2ONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
467 force_hash=self.getPrivateHash(self.profile, entity), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
468 on_new_widget=self.onPrivateCreated, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
469 profile=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
470 ) # 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
|
471 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
472 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
473 def target(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
474 if self.type == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
475 return self.current_target.bare |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
476 return self.current_target |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
477 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
478 ## occupants ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
479 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
480 def setOccupants(self, occupants): |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
481 """Set the whole list of occupants""" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
482 assert len(self.occupants) == 0 |
3028 | 483 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
|
484 # 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
|
485 # 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
|
486 # 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
|
487 # nick=nick, room=self.target)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
488 self.occupants[nick] = Occupant(self, data, self.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
489 |
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
|
490 def updateOccupants(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
|
491 """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
|
492 |
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
|
493 In opposition to setOccupants, this only add missing occupants and remove |
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
|
494 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
|
495 """ |
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
|
496 # 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
|
497 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
|
498 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
|
499 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
|
500 joined_occupants = updated_occupants - local_occupants |
3028 | 501 log.debug("updating occupants for {room}:\n" |
502 "left: {left_occupants}\n" | |
503 "joined: {joined_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
|
504 .format(room=self.target, |
3028 | 505 left_occupants=", ".join(left_occupants), |
506 joined_occupants=", ".join(joined_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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
512 def addUser(self, occupant_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
513 """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
|
514 occupant = Occupant(self, occupant_data, self.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
515 self.occupants[occupant.nick] = occupant |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
516 return occupant |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
517 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
518 def removeUser(self, occupant_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
519 """Remove a user from the group list""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
520 nick = occupant_data["nick"] |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
521 try: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
522 occupant = self.occupants.pop(nick) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
523 except KeyError: |
3028 | 524 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
|
525 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
526 return occupant |
1764
33c815c17fe6
quick_frontend (chat): temporary fix for bug 12:
souliane <souliane@mailoo.org>
parents:
1763
diff
changeset
|
527 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
528 def setUserNick(self, nick): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
529 """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
|
530 self.nick = nick |
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 def changeUserNick(self, old_nick, new_nick): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
533 """Change nick of a user in group list""" |
2788
4a05e67a8025
quick frontend (chat): fixed use of old method printInfo
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
534 log.info("{old} is now known as {new} in room {room_jid}".format( |
4a05e67a8025
quick frontend (chat): fixed use of old method printInfo
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
535 old = old_nick, |
4a05e67a8025
quick frontend (chat): fixed use of old method printInfo
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
536 new = new_nick, |
4a05e67a8025
quick frontend (chat): fixed use of old method printInfo
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
537 room_jid = self.target)) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
538 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
539 ## Messages ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
540 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
541 def manageMessage(self, entity, mess_type): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
542 """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
|
543 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
544 @param entity (jid.JID): (full) jid of the sending entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
545 @param mess_type (str): message type as given by messageNew |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
546 @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
|
547 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
548 if self.type == C.CHAT_GROUP: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
549 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
550 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
|
551 and self.target == entity.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
552 ): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
553 return True |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
554 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
555 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
|
556 return True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
557 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
558 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
559 def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile="@NONE@"): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
560 """Called when history need to be recreated |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
561 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
562 Remove all message from history then call historyPrint |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
563 Must probably be overriden by frontend to clear widget |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
564 @param size (int): number of messages |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
565 @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
|
566 @param profile (str): %(doc_profile)s |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
567 """ |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
568 self.setLocked() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
569 self.messages.clear() |
2864
33a69ee7fbb7
quick frontend(chat): fixed updateHistory bad call to historyPrint
Goffi <goffi@goffi.org>
parents:
2851
diff
changeset
|
570 self.historyPrint(size, filters, profile=profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
571 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
572 def _onHistoryPrinted(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
573 """Method called when history is printed (or failed) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
574 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
575 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
|
576 the focus after the history is printed |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
577 """ |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
578 self.setUnlocked() |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1462
diff
changeset
|
579 |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
580 def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, callback=None, |
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
581 profile="@NONE@"): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
582 """Print the current history |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
583 |
2849
c2858e63cd82
quick frontend(chat): added setLocked/setUnlocked methods:
Goffi <goffi@goffi.org>
parents:
2847
diff
changeset
|
584 Note: self.setUnlocked will be called once history is printed |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
585 @param size (int): number of messages |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
586 @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
|
587 @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
|
588 @param profile (str): %(doc_profile)s |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1462
diff
changeset
|
589 """ |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
590 if filters is None: |
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
591 filters = {} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
592 if size == 0: |
3028 | 593 log.debug("Empty history requested, skipping") |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
594 self._onHistoryPrinted() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
595 return |
3028 | 596 log_msg = _("now we print the history") |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
597 if size != C.HISTORY_LIMIT_DEFAULT: |
3028 | 598 log_msg += _(" ({} messages)".format(size)) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
599 log.debug(log_msg) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
600 |
2020
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
601 if self.type == C.CHAT_ONE2ONE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
602 special = self.host.contact_lists[self.profile].getCache( |
2632
96911768b0f3
quick_frontend (chat): create target in cache if it is not found, avoiding an exception
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
603 self.target, C.CONTACT_SPECIAL, create_if_not_found=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
604 ) |
2020
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
605 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
|
606 # 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
|
607 # 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
|
608 # (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
|
609 # 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
|
610 target = self.target |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
611 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
|
612 else: |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
613 target = self.target.bare |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
614 else: |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
615 # groupchat |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
616 target = self.target.bare |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
617 # FIXME: info not handled correctly |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
618 filters["types"] = C.MESS_TYPE_GROUPCHAT |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
619 |
3078
95c94d94872d
quick frontend(chat): store filters used with initial historyGet
Goffi <goffi@goffi.org>
parents:
3070
diff
changeset
|
620 self.history_filters = filters |
95c94d94872d
quick frontend(chat): store filters used with initial historyGet
Goffi <goffi@goffi.org>
parents:
3070
diff
changeset
|
621 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
622 def _historyGetCb(history): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
623 # 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
|
624 # previous_day = datetime.now().strftime(day_format) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
625 # message_day = datetime.fromtimestamp(timestamp).strftime(self.day_format) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
626 # if previous_day != message_day: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
627 # self.printDayChange(message_day) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
628 # previous_day = message_day |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
629 for data in history: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
630 uid, timestamp, from_jid, to_jid, message, subject, type_, extra = data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
631 from_jid = jid.JID(from_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
632 to_jid = jid.JID(to_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
633 # 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
|
634 # (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
|
635 # continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
636 extra["history"] = True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
637 self.messages[uid] = Message( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
638 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
639 uid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
640 timestamp, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
641 from_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
642 to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
643 message, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
644 subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
645 type_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
646 extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
647 profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
648 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
649 self._onHistoryPrinted() |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
650 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
|
651 callback() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
652 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
653 def _historyGetEb(err): |
3028 | 654 log.error(_("Can't get history: {}").format(err)) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
655 self._onHistoryPrinted() |
2851
7764383a968c
quick_frontend (widget, chat): implementation of new sync mechanism, first draft:
Goffi <goffi@goffi.org>
parents:
2850
diff
changeset
|
656 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
|
657 callback() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
658 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
659 self.host.bridge.historyGet( |
3028 | 660 str(self.host.profiles[profile].whoami.bare), |
661 str(target), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
662 size, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
663 True, |
3028 | 664 {k: str(v) for k,v in filters.items()}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
665 profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
666 callback=_historyGetCb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
667 errback=_historyGetEb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
668 ) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
669 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
670 def messageEncryptionGetCb(self, session_data): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
671 if session_data: |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
672 session_data = data_format.deserialise(session_data) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
673 self.messageEncryptionStarted(session_data) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
674 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
675 def messageEncryptionGetEb(self, failure_): |
3028 | 676 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
|
677 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
678 def getEncryptionState(self): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
679 """Retrieve encryption state with current target. |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
680 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
681 Once state is retrieved, default messageEncryptionStarted will be called if |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
682 suitable |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
683 """ |
2839
76f714b12d21
quick frontend(chat): use bare jid for getEncryptionState, and skip if for group chat
Goffi <goffi@goffi.org>
parents:
2788
diff
changeset
|
684 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
|
685 return |
3028 | 686 self.host.bridge.messageEncryptionGet(str(self.target.bare), self.profile, |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
687 callback=self.messageEncryptionGetCb, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
688 errback=self.messageEncryptionGetEb) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
689 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
690 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
691 def messageNew(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
692 profile): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
693 if self._locked: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
694 self._cache[uid] = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
695 uid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
696 timestamp, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
697 from_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
698 to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
699 msg, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
700 subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
701 type_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
702 extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
703 profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
704 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
705 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
|
706 |
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
|
707 if not msg and not subject and type_ != C.MESS_TYPE_INFO: |
3028 | 708 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
|
709 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
|
710 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
711 if self.type == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
712 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
|
713 # 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
|
714 # widget |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
715 chat_widget = self.getOrCreatePrivateWidget(to_jid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
716 chat_widget.messageNew( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
717 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
|
718 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
719 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
720 if type_ == C.MESS_TYPE_INFO: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
721 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
722 info_type = extra["info_type"] |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
723 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
724 pass |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
725 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
726 user_data = { |
3028 | 727 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
|
728 } |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
729 if info_type == ROOM_USER_JOINED: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
730 self.addUser(user_data) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
731 elif info_type == ROOM_USER_LEFT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
732 self.removeUser(user_data) |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1462
diff
changeset
|
733 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
734 message = Message( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
735 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
|
736 ) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
737 self.messages[uid] = message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
738 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
739 if "received_timestamp" in extra: |
3028 | 740 log.warning("Delayed message received after history, this should not happen") |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
741 self.createMessage(message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
742 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
743 def messageEncryptionStarted(self, session_data): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
744 self.encrypted = True |
3028 | 745 log.debug(_("message encryption started with {target} using {encryption}").format( |
746 target=self.target, encryption=session_data['name'])) | |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
747 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
748 def messageEncryptionStopped(self, session_data): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
749 self.encrypted = False |
3028 | 750 log.debug(_("message encryption stopped with {target} (was using {encryption})") |
751 .format(target=self.target, encryption=session_data['name'])) | |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2632
diff
changeset
|
752 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
753 def createMessage(self, message, append=False): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
754 """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
|
755 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
756 This is only called on messageNew, not on history. |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
757 You need to override historyPrint to handle the later |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
758 @param message(Message): message data |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
759 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
760 raise NotImplementedError |
1786
104874018ab0
quick_frontend, primitivus (chat): move notification command to quick_frontend
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
761 |
2880
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
762 def isUserMoved(self, message): |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
763 """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
|
764 |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
765 @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
|
766 @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
|
767 """ |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
768 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
|
769 return False |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
770 try: |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
771 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
|
772 except KeyError: |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
773 return False |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
774 else: |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
775 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
|
776 |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
777 def handleUserMoved(self, message): |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
778 """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
|
779 |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
780 "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
|
781 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
|
782 @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
|
783 @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
|
784 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
|
785 """ |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
786 if self.isUserMoved(message): |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
787 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
|
788 # 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
|
789 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
|
790 continue |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
791 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
|
792 return False |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
793 elif ( |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
794 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
|
795 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
|
796 ): |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
797 try: |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
798 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
|
799 except AttributeError: |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
800 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
|
801 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
|
802 if message.info_type == ROOM_USER_LEFT: |
3028 | 803 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
|
804 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
|
805 ) |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
806 else: |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
807 wid.message = _( |
3028 | 808 "<=> {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
|
809 ).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
|
810 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
|
811 return True |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
812 return False |
dd650f3e070f
quick frontend(chat): prepared factorisation of merging of user moved info messages:
Goffi <goffi@goffi.org>
parents:
2864
diff
changeset
|
813 |
1749
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
814 def printDayChange(self, day): |
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
815 """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
|
816 |
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
817 @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
|
818 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
819 # 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
|
820 pass |
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
821 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
822 ## Room ## |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
823 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
824 def setSubject(self, subject): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
825 """Set title for a group chat""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
826 if self.type != C.CHAT_GROUP: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
827 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
828 "trying to set subject for a non group chat window" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
829 ) |
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
|
830 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
|
831 |
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
|
832 def changeSubject(self, new_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
|
833 """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
|
834 |
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
|
835 This change the subject on the room itself (i.e. via XMPP), |
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
|
836 while setSubject change the subject of this widget |
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
|
837 """ |
3028 | 838 self.host.bridge.mucSubject(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
|
839 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
840 def addGamePanel(self, widget): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
841 """Insert a game panel to this Chat dialog. |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
842 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
843 @param widget (Widget): the game panel |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
844 """ |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
845 raise NotImplementedError |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
846 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
847 def removeGamePanel(self, widget): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
848 """Remove the game panel from this Chat dialog. |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
849 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
850 @param widget (Widget): the game panel |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
851 """ |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
852 raise NotImplementedError |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
853 |
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
|
854 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
|
855 """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
|
856 |
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
|
857 @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
|
858 """ |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
859 # 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
|
860 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
|
861 |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
862 ## events ## |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
863 |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
864 def onChatState(self, from_jid, state, profile): |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
865 """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
|
866 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
|
867 nick = from_jid.resource |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
868 try: |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
869 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
|
870 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
871 log.warning( |
3028 | 872 "{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
|
873 nick=nick, room=self.target.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
874 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
875 ) |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
876 |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
877 def onMessageState(self, uid, status, profile): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
878 try: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
879 mess_data = self.messages[uid] |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
880 except KeyError: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
881 pass |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
882 else: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
883 mess_data.status = status |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
884 |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
885 def onAvatar(self, entity, filename, profile): |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
886 if self.type == C.CHAT_GROUP: |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
887 if entity.bare == self.target: |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
888 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
889 self.occupants[entity.resource].update({"avatar": filename}) |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
890 except KeyError: |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
891 # 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
|
892 # entity is not here anymore |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
893 pass |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
894 |
3028 | 895 for m in list(self.messages.values()): |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
896 if m.nick == entity.resource: |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
897 for w in m.widgets: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
898 w.update({"avatar": filename}) |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
899 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
900 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
901 entity.bare == self.target.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
902 or entity.bare == self.host.profiles[profile].whoami.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
903 ): |
3028 | 904 log.info("avatar updated for {}".format(entity)) |
905 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
|
906 if m.from_jid.bare == entity.bare: |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2115
diff
changeset
|
907 for w in m.widgets: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2580
diff
changeset
|
908 w.update({"avatar": filename}) |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
909 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
910 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
911 quick_widgets.register(QuickChat) |