annotate src/plugins/plugin_misc_groupblog.py @ 465:78e67a59d51d

plugin groupblog: added getLastGroupBlogs method
author Goffi <goffi@goffi.org>
date Sat, 24 Mar 2012 17:48:12 +0100
parents d9456d94cd12
children 47af60767013
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
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
23 from twisted.internet import protocol, defer
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber import jid
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import error as jab_error
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 import twisted.internet.error
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.xish import domish
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from sat.tools.xml_tools import ElementParser
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
30 from wokkel import disco, pubsub, data_form
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from feed.atom import Entry, Author
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 import uuid
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from time import time
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'
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
36 #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
37 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
38 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
39 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
40 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
41 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
42 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed'
310
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
43 OPT_ACCESS_MODEL = 'pubsub#access_model'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
44 OPT_PERSIST_ITEMS = 'pubsub#persist_items'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
45 OPT_MAX_ITEMS = 'pubsub#max_items'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
46 OPT_NODE_TYPE = 'pubsub#node_type'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
47 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type'
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
48 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 TYPE_COLLECTION = 'collection'
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 PLUGIN_INFO = {
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "name": "Group blogging throught collections",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 "import_name": "groupblog",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "type": "MISC",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "protocols": [],
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "dependencies": ["XEP-0277"],
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "main": "GroupBlog",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "handler": "no",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "description": _("""Implementation of microblogging with roster access""")
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 }
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
62 class NoCompatiblePubSubServerFound(Exception):
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
63 pass
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
64
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 class GroupBlog():
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
66 """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
67
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def __init__(self, host):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 info(_("Group blog plugin initialization"))
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.host = host
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
372
f964dcec1611 core: plugins refactored according to bridge + updatedValue now use profile
Goffi <goffi@goffi.org>
parents: 340
diff changeset
72 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='asss', out_sign='',
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 method=self.sendGroupBlog,
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 doc = { 'summary':"Send a microblog to a list of groups",
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 'param_0':'list of groups which can read the microblog',
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 'param_1':'text to send',
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 'param_2':'%(doc_profile)s'
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 })
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
79
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
80 host.bridge.addMethod("getLastGroupBlogs", ".plugin",
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
81 in_sign='sis', out_sign='aa{ss}',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
82 method=self.getLastGroupBlogs,
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
83 async = True,
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
84 doc = { 'summary':'retrieve items',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
85 'param_0':'jid: publisher of wanted microblog',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
86 'param_1':'max_items: see XEP-0060 #6.5.7',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
87 'param_2':'%(doc_profile)s',
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
88 'return':'list of microblog data (dict)'
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
89 })
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
90
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
91 @defer.inlineCallbacks
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
92 def initialise(self, profile_key):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
93 """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
94 @param client: client of the profile
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
95 @profile_key: %(doc_profile)s"""
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
96 profile = self.host.memory.getProfileName(profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
97 if not profile:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
98 error(_("Unknown profile"))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
99 raise Exception("Unknown profile")
310
53adec87d1d7 plugin group blog: group blog subscription
Goffi <goffi@goffi.org>
parents: 308
diff changeset
100
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
101 client = self.host.getClient(profile)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
102 if not client:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
103 error(_('No client for this profile key: %s') % profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
104 raise Exception("Unknown profile")
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
105 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
106
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
107 #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
108 if not hasattr(client,"item_access_pubsub"):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
109 debug(_('Looking for item-access power pubsub server'))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
110 #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
111 test = self.host.memory.getServerServiceEntities("pubsub", "service", profile)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
112 client.item_access_pubsub = None
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
113 for entity in self.host.memory.getServerServiceEntities("pubsub", "service", profile):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
114 disco = yield client.disco.requestInfo(entity)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
115 if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(disco.features):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
116 info(_("item-access powered pubsub service found: [%s]") % entity.full())
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
117 client.item_access_pubsub = entity
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
118
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
119 if not client.item_access_pubsub:
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
120 error(_("No item-access powered pubsub server found, can't post group blog"))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
121 raise NoCompatiblePubSubServerFound
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 defer.returnValue((profile, client))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
124
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
125
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
126 def _publishMblog(self, service, groups, message, client):
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 """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
128 @param service: jid of the item-access pubsub service
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
129 @param groups: set of groups allowed to see the item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 @param message: message to publish
311
0aa6ca6cdbdd plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents: 310
diff changeset
131 @param client: SatXMPPClient of the published"""
0aa6ca6cdbdd plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents: 310
diff changeset
132 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
133 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
134 field = data_form.Field('list-multi', OPT_ROSTER_GROUPS_ALLOWED, values=groups)
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
135 form.addField(field)
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
136 mblog_item.addChild(form.toElement())
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
137 defer_blog = self.host.plugins["XEP-0060"].publish(service, client.jid.userhost(), items=[mblog_item], profile_key=client.profile)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 defer_blog.addErrback(self._mblogPublicationFailed)
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 def _mblogPublicationFailed(self, failure):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 #TODO
340
2572351d875a plugin groupblog: removed breakpoints, but error handling still need work
Goffi <goffi@goffi.org>
parents: 326
diff changeset
142 pass
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 """Publish a microblog to the node associated to the groups
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 If the node doesn't exist, it is created, then the message is posted
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 @param groups: list of groups allowed to retrieve the microblog
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 @param message: microblog
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 @profile_key: %(doc_profile)s
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 """
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
151 print "sendGroupBlog"
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
152
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
153 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
154 profile, client = result
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
155 _groups = set(groups).intersection(client.roster.getGroups()) #We only keep group which actually exist
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
156 #TODO: send an error signal if user want to post to non existant groups
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
157
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
158 self._publishMblog(client.item_access_pubsub, _groups, message, client)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
159
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
160 self.initialise(profile_key).addCallback(initialised)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
161
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
162
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
163
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
164 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
165 """Get the last published microblogs
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
166 @param pub_jid: jid of the publisher
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
167 @param max_items: how many microblogs we want to get
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
168 @param profile_key: profile key
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
169 @param callback: used for the async answer
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
170 @param errback: used for the async answer
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
171 """
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
172
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
173 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
174 profile, client = result
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
175 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, jid.JID(pub_jid).userhost(),
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
176 max_items=max_items, profile_key=profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
177 d.addCallbacks(lambda items: callback(map(self.host.plugins["XEP-0277"].item2mbdata, items)), errback)
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
178
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
179 assert(callback)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
180 self.initialise(profile_key).addCallback(initialised)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
181 #TODO: we need to use the server corresponding the the host of the jid
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
182