Mercurial > libervia-web
comparison src/browser/sat_browser/chat.py @ 914:0c0551967bdf
server, browser: partial Libervia fix
Libervia was broken following the refactorings. This commit partially fixes it : Libervia is starting, avatar, blog and message are working again, but not everything is restablished yet.
following things have been fixed/changed:
- new dependency: shortuuid
- D-Bus bridge is working again
- fixed naming in several bridge methods
- register method changed to register_signal
- fixed Chat widget, which was not working anymore since the refactoring
- avatar now use avatarGet. Cache dir is accessible using a session specific uuid, to avoid cache leak (i.e. accessing cache of other profiles)
- server: new uuid attribute in session data
Browser code is not fully working yet, notably OTR and contact list are not fully fixed.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Feb 2017 18:32:47 +0100 |
parents | e8b133b77aa4 |
children | 5d9f6d25c586 |
comparison
equal
deleted
inserted
replaced
913:58f611481e6d | 914:0c0551967bdf |
---|---|
27 from sat_frontends.quick_frontend.quick_chat import QuickChat | 27 from sat_frontends.quick_frontend.quick_chat import QuickChat |
28 | 28 |
29 from pyjamas.ui.AbsolutePanel import AbsolutePanel | 29 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
30 from pyjamas.ui.VerticalPanel import VerticalPanel | 30 from pyjamas.ui.VerticalPanel import VerticalPanel |
31 from pyjamas.ui.HorizontalPanel import HorizontalPanel | 31 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
32 from pyjamas.ui.Label import Label | |
33 from pyjamas.ui.HTML import HTML | |
34 from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler | 32 from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler |
35 from pyjamas.ui.HTMLPanel import HTMLPanel | 33 from pyjamas.ui.HTMLPanel import HTMLPanel |
36 from pyjamas import DOM | 34 from pyjamas import DOM |
37 from pyjamas import Window | 35 from pyjamas import Window |
38 | 36 |
39 from datetime import datetime | 37 from datetime import datetime |
40 from time import time | |
41 | 38 |
42 import html_tools | 39 import html_tools |
43 import libervia_widget | 40 import libervia_widget |
44 import base_panel | 41 import base_panel |
45 import contact_panel | 42 import contact_panel |
51 | 48 |
52 | 49 |
53 unicode = str # FIXME: pyjamas workaround | 50 unicode = str # FIXME: pyjamas workaround |
54 | 51 |
55 | 52 |
56 class ChatText(HTMLPanel): | 53 class MessageWidget(HTMLPanel): |
57 | 54 |
58 def __init__(self, timestamp, nick, mymess, msg, extra): | 55 def __init__(self, mess_data): |
59 xhtml = extra.get('xhtml') | 56 """ |
60 _date = datetime.fromtimestamp(float(timestamp or time())) | 57 @param mess_data(quick_chat.Message, None): message data |
61 _msg_class = ["chat_text_msg"] | 58 None: used only for non text widgets (e.g.: focus separator) |
62 if mymess: | 59 """ |
63 _msg_class.append("chat_text_mymess") | 60 self.mess_data = mess_data |
64 HTMLPanel.__init__(self, "<span class='chat_text_timestamp'>%(timestamp)s</span> <span class='chat_text_nick'>%(nick)s</span> <span class='%(msg_class)s'>%(msg)s</span>" % | 61 mess_data.widgets.add(self) |
65 {"timestamp": _date.strftime("%H:%M"), | 62 _msg_class = [] |
66 "nick": "[%s]" % html_tools.html_sanitize(nick), | 63 if mess_data.type == C.MESS_TYPE_INFO: |
67 "msg_class": ' '.join(_msg_class), | 64 markup = "<span class='{msg_class}'>{msg}</span>" |
68 "msg": strings.addURLToText(html_tools.html_sanitize(msg)) if not xhtml else html_tools.inlineRoot(xhtml)} # FIXME: images and external links must be removed according to preferences | 65 |
69 ) | 66 if mess_data.extra.get('info_type') == 'me': |
70 self.setStyleName('chatText') | 67 _msg_class.append('chatTextMe') |
68 else: | |
69 _msg_class.append('chatTextInfo') | |
70 # FIXME: following code was in printInfo before refactoring | |
71 # seems to be used only in radiocol | |
72 # elif type_ == 'link': | |
73 # _wid = HTML(msg) | |
74 # _wid.setStyleName('chatTextInfo-link') | |
75 # if link_cb: | |
76 # _wid.addClickListener(link_cb) | |
77 else: | |
78 markup = "<span class='chat_text_timestamp'>{timestamp}</span> <span class='chat_text_nick'>{nick}</span> <span class='{msg_class}'>{msg}</span>" | |
79 _msg_class.append("chat_text_msg") | |
80 if mess_data.own_mess: | |
81 _msg_class.append("chat_text_mymess") | |
82 | |
83 xhtml = mess_data.main_message_xhtml | |
84 _date = datetime.fromtimestamp(float(mess_data.timestamp)) | |
85 HTMLPanel.__init__(self, markup.format( | |
86 timestamp = _date.strftime("%H:%M"), | |
87 nick = "[{}]".format(html_tools.html_sanitize(mess_data.nick)), | |
88 msg_class = ' '.join(_msg_class), | |
89 msg = strings.addURLToText(html_tools.html_sanitize(mess_data.main_message)) if not xhtml else html_tools.inlineRoot(xhtml) # FIXME: images and external links must be removed according to preferences | |
90 )) | |
91 if mess_data.type != C.MESS_TYPE_INFO: | |
92 self.setStyleName('chatText') | |
71 | 93 |
72 | 94 |
73 class Chat(QuickChat, libervia_widget.LiberviaWidget, KeyboardHandler): | 95 class Chat(QuickChat, libervia_widget.LiberviaWidget, KeyboardHandler): |
74 | 96 |
75 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): | 97 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): |
119 | 141 |
120 self.message_box = editor_widget.MessageBox(self.host) | 142 self.message_box = editor_widget.MessageBox(self.host) |
121 self.message_box.onSelectedChange(self) | 143 self.message_box.onSelectedChange(self) |
122 self.message_box.addKeyboardListener(self) | 144 self.message_box.addKeyboardListener(self) |
123 self.vpanel.add(self.message_box) | 145 self.vpanel.add(self.message_box) |
146 self.postInit() | |
124 | 147 |
125 def onWindowResized(self, width=None, height=None): | 148 def onWindowResized(self, width=None, height=None): |
126 if self.type == C.CHAT_GROUP: | 149 if self.type == C.CHAT_GROUP: |
127 ideal_height = self.content_scroll.getOffsetHeight() | 150 ideal_height = self.content_scroll.getOffsetHeight() |
128 self.occupants_panel.setHeight("%s%s" % (ideal_height, "px")) | 151 self.occupants_panel.setHeight("%s%s" % (ideal_height, "px")) |
208 header_info = extra.pop('header_info', None) | 231 header_info = extra.pop('header_info', None) |
209 if header_info: | 232 if header_info: |
210 self.setHeaderInfo(header_info) | 233 self.setHeaderInfo(header_info) |
211 QuickChat.newMessage(self, from_jid, target, msg, type_, extra, profile) | 234 QuickChat.newMessage(self, from_jid, target, msg, type_, extra, profile) |
212 | 235 |
213 def printInfo(self, msg, type_='normal', extra=None, link_cb=None): | 236 def _onHistoryPrinted(self): |
214 """Print general info | 237 """Refresh or scroll down the focus after the history is printed""" |
215 @param msg: message to print | 238 self.printMessages(clear=False) |
216 @param type_: one of: | 239 super(Chat, self)._onHistoryPrinted() |
217 "normal": general info like "toto has joined the room" (will be sanitized) | 240 |
218 "link": general info that is clickable like "click here to join the main room" (no sanitize done) | 241 def printMessages(self, clear=True): |
219 "me": "/me" information like "/me clenches his fist" ==> "toto clenches his fist" (will stay on one line) | 242 """generate message widgets |
220 @param extra (dict): message data | 243 |
221 @param link_cb: method to call when the info is clicked, ignored if type_ is not 'link' | 244 @param clear(bool): clear message before printing if true |
222 """ | 245 """ |
223 QuickChat.printInfo(self, msg, type_, extra) | 246 if clear: |
224 if extra is None: | 247 # FIXME: clear is not handler |
225 extra = {} | 248 pass |
226 if type_ == 'normal': | 249 for message in self.messages.itervalues(): |
227 _wid = HTML(strings.addURLToText(html_tools.XHTML2Text(msg))) | 250 self.appendMessage(message) |
228 _wid.setStyleName('chatTextInfo') | 251 |
229 elif type_ == 'link': | 252 def createMessage(self, message): |
230 _wid = HTML(msg) | 253 self.appendMessage(message) |
231 _wid.setStyleName('chatTextInfo-link') | 254 |
232 if link_cb: | 255 def appendMessage(self, message): |
233 _wid.addClickListener(link_cb) | 256 self.content.add(MessageWidget(message)) |
234 elif type_ == 'me': | |
235 _wid = Label(msg) | |
236 _wid.setStyleName('chatTextMe') | |
237 else: | |
238 raise ValueError("Unknown printInfo type %s" % type_) | |
239 self.content.add(_wid) | |
240 self.content_scroll.scrollToBottom() | |
241 | |
242 def printMessage(self, nick, my_message, message, timestamp, extra=None, profile=C.PROF_KEY_NONE): | |
243 QuickChat.printMessage(self, nick, my_message, message, timestamp, extra, profile) | |
244 if extra is None: | |
245 extra = {} | |
246 self.content.add(ChatText(timestamp, nick, my_message, message, extra)) | |
247 self.content_scroll.scrollToBottom() | 257 self.content_scroll.scrollToBottom() |
248 | 258 |
249 def notify(self, contact="somebody", msg=""): | 259 def notify(self, contact="somebody", msg=""): |
250 """Notify the user of a new message if primitivus doesn't have the focus. | 260 """Notify the user of a new message if primitivus doesn't have the focus. |
251 | 261 |
252 @param contact (unicode): contact who wrote to the users | 262 @param contact (unicode): contact who wrote to the users |
253 @param msg (unicode): the message that has been received | 263 @param msg (unicode): the message that has been received |
254 """ | 264 """ |
255 self.host.notification.notify(contact, msg) | 265 self.host.notification.notify(contact, msg) |
256 | 266 |
257 def printDayChange(self, day): | 267 # def printDayChange(self, day): |
258 """Display the day on a new line. | 268 # """Display the day on a new line. |
259 | 269 |
260 @param day(unicode): day to display (or not if this method is not overwritten) | 270 # @param day(unicode): day to display (or not if this method is not overwritten) |
261 """ | 271 # """ |
262 self.printInfo("* " + day) | 272 # self.printInfo("* " + day) |
263 | 273 |
264 def setTitle(self, title=None, extra=None): | 274 def setTitle(self, title=None, extra=None): |
265 """Refresh the title of this Chat dialog | 275 """Refresh the title of this Chat dialog |
266 | 276 |
267 @param title (unicode): main title or None to use default | 277 @param title (unicode): main title or None to use default |