Mercurial > libervia-web
diff libervia.py @ 13:0110d4e1d816
microblog panel filtering
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 31 Mar 2011 00:01:16 +0200 |
parents | 331c093e4eb3 |
children | 9bf8ed012adc |
line wrap: on
line diff
--- a/libervia.py Sat Mar 26 17:53:50 2011 +0100 +++ b/libervia.py Thu Mar 31 00:01:16 2011 +0200 @@ -166,12 +166,18 @@ #'text', 'text/plain', and 'Text' are equivalent. try: item = dt.getData("text/plain") + item_type = dt.getData("type") print "message: %s" % item + print "type: %s" % item_type except: print "no message found" item=' ' + item_type = None DOM.eventPreventDefault(event) - self.host.mpanels.insert(0,MicroblogPanel(item)) + _mblog = MicroblogPanel(self.host, item) + if item_type=="GROUP": + _mblog.setAcceptedGroup(item) + self.host.mpanels.insert(0,_mblog) self.host.middle_panel.changePanel(self.data,self.host.mpanels[0]) @@ -194,9 +200,12 @@ class MicroblogPanel(VerticalPanel): - def __init__(self,title=' '): + def __init__(self,host, title=' ', accept_all=False): + self.host = host + self.accept_all = accept_all title=title.replace('<','<').replace('>','>') VerticalPanel.__init__(self) + self.accepted_groups = [] _class = ['mb_panel_header'] if title == ' ': _class.append('empty_header') @@ -211,6 +220,27 @@ _entry = MicroblogEntry(text, author, timestamp) self.add(_entry) + def setAcceptedGroup(self, group): + """Set the group which can be displayed in this panel + @param group: string of the group, or list of string + """ + if isinstance(group, list): + self.accepted_groups.extend(group) + else: + self.accepted_groups.append(group) + + def isJidAccepted(self, jid): + """Tell if a jid is actepted and show in this panel + @param jid: jid + @return: True if the jid is accepted""" + if self.accept_all: + return True + for group in self.accepted_groups: + if self.host.contactPanel.isContactInGroup(group, jid): + return True + return False + + class MiddlePannel(HorizontalPanel): def __init__(self, host): @@ -268,7 +298,7 @@ self.contactPanel = ContactPanel(self) self.panel = MainPanel(self) self.middle_panel = self.panel.middle_panel - self.mpanels = [MicroblogPanel()] + self.mpanels = [MicroblogPanel(self, accept_all=True)] self.middle_panel.changePanel(1,self.mpanels[0]) self.middle_panel.changePanel(0,EmptyPanel(self, 0)) self.middle_panel.changePanel(2,EmptyPanel(self, 2)) @@ -321,7 +351,8 @@ print ("WARNING: No content found in microblog data") return for panel in self.mpanels: - if isinstance(panel,MicroblogPanel): + if isinstance(panel,MicroblogPanel) and panel.isJidAccepted(sender): + print "sender:",sender content = data['content'] author = data.get('author') print "timestamp: %s" % data.get('timestamp')