fix(appearance): sync close Android theme wallpaper fallback
Public projection of telesrv 2c8b7cb4c20692d00017bd84f68dd11d7915ec33 with neutral appearance seed naming. Covers gramsrv#29.
This commit is contained in:
parent
af616e8c12
commit
94f3843d23
5 changed files with 170 additions and 13 deletions
|
|
@ -50,9 +50,56 @@ func LookupWallPaper(input tg.InputWallPaperClass) (tg.WallPaperClass, bool) {
|
|||
}
|
||||
}
|
||||
}
|
||||
// DrKLO normally installs a default theme with the nested wallpaper slug
|
||||
// stored on ThemeAccent. During accent restoration it can instead fall back
|
||||
// to ThemeInfo.slug, which is the slug of the exact Theme advertised by
|
||||
// account.getThemes. Accept that server-issued alias only when every setting
|
||||
// of the matched theme points at one unambiguous file wallpaper.
|
||||
if in, ok := input.(*tg.InputWallPaperSlug); ok {
|
||||
if wallpaper, ok := lookupChatThemeWallpaperAlias(catalog.ChatThemes, in.Slug); ok {
|
||||
return DefaultWallPaper(wallpaper), true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func lookupChatThemeWallpaperAlias(themes []appearance.ChatTheme, slug string) (appearance.Wallpaper, bool) {
|
||||
if slug == "" {
|
||||
return appearance.Wallpaper{}, false
|
||||
}
|
||||
var resolved appearance.Wallpaper
|
||||
found := false
|
||||
for _, theme := range themes {
|
||||
if theme.Slug != slug || len(theme.Settings) == 0 {
|
||||
continue
|
||||
}
|
||||
var themeWallpaper appearance.Wallpaper
|
||||
for i, settings := range theme.Settings {
|
||||
wallpaper := settings.Wallpaper
|
||||
if wallpaper.Slug == "" || wallpaper.ID == 0 {
|
||||
return appearance.Wallpaper{}, false
|
||||
}
|
||||
if i == 0 {
|
||||
themeWallpaper = wallpaper
|
||||
continue
|
||||
}
|
||||
if !sameWallpaperIdentity(themeWallpaper, wallpaper) {
|
||||
return appearance.Wallpaper{}, false
|
||||
}
|
||||
}
|
||||
if found && !sameWallpaperIdentity(resolved, themeWallpaper) {
|
||||
return appearance.Wallpaper{}, false
|
||||
}
|
||||
resolved = themeWallpaper
|
||||
found = true
|
||||
}
|
||||
return resolved, found
|
||||
}
|
||||
|
||||
func sameWallpaperIdentity(a, b appearance.Wallpaper) bool {
|
||||
return a.ID == b.ID && a.AccessHash == b.AccessHash && a.Slug == b.Slug
|
||||
}
|
||||
|
||||
// LookupWallPapers resolves multiple wallpapers from the Default seed catalog.
|
||||
func LookupWallPapers(inputs []tg.InputWallPaperClass) ([]tg.WallPaperClass, bool) {
|
||||
out := make([]tg.WallPaperClass, 0, len(inputs))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue