Try to improve handling avatar updates for new users
This commit is contained in:
@@ -19,6 +19,7 @@ from typing import TYPE_CHECKING, AsyncGenerator, AsyncIterable, Awaitable, cast
|
|||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
|
from telethon import utils
|
||||||
from telethon.tl.types import (
|
from telethon.tl.types import (
|
||||||
Channel,
|
Channel,
|
||||||
ChatPhoto,
|
ChatPhoto,
|
||||||
@@ -283,7 +284,9 @@ class Puppet(DBPuppet, BasePuppet):
|
|||||||
or changed
|
or changed
|
||||||
)
|
)
|
||||||
changed = (
|
changed = (
|
||||||
await self.update_avatar(source, info.photo, client_override=client_override)
|
await self.update_avatar(
|
||||||
|
source, info.photo, entity=info, client_override=client_override
|
||||||
|
)
|
||||||
or changed
|
or changed
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -370,6 +373,7 @@ class Puppet(DBPuppet, BasePuppet):
|
|||||||
self,
|
self,
|
||||||
source: au.AbstractUser,
|
source: au.AbstractUser,
|
||||||
photo: TypeUserProfilePhoto | TypeChatPhoto,
|
photo: TypeUserProfilePhoto | TypeChatPhoto,
|
||||||
|
entity: User | None = None,
|
||||||
client_override: MautrixTelegramClient | None = None,
|
client_override: MautrixTelegramClient | None = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if self.disable_updates:
|
if self.disable_updates:
|
||||||
@@ -390,11 +394,19 @@ class Puppet(DBPuppet, BasePuppet):
|
|||||||
self.avatar_url = None
|
self.avatar_url = None
|
||||||
elif self.photo_id != photo_id or not self.avatar_url:
|
elif self.photo_id != photo_id or not self.avatar_url:
|
||||||
client = client_override or source.client
|
client = client_override or source.client
|
||||||
|
try:
|
||||||
|
peer = await client.get_input_entity(entity or self.peer)
|
||||||
|
except ValueError:
|
||||||
|
if entity:
|
||||||
|
peer = utils.get_input_peer(entity, check_hash=False)
|
||||||
|
else:
|
||||||
|
self.log.warning(f"Couldn't get input entity to update avatar")
|
||||||
|
return False
|
||||||
file = await util.transfer_file_to_matrix(
|
file = await util.transfer_file_to_matrix(
|
||||||
client=client,
|
client=client,
|
||||||
intent=self.default_mxid_intent,
|
intent=self.default_mxid_intent,
|
||||||
location=InputPeerPhotoFileLocation(
|
location=InputPeerPhotoFileLocation(
|
||||||
peer=await client.get_input_entity(self.peer),
|
peer=peer,
|
||||||
photo_id=photo.photo_id,
|
photo_id=photo.photo_id,
|
||||||
big=True,
|
big=True,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user