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))
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func GlobalPrivacySettings() *tg.GlobalPrivacySettings {
|
|||
return &tg.GlobalPrivacySettings{}
|
||||
}
|
||||
|
||||
const chatThemesHash int64 = 2026062501
|
||||
const chatThemesHash int64 = 2026080101
|
||||
const uniqueGiftChatThemesHash int64 = 2026061201
|
||||
const wallPapersHash int64 = 2026062502
|
||||
const peerColorsHash = 2026061202
|
||||
|
|
@ -233,9 +233,14 @@ func WallPapers(hash int64) tg.AccountWallPapersClass {
|
|||
}
|
||||
|
||||
// chatThemeBaseThemes enumerates the base themes every emoji chat theme ships
|
||||
// settings for. The client matches a chat theme's settings to whichever base
|
||||
// theme the user currently runs, and DrKLO's theme picker only surfaces a chat
|
||||
// theme whose settings cover at least four base themes
|
||||
// settings for. The order is part of the DrKLO client contract: the basic Chat
|
||||
// Settings picker selects index 0 for day and index 2 for night, matching its
|
||||
// built-in Blue, Day, Night, Dark Blue ordering. Arctic is an additional base
|
||||
// and therefore follows those four stable slots.
|
||||
//
|
||||
// The client matches a chat theme's settings to whichever base theme the user
|
||||
// currently runs, and DrKLO's theme picker only surfaces a chat theme whose
|
||||
// settings cover at least four base themes
|
||||
// (MediaDataController.generateEmojiPreviewThemes drops anything whose
|
||||
// items.size() < 4, one item per ThemeSettings). dark selects the bubble/accent
|
||||
// palette used for that base theme.
|
||||
|
|
@ -245,9 +250,9 @@ var chatThemeBaseThemes = []struct {
|
|||
}{
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeClassic{} }, false},
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeDay{} }, false},
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeArctic{} }, false},
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeTinted{} }, true},
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeNight{} }, true},
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeTinted{} }, true},
|
||||
{func() tg.BaseThemeClass { return &tg.BaseThemeArctic{} }, false},
|
||||
}
|
||||
|
||||
func AutoDownloadSettings() *tg.AccountAutoDownloadSettings {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/iamxvbaba/td/tg"
|
||||
|
||||
"telesrv/internal/seed/appearance"
|
||||
)
|
||||
|
||||
func TestNotifySettingsDefaultIsAudible(t *testing.T) {
|
||||
|
|
@ -216,6 +218,39 @@ func TestDefaultThemesAreDefaultFlaggedForPicker(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDefaultThemeSettingsFollowDrKLOPickerIndices(t *testing.T) {
|
||||
for _, theme := range DefaultThemeList() {
|
||||
settings, ok := theme.GetSettings()
|
||||
if !ok || len(settings) < 5 {
|
||||
t.Fatalf("theme %d settings len=%d ok=%v, want five stable base slots", theme.ID, len(settings), ok)
|
||||
}
|
||||
if _, ok := settings[0].BaseTheme.(*tg.BaseThemeClassic); !ok {
|
||||
t.Fatalf("theme %d settings[0] base = %T, want classic", theme.ID, settings[0].BaseTheme)
|
||||
}
|
||||
if _, ok := settings[1].BaseTheme.(*tg.BaseThemeDay); !ok {
|
||||
t.Fatalf("theme %d settings[1] base = %T, want day", theme.ID, settings[1].BaseTheme)
|
||||
}
|
||||
if _, ok := settings[2].BaseTheme.(*tg.BaseThemeNight); !ok {
|
||||
t.Fatalf("theme %d settings[2] base = %T, want night", theme.ID, settings[2].BaseTheme)
|
||||
}
|
||||
if _, ok := settings[3].BaseTheme.(*tg.BaseThemeTinted); !ok {
|
||||
t.Fatalf("theme %d settings[3] base = %T, want tinted", theme.ID, settings[3].BaseTheme)
|
||||
}
|
||||
if _, ok := settings[4].BaseTheme.(*tg.BaseThemeArctic); !ok {
|
||||
t.Fatalf("theme %d settings[4] base = %T, want arctic", theme.ID, settings[4].BaseTheme)
|
||||
}
|
||||
wallpaperClass, ok := settings[2].GetWallpaper()
|
||||
wallpaper, fileWallpaper := wallpaperClass.(*tg.WallPaper)
|
||||
if !ok || !fileWallpaper || !wallpaper.GetDark() {
|
||||
t.Fatalf("theme %d night slot wallpaper = %#v ok=%v, want dark file wallpaper", theme.ID, wallpaperClass, ok)
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := ChatThemes(2026062501).(*tg.AccountThemesNotModified); ok {
|
||||
t.Fatal("pre-fix chat theme hash was not invalidated after settings reorder")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupDefaultThemeValidatesIdentity(t *testing.T) {
|
||||
themes := DefaultThemeList()
|
||||
if len(themes) == 0 {
|
||||
|
|
@ -366,12 +401,38 @@ func TestDefaultThemeWallpaperReferencesResolve(t *testing.T) {
|
|||
t.Fatalf("theme %d settings[%d] wallpaper slug lookup = %#v", theme.ID, i, bySlug)
|
||||
}
|
||||
}
|
||||
byThemeSlug, ok := LookupWallPaper(&tg.InputWallPaperSlug{Slug: theme.Slug})
|
||||
if !ok {
|
||||
t.Fatalf("theme %d fallback wallpaper alias %q was not resolvable", theme.ID, theme.Slug)
|
||||
}
|
||||
aliasWallpaper, ok := byThemeSlug.(*tg.WallPaper)
|
||||
firstWallpaperClass, firstOK := settings[0].GetWallpaper()
|
||||
firstWallpaper, firstFile := firstWallpaperClass.(*tg.WallPaper)
|
||||
if !ok || !firstOK || !firstFile || aliasWallpaper.ID != firstWallpaper.ID || aliasWallpaper.Slug != firstWallpaper.Slug {
|
||||
t.Fatalf("theme %d fallback alias = %#v, want settings[0] wallpaper %#v", theme.ID, byThemeSlug, firstWallpaperClass)
|
||||
}
|
||||
}
|
||||
if checked == 0 {
|
||||
t.Fatal("default themes exposed no file wallpapers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatThemeWallpaperAliasRejectsAmbiguousSettings(t *testing.T) {
|
||||
themes := []appearance.ChatTheme{{
|
||||
Slug: "theme-alias",
|
||||
Settings: []appearance.ThemeSettings{
|
||||
{Wallpaper: appearance.Wallpaper{ID: 1, AccessHash: 11, Slug: "wallpaper-one"}},
|
||||
{Wallpaper: appearance.Wallpaper{ID: 2, AccessHash: 22, Slug: "wallpaper-two"}},
|
||||
},
|
||||
}}
|
||||
if _, ok := lookupChatThemeWallpaperAlias(themes, "theme-alias"); ok {
|
||||
t.Fatal("ambiguous theme wallpaper alias was accepted")
|
||||
}
|
||||
if _, ok := lookupChatThemeWallpaperAlias(themes, "unknown"); ok {
|
||||
t.Fatal("unknown theme wallpaper alias was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStarsRevenueStatsIsZeroBalanceCompatStub(t *testing.T) {
|
||||
got := StarsRevenueStats(false)
|
||||
if got == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue