comparison src/plugins/plugin_misc_groupblog.py @ 470:5c916b99d0f6

plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
author Goffi <goffi@goffi.org>
date Sun, 01 Apr 2012 19:48:31 +0200
parents 47af60767013
children 6cd04adddaea
comparison
equal deleted inserted replaced
469:db4c2b82bab6 470:5c916b99d0f6
165 165
166 self.initialise(profile_key).addCallback(initialised) 166 self.initialise(profile_key).addCallback(initialised)
167 167
168 168
169 169
170 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None): 170 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
171 """Get the last published microblogs 171 """Get the last published microblogs
172 @param pub_jid: jid of the publisher 172 @param pub_jid: jid of the publisher
173 @param max_items: how many microblogs we want to get 173 @param max_items: how many microblogs we want to get
174 @param profile_key: profile key 174 @param profile_key: profile key
175 @param callback: used for the async answer 175 @param callback: used for the async answer
178 178
179 def initialised(result): 179 def initialised(result):
180 profile, client = result 180 profile, client = result
181 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(), 181 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
182 max_items=max_items, profile_key=profile_key) 182 max_items=max_items, profile_key=profile_key)
183 d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback) 183 d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items))
184 184
185 assert(callback)
186 self.initialise(profile_key).addCallback(initialised) 185 self.initialise(profile_key).addCallback(initialised)
187 #TODO: we need to use the server corresponding the the host of the jid 186 #TODO: we need to use the server corresponding the the host of the jid
188 187
189 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None): 188 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@'):
190 """Get the last published microblogs for a list of groups or jids 189 """Get the last published microblogs for a list of groups or jids
191 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") 190 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
192 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) 191 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
193 @param max_items: how many microblogs we want to get 192 @param max_items: how many microblogs we want to get
194 @param profile_key: profile key 193 @param profile_key: profile key
195 @param callback: used for the async answer
196 @param errback: used for the async answer
197 """ 194 """
198 def sendResult(result): 195 def sendResult(result):
199 """send result of DeferredList (list of microblogs to the calling method""" 196 """send result of DeferredList (list of microblogs to the calling method"""
200 197
201 ret = {} 198 ret = {}
203 for (success, value) in result: 200 for (success, value) in result:
204 if success: 201 if success:
205 source_jid, data = value 202 source_jid, data = value
206 ret[source_jid] = data 203 ret[source_jid] = data
207 204
208 callback(ret) 205 return ret
209 206
210 def initialised(result): 207 def initialised(result):
211 profile, client = result 208 profile, client = result
212 209
213 if publishers_type == "ALL": 210 if publishers_type == "ALL":
214 contacts = client.roster.getItems() 211 contacts = client.roster.getItems()
215 print "contacts:", contacts
216 jids = [contact.jid.userhost() for contact in contacts] 212 jids = [contact.jid.userhost() for contact in contacts]
217 print "jids:", jids
218 mblogs = [] 213 mblogs = []
219 for _jid in jids: 214 for _jid in jids:
220 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(_jid).userhost(), 215 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(_jid).userhost(),
221 max_items=max_items, profile_key=profile_key) 216 max_items=max_items, profile_key=profile_key)
222 #TODO: check empty result (nothing published so far)
223 d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid) 217 d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
224 mblogs.append(d) 218 mblogs.append(d)
225 dlist = defer.DeferredList(mblogs) 219 dlist = defer.DeferredList(mblogs)
226 dlist.addCallback(sendResult) 220 dlist.addCallback(sendResult)
227 221 return dlist
228 #d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(), 222
229 # max_items=max_items, profile_key=profile_key) 223 return defer.fail("Unknown type")
230 #d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback) 224
231 225
232 assert(callback)
233 #TODO: custom exception 226 #TODO: custom exception
234 if publishers_type not in ["GROUP", "JID", "ALL"]: 227 if publishers_type not in ["GROUP", "JID", "ALL"]:
235 raise Exception("Bad call, unknown publishers_type") 228 raise Exception("Bad call, unknown publishers_type")
236 if publishers_type=="ALL" and publishers: 229 if publishers_type=="ALL" and publishers:
237 raise Exception("Publishers list must be empty when getting microblogs for all contacts") 230 raise Exception("Publishers list must be empty when getting microblogs for all contacts")