feat: sync multilayer td integration

This commit is contained in:
A 2026-07-15 13:32:06 +08:00
parent 20a310f6ca
commit 766c5db992
491 changed files with 26235 additions and 35340 deletions

View file

@ -5,7 +5,7 @@ import (
"telesrv/internal/seed/appearance"
"github.com/gotd/td/tg"
"github.com/iamxvbaba/td/tg"
)
const appearanceSeedDCID = 2
@ -18,16 +18,16 @@ var peerColorOptionsCache = struct {
profile []tg.HelpPeerColorOption
}{}
func seedWallPapers() []tg.WallPaperClass {
func DefaultWallPapers() []tg.WallPaperClass {
catalog := appearance.Default()
out := make([]tg.WallPaperClass, 0, len(catalog.Wallpapers))
for _, wallpaper := range catalog.Wallpapers {
out = append(out, seedWallPaper(wallpaper))
out = append(out, DefaultWallPaper(wallpaper))
}
return out
}
// LookupWallPaper resolves a cloud wallpaper from the default seed catalog.
// LookupWallPaper resolves a cloud wallpaper from the Default seed catalog.
func LookupWallPaper(input tg.InputWallPaperClass) (tg.WallPaperClass, bool) {
if in, ok := input.(*tg.InputWallPaperNoFile); ok {
return &tg.WallPaperNoFile{ID: in.ID}, true
@ -35,13 +35,13 @@ func LookupWallPaper(input tg.InputWallPaperClass) (tg.WallPaperClass, bool) {
catalog := appearance.Default()
for _, wallpaper := range catalog.Wallpapers {
if inputWallPaperMatches(input, wallpaper) {
return seedWallPaper(wallpaper), true
return DefaultWallPaper(wallpaper), true
}
}
return nil, false
}
// LookupWallPapers resolves multiple wallpapers from the default seed catalog.
// LookupWallPapers resolves multiple wallpapers from the Default seed catalog.
func LookupWallPapers(inputs []tg.InputWallPaperClass) ([]tg.WallPaperClass, bool) {
out := make([]tg.WallPaperClass, 0, len(inputs))
for _, input := range inputs {
@ -65,28 +65,28 @@ func inputWallPaperMatches(input tg.InputWallPaperClass, wallpaper appearance.Wa
}
}
func seedWallPaper(in appearance.Wallpaper) tg.WallPaperClass {
func DefaultWallPaper(in appearance.Wallpaper) tg.WallPaperClass {
if in.Type == 1 || in.Document.ID == 0 {
out := &tg.WallPaperNoFile{ID: in.ID}
out.SetDefault(in.Default)
out.SetDark(in.Dark)
out.SetSettings(seedWallPaperSettings(in.Settings))
out.SetSettings(DefaultWallPaperSettings(in.Settings))
return out
}
out := &tg.WallPaper{
ID: in.ID,
AccessHash: in.AccessHash,
Slug: in.Slug,
Document: seedDocument(in.Document),
Document: DefaultDocument(in.Document),
}
out.SetDefault(in.Default)
out.SetPattern(in.Pattern)
out.SetDark(in.Dark)
out.SetSettings(seedWallPaperSettings(in.Settings))
out.SetSettings(DefaultWallPaperSettings(in.Settings))
return out
}
func seedWallPaperSettings(in appearance.WallpaperSettings) tg.WallPaperSettings {
func DefaultWallPaperSettings(in appearance.WallpaperSettings) tg.WallPaperSettings {
var out tg.WallPaperSettings
out.SetBlur(in.Blur)
out.SetMotion(in.Motion)
@ -111,7 +111,7 @@ func seedWallPaperSettings(in appearance.WallpaperSettings) tg.WallPaperSettings
return out
}
func seedDocument(in appearance.Document) tg.DocumentClass {
func DefaultDocument(in appearance.Document) tg.DocumentClass {
if in.ID == 0 {
return &tg.DocumentEmpty{}
}
@ -121,14 +121,14 @@ func seedDocument(in appearance.Document) tg.DocumentClass {
Date: in.Date,
MimeType: in.MimeType,
Size: in.Size,
Thumbs: seedPhotoSizes(in.Thumbs),
Thumbs: DefaultPhotoSizes(in.Thumbs),
DCID: appearanceSeedDCID,
Attributes: seedDocumentAttributes(in.Attributes),
Attributes: DefaultDocumentAttributes(in.Attributes),
FileReference: nil,
}
}
func seedPhotoSizes(in []appearance.PhotoSize) []tg.PhotoSizeClass {
func DefaultPhotoSizes(in []appearance.PhotoSize) []tg.PhotoSizeClass {
out := make([]tg.PhotoSizeClass, 0, len(in))
for _, size := range in {
switch size.Kind {
@ -144,7 +144,7 @@ func seedPhotoSizes(in []appearance.PhotoSize) []tg.PhotoSizeClass {
return out
}
func seedDocumentAttributes(in []appearance.DocumentAttribute) []tg.DocumentAttributeClass {
func DefaultDocumentAttributes(in []appearance.DocumentAttribute) []tg.DocumentAttributeClass {
out := make([]tg.DocumentAttributeClass, 0, len(in))
for _, attr := range in {
switch attr.Kind {
@ -159,20 +159,20 @@ func seedDocumentAttributes(in []appearance.DocumentAttribute) []tg.DocumentAttr
return out
}
func seedPeerColorOptions(profile bool) []tg.HelpPeerColorOption {
func DefaultPeerColorOptions(profile bool) []tg.HelpPeerColorOption {
if profile {
peerColorOptionsCache.profileOnce.Do(func() {
peerColorOptionsCache.profile = buildSeedPeerColorOptions(true)
peerColorOptionsCache.profile = buildDefaultPeerColorOptions(true)
})
return clonePeerColorOptions(peerColorOptionsCache.profile)
}
peerColorOptionsCache.regularOnce.Do(func() {
peerColorOptionsCache.regular = buildSeedPeerColorOptions(false)
peerColorOptionsCache.regular = buildDefaultPeerColorOptions(false)
})
return clonePeerColorOptions(peerColorOptionsCache.regular)
}
func buildSeedPeerColorOptions(profile bool) []tg.HelpPeerColorOption {
func buildDefaultPeerColorOptions(profile bool) []tg.HelpPeerColorOption {
catalog := appearance.Default()
source := catalog.PeerColors
if profile {
@ -193,10 +193,10 @@ func buildSeedPeerColorOptions(profile bool) []tg.HelpPeerColorOption {
if groupMin > 0 {
option.SetGroupMinLevel(groupMin)
}
if colors := seedPeerColorSet(color.Colors); colors != nil {
if colors := DefaultPeerColorSet(color.Colors); colors != nil {
option.SetColors(colors)
}
if colors := seedPeerColorSet(color.DarkColors); colors != nil {
if colors := DefaultPeerColorSet(color.DarkColors); colors != nil {
option.SetDarkColors(colors)
}
out = append(out, option)
@ -246,7 +246,7 @@ func boundedPeerColorMinLevel(level int) int {
return level
}
func seedPeerColorID(id int, profile bool) (bool, bool) {
func DefaultPeerColorID(id int, profile bool) (bool, bool) {
catalog := appearance.Default()
source := catalog.PeerColors
if profile {
@ -263,7 +263,7 @@ func seedPeerColorID(id int, profile bool) (bool, bool) {
return false, true
}
func seedPeerColorSet(in *appearance.ColorSet) tg.HelpPeerColorSetClass {
func DefaultPeerColorSet(in *appearance.ColorSet) tg.HelpPeerColorSetClass {
if in == nil {
return nil
}

View file

@ -3,7 +3,7 @@ package tdesktop
import (
"time"
"github.com/gotd/td/tg"
"github.com/iamxvbaba/td/tg"
"telesrv/internal/links"
)

View file

@ -1,7 +1,7 @@
package tdesktop
import (
"github.com/gotd/td/tg"
"github.com/iamxvbaba/td/tg"
"telesrv/internal/seed/catalog"
)

View file

@ -3,7 +3,7 @@ package tdesktop
import (
"time"
"github.com/gotd/td/tg"
"github.com/iamxvbaba/td/tg"
"telesrv/internal/seed/appearance"
"telesrv/internal/seed/catalog"
@ -147,7 +147,7 @@ func catalogThemeSettings(s appearance.ThemeSettings, base tg.BaseThemeClass) tg
ts.SetMessageColors(append([]int(nil), s.MessageColors...))
}
if s.Wallpaper.ID != 0 || s.Wallpaper.Document.ID != 0 {
ts.SetWallpaper(seedWallPaper(s.Wallpaper))
ts.SetWallpaper(DefaultWallPaper(s.Wallpaper))
}
return ts
}
@ -194,13 +194,13 @@ func UniqueGiftChatThemes(hash int64) tg.AccountChatThemesClass {
}
}
// WallPapers returns the read-only default wallpaper catalog. User wallpaper
// WallPapers returns the read-only Default wallpaper catalog. User wallpaper
// upload/save/install remains outside the current TDesktop compatibility scope.
func WallPapers(hash int64) tg.AccountWallPapersClass {
if hash == wallPapersHash {
return &tg.AccountWallPapersNotModified{}
}
wallpapers := seedWallPapers()
wallpapers := DefaultWallPapers()
return &tg.AccountWallPapers{
Hash: wallPapersHash,
Wallpapers: wallpapers,
@ -425,7 +425,7 @@ var defaultPeerColors = []defaultPeerColor{
// IsPeerColorID reports whether id is in the TDesktop-compatible peer color palette.
func IsPeerColorID(id int) bool {
if found, seeded := seedPeerColorID(id, false); seeded {
if found, seeded := DefaultPeerColorID(id, false); seeded {
return found
}
for _, color := range defaultPeerColors {
@ -438,7 +438,7 @@ func IsPeerColorID(id int) bool {
// IsPeerProfileColorID reports whether id is in the profile background palette.
func IsPeerProfileColorID(id int) bool {
if found, seeded := seedPeerColorID(id, true); seeded {
if found, seeded := DefaultPeerColorID(id, true); seeded {
return found
}
return IsPeerColorID(id)
@ -448,7 +448,7 @@ func PeerColors(hash int) tg.HelpPeerColorsClass {
if hash == peerColorsHash {
return &tg.HelpPeerColorsNotModified{}
}
colors := seedPeerColorOptions(false)
colors := DefaultPeerColorOptions(false)
if len(colors) == 0 {
colors = make([]tg.HelpPeerColorOption, 0, len(defaultPeerColors))
for _, color := range defaultPeerColors {
@ -468,7 +468,7 @@ func PeerProfileColors(hash int) tg.HelpPeerColorsClass {
if hash == peerProfileColorsHash {
return &tg.HelpPeerColorsNotModified{}
}
colors := seedPeerColorOptions(true)
colors := DefaultPeerColorOptions(true)
if len(colors) == 0 {
colors = make([]tg.HelpPeerColorOption, 0, len(defaultPeerColors))
for _, color := range defaultPeerColors {

View file

@ -4,7 +4,7 @@ import (
"math"
"testing"
"github.com/gotd/td/tg"
"github.com/iamxvbaba/td/tg"
)
func TestNotifySettingsDefaultIsAudible(t *testing.T) {
@ -233,7 +233,7 @@ func TestUniqueGiftChatThemesIsEmptyHashableStub(t *testing.T) {
}
}
func TestWallPapersUsesOrangeFileCatalog(t *testing.T) {
func TestWallPapersUsesDefaultFileCatalog(t *testing.T) {
got, ok := WallPapers(0).(*tg.AccountWallPapers)
if !ok {
t.Fatalf("WallPapers(0) = %T, want modified list", got)
@ -249,14 +249,14 @@ func TestWallPapersUsesOrangeFileCatalog(t *testing.T) {
t.Fatalf("WallPapers(0).Wallpapers[0] = %T, want *tg.WallPaper", got.Wallpapers[0])
}
if wallpaper.ID == 0 || wallpaper.AccessHash == 0 || wallpaper.Slug == "" {
t.Fatalf("wallpaper identity = id %d hash %d slug %q, want seed ids", wallpaper.ID, wallpaper.AccessHash, wallpaper.Slug)
t.Fatalf("wallpaper identity = id %d hash %d slug %q, want Default ids", wallpaper.ID, wallpaper.AccessHash, wallpaper.Slug)
}
doc, ok := wallpaper.Document.(*tg.Document)
if !ok {
t.Fatalf("wallpaper document = %T, want *tg.Document", wallpaper.Document)
}
if doc.ID == 0 || doc.AccessHash == 0 || doc.Size == 0 || doc.MimeType == "" || doc.DCID != appearanceSeedDCID {
t.Fatalf("wallpaper document = id %d hash %d size %d mime %q dc %d, want downloadable seed document",
t.Fatalf("wallpaper document = id %d hash %d size %d mime %q dc %d, want downloadable Default document",
doc.ID, doc.AccessHash, doc.Size, doc.MimeType, doc.DCID)
}
if len(doc.Thumbs) == 0 {
@ -392,7 +392,7 @@ func TestPeerColorsAreNonEmptyHashableAccentSets(t *testing.T) {
t.Fatalf("PeerColors(0) = hash %d colors %d, want non-empty stable list", got.Hash, len(got.Colors))
}
if len(got.Colors) != 21 {
t.Fatalf("PeerColors(0).Colors length = %d, want seed palette count 21", len(got.Colors))
t.Fatalf("PeerColors(0).Colors length = %d, want Default palette count 21", len(got.Colors))
}
withExplicitColors := 0
for i, option := range got.Colors {
@ -412,7 +412,7 @@ func TestPeerColorsAreNonEmptyHashableAccentSets(t *testing.T) {
withExplicitColors++
}
if withExplicitColors == 0 {
t.Fatal("PeerColors() has no explicit seed color sets")
t.Fatal("PeerColors() has no explicit Default color sets")
}
if _, ok := PeerColors(got.Hash).(*tg.HelpPeerColorsNotModified); !ok {
t.Fatalf("PeerColors(hash) = %#v, want notModified", PeerColors(got.Hash))
@ -428,7 +428,7 @@ func TestPeerProfileColorsAreNonEmptyHashableProfileSets(t *testing.T) {
t.Fatalf("PeerProfileColors(0) = hash %d colors %d, want non-empty stable list", got.Hash, len(got.Colors))
}
if len(got.Colors) != 16 {
t.Fatalf("PeerProfileColors(0).Colors length = %d, want seed profile palette count 16", len(got.Colors))
t.Fatalf("PeerProfileColors(0).Colors length = %d, want Default profile palette count 16", len(got.Colors))
}
for i, option := range got.Colors {
if !IsPeerProfileColorID(option.ColorID) {