Mercurial > libervia-backend
comparison src/plugins/plugin_misc_groupblog.py @ 310:53adec87d1d7
plugin group blog: group blog subscription
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 11 Apr 2011 12:47:35 +0200 |
parents | ce3607b7198d |
children | 0aa6ca6cdbdd |
comparison
equal
deleted
inserted
replaced
309:f1a3db8ee04a | 310:53adec87d1d7 |
---|---|
32 import uuid | 32 import uuid |
33 from time import time | 33 from time import time |
34 | 34 |
35 MBLOG_COLLECTION = 'MBLOGCOLLECTION' | 35 MBLOG_COLLECTION = 'MBLOGCOLLECTION' |
36 CONFIG_NODE = 'CONFIG' | 36 CONFIG_NODE = 'CONFIG' |
37 NS_ACCESS_MODEL = 'pubsub#access_model' | 37 OPT_ACCESS_MODEL = 'pubsub#access_model' |
38 NS_PERSIST_ITEMS = 'pubsub#persist_items' | 38 OPT_PERSIST_ITEMS = 'pubsub#persist_items' |
39 NS_MAX_ITEMS = 'pubsub#max_items' | 39 OPT_MAX_ITEMS = 'pubsub#max_items' |
40 NS_NODE_TYPE = 'pubsub#node_type' | 40 OPT_NODE_TYPE = 'pubsub#node_type' |
41 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type' | |
42 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth' | |
41 TYPE_COLLECTION = 'collection' | 43 TYPE_COLLECTION = 'collection' |
42 | 44 |
43 PLUGIN_INFO = { | 45 PLUGIN_INFO = { |
44 "name": "Group blogging throught collections", | 46 "name": "Group blogging throught collections", |
45 "import_name": "groupblog", | 47 "import_name": "groupblog", |
82 method=self.sendGroupBlog, | 84 method=self.sendGroupBlog, |
83 doc = { 'summary':"Send a microblog to a list of groups", | 85 doc = { 'summary':"Send a microblog to a list of groups", |
84 'param_0':'list of groups which can read the microblog', | 86 'param_0':'list of groups which can read the microblog', |
85 'param_1':'text to send', | 87 'param_1':'text to send', |
86 'param_2':'%(doc_profile)s' | 88 'param_2':'%(doc_profile)s' |
89 }) | |
90 | |
91 host.bridge.addMethod("subscribeGroupBlog", ".communication", in_sign='ss', out_sign='', | |
92 method=self.subscribeGroupBlog, | |
93 doc = { 'summary':"Subscribe to the group blog of somebody", | |
94 'param_0':'jid of the group node published', | |
95 'param_1':'%(doc_profile)s' | |
87 }) | 96 }) |
88 | 97 |
89 def _getRootNode(self, entity): | 98 def _getRootNode(self, entity): |
90 return "%(entity)s_%(root_suff)s" % {'entity':entity.userhost(), 'root_suff':MBLOG_COLLECTION} | 99 return "%(entity)s_%(root_suff)s" % {'entity':entity.userhost(), 'root_suff':MBLOG_COLLECTION} |
91 | 100 |
103 callback(self._blog_nodes[profile]) | 112 callback(self._blog_nodes[profile]) |
104 | 113 |
105 def _configNodeFail(self, failure, errback): | 114 def _configNodeFail(self, failure, errback): |
106 import pdb | 115 import pdb |
107 pdb.set_trace() | 116 pdb.set_trace() |
108 errback() #FIXME | 117 errback("") #FIXME |
109 | 118 |
110 def _configNodeErr(self, failure, user_jid, pubsub_ent, callback, errback, profile): | 119 def _configNodeErr(self, failure, user_jid, pubsub_ent, callback, errback, profile): |
111 if failure.value.condition == 'item-not-found': | 120 if failure.value.condition == 'item-not-found': |
112 debug(_('Multiblog config node not found, creating it')) | 121 debug(_('Multiblog config node not found, creating it')) |
113 _options = {NS_ACCESS_MODEL:"whitelist", NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1} | 122 _options = {OPT_ACCESS_MODEL:"whitelist", OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1} |
114 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getConfigNode(user_jid), _options, profile_key=profile) | 123 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getConfigNode(user_jid), _options, profile_key=profile) |
115 d.addCallback(self._configNodeCb, callback, profile) | 124 d.addCallback(lambda result: self._configNodeCb([] , callback, profile)) |
116 d.addErrback(self._configNodeFail, errback) | 125 d.addErrback(self._configNodeFail, errback) |
117 else: | 126 else: |
118 self._configNodeFail(failure, errback) | 127 self._configNodeFail(failure, errback) |
119 | 128 |
120 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): | 129 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): |
185 def err_creating_root_node(failure): | 194 def err_creating_root_node(failure): |
186 msg = _("Can't create Root node") | 195 msg = _("Can't create Root node") |
187 error(msg) | 196 error(msg) |
188 raise NodeCreationError(msg) | 197 raise NodeCreationError(msg) |
189 | 198 |
190 _options = {NS_NODE_TYPE:TYPE_COLLECTION} | 199 _options = {OPT_NODE_TYPE:TYPE_COLLECTION} |
191 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getRootNode(user_jid), _options, profile_key=profile) | 200 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getRootNode(user_jid), _options, profile_key=profile) |
192 d.addCallback(self._createNode, name, user_jid, groups, pubsub_ent, message, profile) | 201 d.addCallback(self._createNode, name, user_jid, groups, pubsub_ent, message, profile) |
193 d.addErrback(err_creating_root_node) | 202 d.addErrback(err_creating_root_node) |
194 else: | 203 else: |
195 import pdb | 204 import pdb |
202 @param user_jid: jid of the user creating the node | 211 @param user_jid: jid of the user creating the node |
203 @param groups: list of group than can subscribe to the node | 212 @param groups: list of group than can subscribe to the node |
204 @param pubsub_ent: publish/subscribe service's entity | 213 @param pubsub_ent: publish/subscribe service's entity |
205 @param message: message to publish | 214 @param message: message to publish |
206 @param profile: profile of the user creating the node""" | 215 @param profile: profile of the user creating the node""" |
207 _options = {NS_ACCESS_MODEL:"roster", NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1, | 216 _options = {OPT_ACCESS_MODEL:"roster", OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1, |
208 'pubsub#node_type':'leaf', 'pubsub#collection':self._getRootNode(user_jid), | 217 'pubsub#node_type':'leaf', 'pubsub#collection':self._getRootNode(user_jid), |
209 'pubsub#roster_groups_allowed':groups} | 218 'pubsub#roster_groups_allowed':groups} |
210 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, name, _options, profile_key=profile) | 219 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, name, _options, profile_key=profile) |
211 d.addCallback(self._groupNodeCreated, groups, name, message, user_jid, pubsub_ent, profile) | 220 d.addCallback(self._groupNodeCreated, groups, name, message, user_jid, pubsub_ent, profile) |
212 d.addErrback(self._nodeCreationFailed, name, user_jid, groups, pubsub_ent, message, profile) | 221 d.addErrback(self._nodeCreationFailed, name, user_jid, groups, pubsub_ent, message, profile) |
291 if not client: | 300 if not client: |
292 error(_('No client for this profile key: %s') % profile_key) | 301 error(_('No client for this profile key: %s') % profile_key) |
293 return | 302 return |
294 client.client_initialized.addCallback(after_init) | 303 client.client_initialized.addCallback(after_init) |
295 | 304 |
305 def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT@'): | |
306 debug(_('subscribing mblog nodes')) | |
307 _pub_jid = jid.JID(pub_jid) | |
308 profile = self.host.memory.getProfileName(profile_key) | |
309 if not profile: | |
310 error(_("Unknown profile")) | |
311 return | |
312 | |
313 def after_init(ignore): | |
314 pubsub_ent = self.host.memory.getServerServiceEntity("pubsub", "service", profile) | |
315 _options = {OPT_SUBSCRIPTION_TYPE:'items', OPT_SUBSCRIPTION_DEPTH:'1'} | |
316 d = self.host.plugins["XEP-0060"].subscribe(pubsub_ent, self._getRootNode(_pub_jid), options = _options, profile_key=profile) | |
317 d.addCallback(lambda x: debug(_("%(publisher)s's group node subscribed [%(profile)s]") % {'publisher':_pub_jid.userhost(), 'profile': profile})) | |
318 d.addErrback(lambda x: error(_("Can't subscribe group node [%(profile)s]") % {'profile': profile})) | |
319 | |
320 client = self.host.getClient(profile) | |
321 if not client: | |
322 error(_('No client for this profile key: %s') % profile_key) | |
323 return | |
324 client.client_initialized.addCallback(after_init) |