Mercurial > libervia-backend
annotate src/plugins/plugin_misc_groupblog.py @ 1254:87fbe4640448
test: fixes test for XEP-0085 (use full JID)
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 20 Oct 2014 20:46:10 +0200 |
parents | b4a264915ea9 |
children | bb30bf3ae932 |
rev | line source |
---|---|
307 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
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 |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
307 | 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 | 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 | 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 | 19 |
771 | 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 | 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 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
29 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
|
30 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
|
31 import uuid |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
32 import urllib |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
33 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
34 try: |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
35 from twisted.words.protocols.xmlstream import XMPPHandler |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
36 except ImportError: |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
37 from wokkel.subprotocols import XMPPHandler |
307 | 38 |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
39 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
40 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog' |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
41 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
|
42 NS_COMMENT_PREFIX = 'urn:xmpp:comments:' |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
43 #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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create" |
307 | 49 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
|
50 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
|
51 'GROUP': 'roster', |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
52 '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
|
53 } |
307 | 54 |
55 PLUGIN_INFO = { | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
56 "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
|
57 "import_name": "GROUPBLOG", |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
58 "type": "MISC", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
59 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
60 "dependencies": ["XEP-0277"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
61 "main": "GroupBlog", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
63 "description": _("""Implementation of microblogging with roster access""") |
307 | 64 } |
65 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
66 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
67 class NoCompatiblePubSubServerFound(Exception): |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
68 pass |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
69 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
70 |
471 | 71 class BadAccessTypeError(Exception): |
72 pass | |
73 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
74 |
471 | 75 class BadAccessListError(Exception): |
76 pass | |
77 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
78 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
79 class UnknownType(Exception): |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
80 pass |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
81 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
82 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
83 class GroupBlog(object): |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
84 """This class use a SàT PubSub Service to manage access on microblog""" |
307 | 85 |
86 def __init__(self, host): | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
87 log.info(_("Group blog plugin initialization")) |
307 | 88 self.host = host |
89 | |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
90 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
|
91 method=self.sendGroupBlog, |
3c304929af74
plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents:
703
diff
changeset
|
92 async=True) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
93 |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
94 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
|
95 method=self.deleteGroupBlog, |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
96 async=True) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
97 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
98 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
|
99 method=self.updateGroupBlog, |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
100 async=True) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
101 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
102 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
|
103 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
|
104 async=True) |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
105 |
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
|
106 host.bridge.addMethod("getGroupBlogs", ".plugin", |
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
|
107 in_sign='sass', out_sign='aa{ss}', |
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
|
108 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
|
109 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
|
110 |
892
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
111 host.bridge.addMethod("getGroupBlogsWithComments", ".plugin", |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
112 in_sign='sass', out_sign='a(a{ss}aa{ss})', |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
113 method=self.getGroupBlogsWithComments, |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
114 async=True) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
115 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
116 host.bridge.addMethod("getLastGroupBlogs", ".plugin", |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
117 in_sign='sis', out_sign='aa{ss}', |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
118 method=self.getLastGroupBlogs, |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
119 async=True) |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
120 |
831
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
121 host.bridge.addMethod("getLastGroupBlogsAtom", ".plugin", |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
122 in_sign='sis', out_sign='s', |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
123 method=self.getLastGroupBlogsAtom, |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
124 async=True) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
125 |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
126 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin", |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
127 in_sign='sasis', out_sign='a{saa{ss}}', |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
128 method=self._getMassiveLastGroupBlogs, |
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", |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
132 in_sign='sss', out_sign='aa{ss}', |
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 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
146 def getHandler(self, profile): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
147 return GroupBlog_handler() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
148 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
149 @defer.inlineCallbacks |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
150 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
|
151 """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
|
152 @param profile_key: %(doc_profile)s""" |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
153 profile = self.host.memory.getProfileName(profile_key) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
154 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
|
155 raise exceptions.ProfileUnknownError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
156 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
157 client = self.host.getClient(profile) |
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 #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
|
160 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
|
161 log.debug(_('Looking for item-access powered pubsub server')) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
162 #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
|
163 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
|
164 # 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
|
165 try: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
166 client.item_access_pubsub = item_access_pubsubs.pop() |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
167 log.info(_("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
|
168 except KeyError: |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
169 client.item_access_pubsub = None |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
170 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
171 if not client.item_access_pubsub: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
172 log.error(_("No item-access powered pubsub server found, can't use group blog")) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
173 raise NoCompatiblePubSubServerFound |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
174 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
175 defer.returnValue((profile, client)) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
176 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
177 def pubSubItemsReceivedTrigger(self, event, profile): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
178 """"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
|
179 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
180 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
|
181 # Microblog |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
182 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
|
183 origin_host = publisher.host.split('.') |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
184 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
|
185 #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
|
186 #TODO: automatic security test |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
187 if (not (origin_host) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
188 or len(event_host) < len(origin_host) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
189 or event_host[-len(origin_host):] != origin_host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
190 log.warning("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
|
191 unicode(publisher))) |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
192 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
|
193 |
dafdbe28ca2f
plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents:
616
diff
changeset
|
194 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
|
195 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
196 def gbdataManagementMicroblog(gbdata): |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
197 for gbdatum in gbdata: |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
198 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
|
199 |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
200 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
|
201 d.addCallback(gbdataManagementMicroblog) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
202 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
|
203 |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
204 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
|
205 # Comment |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
206 def gbdataManagementComments(gbdata): |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
207 for gbdatum in gbdata: |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 return False |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
213 return True |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
214 |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
215 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
|
216 """ Convert comments items to groupblog data, and send them as signals |
dafdbe28ca2f
plugin group blog: comments handling (comments are automaticaly requested when a comment node is found)
Goffi <goffi@goffi.org>
parents:
616
diff
changeset
|
217 @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
|
218 @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
|
219 @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
|
220 @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
|
221 """ |
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
|
222 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
|
223 |
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
|
224 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
|
225 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
|
226 # 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
|
227 # 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 |
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
|
233 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
|
234 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
|
235 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
|
236 |
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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 form = data_form.Form.fromElement(form_elt) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
242 |
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
|
243 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
|
244 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
|
245 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
|
246 try: |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
247 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
|
248 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
249 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
|
250 microblog_data["groups"] = '' |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
251 |
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
|
252 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
|
253 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
254 @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
|
255 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
|
256 """ 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
262 def getNodeName(self, publisher): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
263 """Retrieve the name of publisher's node |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
264 @param publisher: publisher's jid |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
265 @return: node's name (string)""" |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
266 return NS_NODE_PREFIX + publisher.userhost() |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
267 |
703
0c2c1dfb79e4
plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents:
660
diff
changeset
|
268 def _publishMblog(self, service, client, access_type, access_list, message, extra): |
307 | 269 """Actually publish the message on the group blog |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
270 @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
|
271 @param client: SatXMPPClient of the publisher |
471 | 272 @param access_type: one of "PUBLIC", "GROUP", "JID" |
273 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item | |
307 | 274 @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
|
275 @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
|
276 - 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
|
277 - rich: if present, contain rich text in currently selected syntax |
471 | 278 """ |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
279 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
|
280 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
|
281 |
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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 |
703
0c2c1dfb79e4
plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents:
660
diff
changeset
|
288 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
|
289 # XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63 |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
290 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
|
291 _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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 } |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
298 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
|
299 _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
|
300 |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
301 # 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
|
302 # 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
|
303 # 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
|
304 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
|
305 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
306 def itemCreated(mblog_item): |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
307 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
|
308 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
309 if access_type == "PUBLIC": |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
310 if access_list: |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
311 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
|
312 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
|
313 form.addField(access) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
314 elif access_type == "GROUP": |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
315 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
|
316 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
|
317 form.addField(access) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
318 form.addField(allowed) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
319 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
|
320 elif access_type == "JID": |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
321 raise NotImplementedError |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
322 else: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
323 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
|
324 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
|
325 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
326 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
|
327 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
|
328 return defer_blog |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
329 |
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
|
330 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
|
331 entry_d.addCallback(itemCreated) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
332 return entry_d |
307 | 333 |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
334 def __fillCommentsElement(self, mblog_data, entry_id, node_name, service_jid): |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
335 """ |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
336 @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
|
337 @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
|
338 @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
|
339 @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
|
340 @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
|
341 """ |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 '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
|
347 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
|
348 |
307 | 349 def _mblogPublicationFailed(self, failure): |
350 #TODO | |
471 | 351 return failure |
307 | 352 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
353 def sendGroupBlog(self, access_type, access_list, message, extra, profile_key=C.PROF_KEY_NONE): |
471 | 354 """Publish a microblog with given item access |
355 @param access_type: one of "PUBLIC", "GROUP", "JID" | |
356 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, | |
357 list of groups or list of jids) for this item | |
307 | 358 @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
|
359 @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
|
360 - 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
|
361 - 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
|
362 @profile_key: %(doc_profile_key)s |
307 | 363 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
364 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
365 def initialised(result): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
366 profile, client = result |
471 | 367 if access_type == "PUBLIC": |
368 if access_list: | |
369 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
|
370 return self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra) |
471 | 371 elif access_type == "GROUP": |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
372 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist |
471 | 373 if not _groups: |
374 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
|
375 return self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra) |
471 | 376 elif access_type == "JID": |
377 raise NotImplementedError | |
378 else: | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
379 log.error(_("Unknown access type")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
380 raise BadAccessTypeError |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
381 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
382 return self._initialise(profile_key).addCallback(initialised) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
383 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
384 def deleteGroupBlog(self, pub_data, comments, profile_key=C.PROF_KEY_NONE): |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
385 """Delete a microblog item from a node. |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
386 @param pub_data: a tuple (service, node identifier, item identifier) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
387 @param comments: comments node identifier (for main item) or empty string |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
388 @param profile_key: %(doc_profile_key)s |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
389 """ |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
390 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
391 def initialised(result): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
392 profile, client = result |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
393 service, node, item_id = pub_data |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
394 service_jid = jid.JID(service) if service else client.item_access_pubsub |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
395 if comments or not node: # main item |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
396 node = self.getNodeName(client.jid) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
397 if comments: |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
398 # remove the associated comments node |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
399 comments_service, comments_node = self.host.plugins["XEP-0277"].parseCommentUrl(comments) |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
400 d = self.host.plugins["XEP-0060"].deleteNode(comments_service, comments_node, profile_key=profile) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
401 d.addErrback(lambda failure: log.error("Deletion of node %s failed: %s" % (comments_node, failure.getErrorMessage()))) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
402 # remove the item itself |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
403 d = self.host.plugins["XEP-0060"].retractItems(service_jid, node, [item_id], profile_key=profile) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
404 d.addErrback(lambda failure: log.error("Deletion of item %s from %s failed: %s" % (item_id, node, failure.getErrorMessage()))) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
405 return d |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
406 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
407 def notify(d): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
408 # TODO: this works only on the same host, and notifications for item deletion should be |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
409 # implemented according to http://xmpp.org/extensions/xep-0060.html#publisher-delete-success-notify |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
410 # instead. The notification mechanism implemented in sat_pubsub and wokkel have apriori |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
411 # a problem with retrieving the subscriptions, or something else. |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
412 service, node, item_id = pub_data |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
413 publisher = self.host.getJidNStream(profile_key)[0] |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
414 profile = self.host.memory.getProfileName(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
|
415 gbdatum = {'id': item_id, 'type': 'main_item' if (comments or not node) else 'comment'} |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
416 self.host.bridge.personalEvent(publisher.full(), "MICROBLOG_DELETE", gbdatum, profile) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
417 return d |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
418 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
419 return self._initialise(profile_key).addCallback(initialised).addCallback(notify) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
420 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
421 def updateGroupBlog(self, pub_data, comments, message, extra, profile_key=C.PROF_KEY_NONE): |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
422 """Modify a microblog node |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
423 @param pub_data: a tuple (service, node identifier, item identifier) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
424 @param comments: comments node identifier (for main item) or empty string |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
425 @param message: new message |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
426 @param extra: dict which option name as key, which can be: |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
427 - allow_comments: True to accept an other level of comments, False else (default: False) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
428 - rich: if present, contain rich text in currently selected syntax |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
429 @param profile_key: %(doc_profile) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
430 """ |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
431 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
432 def initialised(result): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
433 profile, client = result |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 mblog_data[attr] = extra[attr] |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
438 service, node, item_id = pub_data |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
439 service_jid = jid.JID(service) if service else client.item_access_pubsub |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
440 if comments or not node: # main item |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
441 node = self.getNodeName(client.jid) |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
442 mblog_data['id'] = unicode(item_id) |
770
64dd7c0f4feb
plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents:
745
diff
changeset
|
443 if 'published' in extra: |
64dd7c0f4feb
plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents:
745
diff
changeset
|
444 mblog_data['published'] = extra['published'] |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
445 if extra.get('allow_comments', 'False').lower() == 'true': |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
446 comments_service, comments_node = self.host.plugins["XEP-0277"].parseCommentUrl(comments) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
447 # we could use comments_node directly but it's safer to rebuild it |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
448 # XXX: use the item identifier? http://bugs.goffi.org/show_bug.cgi?id=63 |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
449 entry_id = comments_node.split('_')[1].split('__')[0] |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
450 self.__fillCommentsElement(mblog_data, entry_id, node, service_jid) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
451 entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile) |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
452 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service_jid, node, items=[mblog_item], profile_key=profile)) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
453 entry_d.addErrback(lambda failure: log.error("Modification of %s failed: %s" % (pub_data, failure.getErrorMessage()))) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
454 return entry_d |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
455 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
456 return self._initialise(profile_key).addCallback(initialised) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
457 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
458 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
|
459 """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
|
460 @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
|
461 @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
|
462 @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
|
463 - 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
|
464 - 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
|
465 @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
|
466 """ |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
467 def initialised(result): |
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
468 profile, client = result |
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 raise NotImplementedError # TODO |
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
476 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
|
477 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
|
478 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
|
479 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
480 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
|
481 |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
482 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
|
483 """ 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
|
484 |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
485 @param items: iterable of items |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
486 @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
|
487 @param client: SatXMPPClient instance |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
488 @return: deferred which fire list of group blog data """ |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
489 # 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
|
490 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
|
491 |
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
|
492 @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
|
493 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
|
494 try: |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
495 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
|
496 except AttributeError: |
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
|
497 log.warning(_("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
|
498 # 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
|
499 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
|
500 try: |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
501 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
|
502 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
|
503 except KeyError: |
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
|
504 log.error(_("Missing key for blog comment %s") % gbdata['id']) |
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
|
505 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
|
506 # 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
|
507 # 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
|
508 # 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 |
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
|
514 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
|
515 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
|
516 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
|
517 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
518 def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, 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
|
519 """Retrieve previously published items from a publish subscribe node. |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
520 @param pub_jid_s: jid of the publisher |
471 | 521 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
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
|
522 @param item_ids: list of microblogs items IDs |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
523 @param profile_key: profile key |
471 | 524 @return: list of microblog data (dict) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
525 """ |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
526 pub_jid = jid.JID(pub_jid_s) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
527 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
528 def initialised(result): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
529 profile, client = result |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
530 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(pub_jid), |
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
|
531 max_items=max_items, item_ids=item_ids, profile_key=profile_key) |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
532 d.addCallback(self._itemsConstruction, pub_jid, client) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
533 d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !) |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
534 return d |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
535 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
536 #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
|
537 return self._initialise(profile_key).addCallback(initialised) |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
538 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
539 def getGroupBlogs(self, pub_jid_s, item_ids=None, 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
|
540 """Get the published microblogs of the specified IDs. If item_ids is |
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
|
541 None, the result would be the same than calling getLastGroupBlogs |
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
|
542 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
|
543 @param pub_jid_s: jid of the publisher |
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
|
544 @param item_ids: list of microblogs items IDs |
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
|
545 @param profile_key: profile key |
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
|
546 @return: list of microblog data (dict) |
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
|
547 """ |
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
|
548 return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) |
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
|
549 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
550 def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key=C.PROF_KEY_NONE): |
892
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
551 """Get the published microblogs of the specified IDs and their comments. If |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
552 item_ids is None, returns the last published microblogs and their comments. |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
553 @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
|
554 @param item_ids: list of microblogs items IDs |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
555 @param profile_key: profile key |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
556 @return: list of couple (microblog data, list of microblog data) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
557 """ |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
558 def get_comments(data): |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
559 d_list = [] |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
560 for entry in data: |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
561 if entry.get('comments', False): |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
562 d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], profile_key=profile_key) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
563 d.addCallback(lambda data: (entry, data)) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
564 d_list.append(d) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
565 else: |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
566 d_list.append(defer.succeed((entry, []))) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
567 deferred_list = defer.DeferredList(d_list) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
568 deferred_list.addCallback(lambda result: [value for (success, value) in result if success]) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
569 return deferred_list |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
570 |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
571 d = self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
572 d.addCallback(get_comments) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
573 return d |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
574 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
575 def getLastGroupBlogs(self, pub_jid_s, max_items=10, 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
|
576 """Get the last published microblogs |
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
|
577 @param pub_jid_s: jid of the publisher |
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
|
578 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
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
|
579 @param profile_key: profile key |
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
|
580 @return: list of microblog data (dict) |
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
|
581 """ |
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
|
582 return self.__getGroupBlogs(pub_jid_s, max_items=max_items, profile_key=profile_key) |
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
|
583 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
584 def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, 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
|
585 """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
|
586 @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
|
587 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
588 @param profile_key: profile key |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
589 @return: atom XML feed (unicode) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
590 """ |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
591 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
|
592 |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
593 def removeAllURIs(element): |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
594 """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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 removeAllURIs(child) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
601 |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
602 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
|
603 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
|
604 <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
|
605 <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
|
606 <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
|
607 <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
|
608 <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
|
609 <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
|
610 '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
|
611 '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
|
612 '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
|
613 '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
|
614 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
|
615 entry = item.firstChildElement() |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
616 removeAllURIs(entry) |
860
2b98f5631fba
plugin groupblog: bug fix for the atom feed
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
617 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
|
618 return feed + "</feed>" |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
619 |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
620 def initialised(result): |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
621 profile, client = result |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
622 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, 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
|
623 max_items=max_items, profile_key=profile_key) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
624 d.addCallback(items2feed, pub_jid, client) |
1182
4be53c14845e
plugin groupblog: fixes return value of getLastGroupBlogsAtom when an error occured
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
625 d.addErrback(lambda ignore: '') # TODO: more complete error management (log !) |
831
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
626 return d |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
627 |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
628 #TODO: we need to use the server corresponding the the host of the jid |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
629 return self._initialise(profile_key).addCallback(initialised) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
630 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
631 def getGroupBlogComments(self, service_s, node, profile_key=C.PROF_KEY_NONE): |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
632 """Get all comments of given node |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
633 @param service_s: service hosting the node |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
634 @param node: comments node |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
635 @param profile_key: profile key |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
636 @return: list of microblog data (dict) |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
637 """ |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
638 service = jid.JID(service_s) |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
639 |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
640 def initialised(result): |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
641 profile, client = result |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
642 d = self.host.plugins["XEP-0060"].getItems(service, node, |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
643 profile_key=profile_key) |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
644 d.addCallback(self._handleCommentsItems, service, node) |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
645 d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !) |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
646 return d |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
647 |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
648 #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
|
649 return self._initialise(profile_key).addCallback(initialised) |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
650 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
651 def _getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, 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
|
652 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
|
653 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
|
654 else: |
731
80c1072390f3
plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents:
726
diff
changeset
|
655 publishers_jids = publishers |
80c1072390f3
plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents:
726
diff
changeset
|
656 return self.getMassiveLastGroupBlogs(publishers_type, publishers_jids, max_items, 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
|
657 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
658 @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
|
659 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key=C.PROF_KEY_NONE): |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
660 """Get the last published microblogs for a list of groups or jids |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
661 @param publishers_type: type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
662 @param publishers: list of publishers, according to "publishers_type" (list of groups or list of jids) |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
663 @param max_items: how many microblogs we want to get |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
664 @param profile_key: profile key |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
665 """ |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
666 #TODO: custom exception |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
667 if publishers_type not in ["GROUP", "JID", "ALL"]: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
668 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
|
669 if publishers_type == "ALL" and publishers: |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
670 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
671 profile, client = yield self._initialise(profile_key) |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
672 #TODO: we need to use the server corresponding the the host of the jid |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
673 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 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
|
678 jids = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
679 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
|
680 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
|
681 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
|
682 jids = publishers |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
683 else: |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
684 raise UnknownType |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
685 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
686 data = {publisher: 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
|
687 d_dict = yield self.host.plugins["XEP-0060"].getItemsFromMany(client.item_access_pubsub, data, max_items=max_items, profile_key=profile) |
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
|
688 |
b4a264915ea9
plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
689 def cb(jid): |
b4a264915ea9
plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
690 def res(gbdata): |
b4a264915ea9
plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
691 return (jid.full(), gbdata) |
b4a264915ea9
plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
692 return res |
b4a264915ea9
plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
693 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
694 for publisher, d in d_dict.items(): |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
695 d.addCallback(self._itemsConstruction, publisher, client) |
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 d.addCallback(cb(publisher)) |
b4a264915ea9
plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
697 result = yield defer.DeferredList(d_dict.values(), consumeErrors=False) |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
698 defer.returnValue({value[0]: value[1] for success, value in result if success}) |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
699 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
700 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
|
701 def initialised(result): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
702 profile, client = result |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
703 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
|
704 profile_key=profile_key) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
705 return d |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
706 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
707 #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
|
708 return self._initialise(profile_key).addCallback(initialised) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
709 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 else: |
731
80c1072390f3
plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents:
726
diff
changeset
|
714 publishers_jids = publishers |
80c1072390f3
plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents:
726
diff
changeset
|
715 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
|
716 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
717 @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
|
718 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
|
719 """Subscribe microblogs for a list of groups or jids |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
720 @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
|
721 @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
|
722 @param profile_key: profile key |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
723 """ |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
724 #TODO: custom exception |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
725 if publishers_type not in ["GROUP", "JID", "ALL"]: |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
726 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
|
727 if publishers_type == "ALL" and publishers: |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
728 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
729 profile, client = yield self._initialise(profile_key) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
730 #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
|
731 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
732 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
|
733 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
|
734 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
|
735 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
|
736 jids = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
737 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
|
738 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
|
739 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
|
740 jids = publishers |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
741 else: |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
742 raise UnknownType |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
743 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
744 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
|
745 d_list = yield self.host.plugins["XEP-0060"].subscribeToMany(client.item_access_pubsub, node_ids, profile_key=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
|
746 result = yield defer.DeferredList(d_list, consumeErrors=False) |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
747 defer.returnValue(result) |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
1182
diff
changeset
|
748 |
938
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
749 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
|
750 """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
|
751 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
|
752 return defer.DeferredList(calls) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
753 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
754 def deleteAllGroupBlogs(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
|
755 """Delete all the main items and their comments 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
|
756 """ |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
757 def initialised(result): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
758 profile, client = result |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
759 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
|
760 jid_ = client.jid |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
761 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
762 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
|
763 d = self.host.plugins["XEP-0060"].deleteNode(service, main_node, profile_key=profile) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
764 d.addCallback(lambda dummy: log.info(_("All microblog's main items from %s have been deleted!") % jid_.userhost())) |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
765 d.addErrback(lambda failure: log.error(_("Deletion of 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
|
766 {'node': main_node, 'message': failure.getErrorMessage()})) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
767 return d |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
768 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
769 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
|
770 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
771 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
|
772 """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
|
773 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
|
774 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
|
775 """ |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
776 def initialised(result): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
777 """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
|
778 @return: a DeferredList |
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 profile, client = result |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
781 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
|
782 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
|
783 blogs = [] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
784 for jid_ in jids: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
785 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
|
786 d = self.host.plugins["XEP-0060"].getItems(service, main_node, profile_key=profile) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
787 d.addCallback(getComments, client) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
788 d.addErrback(lambda failure, main_node: log.error(_("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
|
789 {'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
|
790 blogs.append(d) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
791 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
792 return defer.DeferredList(blogs) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
793 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
794 def getComments(items, client): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
795 """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
|
796 @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
|
797 @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
|
798 @return: a DeferredList |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
799 """ |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
800 comments = [] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
801 for item in items: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
802 try: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
803 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
|
804 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
|
805 except StopIteration: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
806 continue |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
807 href = link.getAttribute('href') |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
808 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
|
809 d = self.host.plugins["XEP-0060"].getItems(service, node, profile_key=profile_key) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
810 d.addCallback(lambda items, service, node: (service, node, items), service, node) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
811 d.addErrback(lambda failure, node: log.error(_("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
|
812 {'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
|
813 comments.append(d) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
814 dlist = defer.DeferredList(comments) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
815 dlist.addCallback(deleteComments, client) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
816 return dlist |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
817 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
818 def deleteComments(result, client): |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
819 """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
|
820 @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
|
821 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
|
822 @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
|
823 @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
|
824 """ |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
825 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
|
826 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
|
827 if not success: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
828 continue |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
829 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
|
830 item_ids = [] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
831 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
|
832 try: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
833 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
|
834 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
|
835 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
|
836 except StopIteration: |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
837 continue |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
838 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
|
839 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
|
840 deletions = [] |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
841 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
|
842 d = self.host.plugins['XEP-0060'].retractItems(service, node_id, item_ids, profile_key=profile_key) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
843 d.addCallback(lambda dummy, node_id: log.debug(_('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
|
844 {'user': user_jid_s, 'node': node_id}), node_id) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
944
diff
changeset
|
845 d.addErrback(lambda failure, node_id: log.error(_("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
|
846 {'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
|
847 deletions.append(d) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
848 return defer.DeferredList(deletions) |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
849 |
fc7e0828b18e
plugin account, groupblog: user can erase all their microblogs at once
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
850 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
|
851 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
852 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
853 class GroupBlog_handler(XMPPHandler): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
854 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
855 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
856 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
857 return [disco.DiscoFeature(NS_GROUPBLOG)] |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
858 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
859 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
860 return [] |