annotate libervia/backend/plugins/plugin_misc_forums.py @ 4165:81faa85c9cfa

template: add a `bare_jid` filter
author Goffi <goffi@goffi.org>
date Tue, 28 Nov 2023 17:41:49 +0100
parents 4b842c1fb686
children 5d056d524298
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
4 # SAT plugin for pubsub forums
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
24 from libervia.backend.tools.common import uri, data_format
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import jid
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.xish import domish
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.internet import defer
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import shortuuid
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import json
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log = getLogger(__name__)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
32 NS_FORUMS = 'org.salut-a-toi.forums:0'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
33 NS_FORUMS_TOPICS = NS_FORUMS + '#topics'
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 PLUGIN_INFO = {
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_NAME: _("forums management"),
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_IMPORT_NAME: "forums",
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_TYPE: "EXP",
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_PROTOCOLS: [],
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0277"],
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_MAIN: "forums",
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_HANDLER: "no",
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_DESCRIPTION: _("""forums management plugin""")
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 }
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
45 FORUM_ATTR = {'title', 'name', 'main-language', 'uri'}
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
46 FORUM_SUB_ELTS = ('short-desc', 'desc')
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
47 FORUM_TOPICS_NODE_TPL = '{node}#topics_{uuid}'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
48 FORUM_TOPIC_NODE_TPL = '{node}_{uuid}'
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class forums(object):
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
54 log.info(_("forums plugin initialization"))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.host = host
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self._m = self.host.plugins['XEP-0277']
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self._p = self.host.plugins['XEP-0060']
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self._node_options = {
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self._p.OPT_PERSIST_ITEMS: 1,
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self._p.OPT_DELIVER_PAYLOADS: 1,
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 }
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
65 host.register_namespace('forums', NS_FORUMS)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
66 host.bridge.add_method("forums_get", ".plugin",
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 in_sign='ssss', out_sign='s',
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 method=self._get,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
69 async_=True)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
70 host.bridge.add_method("forums_set", ".plugin",
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 in_sign='sssss', out_sign='',
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 method=self._set,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
73 async_=True)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
74 host.bridge.add_method("forum_topics_get", ".plugin",
3549
3fd60beb9b92 plugin forums: use serialised data for extra in forumTopicsGet
Goffi <goffi@goffi.org>
parents: 3515
diff changeset
75 in_sign='ssa{ss}s', out_sign='(aa{ss}s)',
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
76 method=self._get_topics,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
77 async_=True)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
78 host.bridge.add_method("forum_topic_create", ".plugin",
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 in_sign='ssa{ss}s', out_sign='',
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
80 method=self._create_topic,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
81 async_=True)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 @defer.inlineCallbacks
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
84 def _create_forums(self, client, forums, service, node, forums_elt=None, names=None):
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
85 """Recursively create <forums> element(s)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 @param forums(list): forums which may have subforums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 @param service(jid.JID): service where the new nodes will be created
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 @param node(unicode): node of the forums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 will be used as basis for the newly created nodes
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 @param parent_elt(domish.Element, None): element where the forum must be added
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if None, the root <forums> element will be created
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 @return (domish.Element): created forums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 """
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 if not isinstance(forums, list):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
96 raise ValueError(_("forums arguments must be a list of forums"))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 if forums_elt is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
98 forums_elt = domish.Element((NS_FORUMS, 'forums'))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 assert names is None
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 names = set()
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
102 if names is None or forums_elt.name != 'forums':
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
103 raise exceptions.InternalError('invalid forums or names')
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 assert names is not None
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 for forum in forums:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 if not isinstance(forum, dict):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
108 raise ValueError(_("A forum item must be a dictionary"))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 forum_elt = forums_elt.addElement('forum')
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
111 for key, value in forum.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
112 if key == 'name' and key in names:
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
113 raise exceptions.ConflictError(_("following forum name is not unique: {name}").format(name=key))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
114 if key == 'uri' and not value.strip():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
115 log.info(_("creating missing forum node"))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 forum_node = FORUM_TOPICS_NODE_TPL.format(node=node, uuid=shortuuid.uuid())
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 yield self._p.createNode(client, service, forum_node, self._node_options)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
118 value = uri.build_xmpp_uri('pubsub',
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 path=service.full(),
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 node=forum_node)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 if key in FORUM_ATTR:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 forum_elt[key] = value.strip()
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 elif key in FORUM_SUB_ELTS:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 forum_elt.addElement(key, content=value)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
125 elif key == 'sub-forums':
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
126 sub_forums_elt = forum_elt.addElement('forums')
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
127 yield self._create_forums(client, value, service, node, sub_forums_elt, names=names)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
129 log.warning(_("Unknown forum attribute: {key}").format(key=key))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
130 if not forum_elt.getAttribute('title'):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
131 name = forum_elt.getAttribute('name')
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if name:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
133 forum_elt['title'] = name
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
135 raise ValueError(_("forum need a title or a name"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
136 if not forum_elt.getAttribute('uri') and not forum_elt.children:
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
137 raise ValueError(_("forum need uri or sub-forums"))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 defer.returnValue(forums_elt)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
140 def _parse_forums(self, parent_elt=None, forums=None):
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
141 """Recursivly parse a <forums> elements and return corresponding forums data
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 @param item(domish.Element): item with <forums> element
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 @param parent_elt(domish.Element, None): element to parse
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 @return (list): parsed data
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 @raise ValueError: item is invalid
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
148 if parent_elt.name == 'item':
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 forums = []
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
151 forums_elt = next(parent_elt.elements(NS_FORUMS, 'forums'))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
153 raise ValueError(_("missing <forums> element"))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 else:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 forums_elt = parent_elt
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 if forums is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
157 raise exceptions.InternalError('expected forums')
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 if forums_elt.name != 'forums':
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
159 raise ValueError(_('Unexpected element: {xml}').format(xml=forums_elt.toXml()))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 for forum_elt in forums_elt.elements():
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 if forum_elt.name == 'forum':
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 data = {}
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 for attrib in FORUM_ATTR.intersection(forum_elt.attributes):
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 data[attrib] = forum_elt[attrib]
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 unknown = set(forum_elt.attributes).difference(FORUM_ATTR)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 if unknown:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
167 log.warning(_("Following attributes are unknown: {unknown}").format(unknown=unknown))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 for elt in forum_elt.elements():
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if elt.name in FORUM_SUB_ELTS:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
170 data[elt.name] = str(elt)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
171 elif elt.name == 'forums':
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
172 sub_forums = data['sub-forums'] = []
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
173 self._parse_forums(elt, sub_forums)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
174 if not 'title' in data or not {'uri', 'sub-forums'}.intersection(data):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
175 log.warning(_("invalid forum, ignoring: {xml}").format(xml=forum_elt.toXml()))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 else:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 forums.append(data)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
179 log.warning(_("unkown forums sub element: {xml}").format(xml=forum_elt))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 return forums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 def _get(self, service=None, node=None, forums_key=None, profile_key=C.PROF_KEY_NONE):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
184 client = self.host.get_client(profile_key)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 if service.strip():
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 service = jid.JID(service)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 else:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 service = None
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 if not node.strip():
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 node = None
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
191 d = defer.ensureDeferred(self.get(client, service, node, forums_key or None))
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 d.addCallback(lambda data: json.dumps(data))
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 return d
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
195 async def get(self, client, service=None, node=None, forums_key=None):
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 if service is None:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 service = client.pubsub_service
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 if node is None:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 node = NS_FORUMS
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 if forums_key is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
201 forums_key = 'default'
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
202 items_data = await self._p.get_items(client, service, node, item_ids=[forums_key])
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 item = items_data[0][0]
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 # we have the item and need to convert it to json
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
205 forums = self._parse_forums(item)
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
206 return forums
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 def _set(self, forums, service=None, node=None, forums_key=None, profile_key=C.PROF_KEY_NONE):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
209 client = self.host.get_client(profile_key)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 forums = json.loads(forums)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 if service.strip():
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 service = jid.JID(service)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 else:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 service = None
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 if not node.strip():
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 node = None
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
217 return defer.ensureDeferred(
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
218 self.set(client, forums, service, node, forums_key or None)
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
219 )
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
221 async def set(self, client, forums, service=None, node=None, forums_key=None):
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
222 """Create or replace forums structure
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 @param forums(list): list of dictionary as follow:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 a dictionary represent a forum metadata, with the following keys:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 - title: title of the forum
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 - name: short name (unique in those forums) for the forum
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 - main-language: main language to be use in the forums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 - uri: XMPP uri to the microblog node hosting the forum
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 - short-desc: short description of the forum (in main-language)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 - desc: long description of the forum (in main-language)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 - sub-forums: a list of sub-forums with the same structure
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 title or name is needed, and uri or sub-forums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 @param forums_key(unicode, None): key (i.e. item id) of the forums
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 may be used to store different forums structures for different languages
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 None to use "default"
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 """
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 if service is None:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 service = client.pubsub_service
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 if node is None:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 node = NS_FORUMS
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 if forums_key is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
243 forums_key = 'default'
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
244 forums_elt = await self._create_forums(client, forums, service, node)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
245 return await self._p.send_item(
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
246 client, service, node, forums_elt, item_id=forums_key
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
247 )
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
248
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
249 def _get_topics(self, service, node, extra=None, profile_key=C.PROF_KEY_NONE):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
250 client = self.host.get_client(profile_key)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
251 extra = self._p.parse_extra(extra)
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
252 d = defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
253 self.get_topics(
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
254 client, jid.JID(service), node, rsm_request=extra.rsm_request,
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
255 extra=extra.extra
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
256 )
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
257 )
3549
3fd60beb9b92 plugin forums: use serialised data for extra in forumTopicsGet
Goffi <goffi@goffi.org>
parents: 3515
diff changeset
258 d.addCallback(
3fd60beb9b92 plugin forums: use serialised data for extra in forumTopicsGet
Goffi <goffi@goffi.org>
parents: 3515
diff changeset
259 lambda topics_data: (topics_data[0], data_format.serialise(topics_data[1]))
3fd60beb9b92 plugin forums: use serialised data for extra in forumTopicsGet
Goffi <goffi@goffi.org>
parents: 3515
diff changeset
260 )
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 return d
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
263 async def get_topics(self, client, service, node, rsm_request=None, extra=None):
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
264 """Retrieve topics data
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 Topics are simple microblog URIs with some metadata duplicated from first post
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
268 topics_data = await self._p.get_items(
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
269 client, service, node, rsm_request=rsm_request, extra=extra
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
270 )
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 topics = []
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 item_elts, metadata = topics_data
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 for item_elt in item_elts:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
274 topic_elt = next(item_elt.elements(NS_FORUMS, 'topic'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
275 title_elt = next(topic_elt.elements(NS_FORUMS, 'title'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
276 topic = {'uri': topic_elt['uri'],
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
277 'author': topic_elt['author'],
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
278 'title': str(title_elt)}
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 topics.append(topic)
3584
edc79cefe968 plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents: 3549
diff changeset
280 return (topics, metadata)
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
282 def _create_topic(self, service, node, mb_data, profile_key):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
283 client = self.host.get_client(profile_key)
3515
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
284 return defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
285 self.create_topic(client, jid.JID(service), node, mb_data)
3515
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
286 )
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
287
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
288 async def create_topic(self, client, service, node, mb_data):
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
290 title = mb_data['title']
3515
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
291 content = mb_data.pop('content')
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 except KeyError as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
293 raise exceptions.DataError("missing mandatory data: {key}".format(key=e.args[0]))
3515
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
294 else:
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
295 mb_data["content_rich"] = content
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 topic_node = FORUM_TOPIC_NODE_TPL.format(node=node, uuid=shortuuid.uuid())
3515
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
297 await self._p.createNode(client, service, topic_node, self._node_options)
2dce411c2647 plugin misc forums: use rich content in createTopic
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
298 await self._m.send(client, mb_data, service, topic_node)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
299 topic_uri = uri.build_xmpp_uri('pubsub',
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
300 subtype='microblog',
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 path=service.full(),
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 node=topic_node)
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 topic_elt = domish.Element((NS_FORUMS, 'topic'))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
304 topic_elt['uri'] = topic_uri
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
305 topic_elt['author'] = client.jid.userhost()
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
306 topic_elt.addElement('title', content = title)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3931
diff changeset
307 await self._p.send_item(client, service, node, topic_elt)