Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
gajim
gajim
Commits
3e020ef4
Commit
3e020ef4
authored
Aug 25, 2019
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avatar: Support avatar sha via disco info in MUCs
parent
3e1c4791
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
22 deletions
+36
-22
gajim/common/modules/discovery.py
gajim/common/modules/discovery.py
+1
-0
gajim/common/modules/vcard_avatars.py
gajim/common/modules/vcard_avatars.py
+35
-22
No files found.
gajim/common/modules/discovery.py
View file @
3e020ef4
...
...
@@ -210,6 +210,7 @@ def _muc_info_received(self, result, callback=None):
self
.
_log
.
info
(
'MUC info received: %s'
,
result
.
jid
)
if
not
is_error_result
(
result
):
app
.
logger
.
set_last_disco_info
(
result
.
jid
,
result
)
self
.
_con
.
get_module
(
'VCardAvatars'
).
muc_disco_info_update
(
result
)
app
.
nec
.
push_incoming_event
(
NetworkEvent
(
'muc-disco-update'
,
account
=
self
.
_account
,
...
...
gajim/common/modules/vcard_avatars.py
View file @
3e020ef4
...
...
@@ -110,12 +110,32 @@ def _self_update_received(self, properties):
self
.
_log
.
info
(
'Avatar already known: %s %s'
,
jid
,
properties
.
avatar_sha
)
def
muc_disco_info_update
(
self
,
disco_info
):
if
not
disco_info
.
supports
(
nbxmpp
.
NS_VCARD
):
return
field_var
=
'{http://modules.prosody.im/mod_vcard_muc}avatar#sha1'
if
not
disco_info
.
has_field
(
nbxmpp
.
NS_MUC_INFO
,
field_var
):
# Workaround so we dont delete the avatar for servers that dont
# support sha in disco info. Once there is a accepted XEP this
# can be removed
return
avatar_sha
=
disco_info
.
get_field_value
(
nbxmpp
.
NS_MUC_INFO
,
field_var
)
state
=
AvatarState
.
EMPTY
if
not
avatar_sha
else
AvatarState
.
ADVERTISED
self
.
_process_update
(
disco_info
.
jid
,
state
,
avatar_sha
,
True
)
def
_update_received
(
self
,
properties
,
room
=
False
):
jid
=
properties
.
jid
.
getBare
()
self
.
_process_update
(
properties
.
jid
.
getBare
(),
properties
.
avatar_state
,
properties
.
avatar_sha
,
room
)
def
_process_update
(
self
,
jid
,
state
,
avatar_sha
,
room
):
acc_jid
=
self
.
_con
.
get_own_jid
().
getStripped
()
if
properties
.
avatar_
state
==
AvatarState
.
EMPTY
:
if
state
==
AvatarState
.
EMPTY
:
# Empty <photo/> tag, means no avatar is advertised
self
.
_log
.
info
(
'%s has no avatar published'
,
properties
.
jid
)
self
.
_log
.
info
(
'%s has no avatar published'
,
jid
)
# Remove avatar
self
.
_log
.
debug
(
'Remove: %s'
,
jid
)
...
...
@@ -125,42 +145,35 @@ def _update_received(self, properties, room=False):
app
.
logger
.
set_muc_avatar_sha
(
jid
,
None
)
else
:
app
.
logger
.
set_avatar_sha
(
acc_jid
,
jid
,
None
)
app
.
interface
.
update_avatar
(
self
.
_account
,
jid
,
room_avatar
=
room
)
app
.
interface
.
update_avatar
(
self
.
_account
,
jid
,
room_avatar
=
room
)
else
:
self
.
_log
.
info
(
'Update: %s %s'
,
properties
.
jid
,
properties
.
avatar_sha
)
self
.
_log
.
info
(
'Update: %s %s'
,
jid
,
avatar_sha
)
current_sha
=
app
.
contacts
.
get_avatar_sha
(
self
.
_account
,
jid
)
if
properties
.
avatar_sha
==
current_sha
:
self
.
_log
.
info
(
'Avatar already known: %s %s'
,
jid
,
properties
.
avatar_sha
)
if
avatar_sha
==
current_sha
:
self
.
_log
.
info
(
'Avatar already known: %s %s'
,
jid
,
avatar_sha
)
return
if
app
.
interface
.
avatar_exists
(
properties
.
avatar_sha
):
if
app
.
interface
.
avatar_exists
(
avatar_sha
):
# Check if the avatar is already in storage
self
.
_log
.
info
(
'Found avatar in storage'
)
if
room
:
app
.
logger
.
set_muc_avatar_sha
(
jid
,
properties
.
avatar_sha
)
app
.
logger
.
set_muc_avatar_sha
(
jid
,
avatar_sha
)
else
:
app
.
logger
.
set_avatar_sha
(
acc_jid
,
jid
,
properties
.
avatar_sha
)
app
.
contacts
.
set_avatar
(
self
.
_account
,
jid
,
properties
.
avatar_sha
)
app
.
logger
.
set_avatar_sha
(
acc_jid
,
jid
,
avatar_sha
)
app
.
contacts
.
set_avatar
(
self
.
_account
,
jid
,
avatar_sha
)
app
.
interface
.
update_avatar
(
self
.
_account
,
jid
,
room_avatar
=
room
)
return
if
properties
.
avatar_sha
not
in
self
.
_requested_shas
:
self
.
_requested_shas
.
append
(
properties
.
avatar_sha
)
if
avatar_sha
not
in
self
.
_requested_shas
:
self
.
_requested_shas
.
append
(
avatar_sha
)
if
room
:
self
.
_con
.
get_module
(
'VCardTemp'
).
request_vcard
(
RequestAvatar
.
ROOM
,
jid
,
sha
=
properties
.
avatar_sha
)
RequestAvatar
.
ROOM
,
jid
,
sha
=
avatar_sha
)
else
:
self
.
_con
.
get_module
(
'VCardTemp'
).
request_vcard
(
RequestAvatar
.
USER
,
jid
,
sha
=
properties
.
avatar_sha
)
RequestAvatar
.
USER
,
jid
,
sha
=
avatar_sha
)
def
_gc_update_received
(
self
,
properties
):
nick
=
properties
.
jid
.
getResource
()
...
...
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