-def create_contact_list_channel(connection, h):
- if h.get_name() == 'subscribe':
- # The group of contacts for whom you receive presence
- ChannelClass = AllContactsListChannel
- elif h.get_name() == 'publish':
- # The group of contacts who may receive your presence
- ChannelClass = AllContactsListChannel
- elif h.get_name() == 'hide':
- # A group of contacts who are on the publish list but are temporarily
- # disallowed from receiving your presence
- # This doesn't make sense to support
- _moduleLogger.warn("Unsuported type %s" % h.get_name())
- elif h.get_name() == 'allow':
- # A group of contacts who may send you messages
- # @todo Allow-List would be cool to support
- _moduleLogger.warn("Unsuported type %s" % h.get_name())
- elif h.get_name() == 'deny':
- # A group of contacts who may not send you messages
- # @todo Deny-List would be cool to support
- _moduleLogger.warn("Unsuported type %s" % h.get_name())
- elif h.get_name() == 'stored':
- # On protocols where the user's contacts are stored, this contact list
- # contains all stored contacts regardless of subscription status.
- ChannelClass = AllContactsListChannel
- else:
- raise TypeError("Unknown list type : " + h.get_name())
- return ChannelClass(connection, h)
+class DenyContactsListChannel(AllContactsListChannel):
+
+ def _is_on_list(self, number):
+ return self._conn.session.addressbook.is_blocked(number)
+
+
+_LIST_TO_FACTORY = {
+ # The group of contacts for whom you receive presence
+ 'subscribe': AllContactsListChannel,
+ # The group of contacts who may receive your presence
+ 'publish': AllContactsListChannel,
+ # A group of contacts who are on the publish list but are temporarily
+ # disallowed from receiving your presence
+ # This doesn't make sense to support
+ 'hide': None,
+ # A group of contacts who may send you messages
+ # Is this meant to serve as a definitive white list for all contact?
+ 'allow': None,
+ # A group of contacts who may not send you messages
+ 'deny': DenyContactsListChannel,
+ # On protocols where the user's contacts are stored, this contact list
+ # contains all stored contacts regardless of subscription status.
+ 'stored': AllContactsListChannel,
+}
+
+
+_SUPPORTED_LISTS = frozenset(
+ name
+ for name in _LIST_TO_FACTORY.iterkeys()
+ if name is not None
+)
+
+
+def create_contact_list_channel(connection, manager, props, h):
+ factory = _LIST_TO_FACTORY.get(h.get_name(), None)
+ if factory is None:
+ raise telepathy.errors.NotCapable("Unsuported type %s" % h.get_name())
+ return factory(connection, manager, props, h)