added full gifts support

This commit is contained in:
onysd 2026-08-07 10:04:13 +03:00
parent ea5b86de8f
commit 354128c106
35 changed files with 1502 additions and 103 deletions

View file

@ -0,0 +1,50 @@
package domain
import (
"errors"
"time"
)
var (
// ErrGifCatalogUnavailable is returned by the admin GIF-catalog write path
// when no store.GifCatalogStore was configured (files.WithGifCatalog).
ErrGifCatalogUnavailable = errors.New("gif catalog is not configured")
// ErrGifCatalogFileInvalid is returned when an uploaded file isn't a GIF
// or MP4, or exceeds MaxGifCatalogUploadSize.
ErrGifCatalogFileInvalid = errors.New("gif catalog file invalid")
// ErrGifCatalogEntryInvalid is returned for a title that fails validation
// or a document_id that doesn't resolve to an uploaded document.
ErrGifCatalogEntryInvalid = errors.New("gif catalog entry invalid")
// ErrGifCatalogEntryNotFound is returned by an update/delete against an id
// that doesn't exist.
ErrGifCatalogEntryNotFound = errors.New("gif catalog entry not found")
)
const (
// MaxGifCatalogTitleLen bounds an admin-entered catalog entry title.
MaxGifCatalogTitleLen = 128
// MaxGifCatalogEntries caps how many entries @gif serves in one inline
// response -- mirrors MaxBotInlineResults, the TL-level cap the client
// itself enforces per messages.getInlineBotResults response.
MaxGifCatalogEntries = MaxBotInlineResults
// MaxGifCatalogUploadSize bounds one admin-uploaded catalog file.
// 20MB matches MaxBotInlineWebSize, the size a client-side inline GIF
// result is already allowed to be.
MaxGifCatalogUploadSize = MaxBotInlineWebSize
)
// GifCatalogEntry is one admin-curated GIF served by the built-in @gif inline
// bot (see rpc.ServiceBotInlineResults) for the client's GIF picker
// trending/search panel. DocumentID references an already-uploaded document
// (see files.Service.AdminUploadGifMaterial) -- the catalog only tracks which
// documents are featured and in what order, it does not own the media itself.
type GifCatalogEntry struct {
ID int64
Title string
DocumentID int64
Enabled bool
SortOrder int
CreatedBy string
CreatedAt time.Time
UpdatedAt time.Time
}

View file

@ -1,6 +1,10 @@
package domain
import "telesrv/internal/branding"
import (
"strings"
"telesrv/internal/branding"
)
const (
// OfficialSystemUserID 是 Telegram 兼容客户端识别的官方系统账号。
@ -75,6 +79,17 @@ const (
// startup -- not a document minted specifically for this feature -- so it
// resolves the same way any other seeded custom emoji does.
VerifierBotDefaultIconDocumentID int64 = 5237699328843200968
// GifBotUserID is the built-in @gif inline bot: it answers
// messages.getInlineBotResults synchronously (no MTProto session, no Bot API
// process -- see rpc.ServiceBotInlineResults) with the admin-curated GIF
// catalog, the same role Telegram's own @gif plays for the client's GIF
// picker "trending"/search panel. The id is reserved and stable, so a
// restart never re-creates the account under a different identity.
GifBotUserID int64 = 1250000015
// GifBotAccessHash is fixed and double-written with the seed row in this
// feature's migration; the two must never drift.
GifBotAccessHash int64 = 7233282977235616768
)
// officialSystemUserPhotoDCID/Stripped 由 files.Service.SeedOfficialSystemAvatar
@ -270,6 +285,19 @@ func VerifierBotUser() User {
}
}
// GifBotUser returns the built-in @gif account.
func GifBotUser() User {
return User{
ID: GifBotUserID,
AccessHash: GifBotAccessHash,
FirstName: "GIFs",
Username: "gif",
Verified: true,
Bot: true,
BotInfoVersion: 1,
}
}
// SystemUserByID 返回内置系统账号;非系统账号返回 ok=false。
// 所有对 777000 的硬编码注入点统一经此函数,新增内置账号只改这里。
func SystemUserByID(id int64) (User, bool) {
@ -286,6 +314,8 @@ func SystemUserByID(id int64) (User, bool) {
return VerifyBotUser(), true
case VerifierBotUserID:
return VerifierBotUser(), true
case GifBotUserID:
return GifBotUser(), true
}
return User{}, false
}
@ -308,9 +338,29 @@ func SystemUserIDs() []int64 {
ChatBotUserID,
VerifyBotUserID,
VerifierBotUserID,
GifBotUserID,
}
}
// SystemUserByUsername resolves a case-insensitive exact username match
// against every built-in account, e.g. for username-lookup paths that
// otherwise enforce a minimum length shorter than some reserved system
// handles need (@gif is 3 characters -- shorter than
// MinCollectibleUsernameLength's 4-character floor for an ordinary lookup).
func SystemUserByUsername(username string) (User, bool) {
username = NormalizeUsername(username)
if username == "" {
return User{}, false
}
for _, id := range SystemUserIDs() {
u, ok := SystemUserByID(id)
if ok && strings.EqualFold(u.Username, username) {
return u, true
}
}
return User{}, false
}
func SystemUserByPhone(phone string) (User, bool) {
phone = NormalizePhone(phone)
for _, id := range SystemUserIDs() {