# HG changeset patch # User Goffi # Date 1301522476 -7200 # Node ID 0110d4e1d816485e710c5f831ba79b1cc9d02774 # Parent 513fe9bd06658b5f3554473853207ac220457a8e microblog panel filtering diff -r 513fe9bd0665 -r 0110d4e1d816 contact.py --- a/contact.py Sat Mar 26 17:53:50 2011 +0100 +++ b/contact.py Thu Mar 31 00:01:16 2011 +0200 @@ -29,6 +29,7 @@ from pyjamas.dnd import makeDraggable from pyjamas.ui.DragWidget import DragWidget, DragContainer +from tools.jid import JID class GroupLabel(DragWidget, Label): def __init__(self, group): @@ -42,6 +43,7 @@ dt = event.dataTransfer #self.addMessage('types is %s' % dt.getTypes()) dt.setData('Text', self.group) + dt.setData('type', "GROUP") #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) #self.addMessage('types is %s' % dt.getTypes()) dt.setDragImage(self.getElement(), 15, 15) @@ -131,6 +133,18 @@ self.groups[group].add(jid) self._contactList.add(jid) + def isContactInGroup(self, group, contact_jid): + """Test if the contact_jid is in the group + @param group: string of single group, or list of string + @param contact_jid: jid to test + @return: True if contact_jid is in on of the groups""" + print "isContactInGroup: %s, %s" % (group, contact_jid) + print JID(contact_jid) + print self.groups[group] + if self.groups.has_key(group) and contact_jid in self.groups[group]: + return True + return False + def onMouseMove(self, sender, x, y): pass diff -r 513fe9bd0665 -r 0110d4e1d816 libervia.py --- 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') diff -r 513fe9bd0665 -r 0110d4e1d816 tools/__init__.py diff -r 513fe9bd0665 -r 0110d4e1d816 tools/jid.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/jid.py Thu Mar 31 00:01:16 2011 +0200 @@ -0,0 +1,50 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +Libervia: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +""" + + + +class JID(str): + """This class help manage JID (Node@Domaine/Resource)""" + + def __init__(self, jid): + str.__init__(self, jid) + self.__parse() + + def __parse(self): + """find node domaine and resource""" + node_end=self.find('@') + if node_end<0: + node_end=0 + domain_end=self.find('/') + if domain_end<1: + domain_end=len(self) + self.node=self[:node_end] + self.domain=self[(node_end+1) if node_end else 0:domain_end] + self.resource=self[domain_end+1:] + if not node_end: + self.short=self + else: + self.short=self.node+'@'+self.domain + + def is_valid(self): + """return True if the jid is xmpp compliant""" + #FIXME: always return True for the moment + return True