fix: harden channel rights and sticker compatibility
Co-authored-by: HSgram <3013954224@qq.com>
This commit is contained in:
parent
6867d201ed
commit
599453a3c4
33 changed files with 1520 additions and 130 deletions
|
|
@ -102,17 +102,11 @@ func (r *Router) onMessagesGetStickerSet(ctx context.Context, req *tg.MessagesGe
|
|||
zap.Int("documents", len(fallbackDocs)),
|
||||
)
|
||||
}
|
||||
if req.Hash != 0 && req.Hash == fallbackSet.Hash {
|
||||
return &tg.MessagesStickerSetNotModified{}, nil
|
||||
}
|
||||
return tgMessagesStickerSet(fallbackSet, fallbackDocs), nil
|
||||
}
|
||||
// 未 seed 的系统集 / 未知短名:回退兼容 stub,避免破坏客户端。
|
||||
return tdesktop.StickerSet(req), nil
|
||||
}
|
||||
if req.Hash != 0 && req.Hash == set.Hash {
|
||||
return &tg.MessagesStickerSetNotModified{}, nil
|
||||
}
|
||||
set, err = r.stickerSetWithViewerInstallState(ctx, set)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -191,6 +185,43 @@ func (r *Router) onMessagesGetEmojiStickers(ctx context.Context, hash int64) (tg
|
|||
return r.allStickersForKind(ctx, hash, domain.StickerSetKindEmoji)
|
||||
}
|
||||
|
||||
func (r *Router) onMessagesGetEmojiStickerGroups(ctx context.Context, hash int) (tg.MessagesEmojiGroupsClass, error) {
|
||||
empty := func() tg.MessagesEmojiGroupsClass {
|
||||
return &tg.MessagesEmojiGroups{Hash: 0, Groups: []tg.EmojiGroupClass{}}
|
||||
}
|
||||
if r.deps.Files == nil {
|
||||
return empty(), nil
|
||||
}
|
||||
sets := r.stickerCatalogSets(ctx, domain.StickerSetKindEmoji)
|
||||
visible := make([]domain.StickerSet, 0, len(sets))
|
||||
for _, set := range sets {
|
||||
if set.ID == 0 || set.Archived {
|
||||
continue
|
||||
}
|
||||
visible = append(visible, set)
|
||||
}
|
||||
if len(visible) == 0 {
|
||||
return empty(), nil
|
||||
}
|
||||
catalogHash := emojiStickerGroupsHash(visible)
|
||||
if hash != 0 && hash == catalogHash {
|
||||
return &tg.MessagesEmojiGroupsNotModified{}, nil
|
||||
}
|
||||
iconEmojiID := emojiStickerGroupIconID(visible)
|
||||
if iconEmojiID == 0 {
|
||||
return empty(), nil
|
||||
}
|
||||
return &tg.MessagesEmojiGroups{
|
||||
Hash: catalogHash,
|
||||
Groups: []tg.EmojiGroupClass{
|
||||
&tg.EmojiGroupPremium{
|
||||
Title: "Premium",
|
||||
IconEmojiID: iconEmojiID,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Router) onMessagesGetMaskStickers(ctx context.Context, hash int64) (tg.MessagesAllStickersClass, error) {
|
||||
return r.allStickersForKind(ctx, hash, domain.StickerSetKindMasks)
|
||||
}
|
||||
|
|
@ -329,6 +360,13 @@ func (r *Router) onMessagesGetFeaturedEmojiStickers(ctx context.Context, hash in
|
|||
return r.featuredStickersForKind(ctx, hash, domain.StickerSetKindEmoji)
|
||||
}
|
||||
|
||||
func (r *Router) onMessagesGetOldFeaturedStickers(ctx context.Context, req *tg.MessagesGetOldFeaturedStickersRequest) (tg.MessagesFeaturedStickersClass, error) {
|
||||
if req == nil {
|
||||
return r.onMessagesGetFeaturedStickers(ctx, 0)
|
||||
}
|
||||
return r.onMessagesGetFeaturedStickers(ctx, req.Hash)
|
||||
}
|
||||
|
||||
// featuredStickersForKind 把已 seed 的(未归档)贴纸/emoji 集作为 trending 呈现。
|
||||
// 性能:先用集目录 hash 比对,命中即返回 *NotModified——封面文档解析只在 cache-miss
|
||||
// 时发生(一次批量 GetDocuments),避免每次请求都解析封面。
|
||||
|
|
@ -467,6 +505,31 @@ func featuredStickerSetsHash(sets []domain.StickerSet) int64 {
|
|||
return int64(tdesktopCountHash(values))
|
||||
}
|
||||
|
||||
func emojiStickerGroupsHash(sets []domain.StickerSet) int {
|
||||
values := make([]int64, 0, len(sets)*2)
|
||||
for _, set := range sets {
|
||||
if set.ID == 0 || set.Archived {
|
||||
continue
|
||||
}
|
||||
values = append(values, set.ID, int64(set.Hash))
|
||||
}
|
||||
return int(tdesktopCountHash(values) & 0x7fffffff)
|
||||
}
|
||||
|
||||
func emojiStickerGroupIconID(sets []domain.StickerSet) int64 {
|
||||
for _, set := range sets {
|
||||
if set.ThumbDocumentID != 0 {
|
||||
return set.ThumbDocumentID
|
||||
}
|
||||
for _, id := range set.DocumentIDs {
|
||||
if id != 0 {
|
||||
return id
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func boolHashValue(v bool) int64 {
|
||||
if v {
|
||||
return 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue