annotate src/plugins/plugin_misc_groupblog.py @ 477:031b0e0aaab8

plugin groupblog: subscriptions/notifications
author Goffi <goffi@goffi.org>
date Mon, 25 Jun 2012 00:08:16 +0200
parents b9fd32b46306
children f856575a62a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT plugin for microbloging with roster access
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from logging import debug, info, error
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
23 from twisted.internet import defer
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber import jid
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
25
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
26 from wokkel import disco, data_form, iwokkel
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
27
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
28 from zope.interface import implements
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
30 try:
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
31 from twisted.words.protocols.xmlstream import XMPPHandler
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
32 except ImportError:
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
33 from wokkel.subprotocols import XMPPHandler
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
35 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
36 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog'
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
37 NS_NODE_PREFIX = 'urn:xmpp:groupblog:'
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
38 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
39 NS_PUBSUB_EXP = NS_PUBSUB #XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
40 NS_PUBSUB_ITEM_ACCESS = NS_PUBSUB_EXP + "#item-access"
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
41 NS_PUBSUB_CREATOR_JID_CHECK = NS_PUBSUB_EXP + "#creator-jid-check"
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
42 NS_PUBSUB_ITEM_CONFIG = NS_PUBSUB_EXP + "#item-config"
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
43 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create"
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
44 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed'
310
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
45 OPT_ACCESS_MODEL = 'pubsub#access_model'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
46 OPT_PERSIST_ITEMS = 'pubsub#persist_items'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
47 OPT_MAX_ITEMS = 'pubsub#max_items'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
48 OPT_NODE_TYPE = 'pubsub#node_type'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
49 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
50 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 TYPE_COLLECTION = 'collection'
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 PLUGIN_INFO = {
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "name": "Group blogging throught collections",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "import_name": "groupblog",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "type": "MISC",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "protocols": [],
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "dependencies": ["XEP-0277"],
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "main": "GroupBlog",
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
60 "handler": "yes",
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "description": _("""Implementation of microblogging with roster access""")
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 }
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
64 class NoCompatiblePubSubServerFound(Exception):
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
65 pass
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
66
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
67 class BadAccessTypeError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
68 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
69
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
70 class BadAccessListError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
71 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
72
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 class GroupBlog():
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
74 """This class use a SàT PubSub Service to manage access on microblog"""
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def __init__(self, host):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 info(_("Group blog plugin initialization"))
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.host = host
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
80 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='',
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
81 method=self.sendGroupBlog)
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
82
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
83 host.bridge.addMethod("getLastGroupBlogs", ".plugin",
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
84 in_sign='sis', out_sign='aa{ss}',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
85 method=self.getLastGroupBlogs,
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
86 async = True)
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
87
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
88 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
89 in_sign='sasis', out_sign='a{saa{ss}}',
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
90 method=self.getMassiveLastGroupBlogs,
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
91 async = True)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
92
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
93 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
94 method=self.subscribeGroupBlog,
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
95 async = True)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
96
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
97 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
98 method=self.massiveSubscribeGroupBlogs,
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
99 async = True)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
100
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
101 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
102
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
103
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
104 def getHandler(self, profile):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
105 return GroupBlog_handler()
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
106
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
107 @defer.inlineCallbacks
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
108 def initialise(self, profile_key):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
109 """Check that this data for this profile are initialised, and do it else
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
110 @param client: client of the profile
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
111 @profile_key: %(doc_profile)s"""
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
112 profile = self.host.memory.getProfileName(profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
113 if not profile:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
114 error(_("Unknown profile"))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
115 raise Exception("Unknown profile")
310
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
116
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
117 client = self.host.getClient(profile)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
118 if not client:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
119 error(_('No client for this profile key: %s') % profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
120 raise Exception("Unknown profile")
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
121 yield client.client_initialized #we want to be sure that the client is initialized
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
122
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
123 #we first check that we have a item-access pubsub server
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
124 if not hasattr(client,"item_access_pubsub"):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
125 debug(_('Looking for item-access power pubsub server'))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
126 #we don't have any pubsub server featuring item access yet
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
127 client.item_access_pubsub = None
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
128 for entity in self.host.memory.getServerServiceEntities("pubsub", "service", profile):
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
129 _disco = yield client.disco.requestInfo(entity)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
130 #if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
131 if set([NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features):
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
132 info(_("item-access powered pubsub service found: [%s]") % entity.full())
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
133 client.item_access_pubsub = entity
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
134
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
135 if not client.item_access_pubsub:
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
136 error(_("No item-access powered pubsub server found, can't use group blog"))
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
137 raise NoCompatiblePubSubServerFound
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
138
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
139 defer.returnValue((profile, client))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
140
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
141 def pubSubItemsReceivedTrigger(self, event, profile):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
142 """"Trigger which catch groupblogs events"""
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
143 if event.nodeIdentifier.startswith(NS_NODE_PREFIX):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
144 for item in event.items:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
145 microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
146 self.host.bridge.personalEvent(event.sender.full(), "MICROBLOG", microblog_data, profile)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
147 return False
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
148 return True
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
149
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
150
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
151
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
152 def getNodeName(self, publisher):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
153 """Retrieve the name of publisher's node
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
154 @param publisher: publisher's jid
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
155 @return: node's name (string)"""
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
156 return NS_NODE_PREFIX + publisher.userhost()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
157
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
158
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
159
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
160 def _publishMblog(self, service, client, access_type, access_list, message):
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 """Actually publish the message on the group blog
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
162 @param service: jid of the item-access pubsub service
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
163 @param client: SatXMPPClient of the published
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
164 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
165 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 @param message: message to publish
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
167 """
311
0aa6ca6cdbdd plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents: 310
diff changeset
168 mblog_item = self.host.plugins["XEP-0277"].data2entry({'content':message}, client.profile)
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
169 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
170 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
171 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
172 raise BadAccessListError("access_list must be empty for PUBLIC access")
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
173 access = data_form.Field(None, OPT_ACCESS_MODEL, value="open")
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
174 form.addField(access)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
175 elif access_type == "GROUP":
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
176 access = data_form.Field(None, OPT_ACCESS_MODEL, value="roster")
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
177 allowed = data_form.Field(None, OPT_ROSTER_GROUPS_ALLOWED, values=access_list)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
178 form.addField(access)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
179 form.addField(allowed)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
180 mblog_item.addChild(form.toElement())
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
181 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
182 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
183 else:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
184 error(_("Unknown access_type"))
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
185 raise BadAccessTypeError
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
186 defer_blog = self.host.plugins["XEP-0060"].publish(service, self.getNodeName(client.jid), items=[mblog_item], profile_key=client.profile)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187 defer_blog.addErrback(self._mblogPublicationFailed)
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def _mblogPublicationFailed(self, failure):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 #TODO
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
191 return failure
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
193 def sendGroupBlog(self, access_type, access_list, message, profile_key='@DEFAULT@'):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
194 """Publish a microblog with given item access
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
195 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
196 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS,
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
197 list of groups or list of jids) for this item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198 @param message: microblog
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199 @profile_key: %(doc_profile)s
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
200 """
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
201 print "sendGroupBlog"
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
202 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
203 profile, client = result
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
204 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
205 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
206 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
207 self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message)
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
208 elif access_type == "GROUP":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
209 _groups = set(access_list).intersection(client.roster.getGroups()) #We only keep group which actually exist
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
210 if not _groups:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
211 raise BadAccessListError("No valid group")
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
212 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message)
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
213 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
214 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
215 else:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
216 error(_("Unknown access type"))
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
217 raise BadAccessTypeError
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
218
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
219 self.initialise(profile_key).addCallback(initialised)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
220
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
221
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
222
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
223 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
224 """Get the last published microblogs
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
225 @param pub_jid: jid of the publisher
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
226 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
227 @param profile_key: profile key
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
228 @return: list of microblog data (dict)
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
229 """
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
230
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
231 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
232 profile, client = result
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
233 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
234 max_items=max_items, profile_key=profile_key)
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
235 d.addCallback(lambda items: map(self.host.plugins["XEP-0277"].item2mbdata, items))
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
236 d.addErrback(lambda ignore: {}) #TODO: more complete error management (log !)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
237 return d
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
238
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
239 #TODO: we need to use the server corresponding the the host of the jid
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
240 return self.initialise(profile_key).addCallback(initialised)
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
241
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
242 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@DEFAULT@'):
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
243 """Get the last published microblogs for a list of groups or jids
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
244 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
245 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
246 @param max_items: how many microblogs we want to get
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
247 @param profile_key: profile key
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
248 """
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
249 def sendResult(result):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
250 """send result of DeferredList (list of microblogs to the calling method"""
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
251
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
252 ret = {}
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
253
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
254 for (success, value) in result:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
255 if success:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
256 source_jid, data = value
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
257 ret[source_jid] = data
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
258
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
259 return ret
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
260
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
261 def initialised(result):
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
262 profile, client = result
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
263
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
264 if publishers_type == "ALL":
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
265 contacts = client.roster.getItems()
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
266 jids = [contact.jid.userhost() for contact in contacts]
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
267 mblogs = []
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
268 for _jid in jids:
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
269 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
270 max_items=max_items, profile_key=profile_key)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
271 d.addCallback(lambda items, source_jid: (source_jid, map(self.host.plugins["XEP-0277"].item2mbdata, items)), _jid)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
272 mblogs.append(d)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
273 dlist = defer.DeferredList(mblogs)
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
274 dlist.addCallback(sendResult)
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
275 return dlist
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
276
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
277 return defer.fail("Unknown type")
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
278
470
5c916b99d0f6 plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents: 467
diff changeset
279
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
280 #TODO: custom exception
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
281 if publishers_type not in ["GROUP", "JID", "ALL"]:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
282 raise Exception("Bad call, unknown publishers_type")
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
283 if publishers_type=="ALL" and publishers:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
284 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
285 return self.initialise(profile_key).addCallback(initialised)
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
286 #TODO: we need to use the server corresponding the the host of the jid
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
287
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
288 def subscribeGroupBlog(self, pub_jid, profile_key='@DEFAULT'):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
289 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
290 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
291 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
292 profile_key=profile_key)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
293 return d
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
294
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
295 #TODO: we need to use the server corresponding the the host of the jid
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
296 return self.initialise(profile_key).addCallback(initialised)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
297
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
298
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
299 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@DEFAULT@'):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
300 """Subscribe microblogs for a list of groups or jids
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
301 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL")
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
302 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
303 @param profile_key: profile key
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
304 """
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
305 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
306 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
307
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
308 if publishers_type == "ALL":
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
309 contacts = client.roster.getItems()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
310 jids = [contact.jid.userhost() for contact in contacts]
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
311 mblogs = []
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
312 for _jid in jids:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
313 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
314 profile_key=profile_key)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
315 mblogs.append(d)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
316 dlist = defer.DeferredList(mblogs)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
317 return dlist
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
318
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
319 return defer.fail("Unknown type")
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
320
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
321
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
322 #TODO: custom exception
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
323 if publishers_type not in ["GROUP", "JID", "ALL"]:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
324 raise Exception("Bad call, unknown publishers_type")
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
325 if publishers_type=="ALL" and publishers:
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
326 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
327 return self.initialise(profile_key).addCallback(initialised)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
328 #TODO: we need to use the server corresponding the the host of the jid
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
329
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
330
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
331
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
332 class GroupBlog_handler(XMPPHandler):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
333 implements(iwokkel.IDisco)
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
334
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
335 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
336 return [disco.DiscoFeature(NS_GROUPBLOG)]
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
337
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
338 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
339 return []
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
340