Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
44eab3c1
by wurstsalat at 2022-11-25T19:00:31+01:00
6 changed files:
- gajim/common/modules/discovery.py
- gajim/common/modules/user_avatar.py
- gajim/common/modules/vcard_avatars.py
- gajim/gtk/avatar.py
- gajim/gtk/workspace_dialog.py
- gajim/gui_interface.py
Changes:
| ... | ... | @@ -232,8 +232,8 @@ def disco_muc(self, |
| 232 | 232 | if result.vcard is not None:
|
| 233 | 233 | avatar, avatar_sha = result.vcard.get_avatar()
|
| 234 | 234 | if avatar is not None:
|
| 235 | - if not app.interface.avatar_exists(avatar_sha):
|
|
| 236 | - app.interface.save_avatar(avatar)
|
|
| 235 | + if not app.app.avatar_storage.avatar_exists(avatar_sha):
|
|
| 236 | + app.app.avatar_storage.save_avatar(avatar)
|
|
| 237 | 237 | |
| 238 | 238 | app.storage.cache.set_muc(result.info.jid, 'avatar', avatar_sha)
|
| 239 | 239 | app.app.avatar_storage.invalidate_cache(result.info.jid)
|
| ... | ... | @@ -66,11 +66,12 @@ def _avatar_metadata_received(self, |
| 66 | 66 | |
| 67 | 67 | sha = contact.avatar_sha
|
| 68 | 68 | if sha is not None:
|
| 69 | - if sha in metadata.avatar_shas and app.interface.avatar_exists(sha):
|
|
| 69 | + if (sha in metadata.avatar_shas and
|
|
| 70 | + app.app.avatar_storage.avatar_exists(sha)):
|
|
| 70 | 71 | self._log.info('Avatar already known: %s %s', jid, sha)
|
| 71 | 72 | return
|
| 72 | 73 | |
| 73 | - if app.interface.avatar_exists(metadata.default):
|
|
| 74 | + if app.app.avatar_storage.avatar_exists(metadata.default):
|
|
| 74 | 75 | self._log.info('Avatar found in cache, update: %s %s',
|
| 75 | 76 | jid, metadata.default)
|
| 76 | 77 | contact.update_avatar(metadata.default)
|
| ... | ... | @@ -109,5 +110,5 @@ def _request_avatar_data(self, |
| 109 | 110 | return
|
| 110 | 111 | |
| 111 | 112 | self._log.info('Received Avatar: %s %s', contact.jid, avatar.sha)
|
| 112 | - app.interface.save_avatar(avatar.data)
|
|
| 113 | + app.app.avatar_storage.save_avatar(avatar.data)
|
|
| 113 | 114 | contact.update_avatar(avatar.sha) |
| ... | ... | @@ -95,7 +95,7 @@ def _request_vcard(self, |
| 95 | 95 | return
|
| 96 | 96 | |
| 97 | 97 | self._log.info('Received: %s %s', contact.jid, avatar_sha)
|
| 98 | - app.interface.save_avatar(avatar)
|
|
| 98 | + app.app.avatar_storage.save_avatar(avatar)
|
|
| 99 | 99 | |
| 100 | 100 | if isinstance(contact, BareContact):
|
| 101 | 101 | app.storage.cache.set_contact(contact.jid, 'avatar', avatar_sha)
|
| ... | ... | @@ -173,7 +173,7 @@ def _process_update(self, |
| 173 | 173 | self._log.info('Avatar already known: %s %s', jid, avatar_sha)
|
| 174 | 174 | return
|
| 175 | 175 | |
| 176 | - if app.interface.avatar_exists(avatar_sha):
|
|
| 176 | + if app.app.avatar_storage.avatar_exists(avatar_sha):
|
|
| 177 | 177 | # Check if the avatar is already in storage
|
| 178 | 178 | self._log.info('Found avatar in storage')
|
| 179 | 179 | if groupchat:
|
| ... | ... | @@ -214,7 +214,7 @@ def _muc_update_received(self, properties: PresenceProperties) -> None: |
| 214 | 214 | |
| 215 | 215 | else:
|
| 216 | 216 | self._log.info('Update: %s %s', nick, properties.avatar_sha)
|
| 217 | - if not app.interface.avatar_exists(properties.avatar_sha):
|
|
| 217 | + if not app.app.avatar_storage.avatar_exists(properties.avatar_sha):
|
|
| 218 | 218 | if properties.avatar_sha not in self._requested_shas:
|
| 219 | 219 | app.log('avatar').info('Request: %s', nick)
|
| 220 | 220 | self._requested_shas.append(properties.avatar_sha)
|
| ... | ... | @@ -530,6 +530,9 @@ def get_avatar_path(filename: str) -> Optional[Path]: |
| 530 | 530 | return None
|
| 531 | 531 | return path
|
| 532 | 532 | |
| 533 | + def avatar_exists(self, filename: str) -> bool:
|
|
| 534 | + return self.get_avatar_path(filename) is not None
|
|
| 535 | + |
|
| 533 | 536 | def surface_from_filename(self,
|
| 534 | 537 | filename: str,
|
| 535 | 538 | size: int,
|
| ... | ... | @@ -154,7 +154,7 @@ def _on_save(self, _button: Gtk.Button) -> None: |
| 154 | 154 | if use_image:
|
| 155 | 155 | data = self._get_avatar_data()
|
| 156 | 156 | if data is not None:
|
| 157 | - self._avatar_sha = app.interface.save_avatar(data)
|
|
| 157 | + self._avatar_sha = app.app.avatar_storage.save_avatar(data)
|
|
| 158 | 158 | |
| 159 | 159 | if self._workspace_id is not None:
|
| 160 | 160 | app.settings.set_workspace_setting(
|
| ... | ... | @@ -34,7 +34,6 @@ |
| 34 | 34 | from __future__ import annotations
|
| 35 | 35 | |
| 36 | 36 | from typing import Any
|
| 37 | -from typing import Optional
|
|
| 38 | 37 | |
| 39 | 38 | import sys
|
| 40 | 39 | import time
|
| ... | ... | @@ -214,12 +213,6 @@ def process_connections(self) -> bool: |
| 214 | 213 | raise
|
| 215 | 214 | return True # renew timeout (loop for ever)
|
| 216 | 215 | |
| 217 | - def save_avatar(self, data: bytes) -> Optional[str]:
|
|
| 218 | - return app.app.avatar_storage.save_avatar(data)
|
|
| 219 | - |
|
| 220 | - def avatar_exists(self, filename: str) -> bool:
|
|
| 221 | - return app.app.avatar_storage.get_avatar_path(filename) is not None
|
|
| 222 | - |
|
| 223 | 216 | def run(self, _application: Gtk.Application) -> None:
|
| 224 | 217 | # get instances for windows/dialogs that will show_all()/hide()
|
| 225 | 218 | self.instances['file_transfers'] = FileTransfersWindow()
|