plugin misc list: register lists for pubsub invitations

This commit is contained in:
Goffi 2021-02-19 15:52:28 +01:00
commit fe5af39ab5

View file

@ -16,12 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import shortuuid
from typing import Tuple
from typing import List, Tuple, Optional
from twisted.internet import defer
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid
from wokkel import data_form
from sat.core.i18n import _, D_
from sat.core.xmpp import SatXMPPEntity
from sat.core.constants import Const as C
from sat.tools.common import uri
from sat.tools.common import data_format
@ -39,7 +40,8 @@ PLUGIN_INFO = {
C.PI_IMPORT_NAME: "LISTS",
C.PI_TYPE: "EXP",
C.PI_PROTOCOLS: [],
C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY"],
C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY",
"PUBSUB_INVITATION"],
C.PI_MAIN: "PubsubLists",
C.PI_HANDLER: "no",
C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""),
@ -208,6 +210,9 @@ class PubsubLists:
self._s = self.host.plugins["XEP-0346"]
self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS)
host.registerNamespace("tickets", APP_NS_TICKETS)
self.host.plugins["PUBSUB_INVITATION"].register(
APP_NS_TICKETS, self
)
self._p = self.host.plugins["XEP-0060"]
self._m = self.host.plugins["XEP-0277"]
host.bridge.addMethod(
@ -275,6 +280,30 @@ class PubsubLists:
async_=True,
)
async def onInvitationPreflight(
self,
client: SatXMPPEntity,
namespace: str,
name: str,
extra: dict,
service: jid.JID,
node: str,
item_id: Optional[str],
item_elt: domish.Element
) -> None:
try:
schema = await self._s.getSchemaForm(client, service, node)
except Exception as e:
log.warning(f"Can't retrive node schema as {node!r} [{service}]: {e}")
else:
try:
field_type = schema[NS_TICKETS_TYPE]
except KeyError:
log.debug("no type found in list schema")
else:
list_elt = extra["element"] = domish.Element((APP_NS_TICKETS, "list"))
list_elt["type"] = field_type
def _set(self, service, node, values, schema=None, item_id=None, extra='',
profile_key=C.PROF_KEY_NONE):
client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(