Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_chat.py @ 2066:09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
- (XEP-0045): join defered is now fired when room is full joined and history is available
- (XEP-0045): mucJOIN signature has changed, it now returns the same arguments as mucRoomJoined and a boolean which is True if the room was alread joined
- quick frontend (app, chat): adapted code to new changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 09 Sep 2016 23:54:33 +0200 |
parents | 8fa0d95c2142 |
children | 7834743705f0 |
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 |
1766 | 5 # Copyright (C) 2009-2016 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 |
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
907
diff
changeset
|
22 log = getLogger(__name__) |
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 |
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
|
29 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
|
30 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
|
31 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
|
32 # FIXME: pyjamas workaround |
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 getlocale = lambda x: (None, 'utf-8') |
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 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
35 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
36 ROOM_USER_JOINED = 'ROOM_USER_JOINED' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
37 ROOM_USER_LEFT = 'ROOM_USER_LEFT' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
38 ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
39 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
40 # from datetime import datetime |
0 | 41 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
42 try: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
43 # FIXME: to be removed when an acceptable solution is here |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
44 unicode('') # XXX: unicode doesn't exist in pyjamas |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
45 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options |
1462 | 46 unicode = str |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
47 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
48 # FIXME: day_format need to be settable (i18n) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
49 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
50 class Message(object): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
51 """Message metadata""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
52 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
53 def __init__(self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
54 self.parent = parent |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
55 self.profile = profile |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
56 self.uid = uid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
57 self.timestamp = timestamp |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
58 self.from_jid = from_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
59 self.to_jid = to_jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
60 self.message = msg |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
61 self.subject = subject |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
62 self.type = type_ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
63 self.extra = extra |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
64 self.nick = self.getNick(from_jid) |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
65 self._status = None |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
66 # own_mess is True if message was sent by profile's jid |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
67 self.own_mess = (from_jid.resource == self.parent.nick) if self.parent.type == C.CHAT_GROUP else (from_jid.bare == self.host.profiles[profile].whoami.bare) |
1973
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
68 # 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
|
69 if self.parent.type == C.CHAT_GROUP and not self.own_mess: |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
70 for m in msg.itervalues(): |
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.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
|
72 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
|
73 break |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
74 self.handleMe() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
75 self.widgets = set() # widgets linked to this message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
76 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
77 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
78 def host(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
79 return self.parent.host |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
80 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
81 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
82 def info_type(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
83 return self.extra.get('info_type') |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
84 |
1973
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
85 @property |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
86 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
|
87 try: |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
88 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
|
89 except AttributeError: |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
90 return False |
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
91 |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
92 @property |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
93 def main_message(self): |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
94 """Return currently displayed message""" |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 try: |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
99 self.selected_lang = '' |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
100 return self.message[''] |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
101 except KeyError: |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
102 try: |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
103 lang, mess = self.message.iteritems().next() |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
104 self.selected_lang = lang |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
105 return mess |
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
106 except StopIteration: |
2026
cdb2591d0b8b
quick frontend(chat): fixed traceback in log message
Goffi <goffi@goffi.org>
parents:
2024
diff
changeset
|
107 log.error(u"Can't find message for uid {}".format(self.uid)) |
cdb2591d0b8b
quick frontend(chat): fixed traceback in log message
Goffi <goffi@goffi.org>
parents:
2024
diff
changeset
|
108 return '' |
1993
981e2abbb56c
quick_frontend, primitivus: moved main_message property to quick_frontend
Goffi <goffi@goffi.org>
parents:
1973
diff
changeset
|
109 |
2029
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
110 @property |
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
111 def time_text(self): |
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
112 """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
|
113 # 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
|
114 timestamp = time.localtime(self.timestamp) |
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
115 time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M" |
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
|
116 return time.strftime(time_format, timestamp).decode(getlocale()[1]) |
2029
62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
Goffi <goffi@goffi.org>
parents:
2026
diff
changeset
|
117 |
2057
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
118 @property |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
119 def avatar(self): |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
120 contact_list = 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
|
121 return contact_list.getCache(self.from_jid, "avatar") or self.host.getDefaultAvatar(self.from_jid) |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
122 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
123 def getNick(self, entity): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
124 """Return nick of an entity when possible""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
125 contact_list = self.host.contact_lists[self.profile] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
126 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
|
127 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
128 return self.extra['user_nick'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
129 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
130 log.error(u"extra data is missing user nick for uid {}".format(self.uid)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
131 return "" |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2013
diff
changeset
|
132 if self.parent.type == C.CHAT_GROUP or entity in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
133 return entity.resource or "" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
134 if entity.bare in contact_list: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
135 return contact_list.getCache(entity, 'nick') or contact_list.getCache(entity, 'name') or entity.node or entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
136 return entity.node or entity |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
137 |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
138 @property |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
139 def status(self): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
140 return self._status |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
141 |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
142 @status.setter |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
143 def status(self, status): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
144 self._status = status |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
145 for w in self.widgets: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
146 w.updated(["status"]) |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
147 |
2055
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
148 def handleMe(self): |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
149 """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
|
150 |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
151 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
|
152 """ |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
153 # TODO: XHTML-IM /me are not handled |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
154 me = False |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
155 # we need to check /me for every message |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
156 for m in self.message.itervalues(): |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
157 if m.startswith(u"/me "): |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
158 me = True |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
159 else: |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
160 me = False |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
161 break |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
162 if me: |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
163 self.type = C.MESS_TYPE_INFO |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
164 self.extra['info_type'] = 'me' |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
165 nick = self.nick |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
166 for lang, mess in self.message.iteritems(): |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
167 self.message[lang] = u"* " + nick + mess[3:] |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
168 |
ed33cd382bf9
plugin XEP-0245: removed plugin XEP-0245:
Goffi <goffi@goffi.org>
parents:
2051
diff
changeset
|
169 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
170 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
171 class Occupant(object): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
172 """Occupant metadata""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
173 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
174 def __init__(self, parent, data, profile): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
175 self.parent = parent |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
176 self.profile = profile |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
177 self.nick = data['nick'] |
2020
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
178 self._entity = data.get('entity') |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
179 self.affiliation = data['affiliation'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
180 self.role = data['role'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
181 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
|
182 self._state = None |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
183 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
184 @property |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
185 def data(self): |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
186 """reconstruct data dict from attributes""" |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
187 data = {} |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
188 data['nick'] = self.nick |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
189 if self._entity is not None: |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
190 data['entity'] = self._entity |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
191 data['affiliation'] = self.affiliation |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
192 data['role'] = self.role |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
193 return data |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
194 |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
195 @property |
2020
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
196 def jid(self): |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
197 """jid in the room""" |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
198 return jid.JID(u"{}/{}".format(self.parent.target.bare, self.nick)) |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
199 |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
200 @property |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
201 def real_jid(self): |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
202 """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
|
203 return self._entity |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
204 |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
205 @property |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
206 def host(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
207 return self.parent.host |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
208 |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
209 @property |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
210 def state(self): |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
211 return self._state |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
212 |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
213 @state.setter |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
214 def state(self, new_state): |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
215 self._state = new_state |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
216 for w in self.widgets: |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
217 w.updated(["state"]) |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
218 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
219 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
220 class QuickChat(quick_widgets.QuickWidget): |
2040
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2033
diff
changeset
|
221 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
|
222 |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
223 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, 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
|
224 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
225 @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for chat à la IRC |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
226 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
227 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
|
228 quick_widgets.QuickWidget.__init__(self, host, target, profiles=profiles) |
2018
7199e6bdb94e
quick_frontend, primitivus (chat): fixed widget bad locking + don't send notification when locked
Goffi <goffi@goffi.org>
parents:
2015
diff
changeset
|
229 self._locked = True # True when we are waiting for history/search |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
230 # messageNew signals are cached when locked |
2019
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
231 self._cache = OrderedDict() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
232 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
|
233 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
|
234 self.type = type_ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
235 if type_ == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
236 if target.resource: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
237 raise exceptions.InternalError(u"a group chat entity can't have a resource") |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
238 if nick is None: |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
239 raise exceptions.InternalError(u"nick must not be None for group chat") |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
240 |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
241 self.nick = nick |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
242 self.occupants = {} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
243 self.setOccupants(occupants) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
244 else: |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
245 if occupants is not None or nick is not None: |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
246 raise exceptions.InternalError(u"only group chat can have occupants or nick") |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
247 self.messages = OrderedDict() # key: uid, value: Message instance |
1379
da2ea16fabc6
quick_frontend: display MUC games symbols
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
248 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
|
249 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
|
250 lt = time.localtime() |
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
|
251 self.day_change = (lt.tm_year, lt.tm_mon, lt.tm_mday, 0, 0, 0, lt.tm_wday, lt.tm_yday, lt.tm_isdst) # struct_time of day changing time |
72 | 252 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
253 def postInit(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
254 """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
|
255 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
256 handle the display of history and subject |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
257 """ |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
258 self.historyPrint(profile=self.profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
259 if self.subject is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
260 self.setSubject(self.subject) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
261 |
2057
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
262 @property |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
263 def contact_list(self): |
a52a6ed7d48f
quick frontend (chat): added helping properties avatar and contact_list
Goffi <goffi@goffi.org>
parents:
2055
diff
changeset
|
264 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
|
265 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
266 ## Widget management ## |
1764
33c815c17fe6
quick_frontend (chat): temporary fix for bug 12:
souliane <souliane@mailoo.org>
parents:
1763
diff
changeset
|
267 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
268 def __str__(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
269 return u"Chat Widget [target: {}, type: {}, profile: {}]".format(self.target, self.type, self.profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
270 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
271 @staticmethod |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
272 def getWidgetHash(target, profiles): |
2048
aff318d4a786
quick frontend (chat): fixed getWidgetHash
Goffi <goffi@goffi.org>
parents:
2040
diff
changeset
|
273 profile = list(profiles)[0] |
2051
1dc3c7680ea0
quick_frontend (chat): fixed hash generation, tuple was causing trouble when used with unicode() because of dbus.String
Goffi <goffi@goffi.org>
parents:
2048
diff
changeset
|
274 return profile + "\n" + target.bare |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
275 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
276 @staticmethod |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
277 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
|
278 """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
|
279 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
280 This method should be used with force_hash to get unique widget for private MUC conversations |
72 | 281 """ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
282 return (unicode(profile), target) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
283 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
284 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
|
285 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
|
286 if target.resource: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
287 self.current_target = target # FIXME: tmp, must use resource priority throught contactList instead |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
288 |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
289 def recreateArgs(self, args, kwargs): |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
290 """copy important attribute for a new widget""" |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
291 kwargs['type_'] = self.type |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
292 if self.type == C.CHAT_GROUP: |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
293 kwargs['occupants'] = {o.nick: o.data for o in self.occupants.itervalues()} |
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
294 kwargs['subject'] = self.subject |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
295 try: |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
296 kwargs['nick'] = self.nick |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
297 except AttributeError: |
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2063
diff
changeset
|
298 pass |
2063
8fa0d95c2142
quick frontend (chat): recreateArgs implementation
Goffi <goffi@goffi.org>
parents:
2057
diff
changeset
|
299 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
300 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
|
301 """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
|
302 raise NotImplementedError |
0 | 303 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
304 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
|
305 """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
|
306 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
307 @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
|
308 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
309 return self.host.widgets.getOrCreateWidget(QuickChat, entity, type_=C.CHAT_ONE2ONE, force_hash=self.getPrivateHash(self.profile, entity), on_new_widget=self.onPrivateCreated, profile=self.profile) # we force hash to have a new widget, not this one again |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
310 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
311 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
312 def target(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
313 if self.type == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
314 return self.current_target.bare |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
315 return self.current_target |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
316 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
317 ## occupants ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
318 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
319 def setOccupants(self, occupants): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
320 """set the whole list of occupants""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
321 assert len(self.occupants) == 0 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
322 for nick, data in occupants.iteritems(): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
323 self.occupants[nick] = Occupant( |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
324 self, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
325 data, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
326 self.profile |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
327 ) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
328 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
329 def addUser(self, occupant_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
330 """Add user if it is not in the group list""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
331 occupant = Occupant( |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
332 self, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
333 occupant_data, |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
334 self.profile |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
335 ) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
336 self.occupants[occupant.nick] = occupant |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
337 return occupant |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
338 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
339 def removeUser(self, occupant_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
340 """Remove a user from the group list""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
341 nick = occupant_data['nick'] |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
342 try: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
343 occupant = self.occupants.pop(nick) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
344 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
345 log.warning(u"Trying to remove an unknown occupant: {}".format(nick)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
346 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
347 return occupant |
1764
33c815c17fe6
quick_frontend (chat): temporary fix for bug 12:
souliane <souliane@mailoo.org>
parents:
1763
diff
changeset
|
348 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
349 def setUserNick(self, nick): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
350 """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
|
351 self.nick = nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
352 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
353 def changeUserNick(self, old_nick, new_nick): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
354 """Change nick of a user in group list""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
355 self.printInfo("%s is now known as %s" % (old_nick, new_nick)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
356 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
357 ## Messages ## |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
358 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
359 def manageMessage(self, entity, mess_type): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
360 """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
|
361 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
362 @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
|
363 @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
|
364 @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
|
365 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
366 if self.type == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
367 if mess_type in (C.MESS_TYPE_GROUPCHAT, C.MESS_TYPE_INFO) and self.target == entity.bare: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
368 return True |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
369 else: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
370 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
|
371 return True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
372 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
373 |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
374 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
|
375 """Called when history need to be recreated |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
376 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
377 Remove all message from history then call historyPrint |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
378 Must probably be overriden by frontend to clear widget |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
379 @param size (int): number of messages |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
380 @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
|
381 @param profile (str): %(doc_profile)s |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
382 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
383 self._locked = True |
2019
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
384 self._cache = OrderedDict() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
385 self.messages.clear() |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
386 self.historyPrint(size, filters, profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
387 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
388 def _onHistoryPrinted(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
389 """Method called when history is printed (or failed) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
390 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
391 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
|
392 the focus after the history is printed |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
393 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
394 self._locked = False |
2019
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
395 for data in self._cache.itervalues(): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
396 self.messageNew(*data) |
2019
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
397 del self._cache |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1462
diff
changeset
|
398 |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
399 def historyPrint(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
|
400 """Print the current history |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
401 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
402 @param size (int): number of messages |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
403 @param search (str): pattern to filter the history results |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
404 @param profile (str): %(doc_profile)s |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1462
diff
changeset
|
405 """ |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
406 if filters is None: |
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
407 filters = {} |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
408 if size == 0: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
409 log.debug(u"Empty history requested, skipping") |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
410 self._onHistoryPrinted() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
411 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
412 log_msg = _(u"now we print the history") |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
413 if size != C.HISTORY_LIMIT_DEFAULT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
414 log_msg += _(u" ({} messages)".format(size)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
415 log.debug(log_msg) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
416 |
2020
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
417 if self.type == C.CHAT_ONE2ONE: |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
418 special = self.host.contact_lists[self.profile].getCache(self.target, C.CONTACT_SPECIAL) |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
419 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
|
420 # 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
|
421 # 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
|
422 # (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
|
423 # 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
|
424 target = self.target |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
425 filters['not_types'] = C.MESS_TYPE_GROUPCHAT |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
426 else: |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
427 target = self.target.bare |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
428 else: |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
429 # groupchat |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
430 target = self.target.bare |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
431 # FIXME: info not handled correctly |
f67da1cab6d3
quick frontend, primitivus (chat, contact_list): fixed MUC private messages handling:
Goffi <goffi@goffi.org>
parents:
2019
diff
changeset
|
432 filters['types'] = C.MESS_TYPE_GROUPCHAT |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
433 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
434 def _historyGetCb(history): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
435 # 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
|
436 # previous_day = datetime.now().strftime(day_format) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
437 # message_day = datetime.fromtimestamp(timestamp).strftime(self.day_format) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
438 # if previous_day != message_day: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
439 # self.printDayChange(message_day) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
440 # previous_day = message_day |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
441 for data in history: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
442 uid, timestamp, from_jid, to_jid, message, subject, type_, extra = data |
2019
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
443 # cached messages may already be in history |
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
444 # so we check it to avoid duplicates, they'll be added later |
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
445 if uid in self._cache: |
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
446 continue |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
447 from_jid = jid.JID(from_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
448 to_jid = jid.JID(to_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
449 # 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
|
450 # (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
|
451 # continue |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
452 self.messages[uid] = Message(self, uid, timestamp, from_jid, to_jid, message, subject, type_, extra, profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
453 self._onHistoryPrinted() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
454 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
455 def _historyGetEb(err): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
456 log.error(_(u"Can't get history")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
457 self._onHistoryPrinted() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
458 |
2013
b536dd121da1
backend (memory), frontends: improved history filtering:
Goffi <goffi@goffi.org>
parents:
2007
diff
changeset
|
459 self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, filters, profile, callback=_historyGetCb, errback=_historyGetEb) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
460 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
461 def messageNew(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
462 if self._locked: |
2019
c0ff84243650
quick_frontend(chat): better handling of cached signals when initialising widget
Goffi <goffi@goffi.org>
parents:
2018
diff
changeset
|
463 self._cache[uid] = (uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
464 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
465 if self.type == C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
466 if to_jid.resource and type_ != C.MESS_TYPE_GROUPCHAT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
467 # we have a private message, we forward it to a private conversation widget |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
468 chat_widget = self.getOrCreatePrivateWidget(to_jid) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
469 chat_widget.messageNew(uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
470 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
471 if type_ == C.MESS_TYPE_INFO: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
472 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
473 info_type = extra['info_type'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
474 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
475 pass |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
476 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
477 user_data = {k[5:]:v for k,v in extra.iteritems() if k.startswith('user_')} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
478 if info_type == ROOM_USER_JOINED: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
479 self.addUser(user_data) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
480 elif info_type == ROOM_USER_LEFT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
481 self.removeUser(user_data) |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1462
diff
changeset
|
482 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
483 message = Message(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
484 self.messages[uid] = message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
485 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
486 if 'received_timestamp' in extra: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
487 log.warning(u"Delayed message received after history, this should not happen") |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
488 self.createMessage(message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
489 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
490 def createMessage(self, message, append=False): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
491 """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
|
492 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
493 This is only called on messageNew, not on history. |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
494 You need to override historyPrint to handle the later |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
495 @param message(Message): message data |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
496 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
497 raise NotImplementedError |
1786
104874018ab0
quick_frontend, primitivus (chat): move notification command to quick_frontend
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
498 |
1749
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
499 def printDayChange(self, day): |
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
500 """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
|
501 |
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
502 @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
|
503 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
504 # 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
|
505 pass |
d047535e3ed5
quick_frontend: restore printing the day change while displaying history
souliane <souliane@mailoo.org>
parents:
1748
diff
changeset
|
506 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
507 ## Room ## |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
508 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
509 def setSubject(self, subject): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
510 """Set title for a group chat""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
511 if self.type != C.CHAT_GROUP: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
512 raise exceptions.InternalError("trying to set subject for a non group chat window") |
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
|
513 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
|
514 |
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
|
515 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
|
516 """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
|
517 |
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
|
518 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
|
519 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
|
520 """ |
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
|
521 self.host.bridge.mucSubject(unicode(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
|
522 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
523 def addGamePanel(self, widget): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
524 """Insert a game panel to this Chat dialog. |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
525 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
526 @param widget (Widget): the game panel |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
527 """ |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
528 raise NotImplementedError |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
529 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
530 def removeGamePanel(self, widget): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
531 """Remove the game panel from this Chat dialog. |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
532 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
533 @param widget (Widget): the game panel |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
534 """ |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
535 raise NotImplementedError |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
536 |
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
|
537 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
|
538 """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
|
539 |
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
|
540 @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
|
541 """ |
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
|
542 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
|
543 |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
544 ## events ## |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
545 |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
546 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
|
547 """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
|
548 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
|
549 nick = from_jid.resource |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
550 try: |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
551 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
|
552 except KeyError: |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
553 log.warning(u"{nick} not found in {room}, ignoring new chat state".format( |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
554 nick=nick, room=self.target.bare)) |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1993
diff
changeset
|
555 |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
556 def onMessageState(self, uid, status, profile): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
557 try: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
558 mess_data = self.messages[uid] |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
559 except KeyError: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
560 pass |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
561 else: |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
562 mess_data.status = status |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2022
diff
changeset
|
563 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1296
diff
changeset
|
564 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
565 quick_widgets.register(QuickChat) |