Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0277.py @ 1829:6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 23 Jan 2016 19:53:16 +0100 |
parents | 1424cc6f8e98 |
children | 68c0dc13d821 |
rev | line source |
---|---|
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for microblogging over XMPP (xep-0277) |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
1648
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
20 from sat.core.i18n import _, D_ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
859
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
22 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
23 log = getLogger(__name__) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
24 from twisted.words.protocols.jabber import jid, error |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
25 from twisted.words.xish import domish |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
26 from twisted.internet import defer |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
27 from twisted.python import failure |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
28 from sat.core import exceptions |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
29 from sat.tools import xml_tools |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
30 from sat.tools import sat_defer |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
31 from sat.tools import common |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
33 # XXX: tmp.pubsub is actually use instead of wokkel version |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
34 from wokkel import pubsub |
1542
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1516
diff
changeset
|
35 try: |
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1516
diff
changeset
|
36 from feed.date import rfc3339 |
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1516
diff
changeset
|
37 except ImportError: |
94901070478e
plugins: added new MissingModule exceptions to plugins using third party modules
Goffi <goffi@goffi.org>
parents:
1516
diff
changeset
|
38 raise exceptions.MissingModule(u"Missing module pyfeed, please download/install it from http://home.avvanta.com/~steveha/pyfeed.html") |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 import uuid |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
40 import time |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
41 import urlparse |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
42 import urllib |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 NS_MICROBLOG = 'urn:xmpp:microblog:0' |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
45 NS_ATOM = 'http://www.w3.org/2005/Atom' |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
46 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
47 NS_COMMENT_PREFIX = '{}:comments/'.format(NS_MICROBLOG) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
48 |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
51 "name": "Microblogging over XMPP Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 "import_name": "XEP-0277", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
53 "type": "XEP", |
1275
54a898821740
plugin XEP-0277: minor fix in plugin declaration
souliane <souliane@mailoo.org>
parents:
1268
diff
changeset
|
54 "protocols": ["XEP-0277"], |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
55 "dependencies": ["XEP-0163", "XEP-0060", "TEXT-SYNTAXES"], |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
56 "recommendations": ["XEP-0059", "EXTRA-PEP"], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
57 "main": "XEP_0277", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
58 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
59 "description": _("""Implementation of microblogging Protocol""") |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 } |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 |
339
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
63 class NodeAccessChangeException(Exception): |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
64 pass |
b0b773f432e5
plugin XEP-00277: setMicroblogAccess is now asynchronous
Goffi <goffi@goffi.org>
parents:
311
diff
changeset
|
65 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
66 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
67 class XEP_0277(object): |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 def __init__(self, host): |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
70 log.info(_(u"Microblogging plugin initialization")) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 self.host = host |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
72 self._p = self.host.plugins["XEP-0060"] # this facilitate the access to pubsub plugin |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
73 self.rt_sessions = sat_defer.RTDeferredSessions() |
1760
30efe084471c
plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents:
1750
diff
changeset
|
74 self.host.plugins["XEP-0060"].addManagedNode(NS_MICROBLOG, items_cb=self._itemsReceived) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
75 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
76 host.bridge.addMethod("mbSend", ".plugin", |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
77 in_sign='ssa{ss}s', out_sign='', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
78 method=self._mbSend, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
79 async=True) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
80 host.bridge.addMethod("mbRetract", ".plugin", |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
81 in_sign='ssss', out_sign='', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
82 method=self._mbRetract, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
83 async=True) |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
84 host.bridge.addMethod("mbGet", ".plugin", |
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
85 in_sign='ssiasa{ss}s', out_sign='(aa{ss}a{ss})', |
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
86 method=self._mbGet, |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
87 async=True) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
88 host.bridge.addMethod("mbSetAccess", ".plugin", in_sign='ss', out_sign='', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
89 method=self.mbSetAccess, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
90 async=True) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
91 host.bridge.addMethod("mbSetAccess", ".plugin", in_sign='ss', out_sign='', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
92 method=self.mbSetAccess, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
93 async=True) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
94 host.bridge.addMethod("mbSubscribeToMany", ".plugin", in_sign='sass', out_sign='s', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
95 method=self._mbSubscribeToMany) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
96 host.bridge.addMethod("mbGetFromManyRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssaa{ss}a{ss}))', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
97 method=self._mbGetFromManyRTResult, async=True) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
98 host.bridge.addMethod("mbGetFromMany", ".plugin", in_sign='sasia{ss}s', out_sign='s', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
99 method=self._mbGetFromMany) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
100 host.bridge.addMethod("mbGetFromManyWithCommentsRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssa(a{ss}a(sssaa{ss}a{ss}))a{ss}))', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
101 method=self._mbGetFromManyWithCommentsRTResult, async=True) |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
102 host.bridge.addMethod("mbGetFromManyWithComments", ".plugin", in_sign='sasiia{ss}a{ss}s', out_sign='s', |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
103 method=self._mbGetFromManyWithComments) |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
104 host.bridge.addMethod("mbGetAtom", ".plugin", in_sign='ssiasa{ss}s', out_sign='s', |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
105 method=self._mbGetAtom, async=True) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
106 |
1656
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
107 def _checkFeaturesCb(self, available): |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
108 return {'available': C.BOOL_TRUE} |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
109 |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
110 def _checkFeaturesEb(self, fail): |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
111 return {'available': C.BOOL_FALSE} |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
112 |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
113 def getFeatures(self, profile): |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
114 d = self.host.checkFeatures([], identity=('pubsub', 'pep'), profile=profile) |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
115 d.addCallbacks(self._checkFeaturesCb, self._checkFeaturesEb) |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
116 return d |
069abd15354f
plugin XEP-0277: checkFeatures implemented
Goffi <goffi@goffi.org>
parents:
1649
diff
changeset
|
117 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
118 ## plugin management methods ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
119 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
120 def _itemsReceived(self, itemsEvent, profile): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
121 """Callback which manage items notifications (publish + retract)""" |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
122 def manageItem(data, event): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
123 self.host.bridge.psEvent(C.PS_MICROBLOG, itemsEvent.sender.full(), itemsEvent.nodeIdentifier, event, data, profile) |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
124 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
125 for item in itemsEvent.items: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
126 if item.name == C.PS_ITEM: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
127 self.item2mbdata(item).addCallbacks(manageItem, lambda failure: None, (C.PS_PUBLISH,)) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
128 elif item.name == C.PS_RETRACT: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
129 manageItem({'id': item['id']}, C.PS_RETRACT) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
130 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
131 raise exceptions.InternalError("Invalid event value") |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
132 |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
133 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
134 ## data/item transformation ## |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
135 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
136 @defer.inlineCallbacks |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
137 def item2mbdata(self, item_elt): |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
138 """Convert an XML Item to microblog data used in bridge API |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
139 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
140 @param item_elt: domish.Element of microblog item |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
141 @return: microblog data (dictionary) |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
142 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
143 microblog_data = {} |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
144 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
145 def check_conflict(key, increment=False): |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
146 """Check if key is already in microblog data |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
147 |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
148 @param key(unicode): key to check |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
149 @param increment(bool): if suffix the key with an increment |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
150 instead of raising an exception |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
151 @raise exceptions.DataError: the key already exists |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
152 (not raised if increment is True) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
153 """ |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
154 if key in microblog_data: |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
155 if not increment: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
156 raise failure.Failure(exceptions.DataError("key {} is already present for item {}").format(key, item_elt['id'])) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
157 else: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
158 idx=1 # the idx 0 is the key without suffix |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
159 fmt = "{}#{}" |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
160 new_key = fmt.format(key, idx) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
161 while new_key in microblog_data: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
162 idx+=1 |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
163 new_key = fmt.format(key, idx) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
164 key = new_key |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
165 return key |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
166 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
167 @defer.inlineCallbacks |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
168 def parseElement(elem): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
169 """Parse title/content elements and fill microblog_data accordingly""" |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
170 type_ = elem.getAttribute('type') |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
171 if type_ == 'xhtml': |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
172 data_elt = elem.firstChildElement() |
1709
c47ba491a85a
plugin XEP-0277: raise a failure if XHTML content is not wrapped in a <div/>
Goffi <goffi@goffi.org>
parents:
1708
diff
changeset
|
173 if data_elt is None: |
c47ba491a85a
plugin XEP-0277: raise a failure if XHTML content is not wrapped in a <div/>
Goffi <goffi@goffi.org>
parents:
1708
diff
changeset
|
174 raise failure.Failure(exceptions.DataError(u"XHML content not wrapped in a <div/> element, this is not standard !")) |
1822
aaf034bc6f7a
plugin XEP-0277: moved NS_XHTML namespace to constants + adapted parsing to new behaviour of ElementParser
Goffi <goffi@goffi.org>
parents:
1821
diff
changeset
|
175 if data_elt.uri != C.NS_XHTML: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
176 raise failure.Failure(exceptions.DataError(_('Content of type XHTML must declare its namespace!'))) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
177 key = check_conflict(u'{}_xhtml'.format(elem.name)) |
1791 | 178 data = data_elt.toXml() |
1812
160b0d4c6520
plugin XEP-0071, XEP-0277: method clean_xhtml has been renamed to cleanXHTML
souliane <souliane@mailoo.org>
parents:
1802
diff
changeset
|
179 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].cleanXHTML(data) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
180 else: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
181 key = check_conflict(elem.name) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
182 microblog_data[key] = unicode(elem) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
183 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
184 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
185 id_ = item_elt.getAttribute('id', '') # there can be no id for transient nodes |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
186 microblog_data['id'] = id_ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
187 if item_elt.uri not in (pubsub.NS_PUBSUB, NS_PUBSUB_EVENT): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
188 msg = u"Unsupported namespace {ns} in pubsub item {id_}".format(ns=item_elt.uri, id_=id_) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
189 log.warning(msg) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
190 raise failure.Failure(exceptions.DataError(msg)) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
191 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
192 try: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
193 entry_elt = item_elt.elements(NS_ATOM, 'entry').next() |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
194 except StopIteration: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
195 msg = u'No atom entry found in the pubsub item {}'.format(id_) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
196 raise failure.Failure(exceptions.DataError(msg)) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
197 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
198 # atom:id |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
199 try: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
200 id_elt = entry_elt.elements(NS_ATOM, 'id').next() |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
201 except StopIteration: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
202 msg = u'No atom id found in the pubsub item {}, this is not standard !'.format(id_) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
203 log.warning(msg) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
204 microblog_data['atom_id'] = "" |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
205 else: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
206 microblog_data['atom_id'] = unicode(id_elt) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
207 |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
208 # title/content(s) |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
209 |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
210 # FIXME: ATOM and XEP-0277 only allow 1 <title/> element |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
211 # but in the wild we have some blogs with several ones |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
212 # so we don't respect the standard for now (it doesn't break |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
213 # anything anyway), and we'll find a better option later |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
214 # try: |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
215 # title_elt = entry_elt.elements(NS_ATOM, 'title').next() |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
216 # except StopIteration: |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
217 # msg = u'No atom title found in the pubsub item {}'.format(id_) |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
218 # raise failure.Failure(exceptions.DataError(msg)) |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
219 title_elts = list(entry_elt.elements(NS_ATOM, 'title')) |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
220 if not title_elts: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
221 msg = u'No atom title found in the pubsub item {}'.format(id_) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
222 raise failure.Failure(exceptions.DataError(msg)) |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
223 for title_elt in title_elts: |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
224 yield parseElement(title_elt) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
225 |
1708
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
226 # FIXME: as for <title/>, Atom only authorise at most 1 content |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
227 # but XEP-0277 allows several ones. So for no we handle as |
6d6eae490681
plugin XEP-0277: accept several <title/> elements, there is a standard issue so for now it's the most flexible behaviour
Goffi <goffi@goffi.org>
parents:
1699
diff
changeset
|
228 # if more than one can be present |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
229 for content_elt in entry_elt.elements(NS_ATOM, 'content'): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
230 yield parseElement(content_elt) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
231 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
232 # we check that text content is present |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
233 for key in ('title', 'content'): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
234 if key not in microblog_data and ('{}_xhtml'.format(key)) in microblog_data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
235 log.warning(u"item {id_} provide a {key}_xhtml data but not a text one".format(id_=id_, key=key)) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
236 # ... and do the conversion if it's not |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
237 microblog_data[key] = yield self.host.plugins["TEXT-SYNTAXES"].\ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
238 convert(microblog_data['{}_xhtml'.format(key)], |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
239 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_XHTML, |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
240 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_TEXT, |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
241 False) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
242 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
243 if 'content' not in microblog_data: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
244 # use the atom title data as the microblog body content |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
245 microblog_data['content'] = microblog_data['title'] |
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
246 del microblog_data['title'] |
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
247 if 'title_xhtml' in microblog_data: |
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
248 microblog_data['content_xhtml'] = microblog_data['title_xhtml'] |
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
249 del microblog_data['title_xhtml'] |
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
250 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
251 # published/updated dates |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
252 try: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
253 updated_elt = entry_elt.elements(NS_ATOM, 'updated').next() |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
254 except StopIteration: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
255 msg = u'No atom updated element found in the pubsub item {}'.format(id_) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
256 raise failure.Failure(exceptions.DataError(msg)) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
257 microblog_data['updated'] = unicode(rfc3339.tf_from_timestamp(unicode(updated_elt))) |
302
9f3a6cf91668
plugin xep-0277: added getLastMicroblogs method
Goffi <goffi@goffi.org>
parents:
297
diff
changeset
|
258 try: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
259 published_elt = entry_elt.elements(NS_ATOM, 'published').next() |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
260 except StopIteration: |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
261 microblog_data['published'] = microblog_data['updated'] |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
262 else: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
263 microblog_data['published'] = unicode(rfc3339.tf_from_timestamp(unicode(published_elt))) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
264 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
265 # links |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
266 for link_elt in entry_elt.elements(NS_ATOM, 'link'): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
267 if link_elt.getAttribute('rel') == 'replies' and link_elt.getAttribute('title') == 'comments': |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
268 key = check_conflict('comments', True) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
269 microblog_data[key] = link_elt['href'] |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
270 try: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
271 service, node = self.parseCommentUrl(microblog_data[key]) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
272 except: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
273 log.warning(u"Can't parse url {}".format(microblog_data[key])) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
274 del microblog_data[key] |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
275 else: |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
276 microblog_data['{}_service'.format(key)] = service.full() |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
277 microblog_data['{}_node'.format(key)] = node |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
278 else: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
279 rel = link_elt.getAttribute('rel','') |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
280 title = link_elt.getAttribute('title','') |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
281 href = link_elt.getAttribute('href','') |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
282 log.warning(u"Unmanaged link element: rel={rel} title={title} href={href}".format(rel=rel, title=title, href=href)) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
283 |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
284 # author |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
858
diff
changeset
|
285 try: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
286 author_elt = entry_elt.elements(NS_ATOM, 'author').next() |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
287 except StopIteration: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
288 log.debug(u"Can't find author element in item {}".format(id_)) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
289 else: |
1681
c6c835046681
plugin XEP-0277: minor fixes for publisher attribute
Goffi <goffi@goffi.org>
parents:
1680
diff
changeset
|
290 publisher = item_elt.getAttribute("publisher") |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
291 # name |
770
64dd7c0f4feb
plugin groupblog, XEP-0277: store both published and updated timestamps
souliane <souliane@mailoo.org>
parents:
745
diff
changeset
|
292 try: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
293 name_elt = author_elt.elements(NS_ATOM, 'name').next() |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
294 except StopIteration: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
295 log.warning(u"No name element found in author element of item {}".format(id_)) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
296 else: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
297 microblog_data['author'] = unicode(name_elt) |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
298 # uri |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
299 try: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
300 uri_elt = author_elt.elements(NS_ATOM, 'uri').next() |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
301 except StopIteration: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
302 log.debug(u"No uri element found in author element of item {}".format(id_)) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
303 if publisher: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
304 microblog_data['author_jid'] = publisher |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
305 else: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
306 uri = unicode(uri_elt) |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
307 if uri.startswith("xmpp:"): |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
308 uri = uri[5:] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
309 microblog_data['author_jid'] = uri |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
310 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
311 microblog_data['author_jid'] = item_elt.getAttribute("publisher") or "" |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
312 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
313 if not publisher: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
314 log.debug(u"No publisher attribute, we can't verify author jid") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
315 microblog_data['author_jid_verified'] = C.BOOL_FALSE |
1681
c6c835046681
plugin XEP-0277: minor fixes for publisher attribute
Goffi <goffi@goffi.org>
parents:
1680
diff
changeset
|
316 elif jid.JID(publisher).userhostJID() == jid.JID(uri).userhostJID(): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
317 microblog_data['author_jid_verified'] = C.BOOL_TRUE |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
318 else: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
319 log.warning(u"item atom:uri differ from publisher attribute, spoofing attempt ? atom:uri = {} publisher = {}".format(uri, item_elt.getAttribute("publisher"))) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
320 microblog_data['author_jid_verified'] = C.BOOL_FALSE |
1453
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
321 # email |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
322 try: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
323 email_elt = author_elt.elements(NS_ATOM, 'email').next() |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
324 except StopIteration: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
325 pass |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
326 else: |
d5e72362ee91
plugin XEP-0277: better parsing of atom:author element + item2mbdata minor reorganisation for better readability
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
327 microblog_data['author_email'] = unicode(email_elt) |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
328 |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
329 # categories |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
330 categories = (category_elt.getAttribute('term','') for category_elt in entry_elt.elements(NS_ATOM, 'category')) |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
331 common.iter2dict('tag', categories, microblog_data) |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
332 |
1671
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
333 ## the trigger ## |
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
334 # if other plugins have things to add or change |
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
335 yield self.host.trigger.point("XEP-0277_item2data", item_elt, entry_elt, microblog_data) |
1895846fc9cb
plugin XEP-0277, group blog: added item2data trigger + group permission are parsed when receiving a new item
Goffi <goffi@goffi.org>
parents:
1664
diff
changeset
|
336 |
707
890fbf2d7fdd
plugin XEP-0277, groupblog: rich text management for receiving microblogs
Goffi <goffi@goffi.org>
parents:
706
diff
changeset
|
337 defer.returnValue(microblog_data) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
339 @defer.inlineCallbacks |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
340 def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE): |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
341 """Convert a data dict to en entry usable to create an item |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
342 |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
343 @param data: data dict as given by bridge method. |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
344 @param item_id(unicode, None): id of the item to use |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
345 if None the id will be generated randomly |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
346 @return: deferred which fire domish.Element |
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
347 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
348 if item_id is None: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
349 item_id = unicode(uuid.uuid4()) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
350 client = self.host.getClient(profile) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
351 entry_elt = domish.Element((NS_ATOM, 'entry')) |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
352 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
353 ## content and title ## |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
354 synt = self.host.plugins["TEXT-SYNTAXES"] |
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
355 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
356 for elem_name in ('title', 'content'): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
357 for type_ in ['', '_rich', '_xhtml']: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
358 attr = "{}{}".format(elem_name, type_) |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
359 if attr in data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
360 elem = entry_elt.addElement(elem_name) |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
361 if type_: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
362 if type_ == '_rich': # convert input from current syntax to XHTML |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
363 xml_content = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
364 if '{}_xhtml'.format(elem_name) in data: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
365 raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time"))) |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
366 else: |
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
367 xml_content = data[attr] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
368 |
1822
aaf034bc6f7a
plugin XEP-0277: moved NS_XHTML namespace to constants + adapted parsing to new behaviour of ElementParser
Goffi <goffi@goffi.org>
parents:
1821
diff
changeset
|
369 div_elt = xml_tools.ElementParser()(xml_content, namespace=C.NS_XHTML) |
aaf034bc6f7a
plugin XEP-0277: moved NS_XHTML namespace to constants + adapted parsing to new behaviour of ElementParser
Goffi <goffi@goffi.org>
parents:
1821
diff
changeset
|
370 if div_elt.name != 'div' or div_elt.uri != C.NS_XHTML or div_elt.attributes: |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
371 # we need a wrapping <div/> at the top with XHTML namespace |
1822
aaf034bc6f7a
plugin XEP-0277: moved NS_XHTML namespace to constants + adapted parsing to new behaviour of ElementParser
Goffi <goffi@goffi.org>
parents:
1821
diff
changeset
|
372 wrap_div_elt = domish.Element((C.NS_XHTML, 'div')) |
1817
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
373 wrap_div_elt.addChild(div_elt) |
7ef0f5f90862
core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents:
1814
diff
changeset
|
374 div_elt = wrap_div_elt |
1802
fed95a6c56f8
plugin (xep-0277): avoid wrapping XML in an extra <div> in data2entry
Goffi <goffi@goffi.org>
parents:
1791
diff
changeset
|
375 elem.addChild(div_elt) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
376 elem['type'] = 'xhtml' |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
377 if elem_name not in data: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
378 # there is raw text content, which is mandatory |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
379 # so we create one from xhtml content |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
380 elem_txt = entry_elt.addElement(elem_name) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
381 text_content = yield self.host.plugins["TEXT-SYNTAXES"].convert(xml_content, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
382 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_XHTML, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
383 self.host.plugins["TEXT-SYNTAXES"].SYNTAX_TEXT, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
384 False) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
385 elem_txt.addContent(text_content) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
386 elem_txt['type'] = 'text' |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
387 |
832
c4b22aedb7d7
plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
388 else: # raw text only needs to be escaped to get HTML-safe sequence |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
389 elem.addContent(data[attr]) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
390 elem['type'] = 'text' |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
391 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
392 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
393 entry_elt.elements(NS_ATOM, 'title').next() |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
394 except StopIteration: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
395 # we have no title element which is mandatory |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
396 # so we transform content element to title |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
397 elems = list(entry_elt.elements(NS_ATOM, 'content')) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
398 if not elems: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
399 raise exceptions.DataError("There must be at least one content or title element") |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
400 for elem in elems: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
401 elem.name = 'title' |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
402 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
403 ## author ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
404 author_elt = entry_elt.addElement('author') |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
405 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
406 author_name = data['author'] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
407 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
408 # FIXME: must use better name |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
409 author_name = client.jid.user |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
410 author_elt.addElement('name', content=author_name) |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
411 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
412 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
413 author_jid_s = data['author_jid'] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
414 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
415 author_jid_s = client.jid.userhost() |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
416 author_elt.addElement('uri', content="xmpp:{}".format(author_jid_s)) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
417 |
1820
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
418 try: |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
419 author_jid_s = data['author_email'] |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
420 except KeyError: |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
421 pass |
3c8cf120a0fd
plugin XEP-0277: added missing author_email parsing
Goffi <goffi@goffi.org>
parents:
1817
diff
changeset
|
422 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
423 ## published/updated time ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
424 current_time = time.time() |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
425 entry_elt.addElement('updated', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
426 content=rfc3339.timestamp_from_tf(float(data.get('updated', current_time)))) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
427 entry_elt.addElement('published', |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
428 content=rfc3339.timestamp_from_tf(float(data.get('published', current_time)))) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
429 |
1664
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
430 ## categories ## |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
431 for tag in common.dict2iter("tag", data): |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
432 category_elt = entry_elt.addElement("category") |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
433 category_elt['term'] = tag |
5d0ff155be1a
plugin XEP-0277: tags are handled through atom categories
Goffi <goffi@goffi.org>
parents:
1661
diff
changeset
|
434 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
435 ## id ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
436 entry_id = data.get('id', item_id) # FIXME: use a proper id (see XEP-0277 §7.1) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
437 entry_elt.addElement('id', content=entry_id) # |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
438 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
439 ## comments ## |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
440 if 'comments' in data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
441 link_elt = entry_elt.addElement('link') |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
442 link_elt['href'] = data['comments'] |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
443 link_elt['rel'] = 'replies' |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
444 link_elt['title'] = 'comments' |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
445 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
446 ## final item building ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
447 item_elt = pubsub.Item(id=item_id, payload=entry_elt) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
448 |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
449 ## the trigger ## |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
450 # if other plugins have things to add or change |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
451 yield self.host.trigger.point("XEP-0277_data2entry", client, data, entry_elt, item_elt) |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
452 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
453 defer.returnValue(item_elt) |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
454 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
455 ## publish ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
456 |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
457 def getCommentNode(self, item_id): |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
458 """Generate comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
459 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
460 @param item_id(unicode): id of the parent item |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
461 @return (unicode): comment node to use |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
462 """ |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
463 return u"{}{}".format(NS_COMMENT_PREFIX, item_id) |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
464 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
465 def getCommentService(self, client, parent_service=None): |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
466 """Get prefered PubSub service to create comment node |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
467 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
468 @param pubsub_service(jid.JID, None): PubSub service of the parent item |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
469 @param return(jid.JID, None): PubSub service to use |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
470 """ |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
471 return client.pubsub_service if client.pubsub_service is not None else parent_service |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
472 |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
473 @defer.inlineCallbacks |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
474 def _manageComments(self, access, mb_data, service, node, item_id, profile): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
475 """Check comments keys in mb_data and create comments node if necessary |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
476 |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
477 if mb_data['comments'] exists, it is used (or mb_data['comments_service'] and/or mb_data['comments_node']), |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
478 else it is generated (if allow_comments is True). |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
479 @param access(unicode): access model |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
480 @param mb_data(dict): microblog mb_data |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
481 @param service(jid.JID, None): PubSub service of the parent item |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
482 @param node(unicode): node of the parent item |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
483 @param item_id(unicoe): id of the parent item |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
484 """ |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
485 # FIXME: if 'comments' already exists in mb_data, it is not used to create the Node |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
486 allow_comments = C.bool(mb_data.pop("allow_comments", "false")) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
487 if not allow_comments: |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
488 if 'comments' in mb_data: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
489 log.warning(u"comments are not allowed but there is already a comments node, it may be lost: {uri}".format(uri=mb_data['comments'])) |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
490 del mb_data['comments'] |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
491 return |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
492 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
493 client = self.host.getClient(profile) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
494 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
495 options = {self._p.OPT_ACCESS_MODEL: access, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
496 self._p.OPT_PERSIST_ITEMS: 1, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
497 self._p.OPT_MAX_ITEMS: -1, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
498 self._p.OPT_DELIVER_PAYLOADS: 1, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
499 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
500 self._p.OPT_PUBLISH_MODEL: "subscribers", # TODO: should be open if *both* node and item access_model are open (public node and item) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
501 } |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
502 |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
503 # if other plugins need to change the options |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
504 yield self.host.trigger.point("XEP-0277_comments", client, mb_data, options) |
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
505 |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
506 try: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
507 comments_node = mb_data['comments_node'] |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
508 except KeyError: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
509 comments_node = self.getCommentNode(item_id) |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
510 else: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
511 if not comments_node: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
512 raise exceptions.DataError(u"if comments_node is present, it must not be empty") |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
513 |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
514 try: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
515 comments_service = mb_data['comments_service'] |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
516 except KeyError: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
517 comments_service = self.getCommentService(client, service) |
1661
96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
Goffi <goffi@goffi.org>
parents:
1656
diff
changeset
|
518 |
1711
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
519 try: |
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
520 yield self._p.createNode(comments_service, comments_node, options, profile_key=profile) |
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
521 except error.StanzaError as e: |
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
522 if e.condition == 'conflict': |
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
523 log.info(u"node {} already exists on service {}".format(comments_node, comments_service)) |
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
524 else: |
e5b569d0c2e7
plugin XEP-0277: don't try to create a new comments node if it already exists
souliane <souliane@mailoo.org>
parents:
1709
diff
changeset
|
525 raise e |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
526 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
527 if comments_service is None: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
528 comments_service = client.jid.userhostJID() |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
529 |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
530 if 'comments' in mb_data: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
531 if not mb_data['comments']: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
532 raise exceptions.DataError(u"if comments is present, it must not be empty") |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
533 if 'comments_node' in mb_data or 'comments_service' in mb_data: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
534 raise exceptions.DataError(u"You can't use comments_service/comments_node and comments at the same time") |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
535 else: |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1823
diff
changeset
|
536 mb_data['comments'] = self._p.getNodeURI(comments_service, comments_node) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
537 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
538 def _mbSend(self, service, node, data, profile_key): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
539 service = jid.JID(service) if service else None |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
540 node = node if node else NS_MICROBLOG |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
541 profile = self.host.memory.getProfileName(profile_key) |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
542 return self.send(data, service, node, profile) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
543 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
544 @defer.inlineCallbacks |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
545 def send(self, data, service=None, node=NS_MICROBLOG, profile=None): |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
546 """Send XEP-0277's microblog data |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
547 |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
548 @param data(dict): microblog data (must include at least a "content" or a "title" key). |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
549 see http://wiki.goffi.org/wiki/Bridge_API_-_Microblogging/en for details |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
550 @param service(jid.JID, None): PubSub service where the microblog must be published |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
551 None to publish on profile's PEP |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
552 @param node(unicode, None): PubSub node to use (defaut to microblog NS) |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
553 None is equivalend as using default value |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
554 @param profile: %(doc_profile)s |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
555 """ |
1699 | 556 # TODO: check that all data keys are used, this would avoid sending publicly a private message |
557 # by accident (e.g. if group pluging is not loaded, and "grou*" key are not used) | |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
558 assert profile is not None |
1821
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
559 if node is None: |
d6062afdd54f
plugin XEP-0277: comments handling improvments:
Goffi <goffi@goffi.org>
parents:
1820
diff
changeset
|
560 node = NS_MICROBLOG |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
561 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
562 item_id = data.get('id') or unicode(uuid.uuid4()) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
563 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
564 yield self._manageComments(self._p.ACCESS_OPEN, data, service, node, item_id, profile) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
565 except error.StanzaError: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
566 log.warning(u"Can't create comments node for item {}".format(item_id)) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
567 item = yield self.data2entry(data, item_id, profile) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
568 ret = yield self._p.publish(service, node, [item], profile_key=profile) |
706
80e9d3ecb272
plugin XEP-0277, group blog: rich text management for sending microblogs
Goffi <goffi@goffi.org>
parents:
704
diff
changeset
|
569 defer.returnValue(ret) |
293
42438e43104a
Plugin XEP-0277: first draft of microblogging over ip /!\ new dependencies added /!\
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
570 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
571 ## retract ## |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
572 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
573 def _mbRetract(self, service_jid_s, nodeIdentifier, itemIdentifier, profile_key): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
574 """Call self._p._retractItem, but use default node if node is empty""" |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
575 return self._p._retractItem(service_jid_s, nodeIdentifier or NS_MICROBLOG, itemIdentifier, True, profile_key) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
576 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
577 ## get ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
578 |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
579 def _mbGet(self, service_jid_s, node="", max_items=10, item_ids=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
580 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
581 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
582 @param item_ids (list[unicode]): list of item IDs |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
583 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
584 max_items = None if max_items == C.NO_LIMIT else max_items |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
585 extra = self._p.parseExtra(extra_dict) |
1775
0876352459e5
plugin XEP-0277: ignore maxItems if it is null
Goffi <goffi@goffi.org>
parents:
1771
diff
changeset
|
586 return self.mbGet(jid.JID(service_jid_s), node or None, max_items or None, item_ids, extra.rsm_request, extra.extra, profile_key) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
587 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
588 @defer.inlineCallbacks |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
589 def mbGet(self, service_jid, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
590 """Get some microblogs |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
591 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
592 @param service_jid(jid.JID): jid of the publisher |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
593 @param node(unicode, None): node to get (or microblog node if None) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
594 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
595 @param item_ids (list[unicode]): list of item IDs |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
596 @param rsm_request (rsm.RSMRequest): RSM request data |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
597 @param extra (dict): extra data |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
598 @param profile_key: %(doc_profile_key)s |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1233
diff
changeset
|
599 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
600 @return: a deferred couple with the list of items and metadatas. |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
601 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
602 if node is None: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
603 node = NS_MICROBLOG |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
604 items_data = yield self._p.getItems(service_jid, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
605 serialised = yield self._p.serItemsDataD(items_data, self.item2mbdata) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
606 defer.returnValue(serialised) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
607 |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
608 def parseCommentUrl(self, node_url): |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
609 """Parse a XMPP URI |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
610 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
611 Determine the fields comments_service and comments_node of a microblog data |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
612 from the href attribute of an entry's link element. For example this input: |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
613 xmpp:sat-pubsub.libervia.org?node=urn%3Axmpp%3Acomments%3A_c5c4a142-2279-4b2a-ba4c-1bc33aa87634__urn%3Axmpp%3Agroupblog%3Asouliane%40libervia.org |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
614 will return (JID(u'sat-pubsub.libervia.org'), 'urn:xmpp:comments:_c5c4a142-2279-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:souliane@libervia.org') |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
615 @return: a tuple (JID, str) |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
616 """ |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
617 parsed_url = urlparse.urlparse(node_url, 'xmpp') |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
618 service = jid.JID(parsed_url.path) |
1823
1424cc6f8e98
plugin XEP-0277: fixed encoding issue, specially with parseCommentUrl, which could lead to the impossibility to find comments node
Goffi <goffi@goffi.org>
parents:
1822
diff
changeset
|
619 parsed_queries = urlparse.parse_qs(parsed_url.query.encode('utf-8')) |
1424cc6f8e98
plugin XEP-0277: fixed encoding issue, specially with parseCommentUrl, which could lead to the impossibility to find comments node
Goffi <goffi@goffi.org>
parents:
1822
diff
changeset
|
620 node = parsed_queries.get('node', [''])[0].decode('utf-8') |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
621 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
622 if not node: |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
623 raise failure.Failure(exceptions.DataError('Invalid comments link')) |
1421
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
624 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
625 return (service, node) |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
626 |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
627 ## configure ## |
16b1ba7ccaaa
plugins xep-0277: some methods reordering to make the plugin more readable
Goffi <goffi@goffi.org>
parents:
1419
diff
changeset
|
628 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
629 def mbSetAccess(self, access="presence", profile_key=C.PROF_KEY_NONE): |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
630 """Create a microblog node on PEP with given access |
1419
be2df1ddea8e
plugins (groupblog, xep-0277) + tmp(rsm): improved style:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
631 |
304 | 632 If the node already exists, it change options |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
633 @param access: Node access model, according to xep-0060 #4.5 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
634 @param profile_key: profile key""" |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
635 |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
636 _jid, xmlstream = self.host.getJidNStream(profile_key) |
311
0aa6ca6cdbdd
plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents:
310
diff
changeset
|
637 if not _jid: |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
638 log.error(_(u"Can't find profile's jid")) |
311
0aa6ca6cdbdd
plugin group blog: group blog now use PEP to take profit of autosubscribe
Goffi <goffi@goffi.org>
parents:
310
diff
changeset
|
639 return |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
640 _options = {self._p.OPT_ACCESS_MODEL: access, self._p.OPT_PERSIST_ITEMS: 1, self._p.OPT_MAX_ITEMS: -1, self._p.OPT_DELIVER_PAYLOADS: 1, self._p.OPT_SEND_ITEM_SUBSCRIBE: 1} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
641 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
642 def cb(result): |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
643 #Node is created with right permission |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
644 log.debug(_(u"Microblog node has now access %s") % access) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
645 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
646 def fatal_err(s_error): |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
647 #Something went wrong |
1680
1e06a0f8be66
plugin XEP-0277: unicode fixes in logs
Goffi <goffi@goffi.org>
parents:
1679
diff
changeset
|
648 log.error(_(u"Can't set microblog access")) |
468
c97640c90a94
D-Bus Bridge: use inspection to name attribute + fix asynchronous calls for dynamically added method, it now use deferred return value instead of callback/errback attributes
Goffi <goffi@goffi.org>
parents:
465
diff
changeset
|
649 raise NodeAccessChangeException() |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
650 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
651 def err_cb(s_error): |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
652 #If the node already exists, the condition is "conflict", |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
653 #else we have an unmanaged error |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
654 if s_error.value.condition == 'conflict': |
306
169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
Goffi <goffi@goffi.org>
parents:
304
diff
changeset
|
655 #d = self.host.plugins["XEP-0060"].deleteNode(_jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key) |
304 | 656 #d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) |
657 change_node_options().addCallback(cb).addErrback(fatal_err) | |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
658 else: |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
659 fatal_err(s_error) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
660 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
661 def create_node(): |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
662 return self._p.createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
663 |
304 | 664 def change_node_options(): |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
665 return self._p.setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
666 |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
302
diff
changeset
|
667 create_node().addCallback(cb).addErrback(err_cb) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
668 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
669 ## methods to manage several stanzas/jids at once ## |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
670 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
671 # common |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
672 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
673 def _getClientAndNodeData(self, publishers_type, publishers, profile_key): |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
674 """Helper method to construct node_data from publishers_type/publishers |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
675 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
676 @param publishers_type: type of the list of publishers, one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
677 C.ALL: get all jids from roster, publishers is not used |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
678 C.GROUP: get jids from groups |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
679 C.JID: use publishers directly as list of jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
680 @param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
681 @param profile_key: %(doc_profile_key)s |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
682 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
683 client = self.host.getClient(profile_key) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
684 if publishers_type == C.JID: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
685 jids_set = set(publishers) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
686 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
687 jids_set = client.roster.getJidsSet(publishers_type, publishers) |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
688 if publishers_type == C.ALL: |
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
689 try: # display messages from salut-a-toi@libervia.org or other PEP services |
1741
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
690 services = self.host.plugins["EXTRA-PEP"].getFollowedEntities(profile_key) |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
691 except KeyError: |
1741
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
692 pass # plugin is not loaded |
1728
0eaa1a409dfb
plugin XEP-0277, EXTRA-PEP: get massive blogs from all the roster also retrieve items from a special JIDs list defined in EXTRA-PEP
souliane <souliane@mailoo.org>
parents:
1712
diff
changeset
|
693 else: |
1741
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
694 if services: |
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
695 log.debug("Extra PEP followed entities: %s" % ", ".join([unicode(service) for service in services])) |
cc31dd72526d
plugin misc_extra_pep: use a user parameter (jids_list) instead of a general configuration value
souliane <souliane@mailoo.org>
parents:
1734
diff
changeset
|
696 jids_set.update(services) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
697 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
698 node_data = [] |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
699 for jid_ in jids_set: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
700 node_data.append((jid_, NS_MICROBLOG)) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
701 return client, node_data |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
702 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
703 def _checkPublishers(self, publishers_type, publishers): |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
704 """Helper method to deserialise publishers coming from bridge |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
705 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
706 publishers_type(unicode): type of the list of publishers, one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
707 publishers: list of publishers according to type |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
708 @return: deserialised (publishers_type, publishers) tuple |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
709 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
710 if publishers_type == C.ALL: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
711 if publishers: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
712 raise failure.Failure(ValueError("Can't use publishers with {} type".format(publishers_type))) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
713 else: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
714 publishers = None |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
715 elif publishers_type == C.JID: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
716 publishers[:] = [jid.JID(publisher) for publisher in publishers] |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
717 return publishers_type, publishers |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
718 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
719 # subscribe # |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
720 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
721 def _mbSubscribeToMany(self, publishers_type, publishers, profile_key): |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
722 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
723 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
724 @return (str): session id: Use pubsub.getSubscribeRTResult to get the results |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
725 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
726 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
727 return self.mbSubscribeToMany(publishers_type, publishers, profile_key) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
728 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
729 def mbSubscribeToMany(self, publishers_type, publishers, profile_key): |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
730 """Subscribe microblogs for a list of groups or jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
731 |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
732 @param publishers_type: type of the list of publishers, one of: |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
733 C.ALL: get all jids from roster, publishers is not used |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
734 C.GROUP: get jids from groups |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
735 C.JID: use publishers directly as list of jids |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
736 @param publishers: list of publishers, according to "publishers_type" (None, list of groups or list of jids) |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
737 @param profile: %(doc_profile)s |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
738 @return (str): session id |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
739 """ |
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
740 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key) |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1450
diff
changeset
|
741 return self._p.subscribeToMany(node_data, client.jid.userhostJID(), profile_key=profile_key) |
1450
7797dda847ae
plugins xep-0277, groupblog: added subscriteToMany to replace massiveSubscribeGroupBlogs + added SatRosterProtocol.getJidsSet
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
742 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
743 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
744 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
745 def _mbGetFromManyRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
746 """Get real-time results for mbGetFromMany session |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
747 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
748 @param session_id: id of the real-time deferred session |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
749 @param return (tuple): (remaining, results) where: |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
750 - remaining is the number of still expected results |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
751 - results is a list of tuple with |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
752 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
753 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
754 - failure (unicode): empty string in case of success, error message else |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
755 - items_data(list): data as returned by [mbGet] |
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1511
diff
changeset
|
756 - items_metadata(dict): metadata as returned by [mbGet] |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
757 @param profile_key: %(doc_profile_key)s |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
758 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
759 def onSuccess(items_data): |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
760 """convert items elements to list of microblog data in items_data""" |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
761 d = self._p.serItemsDataD(items_data, self.item2mbdata) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
762 d.addCallback(lambda serialised:('', serialised)) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
763 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
764 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
765 profile = self.host.getClient(profile_key).profile |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
766 d = self._p.getRTResults(session_id, |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
767 on_success = onSuccess, |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
768 on_error = lambda failure: (unicode(failure.value), ([],{})), |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
769 profile = profile) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
770 d.addCallback(lambda ret: (ret[0], |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
771 [(service.full(), node, failure, items, metadata) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
772 for (service, node), (success, (failure, (items, metadata))) in ret[1].iteritems()])) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
773 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
774 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
775 def _mbGetFromMany(self, publishers_type, publishers, max_items=10, extra_dict=None, profile_key=C.PROF_KEY_NONE): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
776 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
777 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
778 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
779 max_items = None if max_items == C.NO_LIMIT else max_items |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
780 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
781 extra = self._p.parseExtra(extra_dict) |
1775
0876352459e5
plugin XEP-0277: ignore maxItems if it is null
Goffi <goffi@goffi.org>
parents:
1771
diff
changeset
|
782 return self.mbGetFromMany(publishers_type, publishers, max_items or None, extra.rsm_request, extra.extra, profile_key) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
783 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
784 def mbGetFromMany(self, publishers_type, publishers, max_items=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
785 """Get the published microblogs for a list of groups or jids |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
786 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
787 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
788 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
789 @param max_items (int): optional limit on the number of retrieved items. |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
790 @param rsm_request (rsm.RSMRequest): RSM request data, common to all publishers |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
791 @param extra (dict): Extra data |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
792 @param profile_key: profile key |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
793 @return (str): RT Deferred session id |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
794 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
795 # XXX: extra is unused here so far |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
796 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
797 return self._p.getFromMany(node_data, max_items, rsm_request, profile_key=profile_key) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
798 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
799 # comments # |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
800 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
801 def _mbGetFromManyWithCommentsRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
802 """Get real-time results for [mbGetFromManyWithComments] session |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
803 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
804 @param session_id: id of the real-time deferred session |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
805 @param return (tuple): (remaining, results) where: |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
806 - remaining is the number of still expected results |
1511
83f71763e1a7
plugin XEP-0277: clarify a docstring for one complex method argument
souliane <souliane@mailoo.org>
parents:
1459
diff
changeset
|
807 - results is a list of 5-tuple with |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
808 - service (unicode): pubsub service |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
809 - node (unicode): pubsub node |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
810 - failure (unicode): empty string in case of success, error message else |
1511
83f71763e1a7
plugin XEP-0277: clarify a docstring for one complex method argument
souliane <souliane@mailoo.org>
parents:
1459
diff
changeset
|
811 - items(list[tuple(dict, list)]): list of 2-tuple with |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
812 - item(dict): item microblog data |
1511
83f71763e1a7
plugin XEP-0277: clarify a docstring for one complex method argument
souliane <souliane@mailoo.org>
parents:
1459
diff
changeset
|
813 - comments_list(list[tuple]): list of 5-tuple with |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
814 - service (unicode): pubsub service where the comments node is |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
815 - node (unicode): comments node |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
816 - failure (unicode): empty in case of success, else error message |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
817 - comments(list[dict]): list of microblog data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
818 - comments_metadata(dict): metadata of the comment node |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
819 - metadata(dict): original node metadata |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
820 @param profile_key: %(doc_profile_key)s |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
821 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
822 profile = self.host.getClient(profile_key).profile |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
823 d = self.rt_sessions.getResults(session_id, profile=profile) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
824 d.addCallback(lambda ret: (ret[0], |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
825 [(service.full(), node, failure, items, metadata) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
826 for (service, node), (success, (failure, (items, metadata))) in ret[1].iteritems()])) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
827 return d |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
828 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
829 def _mbGetFromManyWithComments(self, publishers_type, publishers, max_items=10, max_comments=C.NO_LIMIT, extra_dict=None, extra_comments_dict=None, profile_key=C.PROF_KEY_NONE): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
830 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
831 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
832 @param max_comments(int): maximum number of comments to get, C.NO_LIMIT for no limit |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
833 """ |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
834 max_items = None if max_items == C.NO_LIMIT else max_items |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
835 max_comments = None if max_comments == C.NO_LIMIT else max_comments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
836 publishers_type, publishers = self._checkPublishers(publishers_type, publishers) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
837 extra = self._p.parseExtra(extra_dict) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
838 extra_comments = self._p.parseExtra(extra_comments_dict) |
1779
1fa50da8bfbe
plugin XEP-0277: don't use max_comments if it is 0 in getFromManyWthComments bridge callback
Goffi <goffi@goffi.org>
parents:
1775
diff
changeset
|
839 return self.mbGetFromManyWithComments(publishers_type, publishers, max_items or None, max_comments or None, |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
840 extra.rsm_request, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
841 extra.extra, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
842 extra_comments.rsm_request, |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
843 extra_comments.extra, |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
844 profile_key) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
845 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
846 def mbGetFromManyWithComments(self, publishers_type, publishers, max_items=None, max_comments=None, rsm_request=None, extra=None, rsm_comments=None, extra_comments=None, profile_key=C.PROF_KEY_NONE): |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
847 """Helper method to get the microblogs and their comments in one shot |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
848 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
849 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
850 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
851 @param max_items (int): optional limit on the number of retrieved items. |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
852 @param max_comments (int): maximum number of comments to retrieve |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
853 @param rsm_request (rsm.RSMRequest): RSM request for initial items only |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
854 @param extra (dict): extra configuration for initial items only |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
855 @param rsm_comments (rsm.RSMRequest): RSM request for comments only |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
856 @param extra_comments (dict): extra configuration for comments only |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
857 @param profile_key: profile key |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
858 @return (str): RT Deferred session id |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
859 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
860 # XXX: this method seems complicated because it do a couple of treatments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
861 # to serialise and associate the data, but it make life in frontends side |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
862 # a lot easier |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
863 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
864 def getComments(items_data): |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
865 """Retrieve comments and add them to the items_data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
866 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
867 @param items_data: serialised items data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
868 @return (defer.Deferred): list of items where each item is associated |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
869 with a list of comments data (service, node, list of items, metadata) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
870 """ |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
871 items, metadata = items_data |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
872 items_dlist = [] # deferred list for items |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
873 for item in items: |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
874 dlist = [] # deferred list for comments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
875 for key, value in item.iteritems(): |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
876 # we look for comments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
877 if key.startswith('comments') and key.endswith('_service'): |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
878 prefix = key[:key.find('_')] |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
879 service_s = value |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
880 node = item["{}{}".format(prefix, "_node")] |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
881 # time to get the comments |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
882 d = self._p.getItems(jid.JID(service_s), node, max_comments, rsm_request=rsm_comments, extra=extra_comments, profile_key=profile_key) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
883 # then serialise |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
884 d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata)) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
885 # with failure handling |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
886 d.addCallback(lambda serialised_items_data: ('',) + serialised_items_data) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
887 d.addErrback(lambda failure: (unicode(failure.value), [], {})) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
888 # and associate with service/node (needed if there are several comments nodes) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
889 d.addCallback(lambda serialised, service_s=service_s, node=node: (service_s, node) + serialised) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
890 dlist.append(d) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
891 # we get the comments |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
892 comments_d = defer.gatherResults(dlist) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
893 # and add them to the item data |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
894 comments_d.addCallback(lambda comments_data, item=item: (item, comments_data)) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
895 items_dlist.append(comments_d) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
896 # we gather the items + comments in a list |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
897 items_d = defer.gatherResults(items_dlist) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
898 # and add the metadata |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
899 items_d.addCallback(lambda items_completed: (items_completed, metadata)) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
900 return items_d |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
901 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
902 client, node_data = self._getClientAndNodeData(publishers_type, publishers, profile_key) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
903 deferreds = {} |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
904 for service, node in node_data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1454
diff
changeset
|
905 d = deferreds[(service, node)] = self._p.getItems(service, node, max_items, rsm_request=rsm_request, extra=extra, profile_key=profile_key) |
1454
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
906 d.addCallback(lambda items_data: self._p.serItemsDataD(items_data, self.item2mbdata)) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
907 d.addCallback(getComments) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
908 d.addCallback(lambda items_comments_data: ('', items_comments_data)) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
909 d.addErrback(lambda failure: (unicode(failure.value), ([],{}))) |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
910 |
4e2fab4de195
plugin XEP-0277: added mBGetFromManyWithComments to have items + comments in one method call
Goffi <goffi@goffi.org>
parents:
1453
diff
changeset
|
911 return self.rt_sessions.newSession(deferreds, client.profile) |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
912 |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
913 # atom feed |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
914 |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
915 def _mbGetAtom(self, service_jid_s, node="", max_items=10, item_ids=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
916 """Get the atom feed of the last published microblogs |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
917 |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
918 @param service_jid(jid.JID): jid of the publisher |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
919 @param node(unicode, None): node to get (or microblog node if None) |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
920 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
921 @param item_ids (list[unicode]): list of item IDs |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
922 @param rsm_request (rsm.RSMRequest): RSM request data |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
923 @param extra (dict): extra data |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
924 @param profile_key: %(doc_profile_key)s |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
925 @return: a deferred unicode (atom XML feed) |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
926 """ |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
927 max_items = None if max_items == C.NO_LIMIT else max_items |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
928 extra = self._p.parseExtra(extra_dict) |
1775
0876352459e5
plugin XEP-0277: ignore maxItems if it is null
Goffi <goffi@goffi.org>
parents:
1771
diff
changeset
|
929 return self.mbGetAtom(jid.JID(service_jid_s), node or None, max_items or None, item_ids, extra.rsm_request, extra.extra, profile_key) |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
930 |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
931 @defer.inlineCallbacks |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
932 def mbGetAtom(self, service_jid, node=None, max_items=None, item_ids=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
933 """Get the atom feed of the last published microblogs |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
934 |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
935 @param service_jid(jid.JID): jid of the publisher |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
936 @param node(unicode, None): node to get (or microblog node if None) |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
937 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
938 @param item_ids (list[unicode]): list of item IDs |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
939 @param rsm_request (rsm.RSMRequest): RSM request data |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
940 @param extra (dict): extra data |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
941 @param profile_key: %(doc_profile_key)s |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
942 |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
943 @return: a deferred couple with the list of items and metadatas. |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
944 """ |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
945 if node is None: |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
946 node = NS_MICROBLOG |
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
947 |
1648
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
948 feed_elt = domish.Element((NS_ATOM, 'feed')) |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
949 title = D_(u"{user}'s blogposts").format(user=service_jid.user) |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
950 feed_elt.addElement('title', content=title) |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
951 link_feed_elt = feed_elt.addElement('link') |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
952 link_feed_elt['href'] = 'http://{host}/blog/{user}/atom.xml'.format( |
1823
1424cc6f8e98
plugin XEP-0277: fixed encoding issue, specially with parseCommentUrl, which could lead to the impossibility to find comments node
Goffi <goffi@goffi.org>
parents:
1822
diff
changeset
|
953 host=urllib.quote(service_jid.host.encode('utf-8'),''), |
1424cc6f8e98
plugin XEP-0277: fixed encoding issue, specially with parseCommentUrl, which could lead to the impossibility to find comments node
Goffi <goffi@goffi.org>
parents:
1822
diff
changeset
|
954 user=urllib.quote(service_jid.user.encode('utf-8'),'')) |
1648
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
955 link_feed_elt['rel'] = 'self' |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
956 link_blog_elt = feed_elt.addElement('link') |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
957 link_blog_elt['href'] = 'http://{host}/blog/{user}'.format( |
1823
1424cc6f8e98
plugin XEP-0277: fixed encoding issue, specially with parseCommentUrl, which could lead to the impossibility to find comments node
Goffi <goffi@goffi.org>
parents:
1822
diff
changeset
|
958 host=urllib.quote(service_jid.host.encode('utf-8'),''), |
1424cc6f8e98
plugin XEP-0277: fixed encoding issue, specially with parseCommentUrl, which could lead to the impossibility to find comments node
Goffi <goffi@goffi.org>
parents:
1822
diff
changeset
|
959 user=urllib.quote(service_jid.user.encode('utf-8'),'')) |
1648
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
960 feed_elt.addElement('id', content=node) |
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
961 feed_elt.addElement('updated', rfc3339.timestamp_from_tf(rfc3339.tf_utc())) |
1516
afa0894dcc71
plugin XEP-0277, misc_groupblog: move getGroupBlogsAtom to XEP-0277, rename to mbGetAtom
souliane <souliane@mailoo.org>
parents:
1513
diff
changeset
|
962 |
1649
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
963 # FIXME: no cleaning is done here |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
964 # FIXME: no check is done neither, we have to be sure that we get microblogs |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
965 items, metadata = yield self._p.getItems(service_jid, node, max_items=max_items, item_ids=item_ids, rsm_request=rsm_request, extra=extra, profile_key=profile_key) |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
966 |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
967 for item in items: |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
968 entry_elt = item.elements(NS_ATOM, 'entry').next() |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
969 feed_elt.addChild(entry_elt) |
b58c8b4715c6
plugin XEP-0277: fixed entries in atom feed
Goffi <goffi@goffi.org>
parents:
1648
diff
changeset
|
970 |
1648
2b8a975ff712
plugin XEP-0277: fixed unsecure blog feed
Goffi <goffi@goffi.org>
parents:
1542
diff
changeset
|
971 defer.returnValue(u'<?xml version="1.0" encoding="utf-8"?>'+feed_elt.toXml()) |