annotate src/plugins/plugin_misc_groupblog.py @ 1440:226bbe758b1a

plugin misc_groupblog: pubsub response do not fail when target server doesn't handle RSM
author souliane <souliane@mailoo.org>
date Tue, 14 Jul 2015 16:44:15 +0200
parents 7f8af1e69812
children 7797dda847ae
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
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for microbloging with roster access
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 1294
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 770
diff changeset
20 from sat.core.i18n import _
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 892
diff changeset
21 from sat.core.constants import Const as C
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
22 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
23 log = getLogger(__name__)
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
24 from twisted.internet import defer
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import jid
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
26 from twisted.words.xish.domish import Element, generateElementsNamed
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
27 from sat.core import exceptions
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
28 from wokkel import disco, data_form, iwokkel
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
29 from wokkel import rsm
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
30 from zope.interface import implements
831
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
31 from feed import date
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
32 import uuid
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
33 import urllib
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
34
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
35 try:
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
36 from twisted.words.protocols.xmlstream import XMPPHandler
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
37 except ImportError:
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
38 from wokkel.subprotocols import XMPPHandler
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
40 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
41 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog'
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
42 NS_NODE_PREFIX = 'urn:xmpp:groupblog:'
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
43 NS_COMMENT_PREFIX = 'urn:xmpp:comments:'
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
44 #NS_PUBSUB_EXP = 'http://goffi.org/protocol/pubsub' #for non official features
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
45 NS_PUBSUB_EXP = NS_PUBSUB # XXX: we can't use custom namespace as Wokkel's PubSubService use official NS
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
46 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
47 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
48 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
49 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create"
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 TYPE_COLLECTION = 'collection'
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
51 ACCESS_TYPE_MAP = { 'PUBLIC': 'open',
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
52 'GROUP': 'roster',
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
53 'JID': None, #JID is not yet managed
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
54 }
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
56 MAX_ITEMS = 5
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
57 MAX_COMMENTS = 5
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
58 DO_NOT_COUNT_COMMENTS = -1 # must be lower than 0
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
59
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
61 "name": "Group blogging throught collections",
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
62 "import_name": "GROUPBLOG",
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
63 "type": "MISC",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
64 "protocols": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
65 "dependencies": ["XEP-0277"],
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
66 "recommendations": ["XEP-0059"],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
67 "main": "GroupBlog",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
68 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
69 "description": _("""Implementation of microblogging with roster access""")
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 }
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
72
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
73 class NoCompatiblePubSubServerFound(Exception):
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
74 pass
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
75
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
76
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
77 class BadAccessTypeError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
78 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
79
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
80
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
81 class BadAccessListError(Exception):
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
82 pass
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
83
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
84
529
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
85 class UnknownType(Exception):
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
86 pass
c18e0e108925 plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents: 480
diff changeset
87
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
88 class GroupBlog(object):
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
89 """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
90
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
92 log.info(_("Group blog plugin initialization"))
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.host = host
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
95 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='',
704
3c304929af74 plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents: 703
diff changeset
96 method=self.sendGroupBlog,
3c304929af74 plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents: 703
diff changeset
97 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
98
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
99 host.bridge.addMethod("deleteGroupBlog", ".plugin", in_sign='(sss)ss', out_sign='',
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
100 method=self.deleteGroupBlog,
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
101 async=True)
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
102
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
103 host.bridge.addMethod("updateGroupBlog", ".plugin", in_sign='(sss)ssa{ss}s', out_sign='',
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
104 method=self.updateGroupBlog,
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
105 async=True)
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
106
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
107 host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='ssa{ss}s', out_sign='',
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
108 method=self.sendGroupBlogComment,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
109 async=True)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
110
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
111 host.bridge.addMethod("getGroupBlogs", ".plugin",
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
112 in_sign='sasa{ss}bs', out_sign='(aa{ss}a{ss})',
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
113 method=self.getGroupBlogs,
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
114 async=True)
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
115
892
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
116 host.bridge.addMethod("getGroupBlogsWithComments", ".plugin",
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
117 in_sign='sasa{ss}is', out_sign='(a(a{ss}(aa{ss}a{ss}))a{ss})',
892
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
118 method=self.getGroupBlogsWithComments,
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
119 async=True)
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
120
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
121 host.bridge.addMethod("getGroupBlogsAtom", ".plugin",
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
122 in_sign='sa{ss}s', out_sign='s',
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
123 method=self.getGroupBlogsAtom,
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
124 async=True)
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
125
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
126 host.bridge.addMethod("getMassiveGroupBlogs", ".plugin",
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
127 in_sign='sasa{ss}s', out_sign='a{s(aa{ss}a{ss})}',
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
128 method=self._getMassiveGroupBlogs,
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
129 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
130
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
131 host.bridge.addMethod("getGroupBlogComments", ".plugin",
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
132 in_sign='ssa{ss}s', out_sign='(aa{ss}a{ss})',
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
133 method=self.getGroupBlogComments,
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
134 async=True)
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
135
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
136 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
137 method=self.subscribeGroupBlog,
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
138 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
139
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
140 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
141 method=self._massiveSubscribeGroupBlogs,
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
142 async=True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
143
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
144 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
145
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
146 ## plugin management methods ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
147
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
148 def getHandler(self, profile):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
149 return GroupBlog_handler()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
150
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
151 @defer.inlineCallbacks
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
152 def _initialise(self, profile_key):
858
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
153 """Check that the data for this profile are initialised, and do it else
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
154 @param profile_key: %(doc_profile)s"""
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
155 profile = self.host.memory.getProfileName(profile_key)
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
156 if not profile:
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
157 raise exceptions.ProfileUnknownError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
158
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
159 client = self.host.getClient(profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
160
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
161 #we first check that we have a item-access pubsub server
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
162 if not hasattr(client, "item_access_pubsub"):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
163 log.debug(_('Looking for item-access powered pubsub server'))
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
164 #we don't have any pubsub server featuring item access yet
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
165 item_access_pubsubs = yield self.host.findFeaturesSet((NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK), "pubsub", "service", profile_key=profile)
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
166 # item_access_pubsubs = yield self.host.findFeaturesSet((NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK), "pubsub", "service", profile_key=profile)
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
167 try:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
168 client.item_access_pubsub = item_access_pubsubs.pop()
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
169 log.info(_(u"item-access powered pubsub service found: [%s]") % client.item_access_pubsub.full())
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
170 except KeyError:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
171 client.item_access_pubsub = None
465
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 if not client.item_access_pubsub:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
174 log.error(_(u"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
175 raise NoCompatiblePubSubServerFound
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
176
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
177 defer.returnValue((profile, client))
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
178
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
179 def pubSubItemsReceivedTrigger(self, event, profile):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
180 """"Trigger which catch groupblogs events"""
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
181
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
182 if event.nodeIdentifier.startswith(NS_NODE_PREFIX):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
183 # Microblog
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
184 publisher = jid.JID(event.nodeIdentifier[len(NS_NODE_PREFIX):])
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
185 origin_host = publisher.host.split('.')
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
186 event_host = event.sender.host.split('.')
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
187 #FIXME: basic origin check, must be improved
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
188 #TODO: automatic security test
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
189 if (not (origin_host)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
190 or len(event_host) < len(origin_host)
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
191 or event_host[-len(origin_host):] != origin_host):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
192 log.warning(u"Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender),
532
db4ae4d18f09 plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents: 529
diff changeset
193 unicode(publisher)))
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
194 return False
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
195
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
196 client = self.host.getClient(profile)
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
197
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
198 def gbdataManagementMicroblog(gbdata):
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
199 for gbdatum in gbdata:
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
200 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG", gbdatum, profile)
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
201
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
202 d = self._itemsConstruction(event.items, publisher, client)
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
203 d.addCallback(gbdataManagementMicroblog)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
204 return False
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
205
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
206 elif event.nodeIdentifier.startswith(NS_COMMENT_PREFIX):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
207 # Comment
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
208 def gbdataManagementComments(gbdata):
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
209 for gbdatum in gbdata:
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
210 publisher = None # FIXME: see below (_handleCommentsItems)
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
211 self.host.bridge.personalEvent(publisher.full() if publisher else gbdatum["author"], "MICROBLOG", gbdatum, profile)
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
212 d = self._handleCommentsItems(event.items, event.sender, event.nodeIdentifier)
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
213 d.addCallback(gbdataManagementComments)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
214 return False
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
215 return True
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
216
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
217 ## internal helping methodes ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
218
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
219 def _handleCommentsItems(self, items, service, node_identifier):
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
220 """ Convert comments items to groupblog data, and send them as signals
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
221
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
222 @param items: comments items
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
223 @param service: jid of the PubSub service used
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
224 @param node_identifier: comments node
1233
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
225 @return: deferred list of group blog data
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
226 """
1233
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
227 d_list = []
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
228
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
229 def cb(microblog_data):
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
230 publisher = "" # FIXME: publisher attribute for item in SàT pubsub is not managed yet, so
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
231 # publisher is not checked and can be easily spoofed. This need to be fixed
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
232 # quickly.
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
233 microblog_data["service"] = service.userhost()
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
234 microblog_data["node"] = node_identifier
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
235 microblog_data["verified_publisher"] = "true" if publisher else "false"
1233
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
236 return microblog_data
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
237
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
238 for item in items:
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
239 d_list.append(self.item2gbdata(item, "comment").addCallback(cb))
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
240 return defer.DeferredList(d_list, consumeErrors=True).addCallback(lambda result: [value for (success, value) in result if success])
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
241
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
242 def _parseAccessData(self, microblog_data, item):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
243 P = self.host.plugins["XEP-0060"]
660
69a8bfd266a5 core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
Goffi <goffi@goffi.org>
parents: 621
diff changeset
244 form_elts = [child for child in item.elements() if child.name == "x"]
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
245 for form_elt in form_elts:
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
246 form = data_form.Form.fromElement(form_elt)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
247
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
248 if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
249 access_model = form.get(P.OPT_ACCESS_MODEL, 'open')
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
250 if access_model == "roster":
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
251 try:
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
252 microblog_data["groups"] = '\n'.join(form.fields[P.OPT_ROSTER_GROUPS_ALLOWED].values)
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
253 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
254 log.warning("No group found for roster access-model")
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
255 microblog_data["groups"] = ''
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
256
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
257 break
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
258
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
259 @defer.inlineCallbacks
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
260 def item2gbdata(self, item, _type="main_item"):
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
261 """ Convert item to microblog data dictionary + add access data """
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
262 microblog_data = yield self.host.plugins["XEP-0277"].item2mbdata(item)
616
8782f94e761e plugin groupblog: comment item is specified through microblog data, there is no more a specific signal type
Goffi <goffi@goffi.org>
parents: 615
diff changeset
263 microblog_data["type"] = _type
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
264 self._parseAccessData(microblog_data, item)
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
265 defer.returnValue(microblog_data)
534
07f369ed3988 plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents: 532
diff changeset
266
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
267 def getNodeName(self, publisher):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
268 """Retrieve the name of publisher's node
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
269
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
270 @param publisher: publisher's jid
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
271 @return: node's name (string)
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
272 """
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
273 return NS_NODE_PREFIX + publisher.userhost()
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
274
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
275 ## publish ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
276
703
0c2c1dfb79e4 plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents: 660
diff changeset
277 def _publishMblog(self, service, client, access_type, access_list, message, extra):
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
278 """Actually publish the message on the group blog
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
279
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
280 @param service: jid of the item-access pubsub service
858
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
281 @param client: SatXMPPClient of the publisher
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
282 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
283 @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
284 @param message: message to publish
703
0c2c1dfb79e4 plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents: 660
diff changeset
285 @param extra: dict which option name as key, which can be:
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
286 - allow_comments: True to accept comments, False else (default: False)
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
287 - rich: if present, contain rich text in currently selected syntax
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
288 """
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
289 node_name = self.getNodeName(client.jid)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
290 mblog_data = {'content': message}
832
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
291
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
292 for attr in ['content_rich', 'title', 'title_rich']:
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
293 if attr in extra and extra[attr]:
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
294 mblog_data[attr] = extra[attr]
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
295 P = self.host.plugins["XEP-0060"]
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
296 access_model_value = ACCESS_TYPE_MAP[access_type]
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
297
703
0c2c1dfb79e4 plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents: 660
diff changeset
298 if extra.get('allow_comments', 'False').lower() == 'true':
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 742
diff changeset
299 # XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
300 comments_node = self._fillCommentsElement(mblog_data, None, node_name, service)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
301 _options = {P.OPT_ACCESS_MODEL: access_model_value,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
302 P.OPT_PERSIST_ITEMS: 1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
303 P.OPT_MAX_ITEMS: -1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
304 P.OPT_DELIVER_PAYLOADS: 1,
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
305 P.OPT_SEND_ITEM_SUBSCRIBE: 1,
832
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
306 P.OPT_PUBLISH_MODEL: "subscribers", # TODO: should be open if *both* node and item access_model are open (public node and item)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
307 }
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
308 if access_model_value == 'roster':
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
309 _options[P.OPT_ROSTER_GROUPS_ALLOWED] = list(access_list)
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
310
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
311 # FIXME: check comments node creation success, at the moment this is a potential security risk (if the node
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
312 # already exists, the creation will silently fail, but the comments link will stay the same, linking to a
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
313 # node owned by somebody else)
941
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 938
diff changeset
314 self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
315
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
316 def itemCreated(mblog_item):
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
317 form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
318
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
319 if access_type == "PUBLIC":
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
320 if access_list:
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
321 raise BadAccessListError("access_list must be empty for PUBLIC access")
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
322 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
323 form.addField(access)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
324 elif access_type == "GROUP":
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
325 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
326 allowed = data_form.Field(None, P.OPT_ROSTER_GROUPS_ALLOWED, values=access_list)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
327 form.addField(access)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
328 form.addField(allowed)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
329 mblog_item.addChild(form.toElement())
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
330 elif access_type == "JID":
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
331 raise NotImplementedError
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
332 else:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
333 log.error(_("Unknown access_type"))
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
334 raise BadAccessTypeError
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
335
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
336 defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
337 defer_blog.addErrback(self._mblogPublicationFailed)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
338 return defer_blog
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
339
832
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
340 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile)
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
341 entry_d.addCallback(itemCreated)
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
342 return entry_d
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
343
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
344 def _fillCommentsElement(self, mblog_data, entry_id, node_name, service_jid):
858
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
345 """
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
346 @param mblog_data: dict containing the microblog data
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
347 @param entry_id: unique identifier of the entry
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
348 @param node_name: the pubsub node name
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
349 @param service_jid: the JID of the pubsub service
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
350 @return: the comments node string
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
351 """
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
352 if entry_id is None:
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
353 entry_id = unicode(uuid.uuid4())
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
354 comments_node = "%s_%s__%s" % (NS_COMMENT_PREFIX, entry_id, node_name)
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
355 mblog_data['comments'] = "xmpp:%(service)s?%(query)s" % {'service': service_jid.userhost(),
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
356 'query': urllib.urlencode([('node', comments_node.encode('utf-8'))])}
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
357 return comments_node
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
358
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
359 def _mblogPublicationFailed(self, failure):
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
360 #TODO
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
361 return failure
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
362
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 892
diff changeset
363 def sendGroupBlog(self, access_type, access_list, message, extra, profile_key=C.PROF_KEY_NONE):
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
364 """Publish a microblog with given item access
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
365
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
366 @param access_type: one of "PUBLIC", "GROUP", "JID"
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
367 @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
368 list of groups or list of jids) for this item
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
369 @param message: microblog
703
0c2c1dfb79e4 plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents: 660
diff changeset
370 @param extra: dict which option name as key, which can be:
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
371 - allow_comments: True to accept comments, False else (default: False)
706
80e9d3ecb272 plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents: 704
diff changeset
372 - rich: if present, contain rich text in currently selected syntax
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
373 @profile_key: %(doc_profile_key)s
307
1e4575e12581 Group blog first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
374 """
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
375
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
376 def initialised(result):
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
377 profile, client = result
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
378 if access_type == "PUBLIC":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
379 if access_list:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
380 raise Exception("Publishers list must be empty when getting microblogs for all contacts")
704
3c304929af74 plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents: 703
diff changeset
381 return self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
382 elif access_type == "GROUP":
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
383 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
384 if not _groups:
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
385 raise BadAccessListError("No valid group")
704
3c304929af74 plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents: 703
diff changeset
386 return self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra)
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
387 elif access_type == "JID":
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
388 raise NotImplementedError
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 470
diff changeset
389 else:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 944
diff changeset
390 log.error(_("Unknown access type"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
391 raise BadAccessTypeError
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
392
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
393 return self._initialise(profile_key).addCallback(initialised)
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
394
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 892
diff changeset
395 def sendGroupBlogComment(self, node_url, message, extra, profile_key=C.PROF_KEY_NONE):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
396 """Publish a comment in the given node
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
397 @param node url: link to the comments node as specified in XEP-0277 and given in microblog data's comments key
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
398 @param message: comment
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
399 @param extra: dict which option name as key, which can be:
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
400 - allow_comments: True to accept an other level of comments, False else (default: False)
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
401 - rich: if present, contain rich text in currently selected syntax
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
402 @profile_key: %(doc_profile)s
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
403 """
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
404 def initialised(result):
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
405 profile, client = result
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
406 service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url)
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
407 mblog_data = {'content': message}
832
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
408 for attr in ['content_rich', 'title', 'title_rich']:
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
409 if attr in extra and extra[attr]:
c4b22aedb7d7 plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents: 831
diff changeset
410 mblog_data[attr] = extra[attr]
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
411 if 'allow_comments' in extra:
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
412 raise NotImplementedError # TODO
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
413 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
414 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile))
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
415 return entry_d
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
416
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
417 return self._initialise(profile_key).addCallback(initialised)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
418
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
419 def _itemsConstruction(self, items, pub_jid, client):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
420 """ Transforms items to group blog data and manage comments node
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
421
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
422 @param items: iterable of items
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
423 @param pub_jid: jid of the publisher or None to use items data
617
dafdbe28ca2f plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents: 616
diff changeset
424 @param client: SatXMPPClient instance
707
890fbf2d7fdd plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents: 706
diff changeset
425 @return: deferred which fire list of group blog data """
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
426 # TODO: use items data when pub_jid is None
1233
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
427 d_list = []
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
428
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
429 @defer.inlineCallbacks
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
430 def cb(gbdata):
858
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
431 try:
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
432 gbdata['service'] = client.item_access_pubsub.full()
660b3f5b6c78 plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents: 847
diff changeset
433 except AttributeError:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
434 log.warning(_(u"Pubsub service is unknown for blog entry %s") % gbdata['id'])
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
435 # every comments node must be subscribed, except if we are the publisher (we are already subscribed in this case)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
436 if "comments_node" in gbdata and pub_jid.userhostJID() != client.jid.userhostJID():
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
437 try:
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
438 service = jid.JID(gbdata["comments_service"])
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
439 node = gbdata["comments_node"]
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
440 except KeyError:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
441 log.error(_(u"Missing key for blog comment %s") % gbdata['id'])
1233
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
442 defer.returnValue(gbdata)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
443 # TODO: see if it is really needed to check for not subscribing twice to the node
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
444 # It previously worked without this check, but the pubsub service logs were polluted
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
445 # or, if in debug mode, it made sat-pubsub very difficult to debug.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
446 subscribed_nodes = yield self.host.plugins['XEP-0060'].listSubscribedNodes(service, profile=client.profile)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
447 if node not in subscribed_nodes: # avoid sat-pubsub "SubscriptionExists" error
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
448 self.host.plugins["XEP-0060"].subscribe(service, node, profile_key=client.profile)
1233
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
449 defer.returnValue(gbdata)
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
450
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
451 for item in items:
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
452 d_list.append(self.item2gbdata(item).addCallback(cb))
0b87d029f0a3 plugin XEP-0277, groupblog: fixes namespace issue of the items that are received from an event + trap some errors
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
453 return defer.DeferredList(d_list, consumeErrors=True).addCallback(lambda result: [value for (success, value) in result if success])
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
454
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
455 ## modify ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
456
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
457 def updateGroupBlog(self, pub_data, comments, message, extra, profile_key=C.PROF_KEY_NONE):
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
458 """Modify a microblog node
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
459
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
460 @param pub_data: a tuple (service, node identifier, item identifier)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
461 @param comments: comments node identifier (for main item) or empty string
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
462 @param message: new message
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
463 @param extra: dict which option name as key, which can be:
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
464 - allow_comments: True to accept an other level of comments, False else (default: False)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
465 - rich: if present, contain rich text in currently selected syntax
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
466 @param profile_key: %(doc_profile)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
467 """
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
468
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
469 def initialised(result):
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
470 profile, client = result
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
471 mblog_data = {'content': message}
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
472 for attr in ['content_rich', 'title', 'title_rich']:
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
473 if attr in extra and extra[attr]:
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
474 mblog_data[attr] = extra[attr]
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
475 service, node, item_id = pub_data
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
476 service_jid = jid.JID(service) if service else client.item_access_pubsub
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
477 if comments or not node: # main item
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
478 node = self.getNodeName(client.jid)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
479 mblog_data['id'] = unicode(item_id)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
480 if 'published' in extra:
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
481 mblog_data['published'] = extra['published']
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
482 if extra.get('allow_comments', 'False').lower() == 'true':
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
483 comments_service, comments_node = self.host.plugins["XEP-0277"].parseCommentUrl(comments)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
484 # we could use comments_node directly but it's safer to rebuild it
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
485 # XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
486 entry_id = comments_node.split('_')[1].split('__')[0]
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
487 self._fillCommentsElement(mblog_data, entry_id, node, service_jid)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
488 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
489 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service_jid, node, items=[mblog_item], profile_key=profile))
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
490 entry_d.addErrback(lambda failure: log.error(u"Modification of %s failed: %s" % (pub_data, failure.getErrorMessage())))
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
491 return entry_d
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
492
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
493 return self._initialise(profile_key).addCallback(initialised)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
494
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
495 ## get ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
496
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
497 def _getOrCountComments(self, items, max_=0, profile_key=C.PROF_KEY_NONE):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
498 """Get and/or count the comments of the given items.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
499
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
500 @param items (list): items to consider.
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
501 @param max_ (int): maximum number of comments to get, if 0 only count
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
502 them. The count is set to the item data of key "comments_count".
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
503 @param profile_key (str): %(doc_profile_key)s
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
504 @return: a deferred list of:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
505 - if max_ == 0: microblog data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
506 - else: couple (dict, (list[dict], dict)) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
507 - microblog data (main item)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
508 - couple (comments data, RSM response data for the comments)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
509 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
510 def comments_cb(comments_data, entry):
1440
226bbe758b1a plugin misc_groupblog: pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 1425
diff changeset
511 try:
226bbe758b1a plugin misc_groupblog: pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 1425
diff changeset
512 entry['comments_count'] = comments_data[1]['count']
226bbe758b1a plugin misc_groupblog: pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 1425
diff changeset
513 except KeyError: # target pubsub server probably doesn't handle RSM
226bbe758b1a plugin misc_groupblog: pubsub response do not fail when target server doesn't handle RSM
souliane <souliane@mailoo.org>
parents: 1425
diff changeset
514 pass
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
515 return (entry, comments_data) if max_ > 0 else entry
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
516
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
517 assert max_ >= 0
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
518 d_list = []
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
519 for entry in items:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
520 if entry.get('comments', False):
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
521 comments_rsm = {'max_': max_}
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
522 d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], rsm_data=comments_rsm, profile_key=profile_key)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
523 d.addCallback(comments_cb, entry)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
524 d_list.append(d)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
525 else:
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
526 if max_ > 0:
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
527 d_list.append(defer.succeed((entry, ([], {}))))
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
528 else:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
529 d_list.append(defer.succeed(entry))
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
530 deferred_list = defer.DeferredList(d_list)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
531 deferred_list.addCallback(lambda result: [value for (success, value) in result if success])
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
532 return deferred_list
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
533
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
534 def _getGroupBlogs(self, pub_jid_s, item_ids=None, rsm_data=None, max_comments=0, profile_key=C.PROF_KEY_NONE):
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
535 """Retrieve previously published items from a publish subscribe node.
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
536
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
537 @param pub_jid_s: jid of the publisher
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
538 @param item_ids: list of microblogs items IDs
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
539 @param rsm_data (dict): RSM request data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
540 @param max_comments (int): maximum number of comments to retrieve
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
541 @param profile_key (str): %(doc_profile_key)s
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
542 @return: a deferred couple (list, dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
543 - list of:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
544 - if max_comments == 0: microblog data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
545 - else: couple (dict, (list[dict], dict)) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
546 - microblog data (main item)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
547 - couple (comments data, RSM response data for the comments)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
548 - RSM response data
465
78e67a59d51d plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents: 462
diff changeset
549 """
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
550 pub_jid = jid.JID(pub_jid_s)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
551
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
552 def cb(items, client):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
553 d = self._itemsConstruction(items, pub_jid, client)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
554 if max_comments == DO_NOT_COUNT_COMMENTS:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
555 return d
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
556 return d.addCallback(self._getOrCountComments, max_comments, profile_key)
308
ce3607b7198d plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents: 307
diff changeset
557
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
558 return DeferredItems(self, cb, None, profile_key).get(self.getNodeName(pub_jid), item_ids, rsm_data=rsm_data)
462
d9456d94cd12 plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents: 459
diff changeset
559
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
560 def getGroupBlogs(self, pub_jid_s, item_ids=None, rsm_data=None, count_comments=True, profile_key=C.PROF_KEY_NONE):
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
561 """Get the published microblogs of the specified IDs. If item_ids is
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
562 None, the result would be the same than calling getGroupBlogs
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
563 with the default value for the attribute max_items.
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 860
diff changeset
564
892
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
565 @param pub_jid_s: jid of the publisher
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
566 @param item_ids: list of microblogs items IDs
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
567 @param rsm_data (dict): RSM request data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
568 @param count_comments (bool): also count the comments if True
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
569 @param profile_key (str): %(doc_profile_key)s
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
570 @return: a deferred couple (list, dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
571 - list of microblog data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
572 - RSM response data
892
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
573 """
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
574 max_comments = 0 if count_comments else DO_NOT_COUNT_COMMENTS
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
575 return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
576
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
577 def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, rsm_data=None, max_comments=None, profile_key=C.PROF_KEY_NONE):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
578 """Get the published microblogs of the specified IDs and their comments. If
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
579 item_ids is None, returns the last published microblogs and their comments.
892
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
580
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
581 @param pub_jid_s: jid of the publisher
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
582 @param item_ids: list of microblogs items IDs
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
583 @param rsm (dict): RSM request data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
584 @param max_comments (int): maximum number of comments to retrieve
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
585 @param profile_key (str): %(doc_profile_key)s
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
586 @return: a deferred couple (list, dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
587 - list of couple (dict, (list[dict], dict)) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
588 - microblog data (main item)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
589 - couple (comments data, RSM response data for the comments)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
590 - RSM response data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
591 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
592 if max_comments is None:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
593 max_comments = MAX_COMMENTS
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
594 assert max_comments > 0 # otherwise the return signature is not the same
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
595 return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm_data=rsm_data, max_comments=max_comments, profile_key=profile_key)
892
58107179cd97 plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents: 891
diff changeset
596
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
597 def getGroupBlogsAtom(self, pub_jid_s, rsm_data=None, profile_key=C.PROF_KEY_NONE):
831
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
598 """Get the atom feed of the last published microblogs
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
599 @param pub_jid: jid of the publisher
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
600 @param profile_key: profile key
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
601 @return: a deferred unicode (atom XML feed)
831
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
602 """
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
603 pub_jid = jid.JID(pub_jid_s)
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
604
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
605 def removeAllURIs(element):
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
606 """Recursively remove the URIs of the element and its children.
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
607 Without that, the entry would still be valid but not displayed
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
608 by Firefox nor Thunderbird (and probably more readers)"""
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
609 element.uri = element.defaultUri = None
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
610 for child in element.children:
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
611 if isinstance(child, Element):
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
612 removeAllURIs(child)
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
613
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
614 def items2feed(items, pub_jid, client):
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
615 feed = """<?xml version="1.0" encoding="utf-8"?>
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
616 <feed xmlns="http://www.w3.org/2005/Atom">
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
617 <title>%(user)s's blogposts</title>
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
618 <link href="%(feed)s" rel="self" />
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
619 <link href="%(blog)s" />
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
620 <id>%(id)s</id>
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
621 <updated>%(date)s</updated>\n""" % {'user': pub_jid.user,
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
622 'feed': 'http://%s/blog/%s/atom.xml' % (client.jid.host, pub_jid.user),
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
623 'blog': 'http://%s/blog/%s' % (client.jid.host, pub_jid.user),
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
624 'id': self.getNodeName(pub_jid),
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
625 'date': date.rfc3339.timestamp_from_tf(date.rfc3339.tf_utc())}
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
626 for item in items:
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
627 entry = item.firstChildElement()
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
628 removeAllURIs(entry)
860
2b98f5631fba plugin groupblog: bug fix for the atom feed
souliane <souliane@mailoo.org>
parents: 858
diff changeset
629 feed += " " + entry.toXml() + "\n"
831
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
630 return feed + "</feed>"
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
631
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
632 def cb(items, client):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
633 return items2feed(items, pub_jid, client)
831
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
634
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
635 d = DeferredItems(self, cb, lambda dummy: [''], profile_key).get(self.getNodeName(pub_jid), rsm_data=rsm_data)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
636 return d.addCallback(lambda res: res[0])
831
d7f9cd8a08cd plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents: 811
diff changeset
637
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
638 def getGroupBlogComments(self, service_s, node, rsm_data=None, profile_key=C.PROF_KEY_NONE):
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
639 """Get all comments of given node
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
640 @param service_s: service hosting the node
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
641 @param node: comments node
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
642 @param profile_key: profile key
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
643 @return: a deferred couple (list, dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
644 - list of microblog data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
645 - RSM response data
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
646 """
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
647 service = jid.JID(service_s)
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
648
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
649 def cb(items, client):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
650 return self._handleCommentsItems(items, service, node)
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
651
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
652 return DeferredItems(self, cb, None, profile_key).get(node, rsm_data=rsm_data)
621
0e16288d6816 pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents: 619
diff changeset
653
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
654 def _getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
655 if publishers_type == 'JID':
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
656 publishers_jids = [jid.JID(publisher) for publisher in publishers]
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
657 else:
731
80c1072390f3 plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents: 726
diff changeset
658 publishers_jids = publishers
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
659 return self.getMassiveGroupBlogs(publishers_type, publishers_jids, rsm_data, profile_key)
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
660
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
661 def _getPublishersJIDs(self, publishers_type, publishers, client):
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
662 #TODO: custom exception
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
663 if publishers_type not in ["GROUP", "JID", "ALL"]:
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
664 raise Exception("Bad call, unknown publishers_type")
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
665 if publishers_type == "ALL" and publishers:
467
47af60767013 plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents: 465
diff changeset
666 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
667
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
668 if publishers_type == "ALL":
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
669 contacts = client.roster.getItems()
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
670 jids = [contact.jid.userhostJID() for contact in contacts]
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
671 elif publishers_type == "GROUP":
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
672 jids = []
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
673 for _group in publishers:
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
674 jids.extend(client.roster.getJidsFromGroup(_group))
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
675 elif publishers_type == 'JID':
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
676 jids = publishers
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
677 else:
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
678 raise UnknownType
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
679 return jids
1243
b4a264915ea9 plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents: 1233
diff changeset
680
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
681 def getMassiveGroupBlogs(self, publishers_type, publishers, rsm_data=None, profile_key=C.PROF_KEY_NONE):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
682 """Get the last published microblogs for a list of groups or jids
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
683 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
684 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
685 @param rsm_data (dict): RSM request data, common to all publishers
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
686 @param profile_key: profile key
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
687 @return: a deferred dict with:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
688 - key: publisher (unicode)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
689 - value: couple (list[dict], dict) with:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
690 - the microblogs data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
691 - RSM response data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
692 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
693 def cb(items, publisher, client):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
694 d = self._itemsConstruction(items, publisher, client)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
695 return d.addCallback(self._getOrCountComments, False, profile_key)
1243
b4a264915ea9 plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents: 1233
diff changeset
696
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
697 #TODO: we need to use the server corresponding to the host of the jid
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
698 return DeferredItemsFromMany(self, cb, profile_key).get(publishers_type, publishers, rsm_data=rsm_data)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
699
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
700 ## subscribe ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
701
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 892
diff changeset
702 def subscribeGroupBlog(self, pub_jid, profile_key=C.PROF_KEY_NONE):
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
703 def initialised(result):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
704 profile, client = result
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
705 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
706 profile_key=profile_key)
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
707 return d
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
708
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
709 #TODO: we need to use the server corresponding the the host of the jid
708
6aa71c853bf5 plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents: 707
diff changeset
710 return self._initialise(profile_key).addCallback(initialised)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
711
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 892
diff changeset
712 def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE):
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
713 if publishers_type == 'JID':
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
714 publishers_jids = [jid.JID(publisher) for publisher in publishers]
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
715 else:
731
80c1072390f3 plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents: 726
diff changeset
716 publishers_jids = publishers
80c1072390f3 plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents: 726
diff changeset
717 return self.massiveSubscribeGroupBlogs(publishers_type, publishers_jids, profile_key)
726
ade9997fabfa core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents: 708
diff changeset
718
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
719 @defer.inlineCallbacks
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 892
diff changeset
720 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key=C.PROF_KEY_NONE):
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
721 """Subscribe microblogs for a list of groups or jids
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
722 @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
723 @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
724 @param profile_key: profile key
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
725 """
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
726 profile, client = yield self._initialise(profile_key)
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
727 #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
728
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
729 jids = self._getPublishersJIDs(publishers_type, publishers, client)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
730 node_ids = [self.getNodeName(publisher) for publisher in jids]
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
731 d_list = yield self.host.plugins["XEP-0060"].subscribeToMany(client.item_access_pubsub, node_ids, profile_key=profile_key)
1419
be2df1ddea8e plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
732 yield defer.DeferredList(d_list, consumeErrors=False)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
733 defer.returnValue(None)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 1182
diff changeset
734
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
735 ## delete ##
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
736
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
737 def deleteGroupBlog(self, pub_data, comments, profile_key=C.PROF_KEY_NONE):
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
738 """Delete a microblog item from a node.
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
739
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
740 @param pub_data: a tuple (service, node identifier, item identifier)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
741 @param comments: comments node identifier (for main item) or empty string
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
742 @param profile_key: %(doc_profile_key)s
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
743 """
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
744
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
745 def initialised(result):
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
746 profile, client = result
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
747 service, node, item_id = pub_data
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
748 service_jid = jid.JID(service) if service else client.item_access_pubsub
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
749 if comments or not node: # main item
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
750 node = self.getNodeName(client.jid)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
751 if comments:
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
752 # remove the associated comments node
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
753 comments_service, comments_node = self.host.plugins["XEP-0277"].parseCommentUrl(comments)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
754 d = self.host.plugins["XEP-0060"].deleteNode(comments_service, comments_node, profile_key=profile)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
755 d.addErrback(lambda failure: log.error(u"Deletion of node %s failed: %s" % (comments_node, failure.getErrorMessage())))
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
756 # remove the item itself
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
757 d = self.host.plugins["XEP-0060"].retractItems(service_jid, node, [item_id], profile_key=profile)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
758 d.addErrback(lambda failure: log.error(u"Deletion of item %s from %s failed: %s" % (item_id, node, failure.getErrorMessage())))
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
759 return d
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
760
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
761 def notify(d):
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
762 # TODO: this works only on the same host, and notifications for item deletion should be
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
763 # implemented according to http://xmpp.org/extensions/xep-0060.html#publisher-delete-success-notify
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
764 # instead. The notification mechanism implemented in sat_pubsub and wokkel have apriori
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
765 # a problem with retrieving the subscriptions, or something else.
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
766 service, node, item_id = pub_data
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
767 publisher = self.host.getJidNStream(profile_key)[0]
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
768 profile = self.host.memory.getProfileName(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
769 gbdatum = {'id': item_id, 'type': 'main_item' if (comments or not node) else 'comment'}
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
770 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG_DELETE", gbdatum, profile)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
771 return d
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
772
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
773 return self._initialise(profile_key).addCallback(initialised).addCallback(notify)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
774
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
775 def deleteAllGroupBlogsAndComments(self, profile_key=C.PROF_KEY_NONE):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
776 """Delete absolutely all the microblog data that the user has posted"""
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
777 calls = [self.deleteAllGroupBlogs(profile_key), self.deleteAllGroupBlogsComments(profile_key)]
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
778 return defer.DeferredList(calls)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
779
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
780 def deleteAllGroupBlogs(self, profile_key=C.PROF_KEY_NONE):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
781 """Delete all the main items that the user has posted and their comments.
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
782 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
783 def initialised(result):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
784 profile, client = result
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
785 service = client.item_access_pubsub
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
786 jid_ = client.jid
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
787 main_node = self.getNodeName(jid_)
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
788
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
789 def cb(nodes):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
790 d_list = []
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
791 for node in [node for node in nodes if node.endswith(main_node)]:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
792 d = self.host.plugins["XEP-0060"].deleteNode(service, node, profile_key=profile)
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
793 d.addErrback(lambda failure: log.error(_(u"Deletion of node %(node)s failed: %(message)s") %
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
794 {'node': node, 'message': failure.getErrorMessage()}))
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
795 d_list.append(d)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
796 return defer.DeferredList(d_list)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
797
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
798 d = self.host.plugins["XEP-0060"].listNodes(service, profile=profile)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
799 d.addCallback(cb)
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
800 d.addCallback(lambda dummy: log.info(_(u"All microblog's main items from %s have been deleted!") % jid_.userhost()))
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
801 return d
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
802
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
803 return self._initialise(profile_key).addCallback(initialised)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
804
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
805 def deleteAllGroupBlogsComments(self, profile_key=C.PROF_KEY_NONE):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
806 """Delete all the comments that the user posted on other's main items.
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
807 We avoid the conversions from item to microblog data as we only need
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
808 to retrieve some attributes, no need to convert text syntax...
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
809 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
810 def initialised(result):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
811 """Get all the main items from our contact list
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
812 @return: a DeferredList
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
813 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
814 profile, client = result
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
815 service = client.item_access_pubsub
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
816 jids = [contact.jid.userhostJID() for contact in client.roster.getItems()]
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
817 blogs = []
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
818 for jid_ in jids:
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
819 if jid_ == client.jid.userhostJID():
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
820 continue # do not remove the comments on our own node
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
821 main_node = self.getNodeName(jid_)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
822 d = self.host.plugins["XEP-0060"].getItems(service, main_node, profile_key=profile)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
823 d.addCallback(lambda res: getComments(res[0], client))
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
824 d.addErrback(lambda failure, main_node: log.error(_(u"Retrieval of items for node %(node)s failed: %(message)s") %
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
825 {'node': main_node, 'message': failure.getErrorMessage()}), main_node)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
826 blogs.append(d)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
827
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
828 return defer.DeferredList(blogs)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
829
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
830 def getComments(items, client):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
831 """Get all the comments for a list of items
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
832 @param items: a list of main items for one user
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
833 @param client: the client of the user
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
834 @return: a DeferredList
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
835 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
836 comments = []
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
837 for item in items:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
838 try:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
839 entry = generateElementsNamed(item.elements(), 'entry').next()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
840 link = generateElementsNamed(entry.elements(), 'link').next()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
841 except StopIteration:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
842 continue
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
843 href = link.getAttribute('href')
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
844 service, node = self.host.plugins['XEP-0277'].parseCommentUrl(href)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
845 d = self.host.plugins["XEP-0060"].getItems(service, node, profile_key=profile_key)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
846 d.addCallback(lambda items: (service, node, items[0]))
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
847 d.addErrback(lambda failure, node: log.error(_(u"Retrieval of comments for node %(node)s failed: %(message)s") %
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
848 {'node': node, 'message': failure.getErrorMessage()}), node)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
849 comments.append(d)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
850 dlist = defer.DeferredList(comments)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
851 dlist.addCallback(deleteComments, client)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
852 return dlist
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
853
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
854 def deleteComments(result, client):
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
855 """Delete all the comments of the user that are found in result
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
856 @param result: a list of couple (success, value) with success a
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
857 boolean and value a tuple (service as JID, node_id, comment_items)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
858 @param client: the client of the user
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
859 @return: a DeferredList with the deletions result
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
860 """
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
861 user_jid_s = client.jid.userhost()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
862 for (success, value) in result:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
863 if not success:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
864 continue
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
865 service, node_id, comment_items = value
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
866 item_ids = []
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
867 for comment_item in comment_items: # for all the comments on one post
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
868 try:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
869 entry = generateElementsNamed(comment_item.elements(), 'entry').next()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
870 author = generateElementsNamed(entry.elements(), 'author').next()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
871 name = generateElementsNamed(author.elements(), 'name').next()
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
872 except StopIteration:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
873 continue
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
874 if name.children[0] == user_jid_s:
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
875 item_ids.append(comment_item.getAttribute('id'))
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
876 deletions = []
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
877 if item_ids: # remove the comments of the user on the given post
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
878 d = self.host.plugins['XEP-0060'].retractItems(service, node_id, item_ids, profile_key=profile_key)
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
879 d.addCallback(lambda dummy, node_id: log.debug(_(u'Comments of user %(user)s in node %(node)s have been retracted') %
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
880 {'user': user_jid_s, 'node': node_id}), node_id)
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
881 d.addErrback(lambda failure, node_id: log.error(_(u"Retraction of comments from %(user)s in node %(node)s failed: %(message)s") %
938
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
882 {'user': user_jid_s, 'node': node_id, 'message': failure.getErrorMessage()}), node_id)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
883 deletions.append(d)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
884 return defer.DeferredList(deletions)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
885
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
886 return self._initialise(profile_key).addCallback(initialised)
fc7e0828b18e plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents: 916
diff changeset
887
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
888 ## helper classes to manipulate items ##
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 476
diff changeset
889
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
890 class DeferredItems():
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
891 """Retrieve items using XEP-0060"""
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
892
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
893 def __init__(self, parent, cb, eb=None, profile_key=C.PROF_KEY_NONE):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
894 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
895 @param parent (GroupBlog): GroupBlog instance
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
896 @param cb (callable): callback method to be applied on items
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
897 @param eb (callable): errback method to be applied on items
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
898 @param profile_key (str): %(doc_profile_key)s
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
899 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
900 self.parent = parent
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
901 self.cb = cb
1294
8aa4dab01206 plugin groupblog: fixes bad errback default value
souliane <souliane@mailoo.org>
parents: 1281
diff changeset
902 self.eb = (lambda dummy: ([], {})) if eb is None else eb
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
903 self.profile_key = profile_key
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
904
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
905 def get(self, node, item_ids=None, sub_id=None, rsm_data=None):
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
906 """Retrieve and process a page of pubsub items
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
907
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
908 @param node (str): node identifier.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
909 @param item_ids (list[str]): list of items identifiers.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
910 @param sub_id (str): optional subscription identifier.
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
911 @param rsm_data (dict): RSM request data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
912 @return: a deferred couple (list, dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
913 - list of microblog data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
914 - RSM response data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
915 """
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
916 if rsm_data is None:
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
917 rsm_data = {'max_': (len(item_ids) if item_ids else MAX_ITEMS)}
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
918
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
919 def initialised(result):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
920 profile, client = result
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
921 rsm_request = rsm.RSMRequest(**rsm_data)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
922 d = self.parent.host.plugins["XEP-0060"].getItems(client.item_access_pubsub,
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
923 node, rsm_request.max,
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
924 item_ids, sub_id, rsm_request,
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
925 profile_key=profile)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
926
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
927 def cb(result):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
928 d = defer.maybeDeferred(self.cb, result[0], client)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
929 return d.addCallback(lambda items: (items, result[1]))
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
930
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
931 d.addCallbacks(cb, self.eb)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
932 return d
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
933
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
934 #TODO: we need to use the server corresponding to the host of the jid
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
935 return self.parent._initialise(self.profile_key).addCallback(initialised)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
936
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
937
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
938 class DeferredItemsFromMany():
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
939 def __init__(self, parent, cb, profile_key=C.PROF_KEY_NONE):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
940 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
941 @param parent (GroupBlog): GroupBlog instance
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
942 @param cb (callable): callback method to be applied on items
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
943 @param profile_key (str): %(doc_profile_key)s
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
944 """
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
945 self.parent = parent
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
946 self.cb = cb
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
947 self.profile_key = profile_key
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
948
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
949 def _buildData(self, publishers_type, publishers, client):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
950 jids = self.parent._getPublishersJIDs(publishers_type, publishers, client)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
951 return {publisher: self.parent.getNodeName(publisher) for publisher in jids}
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
952
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
953 def get(self, publishers_type, publishers, sub_id=None, rsm_data=None):
1423
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
954 """Retrieve and process a page of pubsub items
882e5fabf68c plugin groupblog, tmp (mam, rsm): some style improvments/fixes:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
955
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
956 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
957 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
958 @param sub_id (str): optional subscription identifier.
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
959 @param rsm_data (dict): RSM request data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
960 @return: a deferred dict with:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
961 - key: publisher (unicode)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
962 - value: couple (list[dict], dict) with:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
963 - the microblogs data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
964 - RSM response data
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
965 """
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
966 if rsm_data is None:
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
967 rsm_data = {'max_': MAX_ITEMS}
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
968
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
969 def initialised(result):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
970 profile, client = result
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
971
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1419
diff changeset
972 data = self._buildData(publishers_type, publishers, client)
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
973 rsm_request = rsm.RSMRequest(**rsm_data)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
974 d = self.parent.host.plugins["XEP-0060"].getItemsFromMany(client.item_access_pubsub,
1425
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
975 data, rsm_request.max, sub_id,
7f8af1e69812 core (tests): fixed bad use of reserved name
Goffi <goffi@goffi.org>
parents: 1423
diff changeset
976 rsm_request, profile_key=profile)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
977
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
978 def cb(publisher):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
979 def callback(result):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
980 d = defer.maybeDeferred(self.cb, result[0], publisher, client)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
981 d.addCallback(lambda items: (publisher.full(), (items, result[1])))
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
982 return d
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
983 return callback
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
984
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
985 def cb_list(result):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
986 return {value[0]: value[1] for success, value in result if success}
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
987
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
988 def main_cb(result):
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
989 d_list = []
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
990 for publisher, d_items in result.items():
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
991 # XXX: trick needed as publisher is a loop variable
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
992 d_list.append(d_items.addCallback(cb(publisher)))
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
993 return defer.DeferredList(d_list, consumeErrors=False).addCallback(cb_list)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
994
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
995 d.addCallback(main_cb)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
996 return d
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
997
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
998 #TODO: we need to use the server corresponding to the host of the jid
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
999 return self.parent._initialise(self.profile_key).addCallback(initialised)
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
1000
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1243
diff changeset
1001
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1002 class GroupBlog_handler(XMPPHandler):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1003 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1004
476
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1005 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1006 return [disco.DiscoFeature(NS_GROUPBLOG)]
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1007
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1008 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
b9fd32b46306 plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents: 471
diff changeset
1009 return []