comparison src/plugins/plugin_xep_0060.py @ 891:a7b2aacf22ac

plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
author souliane <souliane@mailoo.org>
date Tue, 25 Feb 2014 17:49:15 +0100
parents 1fe00f0c9a91
children 1a759096ccbd
comparison
equal deleted inserted replaced
890:10bb8574ab11 891:a7b2aacf22ac
97 97
98 def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'): 98 def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'):
99 profile, client = self.__getClientNProfile(profile_key, 'publish item') 99 profile, client = self.__getClientNProfile(profile_key, 'publish item')
100 return client.publish(service, nodeIdentifier, items, client.parent.jid) 100 return client.publish(service, nodeIdentifier, items, client.parent.jid)
101 101
102 def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'): 102 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, profile_key='@DEFAULT@'):
103 profile, client = self.__getClientNProfile(profile_key, 'get items') 103 profile, client = self.__getClientNProfile(profile_key, 'get items')
104 return client.items(service, node, max_items, sub_id, client.parent.jid) 104 return client.items(service, node, max_items, item_ids, sub_id, client.parent.jid)
105 105
106 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key='@DEFAULT@'): 106 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key='@DEFAULT@'):
107 profile, client = self.__getClientNProfile(profile_key, 'get options') 107 profile, client = self.__getClientNProfile(profile_key, 'get options')
108 return client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier) 108 return client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier)
109 109
137 pubsub.PubSubClient.__init__(self) 137 pubsub.PubSubClient.__init__(self)
138 138
139 def connectionInitialized(self): 139 def connectionInitialized(self):
140 pubsub.PubSubClient.connectionInitialized(self) 140 pubsub.PubSubClient.connectionInitialized(self)
141 141
142 # XXX: this should be done in wokkel 142 # FIXME: we have to temporary override this method here just
143 # to set the attributes itemIdentifiers which is not used
144 # in pubsub.PubSubClient.items
145 def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None,
146 subscriptionIdentifier=None, sender=None):
147 """
148 Retrieve previously published items from a publish subscribe node.
149
150 @param service: The publish subscribe service that keeps the node.
151 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
152
153 @param nodeIdentifier: The identifier of the node.
154 @type nodeIdentifier: C{unicode}
155
156 @param maxItems: Optional limit on the number of retrieved items.
157 @type maxItems: C{int}
158
159 @param itemIdentifiers: Identifiers of the items to be retracted.
160 @type itemIdentifiers: C{set}
161
162 @param subscriptionIdentifier: Optional subscription identifier. In
163 case the node has been subscribed to multiple times, this narrows
164 the results to the specific subscription.
165 @type subscriptionIdentifier: C{unicode}
166 """
167 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
168
169 request = PubSubRequest('items')
170 request.recipient = service
171 request.nodeIdentifier = nodeIdentifier
172 if maxItems:
173 request.maxItems = str(int(maxItems))
174 request.subscriptionIdentifier = subscriptionIdentifier
175 request.sender = sender
176 request.itemIdentifiers = itemIdentifiers # XXX: this line has been added
177
178 def cb(iq):
179 items = []
180 for element in iq.pubsub.items.elements():
181 if element.uri == NS_PUBSUB and element.name == 'item':
182 items.append(element)
183 return items
184
185 d = request.send(self.xmlstream)
186 d.addCallback(cb)
187 return d
188
189 # FIXME: this should be done in wokkel
143 def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None): 190 def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None):
144 """ 191 """
145 Retract items from a publish subscribe node. 192 Retract items from a publish subscribe node.
146 193
147 @param service: The publish subscribe service to delete the node from. 194 @param service: The publish subscribe service to delete the node from.