Fix the last pylint error (do not set the roster contact filter to None)
This commit is contained in:
parent
858e333279
commit
cee802b6ef
3 changed files with 18 additions and 12 deletions
|
@ -21,21 +21,22 @@ from datetime import datetime
|
|||
from poezio.common import safeJID
|
||||
from slixmpp.exceptions import IqError, IqTimeout
|
||||
|
||||
|
||||
class Roster(object):
|
||||
"""
|
||||
The proxy class to get the roster from slixmpp.
|
||||
Caches Contact and RosterGroup objects.
|
||||
"""
|
||||
|
||||
DEFAULT_FILTER = (lambda x, y: None, None)
|
||||
def __init__(self):
|
||||
"""
|
||||
node: the RosterSingle from slixmpp
|
||||
"""
|
||||
self.__node = None
|
||||
self.contact_filter = None # A tuple(function, *args)
|
||||
# function to filter contacts,
|
||||
# on search, for example
|
||||
|
||||
# A tuple(function, *args) function to filter contacts
|
||||
# on search, for example
|
||||
self.contact_filter = self.DEFAULT_FILTER
|
||||
self.folded_groups = set(config.get('folded_roster_groups',
|
||||
section='var').split(':'))
|
||||
self.groups = {}
|
||||
|
@ -170,7 +171,7 @@ class Roster(object):
|
|||
contact_list = []
|
||||
for contact in self.get_contacts():
|
||||
if contact.bare_jid != self.jid:
|
||||
if self.contact_filter:
|
||||
if self.contact_filter is not self.DEFAULT_FILTER:
|
||||
if self.contact_filter[0](contact, self.contact_filter[1]):
|
||||
contact_list.append(contact)
|
||||
else:
|
||||
|
@ -297,8 +298,13 @@ class RosterGroup(object):
|
|||
|
||||
def get_contacts(self, contact_filter=None, sort=''):
|
||||
"""Return the group contacts, filtered and sorted"""
|
||||
contact_list = self.contacts.copy() if not contact_filter\
|
||||
else [contact for contact in self.contacts.copy() if contact_filter[0](contact, contact_filter[1])]
|
||||
if contact_filter is Roster.DEFAULT_FILTER or contact_filter is None:
|
||||
contact_list = self.contacts.copy()
|
||||
else:
|
||||
contact_list = [contact
|
||||
for contact in self.contacts.copy()
|
||||
if contact_filter[0](contact, contact_filter[1])
|
||||
]
|
||||
contact_list = sorted(contact_list, key=SORTING_METHODS['name'])
|
||||
|
||||
for sorting in sort.split(':'):
|
||||
|
|
|
@ -1239,7 +1239,7 @@ class RosterInfoTab(Tab):
|
|||
@refresh_wrapper.always
|
||||
def on_search_terminate(self, txt):
|
||||
curses.curs_set(0)
|
||||
roster.contact_filter = None
|
||||
roster.contact_filter = roster.DEFAULT_FILTER
|
||||
self.reset_help_message()
|
||||
roster.modified()
|
||||
return True
|
||||
|
|
|
@ -93,25 +93,25 @@ class RosterWin(Win):
|
|||
return
|
||||
log.debug('The roster has changed, rebuilding the cache…')
|
||||
# This is a search
|
||||
if roster.contact_filter:
|
||||
if roster.contact_filter is not roster.DEFAULT_FILTER:
|
||||
self.roster_cache = []
|
||||
sort = config.get('roster_sort', 'jid:show') or 'jid:show'
|
||||
for contact in roster.get_contacts_sorted_filtered(sort):
|
||||
self.roster_cache.append(contact)
|
||||
else:
|
||||
show_offline = config.get('roster_show_offline') or roster.contact_filter
|
||||
show_offline = config.get('roster_show_offline')
|
||||
sort = config.get('roster_sort') or 'jid:show'
|
||||
group_sort = config.get('roster_group_sort') or 'name'
|
||||
self.roster_cache = []
|
||||
# build the cache
|
||||
for group in roster.get_groups(group_sort):
|
||||
contacts_filtered = group.get_contacts(roster.contact_filter)
|
||||
contacts_filtered = group.get_contacts()
|
||||
if (not show_offline and group.get_nb_connected_contacts() == 0) or not contacts_filtered:
|
||||
continue # Ignore empty groups
|
||||
self.roster_cache.append(group)
|
||||
if group.folded:
|
||||
continue # ignore folded groups
|
||||
for contact in group.get_contacts(roster.contact_filter, sort):
|
||||
for contact in group.get_contacts(sort=sort):
|
||||
if not show_offline and len(contact) == 0:
|
||||
continue # ignore offline contacts
|
||||
self.roster_cache.append(contact)
|
||||
|
|
Loading…
Reference in a new issue