comparison src/browser/sat_browser/blog.py @ 624:9092e624bb27 frontends_multi_profiles

browser_side: fixes various issues
author souliane <souliane@mailoo.org>
date Sun, 22 Feb 2015 21:51:20 +0100
parents 2c41ce0c3b3f
children 63697f082e8a
comparison
equal deleted inserted replaced
623:4f7550a083b4 624:9092e624bb27
164 self.comment_label = addIcon(u"↶", "Comment this message") 164 self.comment_label = addIcon(u"↶", "Comment this message")
165 self.comment_label.setStyleName('mb_entry_action_larger') 165 self.comment_label.setStyleName('mb_entry_action_larger')
166 is_publisher = self.author == self._blog_panel.host.whoami.bare 166 is_publisher = self.author == self._blog_panel.host.whoami.bare
167 if is_publisher: 167 if is_publisher:
168 self.update_label = addIcon(u"✍", "Edit this message") 168 self.update_label = addIcon(u"✍", "Edit this message")
169 if is_publisher or str(self.node).endswith(self._blog_panel.host.whoami.bare): 169 if is_publisher or str(self.node).endswith(unicode(self._blog_panel.host.whoami.bare)):
170 self.delete_label = addIcon(u"✗", "Delete this message") 170 self.delete_label = addIcon(u"✗", "Delete this message")
171 171
172 def updateAvatar(self, new_avatar): 172 def updateAvatar(self, new_avatar):
173 """Change the avatar of the entry 173 """Change the avatar of the entry
174 @param new_avatar: path to the new image""" 174 @param new_avatar: path to the new image"""
372 self.comments = {} 372 self.comments = {}
373 self.selected_entry = None 373 self.selected_entry = None
374 self.vpanel = VerticalPanel() 374 self.vpanel = VerticalPanel()
375 self.vpanel.setStyleName('microblogPanel') 375 self.vpanel.setStyleName('microblogPanel')
376 self.setWidget(self.vpanel) 376 self.setWidget(self.vpanel)
377 host.addListener('avatar', self.onAvatarUpdate) 377
378 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword)
379 self.avatarListener = self.onAvatarUpdate
380 host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
378 381
379 def __str__(self): 382 def __str__(self):
380 return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile) 383 return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile)
381 384
382 @property 385 @property
383 def target(self): 386 def target(self):
384 return tuple(self.accepted_groups) 387 return tuple(self.accepted_groups)
385 388
386 def onDelete(self): 389 def onDelete(self):
387 quick_widgets.QuickWidget.onDelete(self) 390 quick_widgets.QuickWidget.onDelete(self)
388 self.host.removeListener('avatar', self.onAvatarUpdate) 391 self.host.removeListener('avatar', self.avatarListener)
389 392
390 def onAvatarUpdate(self, jid_, hash_, profile): 393 def onAvatarUpdate(self, jid_, hash_):
391 """Called on avatar update events 394 """Called on avatar update events
392 395
393 @param jid_: jid of the entity with updated avatar 396 @param jid_: jid of the entity with updated avatar
394 @param hash_: hash of the avatar 397 @param hash_: hash of the avatar
395 @param profile: should be C.PROF_KEY_NONE 398 """
396 """ 399 whoami = self.host.profiles[self.profile].whoami
397 whoami = self.host.profiles[self.profile].whoami.bare 400 if self.isJidAccepted(jid_) or jid_.bare == whoami.bare:
398 if self.isJidAccepted(jid_) or jid_.bare == whoami.bare:
399 self.updateValue('avatar', jid_, hash_) 401 self.updateValue('avatar', jid_, hash_)
400 402
401 def refresh(self): 403 def refresh(self):
402 """Refresh the display of this widget. If the unibox is disabled, 404 """Refresh the display of this widget. If the unibox is disabled,
403 display the 'New message' button or an empty bubble on top of the panel""" 405 display the 'New message' button or an empty bubble on top of the panel"""
565 @param mblog_entry: panels.MicroblogItem instance 567 @param mblog_entry: panels.MicroblogItem instance
566 """ 568 """
567 assert isinstance(sender, jid.JID) # FIXME temporary 569 assert isinstance(sender, jid.JID) # FIXME temporary
568 if (mblog_entry.type == "comment" 570 if (mblog_entry.type == "comment"
569 or self.isJidAccepted(sender) 571 or self.isJidAccepted(sender)
570 or (groups == None and sender == self.host.profiles[self.profile].whoami.bare) 572 or (groups is None and sender == self.host.profiles[self.profile].whoami.bare)
571 or (groups and groups.intersection(self.accepted_groups))): 573 or (groups and groups.intersection(self.accepted_groups))):
572 self.addEntry(mblog_entry) 574 self.addEntry(mblog_entry)
573 575
574 def addEntry(self, data, ignore_invalid=False): 576 def addEntry(self, data, ignore_invalid=False):
575 """Add an entry to the panel 577 """Add an entry to the panel
578 @return: the added entry, or None 580 @return: the added entry, or None
579 """ 581 """
580 _entry = MicroblogEntry(self, data) 582 _entry = MicroblogEntry(self, data)
581 if _entry.type == "comment": 583 if _entry.type == "comment":
582 comments_hash = (_entry.service, _entry.node) 584 comments_hash = (_entry.service, _entry.node)
583 if not comments_hash in self.comments: 585 if comments_hash not in self.comments:
584 # The comments node is not known in this panel 586 # The comments node is not known in this panel
585 return None 587 return None
586 parent = self.comments[comments_hash] 588 parent = self.comments[comments_hash]
587 parent_idx = self.vpanel.getWidgetIndex(parent) 589 parent_idx = self.vpanel.getWidgetIndex(parent)
588 # we find or create the panel where the comment must be inserted 590 # we find or create the panel where the comment must be inserted