comparison sat/plugins/plugin_pubsub_cache.py @ 3738:ffa8c8c78115

plugin XEP-0059, cache: allow those plugins to work in component mode rel 364
author Goffi <goffi@goffi.org>
date Tue, 22 Mar 2022 17:00:42 +0100
parents 342e3ddefd23
children c4881833cf8a
comparison
equal deleted inserted replaced
3737:783d6dc87b80 3738:ffa8c8c78115
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import time 19 import time
20 from datetime import datetime 20 from datetime import datetime
21 from typing import Optional, List, Tuple 21 from typing import Optional, List, Tuple, Dict, Any
22 from twisted.words.protocols.jabber import jid, error 22 from twisted.words.protocols.jabber import jid, error
23 from twisted.words.xish import domish 23 from twisted.words.xish import domish
24 from twisted.internet import defer 24 from twisted.internet import defer
25 from wokkel import pubsub, rsm 25 from wokkel import pubsub, rsm
26 from sat.core.i18n import _ 26 from sat.core.i18n import _
37 37
38 PLUGIN_INFO = { 38 PLUGIN_INFO = {
39 C.PI_NAME: "PubSub Cache", 39 C.PI_NAME: "PubSub Cache",
40 C.PI_IMPORT_NAME: "PUBSUB_CACHE", 40 C.PI_IMPORT_NAME: "PUBSUB_CACHE",
41 C.PI_TYPE: C.PLUG_TYPE_PUBSUB, 41 C.PI_TYPE: C.PLUG_TYPE_PUBSUB,
42 C.PI_MODES: C.PLUG_MODE_BOTH,
42 C.PI_PROTOCOLS: [], 43 C.PI_PROTOCOLS: [],
43 C.PI_DEPENDENCIES: ["XEP-0059", "XEP-0060"], 44 C.PI_DEPENDENCIES: ["XEP-0059", "XEP-0060"],
44 C.PI_RECOMMENDATIONS: [], 45 C.PI_RECOMMENDATIONS: [],
45 C.PI_MAIN: "PubsubCache", 46 C.PI_MAIN: "PubsubCache",
46 C.PI_HANDLER: "no", 47 C.PI_HANDLER: "no",
481 node: PubsubNode, 482 node: PubsubNode,
482 max_items: Optional[int] = None, 483 max_items: Optional[int] = None,
483 item_ids: Optional[List[str]] = None, 484 item_ids: Optional[List[str]] = None,
484 sub_id: Optional[str] = None, 485 sub_id: Optional[str] = None,
485 rsm_request: Optional[rsm.RSMRequest] = None, 486 rsm_request: Optional[rsm.RSMRequest] = None,
486 extra: Optional[dict] = None 487 extra: Optional[Dict[str, Any]] = None
487 ) -> Tuple[List[PubsubItem], dict]: 488 ) -> Tuple[List[PubsubItem], dict]:
488 """Get items from cache, using same arguments as for external Pubsub request""" 489 """Get items from cache, using same arguments as for external Pubsub request"""
490 if extra is None:
491 extra = {}
489 if "mam" in extra: 492 if "mam" in extra:
490 raise NotImplementedError("MAM queries are not supported yet") 493 raise NotImplementedError("MAM queries are not supported yet")
491 if max_items is None and rsm_request is None: 494 if max_items is None and rsm_request is None:
492 max_items = 20 495 max_items = 20
493 if max_items is not None: 496 if max_items is not None: