Mercurial > libervia-backend
annotate 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 |
rev | line source |
---|---|
307 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT plugin for microbloging with roster access | |
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from logging import debug, info, error | |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
23 from twisted.internet import protocol, defer |
307 | 24 from twisted.words.protocols.jabber import jid |
25 from twisted.words.protocols.jabber import error as jab_error | |
26 import twisted.internet.error | |
27 from twisted.words.xish import domish | |
28 from sat.tools.xml_tools import ElementParser | |
29 | |
30 from wokkel import disco,pubsub | |
31 from feed.atom import Entry, Author | |
32 import uuid | |
33 from time import time | |
34 | |
35 MBLOG_COLLECTION = 'MBLOGCOLLECTION' | |
36 CONFIG_NODE = 'CONFIG' | |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
37 OPT_ACCESS_MODEL = 'pubsub#access_model' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
38 OPT_PERSIST_ITEMS = 'pubsub#persist_items' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
39 OPT_MAX_ITEMS = 'pubsub#max_items' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
40 OPT_NODE_TYPE = 'pubsub#node_type' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
41 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
42 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth' |
307 | 43 TYPE_COLLECTION = 'collection' |
44 | |
45 PLUGIN_INFO = { | |
46 "name": "Group blogging throught collections", | |
47 "import_name": "groupblog", | |
48 "type": "MISC", | |
49 "protocols": [], | |
50 "dependencies": ["XEP-0277"], | |
51 "main": "GroupBlog", | |
52 "handler": "no", | |
53 "description": _("""Implementation of microblogging with roster access""") | |
54 } | |
55 | |
56 class NodeCreationError(Exception): | |
57 pass | |
58 | |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
59 class NodeDeletionError(Exception): |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
60 pass |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
61 |
307 | 62 class GroupBlog(): |
63 """This class use a PubSub Collection to manage roster access on microblog""" | |
64 | |
65 def __init__(self, host): | |
66 info(_("Group blog plugin initialization")) | |
67 self.host = host | |
68 self._blog_nodes={} | |
69 | |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
70 host.bridge.addMethod("cleanBlogCollection", ".communication", in_sign='s', out_sign='', |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
71 method=self.cleanBlogCollection, |
307 | 72 doc = { |
73 }) | |
74 | |
75 host.bridge.addMethod("getMblogNodes", ".communication", in_sign='s', out_sign='a{sas}', | |
76 method=self.getMblogNodes, | |
77 async = True, | |
78 doc = { 'summary':"retrieve mblog node, and their association with roster's groups", | |
79 'param_0':'%(doc_profile)s', | |
80 'return':'list of microblog data (dict)' | |
81 }) | |
82 | |
83 host.bridge.addMethod("sendGroupBlog", ".communication", in_sign='asss', out_sign='', | |
84 method=self.sendGroupBlog, | |
85 doc = { 'summary':"Send a microblog to a list of groups", | |
86 'param_0':'list of groups which can read the microblog', | |
87 'param_1':'text to send', | |
88 'param_2':'%(doc_profile)s' | |
89 }) | |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
90 |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
91 host.bridge.addMethod("subscribeGroupBlog", ".communication", in_sign='ss', out_sign='', |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
92 method=self.subscribeGroupBlog, |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
93 doc = { 'summary':"Subscribe to the group blog of somebody", |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
94 'param_0':'jid of the group node published', |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
95 'param_1':'%(doc_profile)s' |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
96 }) |
307 | 97 |
98 def _getRootNode(self, entity): | |
99 return "%(entity)s_%(root_suff)s" % {'entity':entity.userhost(), 'root_suff':MBLOG_COLLECTION} | |
100 | |
101 def _getConfigNode(self, entity): | |
102 return "%(entity)s_%(root_suff)s" % {'entity':entity.userhost(), 'root_suff':CONFIG_NODE} | |
103 | |
104 def _configNodeCb(self, result, callback, profile): | |
105 self._blog_nodes[profile] = {} | |
106 for item in result: | |
107 node_ass = item.firstChildElement() | |
108 assert(node_ass.name == "node_association") | |
109 node = node_ass['node'] | |
110 groups = [unicode(group) for group in node_ass.children] | |
111 self._blog_nodes[profile][node] = groups | |
112 callback(self._blog_nodes[profile]) | |
113 | |
114 def _configNodeFail(self, failure, errback): | |
115 import pdb | |
116 pdb.set_trace() | |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
117 errback("") #FIXME |
307 | 118 |
119 def _configNodeErr(self, failure, user_jid, pubsub_ent, callback, errback, profile): | |
120 if failure.value.condition == 'item-not-found': | |
121 debug(_('Multiblog config node not found, creating it')) | |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
122 _options = {OPT_ACCESS_MODEL:"whitelist", OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1} |
307 | 123 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getConfigNode(user_jid), _options, profile_key=profile) |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
124 d.addCallback(lambda result: self._configNodeCb([] , callback, profile)) |
307 | 125 d.addErrback(self._configNodeFail, errback) |
126 else: | |
127 self._configNodeFail(failure, errback) | |
128 | |
129 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): | |
130 debug(_('Getting mblog nodes')) | |
131 profile = self.host.memory.getProfileName(profile_key) | |
132 if not profile: | |
133 error(_("Unknown profile")) | |
134 return {} | |
135 | |
136 def after_init(ignore): | |
137 pubsub_ent = self.host.memory.getServerServiceEntity("pubsub", "service", profile) | |
138 _jid, xmlstream = self.host.getJidNStream(profile_key) | |
139 d = self.host.plugins["XEP-0060"].getItems(pubsub_ent, self._getConfigNode(_jid), profile_key=profile_key) | |
140 d.addCallbacks(self._configNodeCb, self._configNodeErr, callbackArgs=(callback, profile), errbackArgs=(_jid, pubsub_ent, callback, errback, profile)) | |
141 | |
142 client = self.host.getClient(profile) | |
143 if not client: | |
144 error(_('No client for this profile key: %s') % profile_key) | |
145 return | |
146 client.client_initialized.addCallback(after_init) | |
147 | |
148 def _publishMblog(self, name, message, pubsub_ent, profile): | |
149 """Actually publish the message on the group blog | |
150 @param name: name of the node where we publish | |
151 @param message: message to publish | |
152 @param pubsub_ent: entity of the publish-subscribe service | |
153 @param profile: profile of the owner of the group""" | |
154 mblog_item = self.host.plugins["XEP-0277"].data2entry({'content':message}, profile) | |
155 defer_blog = self.host.plugins["XEP-0060"].publish(pubsub_ent, name, items=[mblog_item], profile_key=profile) | |
156 defer_blog.addErrback(self._mblogPublicationFailed) | |
157 | |
158 def _groupNodeCreated(self, ignore, groups, name, message, user_jid, pubsub_ent, profile): | |
159 """A group node as been created, we need to add it to the configure node, and send the message to it | |
160 @param groups: list of groups authorized to subscribe to the node | |
161 @param name: unique name of the group | |
162 @param message: message to publish to the group | |
163 @param user_jid: jid of the owner of the node | |
164 @param pubsub_ent: entity of the publish-subscribe service | |
165 @param profile: profile of the owner of the group""" | |
166 config_node = self._getConfigNode(user_jid) | |
167 _payload = domish.Element(('','node_association')) | |
168 _payload['node'] = name | |
169 for group in groups: | |
170 _payload.addElement('group',content=group) | |
171 config_item = pubsub.Item(payload=_payload) | |
172 defer_config = self.host.plugins["XEP-0060"].publish(pubsub_ent, config_node, items=[config_item], profile_key=profile) | |
173 defer_config.addCallback(lambda x: debug(_("Configuration node updated"))) | |
174 defer_config.addErrback(self._configUpdateFailed) | |
175 | |
176 #Finally, we publish the message | |
177 self._publishMblog(name, message, pubsub_ent, profile) | |
178 | |
179 | |
180 def _mblogPublicationFailed(self, failure): | |
181 #TODO | |
182 import pdb | |
183 pdb.set_trace() | |
184 | |
185 def _configUpdateFailed(self, failure): | |
186 #TODO | |
187 import pdb | |
188 pdb.set_trace() | |
189 | |
190 def _nodeCreationFailed(self, failure, name, user_jid, groups, pubsub_ent, message, profile): | |
191 #TODO | |
192 if failure.value.condition == "item-not-found": | |
193 #The root node doesn't exists | |
194 def err_creating_root_node(failure): | |
195 msg = _("Can't create Root node") | |
196 error(msg) | |
197 raise NodeCreationError(msg) | |
198 | |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
199 _options = {OPT_NODE_TYPE:TYPE_COLLECTION} |
307 | 200 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, self._getRootNode(user_jid), _options, profile_key=profile) |
201 d.addCallback(self._createNode, name, user_jid, groups, pubsub_ent, message, profile) | |
202 d.addErrback(err_creating_root_node) | |
203 else: | |
204 import pdb | |
205 pdb.set_trace() | |
206 | |
207 def _createNode(self, ignore, name, user_jid, groups, pubsub_ent, message, profile): | |
208 """create a group microblog node | |
209 @param ignore: ignored param, necessary to be added as a deferred callback | |
210 @param name: name of the node | |
211 @param user_jid: jid of the user creating the node | |
212 @param groups: list of group than can subscribe to the node | |
213 @param pubsub_ent: publish/subscribe service's entity | |
214 @param message: message to publish | |
215 @param profile: profile of the user creating the node""" | |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
216 _options = {OPT_ACCESS_MODEL:"roster", OPT_PERSIST_ITEMS:1, OPT_MAX_ITEMS:-1, |
307 | 217 'pubsub#node_type':'leaf', 'pubsub#collection':self._getRootNode(user_jid), |
218 'pubsub#roster_groups_allowed':groups} | |
219 d = self.host.plugins["XEP-0060"].createNode(pubsub_ent, name, _options, profile_key=profile) | |
220 d.addCallback(self._groupNodeCreated, groups, name, message, user_jid, pubsub_ent, profile) | |
221 d.addErrback(self._nodeCreationFailed, name, user_jid, groups, pubsub_ent, message, profile) | |
222 | |
223 def _getNodeForGroups(self, groups, profile): | |
224 """Return node associated with the given list of groups | |
225 @param groups: list of groups | |
226 @param profile: profile of publisher""" | |
227 for node in self._blog_nodes[profile]: | |
228 node_groups = self._blog_nodes[profile][node] | |
229 if set(node_groups) == set(groups): | |
230 return node | |
231 return None | |
232 | |
233 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'): | |
234 """Publish a microblog to the node associated to the groups | |
235 If the node doesn't exist, it is created, then the message is posted | |
236 @param groups: list of groups allowed to retrieve the microblog | |
237 @param message: microblog | |
238 @profile_key: %(doc_profile)s | |
239 """ | |
240 profile = self.host.memory.getProfileName(profile_key) | |
241 if not profile: | |
242 error(_("Unknown profile")) | |
243 return | |
244 | |
245 def after_init(ignore): | |
246 _groups = list(set(groups).intersection(client.roster.getGroups())) #We only keep group which actually exist | |
247 #TODO: send an error signal if user want to post to non existant groups | |
248 _groups.sort() | |
249 pubsub_ent = self.host.memory.getServerServiceEntity("pubsub", "service", profile) | |
250 for group in _groups: | |
251 _node = self._getNodeForGroups([group], profile) | |
252 if not _node: | |
253 _node_name = unicode(uuid.uuid4()) | |
254 self._createNode(None, _node_name, client.jid, [group], pubsub_ent, message, profile) | |
255 else: | |
256 self._publishMblog(_node, message, pubsub_ent, profile) | |
257 | |
258 client = self.host.getClient(profile) | |
259 if not client: | |
260 error(_('No client for this profile key: %s') % profile_key) | |
261 return | |
262 client.client_initialized.addCallback(after_init) | |
263 | |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
264 def _doCleaning(self, result, pubsub_ent, profile): |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
265 """Compare the node in config node, and the existing nodes, and delete unknown ones""" |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
266 #TODO: manage groups which don't exist anymore |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
267 assert(len(result)==2) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
268 assert(result[0][0]==True and result[1][0]==True) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
269 config_nodes = [item.firstChildElement()["node"] for item in result[0][1]] |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
270 existing_nodes = [item.nodeIdentifier for item in result[1][1]._items] |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
271 to_delete = set(config_nodes).symmetric_difference(existing_nodes) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
272 def check_deletion(result): |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
273 for (success, value) in result: |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
274 if not success: |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
275 msg = _("Can't delete node") |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
276 error(msg) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
277 raise NodeDeletionError(msg) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
278 #TODO: log node which was not deleted |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
279 |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
280 |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
281 d = defer.DeferredList([self.host.plugins["XEP-0060"].deleteNode(pubsub_ent, node, profile) for node in to_delete]) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
282 d.addCallback(check_deletion) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
283 |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
284 def cleanBlogCollection(self, profile_key='@DEFAULT@'): |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
285 """Remove blog nodes not referenced in config node""" |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
286 debug(_('Getting mblog nodes')) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
287 profile = self.host.memory.getProfileName(profile_key) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
288 if not profile: |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
289 error(_("Unknown profile")) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
290 return {} |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
291 |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
292 def after_init(ignore): |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
293 pubsub_ent = self.host.memory.getServerServiceEntity("pubsub", "service", profile) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
294 _jid, xmlstream = self.host.getJidNStream(profile_key) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
295 d_config = self.host.plugins["XEP-0060"].getItems(pubsub_ent, self._getConfigNode(_jid), profile_key=profile_key) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
296 d_root = client.disco.requestItems(pubsub_ent, self._getRootNode(client.jid)) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
297 defer.DeferredList([d_config, d_root]).addCallback(self._doCleaning, pubsub_ent, profile) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
298 |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
299 client = self.host.getClient(profile) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
300 if not client: |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
301 error(_('No client for this profile key: %s') % profile_key) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
302 return |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
303 client.client_initialized.addCallback(after_init) |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
304 |
310
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
305 def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT@'): |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
306 debug(_('subscribing mblog nodes')) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
307 _pub_jid = jid.JID(pub_jid) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
308 profile = self.host.memory.getProfileName(profile_key) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
309 if not profile: |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
310 error(_("Unknown profile")) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
311 return |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
312 |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
313 def after_init(ignore): |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
314 pubsub_ent = self.host.memory.getServerServiceEntity("pubsub", "service", profile) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
315 _options = {OPT_SUBSCRIPTION_TYPE:'items', OPT_SUBSCRIPTION_DEPTH:'1'} |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
316 d = self.host.plugins["XEP-0060"].subscribe(pubsub_ent, self._getRootNode(_pub_jid), options = _options, profile_key=profile) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
317 d.addCallback(lambda x: debug(_("%(publisher)s's group node subscribed [%(profile)s]") % {'publisher':_pub_jid.userhost(), 'profile': profile})) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
318 d.addErrback(lambda x: error(_("Can't subscribe group node [%(profile)s]") % {'profile': profile})) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
319 |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
320 client = self.host.getClient(profile) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
321 if not client: |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
322 error(_('No client for this profile key: %s') % profile_key) |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
323 return |
53adec87d1d7
plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents:
308
diff
changeset
|
324 client.client_initialized.addCallback(after_init) |