| ... |
... |
@@ -14,7 +14,6 @@ |
|
14
|
14
|
|
|
15
|
15
|
# XEP-0153: vCard-Based Avatars
|
|
16
|
16
|
|
|
17
|
|
-import os
|
|
18
|
17
|
from pathlib import Path
|
|
19
|
18
|
|
|
20
|
19
|
import nbxmpp
|
| ... |
... |
@@ -113,6 +112,7 @@ class VCardAvatars(BaseModule): |
|
113
|
112
|
|
|
114
|
113
|
def _update_received(self, properties, room=False):
|
|
115
|
114
|
jid = properties.jid.getBare()
|
|
|
115
|
+ acc_jid = self._con.get_own_jid().getStripped()
|
|
116
|
116
|
if properties.avatar_state == AvatarState.EMPTY:
|
|
117
|
117
|
# Empty <photo/> tag, means no avatar is advertised
|
|
118
|
118
|
self._log.info('%s has no avatar published', properties.jid)
|
| ... |
... |
@@ -120,8 +120,10 @@ class VCardAvatars(BaseModule): |
|
120
|
120
|
# Remove avatar
|
|
121
|
121
|
self._log.debug('Remove: %s', jid)
|
|
122
|
122
|
app.contacts.set_avatar(self._account, jid, None)
|
|
123
|
|
- acc_jid = self._con.get_own_jid().getStripped()
|
|
124
|
|
- if not room:
|
|
|
123
|
+
|
|
|
124
|
+ if room:
|
|
|
125
|
+ app.logger.set_muc_avatar_sha(jid, None)
|
|
|
126
|
+ else:
|
|
125
|
127
|
app.logger.set_avatar_sha(acc_jid, jid, None)
|
|
126
|
128
|
app.interface.update_avatar(
|
|
127
|
129
|
self._account, jid, room_avatar=room)
|
| ... |
... |
@@ -135,16 +137,21 @@ class VCardAvatars(BaseModule): |
|
135
|
137
|
jid, properties.avatar_sha)
|
|
136
|
138
|
return
|
|
137
|
139
|
|
|
138
|
|
- if room:
|
|
139
|
|
- # We dont save the room avatar hash in our DB, so check
|
|
140
|
|
- # if we previously downloaded it
|
|
141
|
|
- if app.interface.avatar_exists(properties.avatar_sha):
|
|
142
|
|
- app.contacts.set_avatar(self._account,
|
|
143
|
|
- jid,
|
|
144
|
|
- properties.avatar_sha)
|
|
145
|
|
- app.interface.update_avatar(
|
|
146
|
|
- self._account, jid, room_avatar=room)
|
|
147
|
|
- return
|
|
|
140
|
+ if app.interface.avatar_exists(properties.avatar_sha):
|
|
|
141
|
+ # Check if the avatar is already in storage
|
|
|
142
|
+ self._log.info('Found avatar in storage')
|
|
|
143
|
+ if room:
|
|
|
144
|
+ app.logger.set_muc_avatar_sha(jid, properties.avatar_sha)
|
|
|
145
|
+ else:
|
|
|
146
|
+ app.logger.set_avatar_sha(acc_jid,
|
|
|
147
|
+ jid,
|
|
|
148
|
+ properties.avatar_sha)
|
|
|
149
|
+ app.contacts.set_avatar(self._account,
|
|
|
150
|
+ jid,
|
|
|
151
|
+ properties.avatar_sha)
|
|
|
152
|
+ app.interface.update_avatar(
|
|
|
153
|
+ self._account, jid, room_avatar=room)
|
|
|
154
|
+ return
|
|
148
|
155
|
|
|
149
|
156
|
if properties.avatar_sha not in self._requested_shas:
|
|
150
|
157
|
self._requested_shas.append(properties.avatar_sha)
|
| ... |
... |
@@ -173,9 +180,7 @@ class VCardAvatars(BaseModule): |
|
173
|
180
|
app.interface.update_avatar(contact=gc_contact)
|
|
174
|
181
|
else:
|
|
175
|
182
|
self._log.info('Update: %s %s', nick, properties.avatar_sha)
|
|
176
|
|
- path = os.path.join(configpaths.get('AVATAR'),
|
|
177
|
|
- properties.avatar_sha)
|
|
178
|
|
- if not os.path.isfile(path):
|
|
|
183
|
+ if not app.interface.avatar_exists(properties.avatar_sha):
|
|
179
|
184
|
if properties.avatar_sha not in self._requested_shas:
|
|
180
|
185
|
app.log('avatar').info('Request: %s', nick)
|
|
181
|
186
|
self._requested_shas.append(properties.avatar_sha)
|