plugin group blog: group blog subscription
This commit is contained in:
parent
d7402734e6
commit
3728cc251b
1 changed files with 46 additions and 13 deletions
|
|
@ -34,10 +34,12 @@ from time import time
|
|||
|
||||
MBLOG_COLLECTION = 'MBLOGCOLLECTION'
|
||||
CONFIG_NODE = 'CONFIG'
|
||||
NS_ACCESS_MODEL = 'pubsub#access_model'
|
||||
NS_PERSIST_ITEMS = 'pubsub#persist_items'
|
||||
NS_MAX_ITEMS = 'pubsub#max_items'
|
||||
NS_NODE_TYPE = 'pubsub#node_type'
|
||||
OPT_ACCESS_MODEL = 'pubsub#access_model'
|
||||
OPT_PERSIST_ITEMS = 'pubsub#persist_items'
|
||||
OPT_MAX_ITEMS = 'pubsub#max_items'
|
||||
OPT_NODE_TYPE = 'pubsub#node_type'
|
||||
OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type'
|
||||
OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
|
||||
TYPE_COLLECTION = 'collection'
|
||||
|
||||
PLUGIN_INFO = {
|
||||
|
|
@ -85,6 +87,13 @@ class GroupBlog():
|
|||
'param_1':'text to send',
|
||||
'param_2':'%(doc_profile)s'
|
||||
})
|
||||
|
||||
host.bridge.addMethod("subscribeGroupBlog", ".communication", in_sign='ss', out_sign='',
|
||||
method=self.subscribeGroupBlog,
|
||||
doc = { 'summary':"Subscribe to the group blog of somebody",
|
||||
'param_0':'jid of the group node published',
|
||||
'param_1':'%(doc_profile)s'
|
||||
})
|
||||
|
||||
def _getRootNode(self, entity):
|
||||
return "%(entity)s_%(root_suff)s" % {'entity':entity.userhost(), 'root_suff':MBLOG_COLLECTION}
|
||||
|
|
@ -105,14 +114,14 @@ class GroupBlog():
|
|||
def _configNodeFail(self, failure, errback):
|
||||
import pdb
|
||||
pdb.set_trace()
|
||||
errback() #FIXME
|
||||
errback("") #FIXME
|
||||
|
||||
def _configNodeErr(self, failure, user_jid, pubsub_ent, callback, errback, profile):
|
||||
if failure.value.condition == 'item-not-found':
|
||||
debug(_('Multiblog config node not found, creating it'))
|
||||
_options = {NS_ACCESS_MODEL:"whitelist", NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1}
|
||||
_options = {OPT_ACCESS_MODEL:"whitelist", OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1}
|
||||
d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getConfigNode(user_jid), _options, profile_key=profile)
|
||||
d.addCallback(self._configNodeCb, callback, profile)
|
||||
d.addCallback(lambda result: self._configNodeCb([] , callback, profile))
|
||||
d.addErrback(self._configNodeFail, errback)
|
||||
else:
|
||||
self._configNodeFail(failure, errback)
|
||||
|
|
@ -187,7 +196,7 @@ class GroupBlog():
|
|||
error(msg)
|
||||
raise NodeCreationError(msg)
|
||||
|
||||
_options = {NS_NODE_TYPE:TYPE_COLLECTION}
|
||||
_options = {OPT_NODE_TYPE:TYPE_COLLECTION}
|
||||
d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getRootNode(user_jid), _options, profile_key=profile)
|
||||
d.addCallback(self._createNode, name, user_jid, groups, pubsub_ent, message, profile)
|
||||
d.addErrback(err_creating_root_node)
|
||||
|
|
@ -204,7 +213,7 @@ class GroupBlog():
|
|||
@param pubsub_ent: publish/subscribe service's entity
|
||||
@param message: message to publish
|
||||
@param profile: profile of the user creating the node"""
|
||||
_options = {NS_ACCESS_MODEL:"roster", NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1,
|
||||
_options = {OPT_ACCESS_MODEL:"roster", OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1,
|
||||
'pubsub#node_type':'leaf', 'pubsub#collection':self._getRootNode(user_jid),
|
||||
'pubsub#roster_groups_allowed':groups}
|
||||
d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, name, _options, profile_key=profile)
|
||||
|
|
@ -293,3 +302,23 @@ class GroupBlog():
|
|||
return
|
||||
client.client_initialized.addCallback(after_init)
|
||||
|
||||
def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT@'):
|
||||
debug(_('subscribing mblog nodes'))
|
||||
_pub_jid = jid.JID(pub_jid)
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Unknown profile"))
|
||||
return
|
||||
|
||||
def after_init(ignore):
|
||||
pubsub_ent = self.host.memory.getServerServiceEntity("pubsub", "service", profile)
|
||||
_options = {OPT_SUBSCRIPTION_TYPE:'items', OPT_SUBSCRIPTION_DEPTH:'1'}
|
||||
d = self.host.plugins["XEP-0060"].subscribe(pubsub_ent, self._getRootNode(_pub_jid), options = _options, profile_key=profile)
|
||||
d.addCallback(lambda x: debug(_("%(publisher)s's group node subscribed [%(profile)s]") % {'publisher':_pub_jid.userhost(), 'profile': profile}))
|
||||
d.addErrback(lambda x: error(_("Can't subscribe group node [%(profile)s]") % {'profile': profile}))
|
||||
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
error(_('No client for this profile key: %s') % profile_key)
|
||||
return
|
||||
client.client_initialized.addCallback(after_init)
|
||||
|
|
|
|||
Loading…
Reference in a new issue