fix: sync preserve iOS theme accent visibility

This commit is contained in:
iamxvbaba 2026-07-28 16:22:34 +08:00
parent 209a0d279b
commit a989e118d7
6 changed files with 408 additions and 22 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/iamxvbaba/td/tg"
ioscompat "telesrv/internal/compat/ios"
"telesrv/internal/compat/tdesktop"
"telesrv/internal/domain"
)
@ -45,13 +46,45 @@ func (r *Router) onAccountGetThemes(ctx context.Context, req *tg.AccountGetTheme
}
}
}
hash := themesListHash(themes)
if ClientTypeFrom(ctx) == ClientTypeIOS {
themes = ioscompat.ProjectThemes(themes)
}
hash, err := themesListHash(themes)
if err != nil {
return nil, internalErr()
}
if req != nil && req.GetHash() == hash {
return &tg.AccountThemesNotModified{}, nil
}
return &tg.AccountThemes{Hash: hash, Themes: themes}, nil
}
// onAccountGetChatThemes applies the same iOS ARGB projection as account.getThemes.
// The projected content hash is intentionally distinct from the historical
// Android/TDesktop catalog hash, forcing clients with the transparent-color
// response cached to fetch the corrected payload once.
func (r *Router) onAccountGetChatThemes(ctx context.Context, hash int64) (tg.AccountThemesClass, error) {
if _, _, err := r.currentUserID(ctx); err != nil {
return nil, internalErr()
}
if ClientTypeFrom(ctx) != ClientTypeIOS {
return tdesktop.ChatThemes(hash), nil
}
base, ok := tdesktop.ChatThemes(0).(*tg.AccountThemes)
if !ok {
return nil, internalErr()
}
themes := ioscompat.ProjectThemes(base.Themes)
projectedHash, err := themesListHash(themes)
if err != nil {
return nil, internalErr()
}
if hash == projectedHash {
return &tg.AccountThemesNotModified{}, nil
}
return &tg.AccountThemes{Hash: projectedHash, Themes: themes}, nil
}
// onAccountUploadTheme 把客户端上传的 .attheme 文件落成可下载的 Document 并返回。
// 它不创建主题实体——客户端随后用返回的 Document 调 createTheme/updateTheme。
func (r *Router) onAccountUploadTheme(ctx context.Context, req *tg.AccountUploadThemeRequest) (tg.DocumentClass, error) {
@ -128,7 +161,7 @@ func (r *Router) onAccountCreateTheme(ctx context.Context, req *tg.AccountCreate
return nil, themeErr(err)
}
r.invalidateRPCProjectionForUser(userID)
return r.tgTheme(ctx, t, userID), nil
return projectThemeForClient(ctx, r.tgTheme(ctx, t, userID)), nil
}
// onAccountUpdateTheme 更新创建者自己的主题(部分字段)。
@ -172,7 +205,7 @@ func (r *Router) onAccountUpdateTheme(ctx context.Context, req *tg.AccountUpdate
return nil, themeErr(err)
}
r.invalidateRPCProjectionForUser(userID)
return r.tgTheme(ctx, t, userID), nil
return projectThemeForClient(ctx, r.tgTheme(ctx, t, userID)), nil
}
// onAccountSaveTheme 把主题加入/移出用户的已存列表。
@ -261,5 +294,16 @@ func (r *Router) onAccountGetTheme(ctx context.Context, req *tg.AccountGetThemeR
if !ok {
return nil, themeInvalidErr()
}
return r.tgTheme(ctx, t, userID), nil
return projectThemeForClient(ctx, r.tgTheme(ctx, t, userID)), nil
}
func projectThemeForClient(ctx context.Context, theme *tg.Theme) *tg.Theme {
if theme == nil || ClientTypeFrom(ctx) != ClientTypeIOS {
return theme
}
projected := ioscompat.ProjectThemes([]tg.Theme{*theme})
if len(projected) == 0 {
return theme
}
return &projected[0]
}