comparison libervia/backend/plugins/plugin_xep_0048.py @ 4327:554a87ae17a6

plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks): - Former bookmarks implementation is now labeled as "legacy". - XEP-0402 is now used for bookmarks when relevant namespaces are found, and it fallbacks to legacy XEP-0048/XEP-0049 bookmarks otherwise. - CLI legacy bookmark commands have been moved to `bookmarks legacy` - CLI bookmarks commands now use the new XEP-0402 (with fallback to legacy one automatically used if necessary).
author Goffi <goffi@goffi.org>
date Wed, 20 Nov 2024 11:43:27 +0100
parents 0d7bb4df2343
children 111dce64dcb5
comparison
equal deleted inserted replaced
4326:5fd6a4dc2122 4327:554a87ae17a6
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 3
4 # SAT plugin for Bookmarks (xep-0048) 4 # Libervia plugin for Bookmarks (xep-0048)
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org)
6 6
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by 8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or 9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version. 10 # (at your option) any later version.
69 help_string=D_("Use and manage bookmarks"), 69 help_string=D_("Use and manage bookmarks"),
70 ) 70 )
71 self.__selected_id = host.register_callback( 71 self.__selected_id = host.register_callback(
72 self._bookmark_selected_cb, with_data=True 72 self._bookmark_selected_cb, with_data=True
73 ) 73 )
74 # XXX: We're transitionning to XEP-0402, so we mark bridge method as "legacy"
75 # here.
74 host.bridge.add_method( 76 host.bridge.add_method(
75 "bookmarks_list", 77 "bookmarks_legacy_list",
76 ".plugin", 78 ".plugin",
77 in_sign="sss", 79 in_sign="sss",
78 out_sign="a{sa{sa{ss}}}", 80 out_sign="a{sa{sa{ss}}}",
79 method=self._bookmarks_list, 81 method=self.bookmarks_list,
80 async_=True, 82 async_=True,
81 ) 83 )
82 host.bridge.add_method( 84 host.bridge.add_method(
83 "bookmarks_remove", 85 "bookmarks_legacy_remove",
84 ".plugin", 86 ".plugin",
85 in_sign="ssss", 87 in_sign="ssss",
86 out_sign="", 88 out_sign="",
87 method=self._bookmarks_remove, 89 method=self.bookmarks_remove,
88 async_=True, 90 async_=True,
89 ) 91 )
90 host.bridge.add_method( 92 host.bridge.add_method(
91 "bookmarks_add", 93 "bookmarks_legacy_add",
92 ".plugin", 94 ".plugin",
93 in_sign="ssa{ss}ss", 95 in_sign="ssa{ss}ss",
94 out_sign="", 96 out_sign="",
95 method=self._bookmarks_add, 97 method=self.bookmarks_add,
96 async_=True, 98 async_=True,
97 ) 99 )
98 try: 100 try:
99 self.private_plg = self.host.plugins["XEP-0049"] 101 self.private_plg = self.host.plugins["XEP-0049"]
100 except KeyError: 102 except KeyError:
417 log.debug("Bookmark is not present in private storage") 419 log.debug("Bookmark is not present in private storage")
418 420
419 if storage_type == "pubsub": 421 if storage_type == "pubsub":
420 raise NotImplementedError 422 raise NotImplementedError
421 423
422 def _bookmarks_list(self, type_, storage_location, profile_key=C.PROF_KEY_NONE): 424 def bookmarks_list(
425 self,
426 type_: str,
427 storage_location: str,
428 profile_key: str = C.PROF_KEY_NONE
429 ) -> defer.Deferred[dict]:
423 """Return stored bookmarks 430 """Return stored bookmarks
424 431
425 @param type_: bookmark type, one of: 432 @param type_: bookmark type, one of:
426 - XEP_0048.MUC_TYPE: Multi-User chat room 433 - XEP_0048.MUC_TYPE: Multi-User chat room
427 - XEP_0048.URL_TYPE: web page URL 434 - XEP_0048.URL_TYPE: web page URL
456 463
457 for _storage_location in ("local", "private", "pubsub"): 464 for _storage_location in ("local", "private", "pubsub"):
458 if storage_location in ("all", _storage_location): 465 if storage_location in ("all", _storage_location):
459 ret[_storage_location] = {} 466 ret[_storage_location] = {}
460 if _storage_location in ("private",): 467 if _storage_location in ("private",):
461 # we update distant bookmarks, just in case an other client added something 468 # we update distant bookmarks, just in case an other client added
469 # something
462 d = self._get_server_bookmarks(_storage_location, client.profile) 470 d = self._get_server_bookmarks(_storage_location, client.profile)
463 else: 471 else:
464 d = defer.succeed(None) 472 d = defer.succeed(None)
465 d.addCallback(fill_bookmarks, _storage_location) 473 d.addCallback(fill_bookmarks, _storage_location)
466 ret_d.addCallback(lambda __: d) 474 ret_d.addCallback(lambda __: d)
467 475
468 return ret_d 476 return ret_d
469 477
470 def _bookmarks_remove( 478 def bookmarks_remove(
471 self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE 479 self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE
472 ): 480 ):
473 """Return stored bookmarks 481 """Return stored bookmarks
474 482
475 @param type_: bookmark type, one of: 483 @param type_: bookmark type, one of:
485 """ 493 """
486 if type_ == XEP_0048.MUC_TYPE: 494 if type_ == XEP_0048.MUC_TYPE:
487 location = jid.JID(location) 495 location = jid.JID(location)
488 return self.remove_bookmark(type_, location, storage_location, profile_key) 496 return self.remove_bookmark(type_, location, storage_location, profile_key)
489 497
490 def _bookmarks_add( 498 def bookmarks_add(
491 self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE 499 self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE
492 ): 500 ):
493 if type_ == XEP_0048.MUC_TYPE: 501 if type_ == XEP_0048.MUC_TYPE:
494 location = jid.JID(location) 502 location = jid.JID(location)
495 return self.add_bookmark(type_, location, data, storage_type, profile_key) 503 return self.add_bookmark(type_, location, data, storage_type, profile_key)