Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
199
Issues
199
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
poezio
Commits
f5ad5199
Commit
f5ad5199
authored
Jan 29, 2021
by
mathieui
Committed by
Link Mauve
Feb 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use async properly on session start
parent
26258313
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
55 deletions
+46
-55
poezio/bookmarks.py
poezio/bookmarks.py
+18
-27
poezio/core/core.py
poezio/core/core.py
+11
-10
poezio/core/handlers.py
poezio/core/handlers.py
+17
-18
No files found.
poezio/bookmarks.py
View file @
f5ad5199
...
...
@@ -246,46 +246,37 @@ class BookmarkList:
if
config
.
get
(
'use_remote_bookmarks'
):
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."""
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
):
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
):
async
def
get_privatexml
(
self
,
xmpp
):
"""
Fetch the remote bookmarks stored via privatexml.
"""
def
_cb
(
iq
):
if
iq
[
'type'
]
==
'result'
:
for
conf
in
iq
[
'private'
][
'bookmarks'
][
'conferences'
]:
b
=
Bookmark
.
parse
(
conf
)
self
.
append
(
b
)
if
callback
:
callback
(
iq
)
xmpp
.
plugin
[
'xep_0048'
].
get_bookmarks
(
method
=
'xep_0049'
,
callback
=
_cb
)
iq
=
await
xmpp
.
plugin
[
'xep_0048'
].
get_bookmarks
(
method
=
'xep_0049'
)
for
conf
in
iq
[
'private'
][
'bookmarks'
][
'conferences'
]:
bookm
=
Bookmark
.
parse
(
conf
)
self
.
append
(
bookm
)
return
iq
def
get_remote
(
self
,
xmpp
,
information
,
callback
):
async
def
get_remote
(
self
,
xmpp
,
information
):
"""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'
)
return
if
self
.
preferred
==
'pep'
:
self
.
get_pep
(
xmpp
,
callback
=
callback
)
return
await
self
.
get_pep
(
xmpp
)
else
:
self
.
get_privatexml
(
xmpp
,
callback
=
callback
)
return
await
self
.
get_privatexml
(
xmpp
)
def
get_local
(
self
):
"""Add the locally stored bookmarks to the list."""
...
...
poezio/core/core.py
View file @
f5ad5199
...
...
@@ -44,7 +44,10 @@ from poezio import theming
from
poezio
import
timed_events
from
poezio
import
windows
from
poezio.bookmarks
import
BookmarkList
from
poezio.bookmarks
import
(
BookmarkList
,
Bookmark
,
)
from
poezio.common
import
get_error_message
from
poezio.config
import
config
,
firstrun
from
poezio.contact
import
Contact
,
Resource
...
...
@@ -1710,7 +1713,7 @@ class Core:
shortdesc
=
'Send your gaming activity.'
,
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
:
self
.
register_command
(
'block'
,
...
...
@@ -1729,7 +1732,7 @@ class Core:
####################### 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`"""
for
bm
in
bookmarks
:
if
not
(
bm
.
autojoin
or
config
.
get
(
'open_all_bookmarks'
)):
...
...
@@ -1745,14 +1748,16 @@ class Core:
if
bm
.
autojoin
:
tab
.
join
()
def
check_bookmark_storage
(
self
,
features
):
async
def
check_bookmark_storage
(
self
,
features
:
List
[
str
]
):
private
=
'jabber:iq:private'
in
features
pep_
=
'http://jabber.org/protocol/pubsub#publish'
in
features
self
.
bookmarks
.
available_storage
[
'private'
]
=
private
self
.
bookmarks
.
available_storage
[
'pep'
]
=
pep_
def
_join_remote_only
(
iq
):
if
iq
[
'type'
]
==
'error'
:
if
not
self
.
xmpp
.
anon
and
config
.
get
(
'use_remote_bookmarks'
):
try
:
await
self
.
bookmarks
.
get_remote
(
self
.
xmpp
,
self
.
information
)
except
IqError
as
iq
:
type_
=
iq
[
'error'
][
'type'
]
condition
=
iq
[
'error'
][
'condition'
]
if
not
(
type_
==
'cancel'
and
condition
==
'item-not-found'
):
...
...
@@ -1763,10 +1768,6 @@ class Core:
remote_bookmarks
=
self
.
bookmarks
.
remote
()
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
:
"""
Display the error in the tab
...
...
poezio/core/handlers.py
View file @
f5ad5199
...
...
@@ -79,27 +79,26 @@ class HandlerCore:
def
__init__
(
self
,
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
"""
def
callback
(
iq
):
if
not
iq
:
return
features
=
iq
[
'disco_info'
][
'features'
]
rostertab
=
self
.
core
.
tabs
.
by_name_and_class
(
'Roster'
,
tabs
.
RosterInfoTab
)
rostertab
.
check_blocking
(
features
)
rostertab
.
check_saslexternal
(
features
)
self
.
core
.
check_blocking
(
features
)
if
(
config
.
get
(
'enable_carbons'
)
and
'urn:xmpp:carbons:2'
in
features
):
self
.
core
.
xmpp
.
plugin
[
'xep_0280'
].
enable
()
self
.
core
.
check_bookmark_storage
(
features
)
self
.
core
.
xmpp
.
plugin
[
'xep_0030'
].
get_info
(
jid
=
self
.
core
.
xmpp
.
boundjid
.
domain
,
callback
=
callback
)
iq
=
await
self
.
core
.
xmpp
.
plugin
[
'xep_0030'
].
get_info
(
jid
=
self
.
core
.
xmpp
.
boundjid
.
domain
)
features
=
iq
[
'disco_info'
][
'features'
]
rostertab
=
self
.
core
.
tabs
.
by_name_and_class
(
'Roster'
,
tabs
.
RosterInfoTab
)
rostertab
.
check_saslexternal
(
features
)
rostertab
.
check_blocking
(
features
)
self
.
core
.
check_blocking
(
features
)
if
(
config
.
get
(
'enable_carbons'
)
and
'urn:xmpp:carbons:2'
in
features
):
self
.
core
.
xmpp
.
plugin
[
'xep_0280'
].
enable
()
await
self
.
core
.
check_bookmark_storage
(
features
)
def
find_identities
(
self
,
_
):
asyncio
.
ensure_future
(
...
...
@@ -1348,7 +1347,7 @@ class HandlerCore:
pres
.
send
()
self
.
core
.
bookmarks
.
get_local
()
# 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'
):
self
.
core
.
xmpp
.
plugin
[
'xep_0172'
].
publish_nick
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment