Ignore:
Timestamp:
Aug 30, 2016, 9:42:32 PM (6 years ago)
Author:
souliane <souliane@…>
Branch:
default
committer:
souliane <souliane@mailoo.org> 1472587266 -7200
hg-git-rename-source:
git
Message:

implement item retract + notification

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r166 r225  
    4040                    'pubsub[@xmlns="' + NS_PUBSUB + '" or ' + \
    4141                           '@xmlns="' + NS_PUBSUB_OWNER + '"]'
     42
     43BOOL_TRUE = ('1','true')
     44BOOL_FALSE = ('0','false')
    4245
    4346class SubscriptionPending(Exception):
     
    250253    subscriptions = None
    251254    affiliations = None
     255    notify = None
    252256
    253257    # Map request iq type and subelement name to request verb
     
    291295        'configureSet': ['nodeOrEmpty', 'configure'],
    292296        'items': ['node', 'maxItems', 'itemIdentifiers', 'subidOrNone'],
    293         'retract': ['node', 'itemIdentifiers'],
     297        'retract': ['node', 'notify', 'itemIdentifiers'],
    294298        'purge': ['node'],
    295299        'delete': ['node'],
     
    564568
    565569
     570    def _parse_notify(self, verbElement):
     571        value = verbElement.getAttribute('notify')
     572
     573        if value:
     574            if value in BOOL_TRUE:
     575                self.notify = True
     576            elif value in BOOL_FALSE:
     577                self.notify = False
     578            else:
     579                raise BadRequest(text="Field notify must be a boolean value")
     580
     581
     582    def _render_notify(self, verbElement):
     583        if self.notify is not None:
     584            verbElement['notify'] = "true" if self.notify else "false"
     585
     586
    566587    def parseElement(self, element):
    567588        """
     
    950971        return d
    951972
     973    def retractItems(self, service, nodeIdentifier, itemIdentifiers, notify=None, sender=None):
     974        """
     975        Retract items from a publish subscribe node.
     976
     977        @param service: The publish subscribe service to delete the node from.
     978        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
     979        @param nodeIdentifier: The identifier of the node.
     980        @type nodeIdentifier: C{unicode}
     981        @param itemIdentifiers: Identifiers of the items to be retracted.
     982        @type itemIdentifiers: C{set}
     983        @param notify: True if notification is required
     984        @type notify: C{unicode}
     985        """
     986        request = self._request_class('retract')
     987        request.recipient = service
     988        request.nodeIdentifier = nodeIdentifier
     989        request.itemIdentifiers = itemIdentifiers
     990        request.notify = notify
     991        request.sender = sender
     992        return request.send(self.xmlstream)
    952993
    953994    def getOptions(self, service, nodeIdentifier, subscriber,
     
    13731414
    13741415
     1416    def notifyRetract(self, service, nodeIdentifier, notifications):
     1417        for subscriber, subscriptions, items in notifications:
     1418            message = self._createNotification('items', service,
     1419                                               nodeIdentifier, subscriber,
     1420                                               subscriptions)
     1421            for item in items:
     1422                retract = domish.Element((None, "retract"))
     1423                retract['id'] = item['id']
     1424                message.event.items.addChild(retract)
     1425            self.send(message)
     1426
     1427
    13751428    def notifyDelete(self, service, nodeIdentifier, subscribers,
    13761429                           redirectURI=None):
Note: See TracChangeset for help on using the changeset viewer.