fix for system account avatar

This commit is contained in:
onysd 2026-07-13 11:05:37 +03:00
parent a336c99d6d
commit 0fbfc8cd71

View file

@ -3,6 +3,7 @@ package files
import ( import (
"context" "context"
_ "embed" _ "embed"
"fmt"
"time" "time"
"telesrv/internal/domain" "telesrv/internal/domain"
@ -15,15 +16,18 @@ var officialSystemAvatarPNG []byte
// account's (777000) profile photo from the bundled brand logo, writing it // account's (777000) profile photo from the bundled brand logo, writing it
// under the fixed domain.OfficialSystemUserPhotoID so the photo/blob layer // under the fixed domain.OfficialSystemUserPhotoID so the photo/blob layer
// and the pure domain.OfficialSystemUser() struct literal stay in sync // and the pure domain.OfficialSystemUser() struct literal stay in sync
// across restarts. Returns true if it actually wrote a new photo. // across restarts. It also registers the photo as the account's *current*
// profile photo (the profile_photos association) — without this, list
// views render the avatar from the hardcoded User struct fields, but
// users.getFullUser (triggered on chat open) reads only the association,
// finds nothing, and the client wipes the avatar it just showed.
// Returns true if it actually wrote a new photo.
func (s *Service) SeedOfficialSystemAvatar(ctx context.Context) (bool, error) { func (s *Service) SeedOfficialSystemAvatar(ctx context.Context) (bool, error) {
photoID := domain.OfficialSystemUserPhotoID photoID := domain.OfficialSystemUserPhotoID
if existing, found, err := s.media.GetPhoto(ctx, photoID); err != nil { wrote := false
if _, found, err := s.media.GetPhoto(ctx, photoID); err != nil {
return false, err return false, err
} else if found { } else if !found {
domain.SetOfficialSystemUserAvatar(existing.DCID, domain.StrippedFromSizes(existing.Sizes))
return false, nil
}
sizes, err := s.putPhotoStaticSizes(ctx, photoID, officialSystemAvatarPNG, photoSizeSpecsForAvatar(officialSystemAvatarPNG)) sizes, err := s.putPhotoStaticSizes(ctx, photoID, officialSystemAvatarPNG, photoSizeSpecsForAvatar(officialSystemAvatarPNG))
if err != nil { if err != nil {
return false, err return false, err
@ -39,6 +43,15 @@ func (s *Service) SeedOfficialSystemAvatar(ctx context.Context) (bool, error) {
if err := s.media.PutPhoto(ctx, photo); err != nil { if err := s.media.PutPhoto(ctx, photo); err != nil {
return false, err return false, err
} }
domain.SetOfficialSystemUserAvatar(photo.DCID, domain.StrippedFromSizes(photo.Sizes)) wrote = true
return true, nil }
photo, ok, err := s.SetCurrentProfilePhoto(ctx, domain.PeerTypeUser, domain.OfficialSystemUserID, photoID, int(time.Now().Unix()))
if err != nil {
return false, err
}
if !ok {
return false, fmt.Errorf("official system avatar photo %d not found after seeding", photoID)
}
domain.SetOfficialSystemUserAvatar(photo.DCID, domain.StrippedFromSizes(photo.Sizes))
return wrote, nil
} }