Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0402.py @ 4332:71c939e34ca6
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | 554a87ae17a6 |
children |
rev | line source |
---|---|
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia plugin to handle chat room bookmarks via PEP |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from typing import Iterator, Self, cast |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from pydantic import BaseModel, Field, RootModel |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.internet import defer |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.words.protocols.jabber import jid |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from wokkel import pubsub |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from libervia.backend.core import exceptions |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from libervia.backend.core.constants import Const as C |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from libervia.backend.core.core_types import SatXMPPEntity |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from libervia.backend.core.i18n import _ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from libervia.backend.core.log import getLogger |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from libervia.backend.models.types import DomishElementType, JIDType |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from libervia.backend.plugins.plugin_xep_0045 import XEP_0045 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from libervia.backend.plugins.plugin_xep_0048 import XEP_0048 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from libervia.backend.plugins.plugin_xep_0060 import XEP_0060 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 from libervia.backend.tools import utils |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from libervia.backend.tools.common import data_format |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 log = getLogger(__name__) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 PLUGIN_INFO = { |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_NAME: "PEP Native Bookmarks", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 C.PI_IMPORT_NAME: "XEP-0402", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 C.PI_TYPE: "XEP", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 C.PI_MODES: C.PLUG_MODE_BOTH, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 C.PI_PROTOCOLS: [], |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 C.PI_DEPENDENCIES: ["XEP-0048", "XEP-0060", "XEP-0163", "XEP-0045"], |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 C.PI_RECOMMENDATIONS: [], |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 C.PI_MAIN: "XEP_0402", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 C.PI_HANDLER: "no", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 C.PI_DESCRIPTION: _("""Bookmark chat rooms, and handle their joined state."""), |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 } |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 NS_BOOKMARKS2 = "urn:xmpp:bookmarks:1" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 NS_BOOKMARKS2_COMPAT = f"{NS_BOOKMARKS2}#compat" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 class Conference(BaseModel): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 Model for conference data. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 autojoin: bool = Field( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 False, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 description="Whether the client should automatically join the conference room on " |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 "login.", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 name: str | None = Field( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 None, description="A friendly name for the bookmark, specified by the user." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 nick: str | None = Field( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 None, description="The user's preferred roomnick for the chatroom." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 password: str | None = Field( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 None, description="A password used to access the chatroom." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 extensions: list[DomishElementType] = Field( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 default_factory=list, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 description="A set of child elements (of potentially any namespace).", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 def set_attributes(self, conference_elt: domish.Element) -> None: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 """Set <conference> element attributes from this instance's data.""" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 if self.autojoin: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 conference_elt["autojoin"] = "true" if self.autojoin else "false" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 if self.name: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 conference_elt["name"] = self.name |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 def set_children(self, conference_elt: domish.Element) -> None: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 """Set <conference> element children from this instance's data.""" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 if self.nick: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 nick_elt = conference_elt.addElement((NS_BOOKMARKS2, "nick")) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 nick_elt.addContent(self.nick) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 if self.password: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 password_elt = conference_elt.addElement((NS_BOOKMARKS2, "password")) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 password_elt.addContent(self.password) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 for extension in self.extensions: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 conference_elt.addChild(extension) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 @classmethod |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 def from_element(cls, conference_elt: domish.Element) -> Self: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 Create a Conference instance from a <conference> element or its parent. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 @param conference_elt: The <conference> element or a parent element. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 @return: Conference instance. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 @raise exceptions.NotFound: If the <conference> element is not found. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 if conference_elt.uri != NS_BOOKMARKS2 or conference_elt.name != "conference": |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 child_conference_elt = next( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 conference_elt.elements(NS_BOOKMARKS2, "conference"), None |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 if child_conference_elt is None: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 raise exceptions.NotFound("<conference> element not found") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 conference_elt = child_conference_elt |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 kwargs = {} |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 if conference_elt.hasAttribute("autojoin"): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 kwargs["autojoin"] = conference_elt["autojoin"] == "true" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 if conference_elt.hasAttribute("name"): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 kwargs["name"] = conference_elt["name"] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 nick_elt = next(conference_elt.elements(NS_BOOKMARKS2, "nick"), None) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 if nick_elt: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 kwargs["nick"] = str(nick_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 password_elt = next(conference_elt.elements(NS_BOOKMARKS2, "password"), None) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 if password_elt: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 kwargs["password"] = str(password_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 kwargs["extensions"] = [ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 child for child in conference_elt.elements() if child.uri != NS_BOOKMARKS2 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 ] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 return cls(**kwargs) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 def to_element(self) -> domish.Element: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 """Build the <conference> element from this instance's data. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 @return: <conference> element. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 conference_elt = domish.Element((NS_BOOKMARKS2, "conference")) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 self.set_attributes(conference_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 self.set_children(conference_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 return conference_elt |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 class Bookmarks(RootModel): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 root: dict[JIDType, Conference] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 def items(self): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 return self.root.items() |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 def __dict__(self) -> dict[JIDType, Conference]: # type: ignore |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 return self.root |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 def __iter__(self) -> Iterator[JIDType]: # type: ignore |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 return iter(self.root) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 def __getitem__(self, item): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 return self.root[item] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 @classmethod |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 def from_elements(cls, items_elt: list[domish.Element]) -> Self: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 """Convert list of items to instance of Bookmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 @param items_elt: list of <item> elements from boorkmarks node. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 bookmarks = {} |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 for item_elt in items_elt: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 try: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 bookmark_jid = jid.JID(item_elt["id"]) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 except RuntimeError as e: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 log.warning(f"Can't parse bookmark jid {e}: {item_elt.toXml()}") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 continue |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 try: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 conference = Conference.from_element(item_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 except exceptions.NotFound: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 log.warning(f"Can't find conference data in bookmark: {item_elt}") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 bookmarks[bookmark_jid] = conference |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 return cls(bookmarks) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 class XEP_0402: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 namespace = NS_BOOKMARKS2 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 def __init__(self, host): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 self.host = host |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 self._legacy = cast(XEP_0048, host.plugins["XEP-0048"]) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 self._p = cast(XEP_0060, host.plugins["XEP-0060"]) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 self._muc = cast(XEP_0045, host.plugins["XEP-0045"]) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 host.bridge.add_method( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 "bookmark_get", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 ".plugin", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 in_sign="ss", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 out_sign="s", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 method=self._bookmark_get, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 async_=True, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 host.bridge.add_method( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 "bookmarks_list", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 ".plugin", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 in_sign="ss", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 out_sign="s", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 method=self._bookmarks_list, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 async_=True, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 host.bridge.add_method( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 "bookmark_remove", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 ".plugin", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 in_sign="ss", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 out_sign="", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 method=self._bookmark_remove, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 async_=True, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 host.bridge.add_method( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 "bookmarks_set", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 ".plugin", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 in_sign="ss", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 out_sign="", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 method=self._bookmarks_set, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 async_=True, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 host.plugins["XEP-0163"].add_pep_event( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 None, NS_BOOKMARKS2, self._on_bookmark_event |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 host.register_namespace("bookmarks2", NS_BOOKMARKS2) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 async def _on_bookmark_event( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 self, items_events: pubsub.ItemsEvent, profile: str |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 ) -> None: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 client = self.host.get_client(profile) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 if items_events.sender != client.jid.userhostJID(): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 log.warning( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 "Bookmark event Unexpectedly send for another account " |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 f"({items_events.sender})." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 for item_elt in items_events.items: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 try: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 room_jid = jid.JID(item_elt["id"]) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 except Exception as e: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 log.warning( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 f'Ignoring bookmark due to invalid JID in "id" ({e}): ' |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 f"{item_elt.toXml()}" |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 continue |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 try: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 conference = Conference.from_element(item_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 except exceptions.NotFound: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 log.warning("Ignoring invalid bookmark element: {item_elt.toXml()}") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 except Exception: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 log.exception("Can't parse bookmark item: {item_elt.toXml()}") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 if conference.autojoin: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 await self._muc.join( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 client, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 room_jid, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 conference.nick, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 {"password": conference.password}, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 await self._muc.leave(client, room_jid) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 @utils.ensure_deferred |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 async def _bookmark_get(self, bookmark_jid: str, profile: str) -> str: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 """List current boorkmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 @param extra_s: Serialised extra. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 Reserved for future use. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 @param profile: Profile to use. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 client = self.host.get_client(profile) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 conference = await self.get(client, jid.JID(bookmark_jid)) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 return conference.model_dump_json(exclude_none=True) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 async def get(self, client: SatXMPPEntity, bookmark_jid: jid.JID) -> Conference: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 """Helper method to get a single bookmark. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 @param client: profile session. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 @bookmark_jid: JID of the boorkmark to get. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 @return: Conference instance. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 pep_jid = client.jid.userhostJID() |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 if await self.host.memory.disco.has_feature( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 client, NS_BOOKMARKS2_COMPAT, pep_jid |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 ): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 items, __ = await self._p.get_items( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 client, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 client.jid.userhostJID(), |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 NS_BOOKMARKS2, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 item_ids=[bookmark_jid.full()], |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 return Conference.from_element(items[0]) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 # No compatibility layer, we use legacy bookmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 bookmarks = await self.list(client) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 return bookmarks[bookmark_jid] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 def _bookmark_remove(self, bookmark_jid: str, profile: str) -> defer.Deferred[None]: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 d = defer.ensureDeferred( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 self.remove(self.host.get_client(profile), jid.JID(bookmark_jid)) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 return d |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 async def remove(self, client: SatXMPPEntity, bookmark_jid: jid.JID) -> None: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 """Helper method to delete an existing bookmark. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 @param client: Profile session. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 @param bookmark_jid: Bookmark to delete. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 pep_jid = client.jid.userhostJID() |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 if await self.host.memory.disco.has_feature( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 client, NS_BOOKMARKS2_COMPAT, pep_jid |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 ): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 await self._p.retract_items( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 client, client.jid.userhostJID(), NS_BOOKMARKS2, [bookmark_jid.full()] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 log.debug( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 f"[{client.profile}] No compatibility layer found, we use legacy " |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 "bookmarks." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 await self._legacy.remove_bookmark( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 self._legacy.MUC_TYPE, bookmark_jid, "private", client.profile |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 @utils.ensure_deferred |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 async def _bookmarks_list(self, extra_s: str, profile: str) -> str: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 """List current boorkmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 @param extra_s: Serialised extra. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 Reserved for future use. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 @param profile: Profile to use. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 client = self.host.get_client(profile) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 extra = data_format.deserialise(extra_s) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 bookmarks = await self.list(client, extra) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 return bookmarks.model_dump_json(exclude_none=True) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 async def list(self, client: SatXMPPEntity, extra: dict | None = None) -> Bookmarks: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 """List bookmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 If there is a compatibility layer announced, Bookmarks2 will be used, otherwise |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 legacy bookmarks will be used. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 @param client: Client session. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 @param extra: extra dat) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 @return: bookmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 pep_jid = client.jid.userhostJID() |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 if await self.host.memory.disco.has_feature( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 client, NS_BOOKMARKS2_COMPAT, pep_jid |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 ): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 items, __ = await self._p.get_items( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 client, client.jid.userhostJID(), NS_BOOKMARKS2 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 return Bookmarks.from_elements(items) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 # There is no compatibility layer on the PEP server, so we use legacy |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 # bookmarks as recommended at |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 # https://docs.modernxmpp.org/client/groupchat/#bookmarks |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 log.debug( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 f"[{client.profile}] No compatibility layer found, we use legacy " |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 "bookmarks." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 legacy_data = await self._legacy.bookmarks_list( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 self._legacy.MUC_TYPE, "private", client.profile |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 private_bookmarks = legacy_data["private"] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 bookmarks_dict = {} |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 for jid, bookmark_data in private_bookmarks.items(): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 autojoin = C.bool(bookmark_data.get("autojoin", C.BOOL_FALSE)) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 name = bookmark_data.get("name") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
377 nick = bookmark_data.get("nick") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 password = bookmark_data.get("password") |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 conference = Conference( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 autojoin=autojoin, name=name, nick=nick, password=password |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 bookmarks_dict[jid] = conference |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 return Bookmarks(bookmarks_dict) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 @utils.ensure_deferred |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 async def _bookmarks_set(self, bookmarks_raw: str, profile: str) -> None: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 """Add or update one or more bookmarks. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 @param bookmarks_raw: serialised bookmark. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 It must deserialise to a dict mapping from bookmark JID to Conference data. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 @param profile: Profile to use. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 """ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 client = self.host.get_client(profile) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 bookmarks = Bookmarks.model_validate_json(bookmarks_raw) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 pep_jid = client.jid.userhostJID() |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 if await self.host.memory.disco.has_feature( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 client, NS_BOOKMARKS2_COMPAT, pep_jid |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 ): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 bookmark_items = [] |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 for bookmark_jid, conference in bookmarks.items(): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 item_elt = domish.Element((pubsub.NS_PUBSUB, "item")) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 item_elt["id"] = bookmark_jid.full() |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 item_elt.addChild(conference.to_element()) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 bookmark_items.append(item_elt) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 await self._p.send_items( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 client, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 None, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 NS_BOOKMARKS2, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 bookmark_items, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 extra={ |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 self._p.EXTRA_PUBLISH_OPTIONS: { |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 "pubsub#access_model": self._p.ACCESS_WHITELIST |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 }, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 self._p.EXTRA_AUTOCREATE: True, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 }, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 log.debug( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 f"[{client.profile}] No compatibility layer found, we use legacy " |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 "bookmarks." |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 # XXX: We add every bookmark one by one, which is inefficient. The legacy |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 # plugin likely implemented this way because end-users typically add bookmarks |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 # individually. Nowadays, very few servers, if any, still implement XEP-0048 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 # without the XEP-0402 compatibility layer, so it's not worth spending time to |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 # improve the legacy XEP-0048 plugin. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 for bookmark_jid, conference in bookmarks.items(): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 bookmark_data = {} |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 if conference.autojoin: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 bookmark_data["autojoin"] = C.BOOL_TRUE |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 for attribute in ("name", "nick", "password"): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 value = getattr(conference, attribute) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 if value: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 bookmark_data[attribute] = value |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 await self._legacy.add_bookmark( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 self._legacy.MUC_TYPE, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 bookmark_jid, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 bookmark_data, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 storage_type="private", |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
442 profile_key=client.profile, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 ) |