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
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lumi
poezio
Commits
a2ad4af7
Commit
a2ad4af7
authored
Mar 30, 2018
by
Link Mauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use slixmpp’s new cache module for avatars too.
parent
b03a92e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
31 deletions
+15
-31
poezio/core/core.py
poezio/core/core.py
+3
-1
poezio/core/handlers.py
poezio/core/handlers.py
+12
-30
No files found.
poezio/core/core.py
View file @
a2ad4af7
...
...
@@ -18,6 +18,7 @@ import sys
import
time
from
slixmpp.xmlstream.handler
import
Callback
from
slixmpp.util
import
FileSystemPerJidCache
from
poezio
import
connection
from
poezio
import
decorators
...
...
@@ -30,7 +31,7 @@ from poezio import windows
from
poezio.bookmarks
import
BookmarkList
from
poezio.common
import
safeJID
from
poezio.config
import
config
,
firstrun
from
poezio.config
import
config
,
firstrun
,
CACHE_DIR
from
poezio.contact
import
Contact
,
Resource
from
poezio.daemon
import
Executor
from
poezio.fifo
import
Fifo
...
...
@@ -76,6 +77,7 @@ class Core(object):
self
.
bookmarks
=
BookmarkList
()
self
.
debug
=
False
self
.
remote_fifo
=
None
self
.
avatar_cache
=
FileSystemPerJidCache
(
CACHE_DIR
,
'avatars'
,
binary
=
True
)
# a unique buffer used to store global information
# that are displayed in almost all tabs, in an
# information window.
...
...
poezio/core/handlers.py
View file @
a2ad4af7
...
...
@@ -395,19 +395,15 @@ class HandlerCore:
except
Exception
:
log
.
debug
(
'Failed getting metadata from 0084:'
,
exc_info
=
True
)
return
cache_dir
=
path
.
join
(
CACHE_DIR
,
'avatars'
,
jid
)
for
info
in
metadata
:
avatar_hash
=
info
[
'id'
]
# First check whether we have it in cache.
cached_path
=
path
.
join
(
cache_dir
,
avatar_hash
)
try
:
with
open
(
cached_path
,
'rb'
)
as
avatar_file
:
contact
.
avatar
=
avatar_file
.
read
()
log
.
debug
(
'Using cached avatar'
)
cached_avatar
=
self
.
core
.
avatar_cache
.
retrieve_by_jid
(
jid
,
avatar_hash
)
if
cached_avatar
:
contact
.
avatar
=
cached_avatar
log
.
debug
(
'Using cached avatar for %s'
,
jid
)
return
except
OSError
:
pass
# If we didn’t have any, query the data instead.
if
not
info
[
'url'
]:
...
...
@@ -429,16 +425,11 @@ class HandlerCore:
log
.
debug
(
'Received %s avatar: %s'
,
jid
,
info
[
'type'
])
# Now we save the data on the file system to not have to request it again.
try
:
makedirs
(
cache_dir
,
exist_ok
=
True
)
with
open
(
cached_path
,
'wb'
)
as
avatar_file
:
avatar_file
.
write
(
contact
.
avatar
)
except
OSError
:
if
not
self
.
core
.
avatar_cache
.
store_by_jid
(
jid
,
avatar_hash
,
contact
.
avatar
):
log
.
debug
(
'Failed writing %s avatar to cache:'
,
'Failed writing %s
’s
avatar to cache:'
,
jid
,
exc_info
=
True
)
pass
return
@
asyncio
.
coroutine
...
...
@@ -451,15 +442,11 @@ class HandlerCore:
log
.
debug
(
'Received vCard avatar update from %s: %s'
,
jid
,
avatar_hash
)
# First check whether we have it in cache.
cache_dir
=
path
.
join
(
CACHE_DIR
,
'avatars'
,
jid
)
cached_path
=
path
.
join
(
cache_dir
,
avatar_hash
)
try
:
with
open
(
cached_path
,
'rb'
)
as
avatar_file
:
contact
.
avatar
=
avatar_file
.
read
()
log
.
debug
(
'Using cached avatar'
)
cached_avatar
=
self
.
core
.
avatar_cache
.
retrieve_by_jid
(
jid
,
avatar_hash
)
if
cached_avatar
:
contact
.
avatar
=
cached_avatar
log
.
debug
(
'Using cached avatar for %s'
,
jid
)
return
except
OSError
:
pass
# If we didn’t have any, query the vCard instead.
try
:
...
...
@@ -476,13 +463,8 @@ class HandlerCore:
log
.
debug
(
'Received %s avatar: %s'
,
jid
,
avatar
[
'TYPE'
])
# Now we save the data on the file system to not have to request it again.
try
:
makedirs
(
cache_dir
,
exist_ok
=
True
)
with
open
(
cached_path
,
'wb'
)
as
avatar_file
:
avatar_file
.
write
(
contact
.
avatar
)
except
OSError
:
log
.
debug
(
'Failed writing %s avatar to cache:'
,
jid
,
exc_info
=
True
)
pass
if
not
self
.
core
.
avatar_cache
.
store_by_jid
(
jid
,
avatar_hash
,
contact
.
avatar
):
log
.
debug
(
'Failed writing %s’s avatar to cache:'
,
jid
,
exc_info
=
True
)
def
on_nick_received
(
self
,
message
):
"""
...
...
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