summaryrefslogtreecommitdiff
path: root/poezio/bookmarks.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-01-29 17:56:51 +0100
committerLink Mauve <linkmauve@linkmauve.fr>2021-02-03 15:22:09 +0100
commit19b58d86f5c8e9cc761f0e1e0f85be32016e4235 (patch)
treeacf4ebff3500011316860f1a2bc64ba57e74f260 /poezio/bookmarks.py
parentf2aaba982b9a13b0362909c6703c8ba3211b88e5 (diff)
downloadpoezio-19b58d86f5c8e9cc761f0e1e0f85be32016e4235.tar.gz
poezio-19b58d86f5c8e9cc761f0e1e0f85be32016e4235.tar.bz2
poezio-19b58d86f5c8e9cc761f0e1e0f85be32016e4235.tar.xz
poezio-19b58d86f5c8e9cc761f0e1e0f85be32016e4235.zip
bookmarks: get rid of callbacks
Diffstat (limited to 'poezio/bookmarks.py')
-rw-r--r--poezio/bookmarks.py54
1 files changed, 33 insertions, 21 deletions
diff --git a/poezio/bookmarks.py b/poezio/bookmarks.py
index f62f67ce..b1ad1f9c 100644
--- a/poezio/bookmarks.py
+++ b/poezio/bookmarks.py
@@ -30,9 +30,19 @@ Adding a remote bookmark:
import functools
import logging
-from typing import Optional, List, Union
-
-from slixmpp import InvalidJID, JID
+from typing import (
+ Callable,
+ List,
+ Optional,
+ Union,
+)
+
+from slixmpp import (
+ InvalidJID,
+ JID,
+ ClientXMPP,
+)
+from slixmpp.exceptions import IqError, IqTimeout
from slixmpp.plugins.xep_0048 import Bookmarks, Conference, URL
from poezio.config import config
@@ -213,17 +223,17 @@ class BookmarkList:
self.preferred = value
config.set_and_save('use_bookmarks_method', value)
- def save_remote(self, xmpp, callback):
+ async def save_remote(self, xmpp: ClientXMPP):
"""Save the remote bookmarks."""
if not any(self.available_storage.values()):
return
method = 'xep_0049' if self.preferred == 'privatexml' else 'xep_0223'
if method:
- xmpp.plugin['xep_0048'].set_bookmarks(
+ return await xmpp.plugin['xep_0048'].set_bookmarks(
stanza_storage(self.bookmarks),
method=method,
- callback=callback)
+ )
def save_local(self):
"""Save the local bookmarks."""
@@ -231,22 +241,24 @@ class BookmarkList:
if bookmark.method == 'local')
config.set_and_save('rooms', local)
- def save(self, xmpp, core=None, callback=None):
+ async def save(self, xmpp: ClientXMPP, core=None):
"""Save all the bookmarks."""
self.save_local()
-
- def _cb(iq):
- if callback:
- callback(iq)
- if iq["type"] == "error" and core:
- core.information('Could not save remote bookmarks.', 'Error')
- elif core:
- core.information('Bookmarks saved', 'Info')
-
if config.get('use_remote_bookmarks'):
- self.save_remote(xmpp, _cb)
-
- async def get_pep(self, xmpp):
+ try:
+ result = await self.save_remote(xmpp)
+ if core is not None:
+ core.information('Bookmarks saved', 'Info')
+ return result
+ except (IqError, IqTimeout) as iq:
+ if core is not None:
+ core.information(
+ 'Could not save remote bookmarks.',
+ 'Error'
+ )
+ raise
+
+ async def get_pep(self, xmpp: ClientXMPP):
"""Add the remotely stored bookmarks via pep to the list."""
iq = await xmpp.plugin['xep_0048'].get_bookmarks(method='xep_0223')
for conf in iq['pubsub']['items']['item']['bookmarks'][
@@ -257,7 +269,7 @@ class BookmarkList:
self.append(bookm)
return iq
- async def get_privatexml(self, xmpp):
+ async def get_privatexml(self, xmpp: ClientXMPP):
"""
Fetch the remote bookmarks stored via privatexml.
"""
@@ -268,7 +280,7 @@ class BookmarkList:
self.append(bookm)
return iq
- async def get_remote(self, xmpp, information):
+ async def get_remote(self, xmpp: ClientXMPP, information: Callable):
"""Add the remotely stored bookmarks to the list."""
if xmpp.anon or not any(self.available_storage.values()):
information('No remote bookmark storage available', 'Warning')