comparison browser_side/panels.py @ 260:533d68585866

browser side: if 'xhtml' key is present in microblog data, rich content is displayed
author Goffi <goffi@goffi.org>
date Fri, 15 Nov 2013 15:34:55 +0100
parents da0487f0a2e7
children 3df0c3634c29
comparison
equal deleted inserted replaced
259:a20815c75c15 260:533d68585866
232 if _txt: 232 if _txt:
233 target_hook, _type, msg = target 233 target_hook, _type, msg = target
234 if target_hook: 234 if target_hook:
235 parsed_txt, data = target_hook 235 parsed_txt, data = target_hook
236 if _type == "PUBLIC": 236 if _type == "PUBLIC":
237 self.host.bridge.call("sendMblog", None, "PUBLIC", None, parsed_txt) 237 self.host.bridge.call("sendMblog", None, "PUBLIC", None, parsed_txt, {})
238 elif _type == "GROUP": 238 elif _type == "GROUP":
239 self.host.bridge.call("sendMblog", None, "GROUP", data, parsed_txt) 239 self.host.bridge.call("sendMblog", None, "GROUP", data, parsed_txt, {})
240 elif _type == "STATUS": 240 elif _type == "STATUS":
241 self.host.bridge.call('setStatus', None, parsed_txt) 241 self.host.bridge.call('setStatus', None, parsed_txt)
242 else: 242 else:
243 print "ERROR: Unknown target hook type" 243 print "ERROR: Unknown target hook type"
244 else: # we send the message to the selected target 244 else: # we send the message to the selected target
303 303
304 def __init__(self, data): 304 def __init__(self, data):
305 self.id = data['id'] 305 self.id = data['id']
306 self.type = data.get('type', 'main_item') 306 self.type = data.get('type', 'main_item')
307 self.content = data['content'] 307 self.content = data['content']
308 self.xhtml = data.get('xhtml')
308 self.author = data['author'] 309 self.author = data['author']
309 self.timestamp = float(data.get('timestamp', 0)) # XXX: int doesn't work here 310 self.timestamp = float(data.get('timestamp', 0)) # XXX: int doesn't work here
310 self.comments = data.get('comments', False) 311 self.comments = data.get('comments', False)
311 if self.comments: 312 if self.comments:
312 try: 313 try:
335 336
336 self.panel = HTMLPanel(""" 337 self.panel = HTMLPanel("""
337 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div> 338 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div>
338 <div class="mb_entry_avatar" id='id_avatar'></div> 339 <div class="mb_entry_avatar" id='id_avatar'></div>
339 <div class="mb_entry_dialog"> 340 <div class="mb_entry_dialog">
340 <p class="bubble">%(body)s</p> 341 <div class="bubble">%(body)s</div>
341 </div> 342 </div>
342 """ % {"author": html_sanitize(self.author), 343 """ % {"author": html_sanitize(self.author),
343 "timestamp": _datetime, 344 "timestamp": _datetime,
344 "body": addURLToText(html_sanitize(mblog_entry.content)) 345 "body": addURLToText(html_sanitize(mblog_entry.content)) if not mblog_entry.xhtml else mblog_entry.xhtml
345 }) 346 })
346 self.avatar = Image(blog_panel.host.getAvatar(self.author)) 347 self.avatar = Image(blog_panel.host.getAvatar(self.author))
347 self.panel.add(self.avatar, "id_avatar") 348 self.panel.add(self.avatar, "id_avatar")
348 self.panel.setStyleName('mb_entry') 349 self.panel.setStyleName('mb_entry')
349 self.add(self.panel) 350 self.add(self.panel)
440 if not comments_node: 441 if not comments_node:
441 raise Exception("ERROR: comments node is empty") 442 raise Exception("ERROR: comments node is empty")
442 self.host.bridge.call("sendMblogComment", None, comments_node, text) 443 self.host.bridge.call("sendMblogComment", None, comments_node, text)
443 elif not self._accepted_groups: 444 elif not self._accepted_groups:
444 # we are entering a public microblog 445 # we are entering a public microblog
445 self.host.bridge.call("sendMblog", None, "PUBLIC", None, text) 446 self.host.bridge.call("sendMblog", None, "PUBLIC", None, text, {})
446 else: 447 else:
447 # we are entering a microblog restricted to a group 448 # we are entering a microblog restricted to a group
448 # FIXME: manage several groups 449 # FIXME: manage several groups
449 self.host.bridge.call("sendMblog", None, "GROUP", self._accepted_groups[0], text) 450 self.host.bridge.call("sendMblog", None, "GROUP", self._accepted_groups[0], text, {})
450 451
451 def accept_all(self): 452 def accept_all(self):
452 return not self._accepted_groups # we accept every microblog only if we are not filtering by groups 453 return not self._accepted_groups # we accept every microblog only if we are not filtering by groups
453 454
454 def getEntries(self): 455 def getEntries(self):
746 msg = "This message will be sent to all the participants of the multi-user room <span class='warningTarget'>%s</span>" % self.target 747 msg = "This message will be sent to all the participants of the multi-user room <span class='warningTarget'>%s</span>" % self.target
747 return ("ONE2ONE" if self.type == "one2one" else "GROUP", msg) 748 return ("ONE2ONE" if self.type == "one2one" else "GROUP", msg)
748 749
749 def onTextEntered(self, text): 750 def onTextEntered(self, text):
750 mess_type = "groupchat" if self.type == 'group' else "chat" 751 mess_type = "groupchat" if self.type == 'group' else "chat"
751 self.host.bridge.call('sendMessage', None, str(self.target), text, '', mess_type) 752 self.host.bridge.call('sendMessage', None, str(self.target), text, '', mess_type, {})
752 self.state_machine._onEvent("active") 753 self.state_machine._onEvent("active")
753 754
754 def onQuit(self): 755 def onQuit(self):
755 base_widget.LiberviaWidget.onQuit(self) 756 base_widget.LiberviaWidget.onQuit(self)
756 if self.type == 'group': 757 if self.type == 'group':