plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
This commit is contained in:
parent
bb0f290924
commit
723b468fcc
3 changed files with 19 additions and 20 deletions
|
|
@ -170,8 +170,8 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
def getRoomsJoined(self, profile_key):
|
def getRoomsJoined(self, profile_key):
|
||||||
return self.db_plugin_iface.getRoomsJoined(profile_key)
|
return self.db_plugin_iface.getRoomsJoined(profile_key)
|
||||||
|
|
||||||
def getRoomsSubjectss(self, profile_key):
|
def getRoomsSubjects(self, profile_key):
|
||||||
return self.db_plugin_iface.getRoomsSubjectss(profile_key)
|
return self.db_plugin_iface.getRoomsSubjects(profile_key)
|
||||||
|
|
||||||
def joinMUC(self, room_jid, nick, options, profile_key):
|
def joinMUC(self, room_jid, nick, options, profile_key):
|
||||||
if options == None:
|
if options == None:
|
||||||
|
|
@ -243,12 +243,15 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||||
return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||||
|
|
||||||
def getMblogNodes(self, profile_key, callback=None, errback=None):
|
|
||||||
return self.db_plugin_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback)
|
|
||||||
|
|
||||||
def sendGroupBlog(self, groups, message, profile_key):
|
def sendGroupBlog(self, groups, message, profile_key):
|
||||||
return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key)
|
return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key)
|
||||||
|
|
||||||
|
def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||||
|
return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||||
|
|
||||||
|
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||||
|
return self.db_plugin_iface.getMassiveLastGroupBlogs(publishers_type, publishers, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||||
|
|
||||||
def sendPersonalEvent(self, event_type, data, profile_key):
|
def sendPersonalEvent(self, event_type, data, profile_key):
|
||||||
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
|
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,9 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
|
||||||
return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||||
|
|
||||||
|
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
|
||||||
|
return self.db_plugin_iface.getMassiveLastGroupBlogs(publishers_type, publishers, max_items, profile_key, reply_handler=callback, error_handler=errback)
|
||||||
|
|
||||||
def sendPersonalEvent(self, event_type, data, profile_key):
|
def sendPersonalEvent(self, event_type, data, profile_key):
|
||||||
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
|
return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ class GroupBlog():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
|
def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
|
||||||
"""Get the last published microblogs
|
"""Get the last published microblogs
|
||||||
@param pub_jid: jid of the publisher
|
@param pub_jid: jid of the publisher
|
||||||
@param max_items: how many microblogs we want to get
|
@param max_items: how many microblogs we want to get
|
||||||
|
|
@ -180,20 +180,17 @@ class GroupBlog():
|
||||||
profile, client = result
|
profile, client = result
|
||||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
|
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
|
||||||
max_items=max_items, profile_key=profile_key)
|
max_items=max_items, profile_key=profile_key)
|
||||||
d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback)
|
d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items))
|
||||||
|
|
||||||
assert(callback)
|
|
||||||
self.initialise(profile_key).addCallback(initialised)
|
self.initialise(profile_key).addCallback(initialised)
|
||||||
#TODO: we need to use the server corresponding the the host of the jid
|
#TODO: we need to use the server corresponding the the host of the jid
|
||||||
|
|
||||||
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
|
def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@'):
|
||||||
"""Get the last published microblogs for a list of groups or jids
|
"""Get the last published microblogs for a list of groups or jids
|
||||||
@param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
@param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
|
||||||
@param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
|
@param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
|
||||||
@param max_items: how many microblogs we want to get
|
@param max_items: how many microblogs we want to get
|
||||||
@param profile_key: profile key
|
@param profile_key: profile key
|
||||||
@param callback: used for the async answer
|
|
||||||
@param errback: used for the async answer
|
|
||||||
"""
|
"""
|
||||||
def sendResult(result):
|
def sendResult(result):
|
||||||
"""send result of DeferredList (list of microblogs to the calling method"""
|
"""send result of DeferredList (list of microblogs to the calling method"""
|
||||||
|
|
@ -205,31 +202,27 @@ class GroupBlog():
|
||||||
source_jid, data = value
|
source_jid, data = value
|
||||||
ret[source_jid] = data
|
ret[source_jid] = data
|
||||||
|
|
||||||
callback(ret)
|
return ret
|
||||||
|
|
||||||
def initialised(result):
|
def initialised(result):
|
||||||
profile, client = result
|
profile, client = result
|
||||||
|
|
||||||
if publishers_type == "ALL":
|
if publishers_type == "ALL":
|
||||||
contacts = client.roster.getItems()
|
contacts = client.roster.getItems()
|
||||||
print "contacts:", contacts
|
|
||||||
jids = [contact.jid.userhost() for contact in contacts]
|
jids = [contact.jid.userhost() for contact in contacts]
|
||||||
print "jids:", jids
|
|
||||||
mblogs = []
|
mblogs = []
|
||||||
for _jid in jids:
|
for _jid in jids:
|
||||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(_jid).userhost(),
|
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(_jid).userhost(),
|
||||||
max_items=max_items, profile_key=profile_key)
|
max_items=max_items, profile_key=profile_key)
|
||||||
#TODO: check empty result (nothing published so far)
|
|
||||||
d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
|
d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
|
||||||
mblogs.append(d)
|
mblogs.append(d)
|
||||||
dlist = defer.DeferredList(mblogs)
|
dlist = defer.DeferredList(mblogs)
|
||||||
dlist.addCallback(sendResult)
|
dlist.addCallback(sendResult)
|
||||||
|
return dlist
|
||||||
|
|
||||||
|
return defer.fail("Unknown type")
|
||||||
|
|
||||||
#d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
|
|
||||||
# max_items=max_items, profile_key=profile_key)
|
|
||||||
#d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback)
|
|
||||||
|
|
||||||
assert(callback)
|
|
||||||
#TODO: custom exception
|
#TODO: custom exception
|
||||||
if publishers_type not in ["GROUP", "JID", "ALL"]:
|
if publishers_type not in ["GROUP", "JID", "ALL"]:
|
||||||
raise Exception("Bad call, unknown publishers_type")
|
raise Exception("Bad call, unknown publishers_type")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue