Mercurial > libervia-backend
annotate src/plugins/plugin_misc_groupblog.py @ 892:58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 28 Feb 2014 11:19:08 +0100 |
parents | a7b2aacf22ac |
children | 1a759096ccbd |
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 _ |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
21 from logging import debug, info, warning, error |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
22 from twisted.internet import defer |
307 | 23 from twisted.words.protocols.jabber import jid |
831
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
24 from twisted.words.xish.domish import Element |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
25 from sat.core import exceptions |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
26 from wokkel import disco, data_form, iwokkel |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
27 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
|
28 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
|
29 import uuid |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
30 import urllib |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
31 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
32 try: |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
33 from twisted.words.protocols.xmlstream import XMPPHandler |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
34 except ImportError: |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
35 from wokkel.subprotocols import XMPPHandler |
307 | 36 |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
37 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
38 NS_GROUPBLOG = 'http://goffi.org/protocol/groupblog' |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
39 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
|
40 NS_COMMENT_PREFIX = 'urn:xmpp:comments:' |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
41 #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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 NS_PUBSUB_AUTO_CREATE = NS_PUBSUB + "#auto-create" |
307 | 47 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
|
48 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
|
49 'GROUP': 'roster', |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
50 '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
|
51 } |
307 | 52 |
53 PLUGIN_INFO = { | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
54 "name": "Group blogging throught collections", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
55 "import_name": "groupblog", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
56 "type": "MISC", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
57 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
58 "dependencies": ["XEP-0277"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
59 "main": "GroupBlog", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
60 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
61 "description": _("""Implementation of microblogging with roster access""") |
307 | 62 } |
63 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
64 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
65 class NoCompatiblePubSubServerFound(Exception): |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
66 pass |
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
67 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
68 |
471 | 69 class BadAccessTypeError(Exception): |
70 pass | |
71 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
72 |
471 | 73 class BadAccessListError(Exception): |
74 pass | |
75 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
76 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
77 class UnknownType(Exception): |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
78 pass |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
79 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
80 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
81 class GroupBlog(object): |
462
d9456d94cd12
plugin groupblog: next-gen group blog first draft
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
82 """This class use a SàT PubSub Service to manage access on microblog""" |
307 | 83 |
84 def __init__(self, host): | |
85 info(_("Group blog plugin initialization")) | |
86 self.host = host | |
87 | |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
88 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
|
89 method=self.sendGroupBlog, |
3c304929af74
plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents:
703
diff
changeset
|
90 async=True) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
91 |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
92 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
|
93 method=self.deleteGroupBlog, |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
94 async=True) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
95 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
96 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
|
97 method=self.updateGroupBlog, |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
98 async=True) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
99 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
100 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
|
101 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
|
102 async=True) |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
103 |
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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 |
892
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
109 host.bridge.addMethod("getGroupBlogsWithComments", ".plugin", |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
110 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
|
111 method=self.getGroupBlogsWithComments, |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
112 async=True) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
113 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
114 host.bridge.addMethod("getLastGroupBlogs", ".plugin", |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
115 in_sign='sis', out_sign='aa{ss}', |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
116 method=self.getLastGroupBlogs, |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
117 async=True) |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
118 |
831
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
119 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
|
120 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
|
121 method=self.getLastGroupBlogsAtom, |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
122 async=True) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
123 |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
124 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin", |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
125 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
|
126 method=self._getMassiveLastGroupBlogs, |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
127 async=True) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
128 |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
129 host.bridge.addMethod("getGroupBlogComments", ".plugin", |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
130 in_sign='sss', out_sign='aa{ss}', |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
131 method=self.getGroupBlogComments, |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
132 async=True) |
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
133 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
134 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
|
135 method=self.subscribeGroupBlog, |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
136 async=True) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
137 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
138 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
|
139 method=self._massiveSubscribeGroupBlogs, |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
140 async=True) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
141 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
142 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
143 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
144 def getHandler(self, profile): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
145 return GroupBlog_handler() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
146 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
147 @defer.inlineCallbacks |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
148 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
|
149 """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
|
150 @param profile_key: %(doc_profile)s""" |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
151 profile = self.host.memory.getProfileName(profile_key) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
152 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
|
153 raise exceptions.ProfileUnknownError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
154 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
155 client = self.host.getClient(profile) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
156 if not client: |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
157 error(_('No client for this profile key: %s') % profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
158 raise Exception("Unknown profile") |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
159 yield client.client_initialized # we want to be sure that the client is initialized |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
160 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
161 #we first check that we have a item-access pubsub server |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
162 if not hasattr(client, "item_access_pubsub"): |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
163 debug(_('Looking for item-access power pubsub server')) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
164 #we don't have any pubsub server featuring item access yet |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
165 client.item_access_pubsub = None |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
166 client._item_access_pubsub_pending = defer.Deferred() |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
731
diff
changeset
|
167 for entity in self.host.memory.getServerServiceEntities("pubsub", "service", profile=profile): |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
168 _disco = yield client.disco.requestInfo(entity) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
169 #if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
170 if set([NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features): |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
171 info(_("item-access powered pubsub service found: [%s]") % entity.full()) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
172 client.item_access_pubsub = entity |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
173 client._item_access_pubsub_pending.callback(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
174 |
618
e2c33a16d235
plugin groupblog: fixed bad inialisation check
Goffi <goffi@goffi.org>
parents:
617
diff
changeset
|
175 if hasattr(client, "_item_access_pubsub_pending"): |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
176 #XXX: we need to wait for item access pubsub service check |
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
|
177 yield client._item_access_pubsub_pending |
478
f856575a62a6
plugin groupblog: fixed initialisation
Goffi <goffi@goffi.org>
parents:
477
diff
changeset
|
178 del client._item_access_pubsub_pending |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
179 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
180 if not client.item_access_pubsub: |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
181 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
|
182 raise NoCompatiblePubSubServerFound |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
183 |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
184 defer.returnValue((profile, client)) |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
185 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
186 def pubSubItemsReceivedTrigger(self, event, profile): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
187 """"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
|
188 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
189 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
|
190 # Microblog |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
191 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
|
192 origin_host = publisher.host.split('.') |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
193 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
|
194 #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
|
195 #TODO: automatic security test |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
196 if (not (origin_host) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
197 or len(event_host) < len(origin_host) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
198 or event_host[-len(origin_host):] != origin_host): |
532
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
199 warning("Host incoherence between %s and %s (hack attempt ?)" % (unicode(event.sender), |
db4ae4d18f09
plugin group blog: security check + fixed publisher in personalEvent signal
Goffi <goffi@goffi.org>
parents:
529
diff
changeset
|
200 unicode(publisher))) |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
201 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
|
202 |
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 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
|
204 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
205 def gbdataManagementMicroblog(gbdata): |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
206 for gbdatum in gbdata: |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
207 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
|
208 |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
209 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
|
210 d.addCallback(gbdataManagementMicroblog) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
211 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
|
212 |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
213 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
|
214 # Comment |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
215 def gbdataManagementComments(gbdata): |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
216 for gbdatum in gbdata: |
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 return False |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
222 return True |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
223 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
224 @defer.inlineCallbacks |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
225 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
|
226 """ 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
|
227 @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
|
228 @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
|
229 @param node_identifier: comments node |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
230 @return: 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
|
231 """ |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
232 ret = [] |
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
|
233 for item in 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
|
234 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
|
235 # 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
|
236 # quickly. |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
237 microblog_data = yield self.item2gbdata(item, "comment") |
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
|
238 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
|
239 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
|
240 microblog_data["verified_publisher"] = "true" if publisher else "false" |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
241 ret.append(microblog_data) |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
242 defer.returnValue(ret) |
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
|
243 |
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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 form = data_form.Form.fromElement(form_elt) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
249 |
534
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
250 if (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
|
251 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
|
252 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
|
253 try: |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
254 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
|
255 except KeyError: |
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 warning("No group found for roster access-model") |
07f369ed3988
plugin group blog: item configuration data (which groups are allowed) are parsed and added to microblog data
Goffi <goffi@goffi.org>
parents:
532
diff
changeset
|
257 microblog_data["groups"] = '' |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
258 |
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 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
|
260 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
261 @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
|
262 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
|
263 """ 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
269 def getNodeName(self, publisher): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
270 """Retrieve the name of publisher's node |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
271 @param publisher: publisher's jid |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
272 @return: node's name (string)""" |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
273 return NS_NODE_PREFIX + publisher.userhost() |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
274 |
703
0c2c1dfb79e4
plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents:
660
diff
changeset
|
275 def _publishMblog(self, service, client, access_type, access_list, message, extra): |
307 | 276 """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
|
277 @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
|
278 @param client: SatXMPPClient of the publisher |
471 | 279 @param access_type: one of "PUBLIC", "GROUP", "JID" |
280 @param access_list: set of entities (empty list for all, groups or jids) allowed to see the item | |
307 | 281 @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
|
282 @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
|
283 - 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
|
284 - rich: if present, contain rich text in currently selected syntax |
471 | 285 """ |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
286 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
|
287 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
|
288 |
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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 |
703
0c2c1dfb79e4
plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents:
660
diff
changeset
|
295 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
|
296 # 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
|
297 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
|
298 _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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 } |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
305 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
|
306 _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
|
307 |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
308 # 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
|
309 # 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
|
310 # node owned by somebody else) |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
311 defer_blog = self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile) |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
312 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
313 def itemCreated(mblog_item): |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
314 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
|
315 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
316 if access_type == "PUBLIC": |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
317 if access_list: |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
318 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
|
319 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
|
320 form.addField(access) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
321 elif access_type == "GROUP": |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
322 access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
323 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
|
324 form.addField(access) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
325 form.addField(allowed) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
326 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
|
327 elif access_type == "JID": |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
328 raise NotImplementedError |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
329 else: |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
330 error(_("Unknown access_type")) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
331 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
|
332 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
333 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
|
334 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
|
335 return defer_blog |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
336 |
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
|
337 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
|
338 entry_d.addCallback(itemCreated) |
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
339 return entry_d |
307 | 340 |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
341 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
|
342 """ |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
343 @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
|
344 @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
|
345 @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
|
346 @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
|
347 @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
|
348 """ |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
349 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
|
350 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
|
351 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
|
352 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
|
353 '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
|
354 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
|
355 |
307 | 356 def _mblogPublicationFailed(self, failure): |
357 #TODO | |
471 | 358 return failure |
307 | 359 |
703
0c2c1dfb79e4
plugin group blog: renamed options parameter as extra for consistency with sendMessage
Goffi <goffi@goffi.org>
parents:
660
diff
changeset
|
360 def sendGroupBlog(self, access_type, access_list, message, extra, profile_key='@NONE@'): |
471 | 361 """Publish a microblog with given item access |
362 @param access_type: one of "PUBLIC", "GROUP", "JID" | |
363 @param access_list: list of authorized entity (empty list for PUBLIC ACCESS, | |
364 list of groups or list of jids) for this item | |
307 | 365 @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
|
366 @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
|
367 - 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
|
368 - 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
|
369 @profile_key: %(doc_profile_key)s |
307 | 370 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
371 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
372 def initialised(result): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
373 profile, client = result |
471 | 374 if access_type == "PUBLIC": |
375 if access_list: | |
376 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
|
377 return self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra) |
471 | 378 elif access_type == "GROUP": |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
379 _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist |
471 | 380 if not _groups: |
381 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
|
382 return self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra) |
471 | 383 elif access_type == "JID": |
384 raise NotImplementedError | |
385 else: | |
386 error(_("Unknown access type")) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
387 raise BadAccessTypeError |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
388 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
389 return self._initialise(profile_key).addCallback(initialised) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
390 |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
391 def deleteGroupBlog(self, pub_data, comments, profile_key='@NONE@'): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
392 """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
|
393 @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
|
394 @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
|
395 @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
|
396 """ |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
397 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
398 def initialised(result): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
399 profile, client = result |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
400 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
|
401 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
|
402 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
|
403 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
|
404 if comments: |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
405 # 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
|
406 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
|
407 d = self.host.plugins["XEP-0060"].deleteNode(comments_service, comments_node, profile_key=profile) |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
408 d.addErrback(lambda failure: 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
|
409 # 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
|
410 d = self.host.plugins["XEP-0060"].retractItems(service_jid, node, [item_id], profile_key=profile) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
411 d.addErrback(lambda failure: error("Deletion of item %s from %s failed: %s" % (item_id, node, failure.getErrorMessage()))) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
412 return d |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
413 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
414 def notify(d): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
415 # 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
|
416 # implemented according to http://xmpp.org/extensions/xep-0060.html#publisher-delete-success-notify |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
417 # instead. The notification mechanisms implemented in sat_pubsub and wokkel seem not compatible, |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
418 # see wokkel.pubsub.PubSubClient._onEvent_items and sat_pubsub.backend._doNotifyRetraction |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 return d |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
425 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
426 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
|
427 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
428 def updateGroupBlog(self, pub_data, comments, message, extra, profile_key='@NONE@'): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
429 """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
|
430 @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
|
431 @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
|
432 @param message: new message |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
433 @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
|
434 - 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
|
435 - 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
|
436 @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
|
437 """ |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
438 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
439 def initialised(result): |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
440 profile, client = result |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 if 'published' in extra: |
64dd7c0f4feb
plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents:
745
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 # 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
|
455 # 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
|
456 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
|
457 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
|
458 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
|
459 entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service_jid, node, items=[mblog_item], profile_key=profile)) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
460 entry_d.addErrback(lambda failure: error("Modification of %s failed: %s" % (pub_data, failure.getErrorMessage()))) |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
461 return entry_d |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
462 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
463 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
|
464 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
465 def sendGroupBlogComment(self, node_url, message, extra, profile_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
|
466 """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
|
467 @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
|
468 @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
|
469 @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
|
470 - 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
|
471 - 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
|
472 @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
|
473 """ |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
474 def initialised(result): |
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
475 profile, client = result |
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 raise NotImplementedError # TODO |
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
487 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
|
488 |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
489 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
490 @defer.inlineCallbacks |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
491 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
|
492 """ Transforms items to group blog data and manage comments node |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
493 @param items: iterable of items |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
494 @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
|
495 @param client: SatXMPPClient instance |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
496 @return: deferred which fire list of group blog data """ |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
497 # TODO: use items data when pub_jid is None |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
498 ret = [] |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
499 for item in items: |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
500 gbdata = yield self.item2gbdata(item) |
858
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
501 try: |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
502 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
|
503 except AttributeError: |
660b3f5b6c78
plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling:
souliane <souliane@mailoo.org>
parents:
847
diff
changeset
|
504 pass |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
505 ret.append(gbdata) |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
506 # if there is a comments node, we subscribe to it |
619
1de01a2154e2
plugin group blog: getItems for comments fixed when we are the publisher of the parent node
Goffi <goffi@goffi.org>
parents:
618
diff
changeset
|
507 if "comments_node" in gbdata: |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
508 try: |
619
1de01a2154e2
plugin group blog: getItems for comments fixed when we are the publisher of the parent node
Goffi <goffi@goffi.org>
parents:
618
diff
changeset
|
509 # every comments node must be subscribed, except if we are the publisher (we are already subscribed in this case) |
1de01a2154e2
plugin group blog: getItems for comments fixed when we are the publisher of the parent node
Goffi <goffi@goffi.org>
parents:
618
diff
changeset
|
510 if pub_jid.userhostJID() != client.jid.userhostJID(): |
1de01a2154e2
plugin group blog: getItems for comments fixed when we are the publisher of the parent node
Goffi <goffi@goffi.org>
parents:
618
diff
changeset
|
511 self.host.plugins["XEP-0060"].subscribe(jid.JID(gbdata["comments_service"]), gbdata["comments_node"], |
1de01a2154e2
plugin group blog: getItems for comments fixed when we are the publisher of the parent node
Goffi <goffi@goffi.org>
parents:
618
diff
changeset
|
512 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
|
513 except KeyError: |
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
514 warning("Missing key for comments") |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
515 defer.returnValue(ret) |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
516 |
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
|
517 def __getGroupBlogs(self, pub_jid_s, max_items=10, item_ids=None, profile_key='@NONE@'): |
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
|
518 """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
|
519 @param pub_jid_s: jid of the publisher |
471 | 520 @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
|
521 @param item_ids: list of microblogs items IDs |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
522 @param profile_key: profile key |
471 | 523 @return: list of microblog data (dict) |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
524 """ |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
525 pub_jid = jid.JID(pub_jid_s) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
526 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
527 def initialised(result): |
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 return d |
308
ce3607b7198d
plugin group blog: blog collection cleaning
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
534 |
465
78e67a59d51d
plugin groupblog: added getLastGroupBlogs method
Goffi <goffi@goffi.org>
parents:
462
diff
changeset
|
535 #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
|
536 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
|
537 |
891
a7b2aacf22ac
plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents:
860
diff
changeset
|
538 def getGroupBlogs(self, pub_jid_s, item_ids=None, profile_key='@NONE@'): |
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
|
539 """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
|
540 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
|
541 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
|
542 @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
|
543 @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
|
544 @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
|
545 @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
|
546 """ |
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 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
|
548 |
892
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
549 def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key='@NONE@'): |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
550 """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
|
551 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
|
552 @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
|
553 @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
|
554 @param profile_key: profile key |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
555 @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
|
556 """ |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
557 def get_comments(data): |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
558 d_list = [] |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
559 for entry in data: |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
560 if entry.get('comments', False): |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
561 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
|
562 d.addCallback(lambda data: (entry, data)) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
563 d_list.append(d) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
564 else: |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
565 d_list.append(defer.succeed((entry, []))) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
566 deferred_list = defer.DeferredList(d_list) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
567 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
|
568 return deferred_list |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
569 |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
570 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
|
571 d.addCallback(get_comments) |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
572 return d |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
573 |
58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
souliane <souliane@mailoo.org>
parents:
891
diff
changeset
|
574 |
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
|
575 def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'): |
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 |
831
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
584 def getLastGroupBlogsAtom(self, pub_jid_s, max_items=10, profile_key='@NONE@'): |
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) |
d7f9cd8a08cd
plugin groupblog: added method getLastGroupBlogsAtom returns the Atom feed of blog posts
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
625 d.addErrback(lambda ignore: {}) # TODO: more complete error management (log !) |
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 |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
631 def getGroupBlogComments(self, service_s, node, profile_key='@NONE@'): |
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 |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
651 def _getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'): |
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 |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
658 def getMassiveLastGroupBlogs(self, publishers_type, publishers, max_items=10, profile_key='@NONE@'): |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
659 """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
|
660 @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
|
661 @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
|
662 @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
|
663 @param profile_key: profile key |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
664 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
665 |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
666 def sendResult(result): |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
667 """send result of DeferredList (list of microblogs to the calling method""" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
668 |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
669 ret = {} |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
670 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
671 for (success, value) in result: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
672 if success: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
673 source_jid, data = value |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
674 ret[source_jid] = data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
675 |
470
5c916b99d0f6
plugin groupblog, D-Bus frontend: added getLastGroupBlogs and getMassiveLastGroupBlogs
Goffi <goffi@goffi.org>
parents:
467
diff
changeset
|
676 return ret |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
677 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
678 def initialised(result): |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
679 profile, client = result |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
680 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
681 if publishers_type == "ALL": |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
682 contacts = client.roster.getItems() |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
683 jids = [contact.jid.userhostJID() for contact in contacts] |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
684 elif publishers_type == "GROUP": |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
685 jids = [] |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
686 for _group in publishers: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
687 jids.extend(client.roster.getJidsFromGroup(_group)) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
688 elif publishers_type == 'JID': |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
689 jids = publishers |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
690 else: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
691 raise UnknownType |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
692 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
693 mblogs = [] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
694 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
695 |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
696 for jid_ in jids: |
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
697 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid_), |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
698 max_items=max_items, profile_key=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
|
699 d.addCallback(self._itemsConstruction, jid_, client) |
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
700 d.addCallback(lambda gbdata, source_jid: (source_jid, gbdata), jid_.full()) |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
701 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
702 mblogs.append(d) |
847
071524bfcc7d
plugin groupblog: do not log error message when asking for the entries of a non existent node (e.g the contact hasn't posted any message yet)
souliane <souliane@mailoo.org>
parents:
832
diff
changeset
|
703 # consume the failure "StanzaError with condition u'item-not-found'" |
071524bfcc7d
plugin groupblog: do not log error message when asking for the entries of a non existent node (e.g the contact hasn't posted any message yet)
souliane <souliane@mailoo.org>
parents:
832
diff
changeset
|
704 # when the node doesn't exist (e.g that JID hasn't posted any message) |
071524bfcc7d
plugin groupblog: do not log error message when asking for the entries of a non existent node (e.g the contact hasn't posted any message yet)
souliane <souliane@mailoo.org>
parents:
832
diff
changeset
|
705 dlist = defer.DeferredList(mblogs, consumeErrors=True) |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
706 dlist.addCallback(sendResult) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
707 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
708 return dlist |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
709 |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
710 #TODO: custom exception |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
711 if publishers_type not in ["GROUP", "JID", "ALL"]: |
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
712 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
|
713 if publishers_type == "ALL" and publishers: |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
714 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
715 return self._initialise(profile_key).addCallback(initialised) |
467
47af60767013
plugin group blog: getMassiveGroupBlog first draft
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
716 #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
|
717 |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
718 def subscribeGroupBlog(self, pub_jid, profile_key='@NONE@'): |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
719 def initialised(result): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
720 profile, client = result |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
721 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
|
722 profile_key=profile_key) |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
723 return d |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
724 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
725 #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
|
726 return self._initialise(profile_key).addCallback(initialised) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
727 |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
728 def _massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'): |
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
729 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
|
730 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
|
731 else: |
731
80c1072390f3
plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents:
726
diff
changeset
|
732 publishers_jids = publishers |
80c1072390f3
plugin microbloging: fixes bad calls
Goffi <goffi@goffi.org>
parents:
726
diff
changeset
|
733 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
|
734 |
621
0e16288d6816
pluging groupblog: comments handling:
Goffi <goffi@goffi.org>
parents:
619
diff
changeset
|
735 def massiveSubscribeGroupBlogs(self, publishers_type, publishers, profile_key='@NONE@'): |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
736 """Subscribe microblogs for a list of groups or jids |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
737 @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
|
738 @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
|
739 @param profile_key: profile key |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
740 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
741 |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
742 def initialised(result): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
743 profile, client = result |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
744 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
745 if publishers_type == "ALL": |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
746 contacts = client.roster.getItems() |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
747 jids = [contact.jid.userhostJID() for contact in contacts] |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
748 elif publishers_type == "GROUP": |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
749 jids = [] |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
750 for _group in publishers: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
751 jids.extend(client.roster.getJidsFromGroup(_group)) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
752 elif publishers_type == 'JID': |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
753 jids = publishers |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
754 else: |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
755 raise UnknownType |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
756 |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
757 mblogs = [] |
726
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
758 for jid_ in jids: |
ade9997fabfa
core: use of Twisted JID instead of string bare jid in roster SatRosterProtocol
Goffi <goffi@goffi.org>
parents:
708
diff
changeset
|
759 d = self.host.plugins["XEP-0060"].subscribe(client.item_access_pubsub, self.getNodeName(jid_), |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
760 profile_key=profile_key) |
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
761 mblogs.append(d) |
847
071524bfcc7d
plugin groupblog: do not log error message when asking for the entries of a non existent node (e.g the contact hasn't posted any message yet)
souliane <souliane@mailoo.org>
parents:
832
diff
changeset
|
762 # consume the failure "StanzaError with condition u'item-not-found'" |
071524bfcc7d
plugin groupblog: do not log error message when asking for the entries of a non existent node (e.g the contact hasn't posted any message yet)
souliane <souliane@mailoo.org>
parents:
832
diff
changeset
|
763 # when the node doesn't exist (e.g that JID hasn't posted any message) |
071524bfcc7d
plugin groupblog: do not log error message when asking for the entries of a non existent node (e.g the contact hasn't posted any message yet)
souliane <souliane@mailoo.org>
parents:
832
diff
changeset
|
764 dlist = defer.DeferredList(mblogs, consumeErrors=True) |
529
c18e0e108925
plugin groupblog: fixed GROUP and JID publishers_type in getMassiveLastGroupBlogs and massiveSubscribeGroupBlogs
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
765 return dlist |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
766 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
767 #TODO: custom exception |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
768 if publishers_type not in ["GROUP", "JID", "ALL"]: |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
769 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
|
770 if publishers_type == "ALL" and publishers: |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
771 raise Exception("Publishers list must be empty when getting microblogs for all contacts") |
708
6aa71c853bf5
plugin group blog: management of extra data/rich text for blog comments
Goffi <goffi@goffi.org>
parents:
707
diff
changeset
|
772 return self._initialise(profile_key).addCallback(initialised) |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
773 #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
|
774 |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
476
diff
changeset
|
775 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
776 class GroupBlog_handler(XMPPHandler): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
777 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
778 |
476
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
779 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
780 return [disco.DiscoFeature(NS_GROUPBLOG)] |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
781 |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
782 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
b9fd32b46306
plugin groupblog: added disco info + misc fixes
Goffi <goffi@goffi.org>
parents:
471
diff
changeset
|
783 return [] |