fix: sync birthday updates and system sticker sets

This commit is contained in:
A 2026-07-05 15:15:32 +08:00
parent c38dd73fdd
commit ddcf2d31ca
10 changed files with 431 additions and 35 deletions

View file

@ -295,7 +295,8 @@ func (s *Service) importStickerSetDir(ctx context.Context, setDir, systemKey str
return nil // 该目录无 set_info.json → 跳过
}
var info struct {
Result seedStickerSetResultJSON `json:"result"`
InputSetType string `json:"input_set_type"`
Result seedStickerSetResultJSON `json:"result"`
}
if err := json.Unmarshal(raw, &info); err != nil {
return fmt.Errorf("parse %s: %w", infoPath, err)
@ -304,13 +305,18 @@ func (s *Service) importStickerSetDir(ctx context.Context, setDir, systemKey str
if sj.ID == 0 {
return nil
}
if systemKey == "" {
systemKey = systemKeyForInputSetType(info.InputSetType)
}
kind := stickerSetKind(sj, systemKey)
// 增量 seed:集已存在且内容 hash 未变则跳过(不重读文档/重传 blob)。force 时强制重导
// (缩略图内联缓存修复路径)。这让 seedStickerSets 可在非空 store 上每次启动安全重扫,
// 仅导入新增/变更集。
// 仅导入新增/变更集;但系统集分类由导出元数据决定,旧库中 hash 相同但 system_key/kind
// 错误的记录必须重写,避免 constructor 方式取不到同一个资源集。
if !force {
if existing, found, err := s.media.GetStickerSetByID(ctx, sj.ID); err != nil {
return err
} else if found && existing.Hash == sj.Hash {
} else if found && existing.Hash == sj.Hash && existing.SystemKey == systemKey && existing.Kind == kind {
return nil
}
}
@ -333,7 +339,6 @@ func (s *Service) importStickerSetDir(ctx context.Context, setDir, systemKey str
}
}
kind := stickerSetKind(sj, systemKey)
set := domain.StickerSet{
ID: sj.ID,
AccessHash: sj.AccessHash,
@ -558,6 +563,8 @@ func systemKeyForDefaultSet(dirName string) string {
return domain.StickerSetSystemKeyEmojiDefaultTopicIcons
case "DefaultSet_PremiumGifts":
return domain.StickerSetSystemKeyPremiumGifts
case "DefaultSet_TonGifts":
return domain.StickerSetSystemKeyTonGifts
case "DefaultSet_Dice_Normal":
return "dice:\U0001f3b2"
case "DefaultSet_Dice_Dart":
@ -575,6 +582,30 @@ func systemKeyForDefaultSet(dirName string) string {
}
}
func systemKeyForInputSetType(inputSetType string) string {
normalized := strings.TrimSpace(inputSetType)
normalized = strings.TrimPrefix(normalized, "*")
normalized = strings.TrimPrefix(normalized, "tg.")
switch normalized {
case "InputStickerSetAnimatedEmoji":
return "animated_emoji"
case "InputStickerSetAnimatedEmojiAnimations":
return "animated_emoji_animations"
case "InputStickerSetEmojiGenericAnimations":
return "emoji_generic_animations"
case "InputStickerSetEmojiDefaultStatuses", "InputStickerSetEmojiChannelDefaultStatuses":
return domain.StickerSetSystemKeyEmojiDefaultStatuses
case "InputStickerSetEmojiDefaultTopicIcons":
return domain.StickerSetSystemKeyEmojiDefaultTopicIcons
case "InputStickerSetPremiumGifts":
return domain.StickerSetSystemKeyPremiumGifts
case "InputStickerSetTonGifts":
return domain.StickerSetSystemKeyTonGifts
default:
return ""
}
}
func stickerSetKind(sj seedStickerSetJSON, systemKey string) domain.StickerSetKind {
switch {
case systemKey != "":