Commit f5ad5199 authored by mathieui's avatar mathieui Committed by Link Mauve

Use async properly on session start

parent 26258313
...@@ -246,46 +246,37 @@ class BookmarkList: ...@@ -246,46 +246,37 @@ class BookmarkList:
if config.get('use_remote_bookmarks'): if config.get('use_remote_bookmarks'):
self.save_remote(xmpp, _cb) self.save_remote(xmpp, _cb)
def get_pep(self, xmpp, callback): async def get_pep(self, xmpp):
"""Add the remotely stored bookmarks via pep to the list.""" """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'][
'conferences']:
if isinstance(conf, URL):
continue
bookm = Bookmark.parse(conf)
self.append(bookm)
return iq
def _cb(iq): async def get_privatexml(self, xmpp):
if iq['type'] == 'result':
for conf in iq['pubsub']['items']['item']['bookmarks'][
'conferences']:
if isinstance(conf, URL):
continue
b = Bookmark.parse(conf)
self.append(b)
if callback:
callback(iq)
xmpp.plugin['xep_0048'].get_bookmarks(method='xep_0223', callback=_cb)
def get_privatexml(self, xmpp, callback):
""" """
Fetch the remote bookmarks stored via privatexml. Fetch the remote bookmarks stored via privatexml.
""" """
def _cb(iq): iq = await xmpp.plugin['xep_0048'].get_bookmarks(method='xep_0049')
if iq['type'] == 'result': for conf in iq['private']['bookmarks']['conferences']:
for conf in iq['private']['bookmarks']['conferences']: bookm = Bookmark.parse(conf)
b = Bookmark.parse(conf) self.append(bookm)
self.append(b) return iq
if callback:
callback(iq)
xmpp.plugin['xep_0048'].get_bookmarks(method='xep_0049', callback=_cb)
def get_remote(self, xmpp, information, callback): async def get_remote(self, xmpp, information):
"""Add the remotely stored bookmarks to the list.""" """Add the remotely stored bookmarks to the list."""
if xmpp.anon or not any(self.available_storage.values()): if xmpp.anon or not any(self.available_storage.values()):
information('No remote bookmark storage available', 'Warning') information('No remote bookmark storage available', 'Warning')
return return
if self.preferred == 'pep': if self.preferred == 'pep':
self.get_pep(xmpp, callback=callback) return await self.get_pep(xmpp)
else: else:
self.get_privatexml(xmpp, callback=callback) return await self.get_privatexml(xmpp)
def get_local(self): def get_local(self):
"""Add the locally stored bookmarks to the list.""" """Add the locally stored bookmarks to the list."""
......
...@@ -44,7 +44,10 @@ from poezio import theming ...@@ -44,7 +44,10 @@ from poezio import theming
from poezio import timed_events from poezio import timed_events
from poezio import windows from poezio import windows
from poezio.bookmarks import BookmarkList from poezio.bookmarks import (
BookmarkList,
Bookmark,
)
from poezio.common import get_error_message from poezio.common import get_error_message
from poezio.config import config, firstrun from poezio.config import config, firstrun
from poezio.contact import Contact, Resource from poezio.contact import Contact, Resource
...@@ -1710,7 +1713,7 @@ class Core: ...@@ -1710,7 +1713,7 @@ class Core:
shortdesc='Send your gaming activity.', shortdesc='Send your gaming activity.',
completion=None) completion=None)
def check_blocking(self, features): def check_blocking(self, features: List[str]):
if 'urn:xmpp:blocking' in features and not self.xmpp.anon: if 'urn:xmpp:blocking' in features and not self.xmpp.anon:
self.register_command( self.register_command(
'block', 'block',
...@@ -1729,7 +1732,7 @@ class Core: ...@@ -1729,7 +1732,7 @@ class Core:
####################### Random things to move ################################# ####################### Random things to move #################################
def join_initial_rooms(self, bookmarks): def join_initial_rooms(self, bookmarks: List[Bookmark]):
"""Join all rooms given in the iterator `bookmarks`""" """Join all rooms given in the iterator `bookmarks`"""
for bm in bookmarks: for bm in bookmarks:
if not (bm.autojoin or config.get('open_all_bookmarks')): if not (bm.autojoin or config.get('open_all_bookmarks')):
...@@ -1745,14 +1748,16 @@ class Core: ...@@ -1745,14 +1748,16 @@ class Core:
if bm.autojoin: if bm.autojoin:
tab.join() tab.join()
def check_bookmark_storage(self, features): async def check_bookmark_storage(self, features: List[str]):
private = 'jabber:iq:private' in features private = 'jabber:iq:private' in features
pep_ = 'http://jabber.org/protocol/pubsub#publish' in features pep_ = 'http://jabber.org/protocol/pubsub#publish' in features
self.bookmarks.available_storage['private'] = private self.bookmarks.available_storage['private'] = private
self.bookmarks.available_storage['pep'] = pep_ self.bookmarks.available_storage['pep'] = pep_
def _join_remote_only(iq): if not self.xmpp.anon and config.get('use_remote_bookmarks'):
if iq['type'] == 'error': try:
await self.bookmarks.get_remote(self.xmpp, self.information)
except IqError as iq:
type_ = iq['error']['type'] type_ = iq['error']['type']
condition = iq['error']['condition'] condition = iq['error']['condition']
if not (type_ == 'cancel' and condition == 'item-not-found'): if not (type_ == 'cancel' and condition == 'item-not-found'):
...@@ -1763,10 +1768,6 @@ class Core: ...@@ -1763,10 +1768,6 @@ class Core:
remote_bookmarks = self.bookmarks.remote() remote_bookmarks = self.bookmarks.remote()
self.join_initial_rooms(remote_bookmarks) self.join_initial_rooms(remote_bookmarks)
if not self.xmpp.anon and config.get('use_remote_bookmarks'):
self.bookmarks.get_remote(self.xmpp, self.information,
_join_remote_only)
def room_error(self, error: IqError, room_name: str) -> None: def room_error(self, error: IqError, room_name: str) -> None:
""" """
Display the error in the tab Display the error in the tab
......
...@@ -79,27 +79,26 @@ class HandlerCore: ...@@ -79,27 +79,26 @@ class HandlerCore:
def __init__(self, core): def __init__(self, core):
self.core = core self.core = core
def on_session_start_features(self, _): async def on_session_start_features(self, _):
""" """
Enable carbons & blocking on session start if wanted and possible Enable carbons & blocking on session start if wanted and possible
""" """
def callback(iq):
if not iq: iq = await self.core.xmpp.plugin['xep_0030'].get_info(
return jid=self.core.xmpp.boundjid.domain
features = iq['disco_info']['features'] )
rostertab = self.core.tabs.by_name_and_class( features = iq['disco_info']['features']
'Roster', tabs.RosterInfoTab)
rostertab.check_blocking(features) rostertab = self.core.tabs.by_name_and_class(
rostertab.check_saslexternal(features) 'Roster', tabs.RosterInfoTab)
self.core.check_blocking(features) rostertab.check_saslexternal(features)
if (config.get('enable_carbons') rostertab.check_blocking(features)
and 'urn:xmpp:carbons:2' in features): self.core.check_blocking(features)
self.core.xmpp.plugin['xep_0280'].enable() if (config.get('enable_carbons')
self.core.check_bookmark_storage(features) and 'urn:xmpp:carbons:2' in features):
self.core.xmpp.plugin['xep_0280'].enable()
self.core.xmpp.plugin['xep_0030'].get_info( await self.core.check_bookmark_storage(features)
jid=self.core.xmpp.boundjid.domain, callback=callback)
def find_identities(self, _): def find_identities(self, _):
asyncio.ensure_future( asyncio.ensure_future(
...@@ -1348,7 +1347,7 @@ class HandlerCore: ...@@ -1348,7 +1347,7 @@ class HandlerCore:
pres.send() pres.send()
self.core.bookmarks.get_local() self.core.bookmarks.get_local()
# join all the available bookmarks. As of yet, this is just the local ones # join all the available bookmarks. As of yet, this is just the local ones
self.core.join_initial_rooms(self.core.bookmarks) self.core.join_initial_rooms(self.core.bookmarks.local())
if config.get('enable_user_nick'): if config.get('enable_user_nick'):
self.core.xmpp.plugin['xep_0172'].publish_nick( self.core.xmpp.plugin['xep_0172'].publish_nick(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment