Add fallback for user avatar URL in notifications
Ensures that a default avatar URL is used if the user object lacks an avatar_url attribute or if an exception occurs, improving robustness of notification cover images.
This commit is contained in:
@@ -117,10 +117,14 @@ class ChannelMessageBase(NotificationDetail):
|
||||
receiver: list[int],
|
||||
channel_type: "ChannelType",
|
||||
) -> Self:
|
||||
try:
|
||||
avatar_url = getattr(user, 'avatar_url', 'https://lazer-data.g0v0.top/default.jpg') or 'https://lazer-data.g0v0.top/default.jpg'
|
||||
except Exception:
|
||||
avatar_url = 'https://lazer-data.g0v0.top/default.jpg'
|
||||
instance = cls(
|
||||
title=truncate(message.content, CONTENT_TRUNCATE),
|
||||
type=channel_type.value.lower(),
|
||||
cover_url=user.avatar_url,
|
||||
cover_url=avatar_url,
|
||||
)
|
||||
instance._message = message
|
||||
instance._user = user
|
||||
|
||||
Reference in New Issue
Block a user