diff --git a/_schema/layers/LAYER233_REVIEW.md b/_schema/layers/LAYER233_REVIEW.md index 7f278bf76b..5a3035cab8 100644 --- a/_schema/layers/LAYER233_REVIEW.md +++ b/_schema/layers/LAYER233_REVIEW.md @@ -52,13 +52,14 @@ decision below). | Canonical `channels.toggleForum` encoded for 225–232 (canonical→profile) | The required-field projection mechanically drops `sidebar` and emits the historical `#3ff75734` body. Server obligation: a canonical `#a2952b54` request carries the client's explicit `sidebar`; a historical request arrives with `sidebar=false`. A server that wants to keep a sidebar layout chosen by a Layer 233 client may preserve it for historical sessions. | | `channel.forum_sidebar`, `user.bot_forum_sidebar` encoded for 225–232 | Drop (generic optional-field default). Layout metadata only: no permission, consent, credential or PTS meaning, and the historical constructor keeps its field set. Wire IDs are unchanged, so the flags are canonical-only for 225–232. | | Six new updates (`updateEditForumTopic`, `updateBotWidgetQuery`, `updateInlineBotWidgetQuery`, `updateBotWidgetCopyQuery`, `updateMessageWidgetData`, `updateTranscribedAudioFile`) projected to 225–232 | Drop. Every prior non-wallet update added in Layers 225–229 was dropped (`updateJoinChatWebViewDecision`, `updateNewBotConnection`, `updateWebBrowserException`, `updateWebBrowserSettings`, the four ephemeral updates, and `updateEphemeralBotCallbackQuery`); only the Layer 230 wallet/TON-session updates were rejected. The widget, transcription and forum-UI features are unavailable to old profiles, and a dropped interactive widget query cannot authorize a wallet transaction. `updateMessageWidgetData` is the first dropped update with `pts`/`pts_count`: a 225–232 session sees a pts gap when it is emitted and recovers through `updates.getDifference`/`updates.getChannelDifference`, where the update is dropped again from `other_updates` while the returned state still covers its pts. A server emitting it must account for that gap. | -| New widget methods, results and `WidgetQueryType`/`UserWallet` types in historical profiles | Unavailable (generic canonical-only default). No alias and no byte bridge. `messageMediaWidget` in the optional `message.media` falls under the generic optional-field drop: 225–232 receive the message without media, so a widget-only message arrives empty. A server that wants an "unsupported message" placeholder must substitute `messageMediaUnsupported` itself. | +| New widget methods, results and `WidgetQueryType`/`UserWallet` types in historical profiles | Unavailable (generic canonical-only default). No alias and no byte bridge. `messageMediaWidget` in the optional `message.media` is projected to `messageMediaUnsupported#9f84f49e` for 225–232 (new-only project hook `layerProjectLegacyWidgetMedia`): a widget-only message reaches an older client as an explicit unsupported-media placeholder instead of an empty text message. | | Legacy `payments.getStarGiftWithdrawalUrlLegacy#d06e93a8` | Still owned by the canonical Go model. Exact profile 232 defines the temporary-password method `#c8ca817b`, not `#d06e93a8`, so unlike the Layer 232 record it no longer admits the promoted legacy wire; the SRP constructor remains available in exact profiles 225–231. | -The policy has 305 entries: the 249 reviewed decisions are retained unchanged, -and 56 new obligations are explicit (eight `channels.toggleForum` request -defaults and 48 update drops, six constructors × eight historical profiles). -No obligation uses a hook; no stale key remains. +The policy has 313 entries: the 249 reviewed decisions are retained unchanged, +and 64 new obligations are explicit (eight `channels.toggleForum` request +defaults, 48 update drops and eight `messageMediaWidget` new-only projections, +six constructors × eight historical profiles). One obligation uses a typed hook +(`layerProjectLegacyWidgetMedia`); no stale key remains. ## Verification matrix @@ -81,8 +82,8 @@ On Windows/amd64, Go 1.27.3: - Schema import verified against the locked Git blob and normalized SHA-256; `canonical_layer` moved to 233 and `layer-233.tl` was written with its provenance. -- Policy audit: 249 retained entries, zero stale, 56 new obligations, all - reviewed above. The reviewed policy document now holds 305 entries. +- Policy audit: 249 retained entries, zero stale, 64 new obligations, all + reviewed above. The reviewed policy document now holds 313 entries. - `go generate .` reproduced the canonical `tg` model plus the `tlprofile` sidecar with `Profile233` and `ProfileCanonical = 233`; the execution-plan audit was regenerated. diff --git a/_schema/layers/README.md b/_schema/layers/README.md index aebe74a562..6bbb35f705 100644 --- a/_schema/layers/README.md +++ b/_schema/layers/README.md @@ -178,8 +178,12 @@ and `user` gain optional forum-sidebar layout flags (wire IDs unchanged), while `sidebar=false`, the layout an old client chose, instead of being rejected; the six new update constructors drop for 225–232 like every prior non-wallet update. `updateMessageWidgetData` is the first dropped update with `pts`, so a -historical session recovers its gap through difference. The policy has 305 -entries (249 existing plus eight request defaults and 48 update drops). No +historical session recovers its gap through difference. `messageMediaWidget` +projects to `messageMediaUnsupported#9f84f49e` for 225–232 instead of dropping +the media, so a widget-only message reaches an older client as an unsupported +placeholder rather than an empty text message. The policy has 313 entries (249 +existing plus eight `channels.toggleForum` request defaults, 48 update drops and +eight `messageMediaWidget` new-only projections). No existing update's `pts`/`pts_count` field changes and the MTProto transport schema is unchanged. diff --git a/_schema/layers/policy.json b/_schema/layers/policy.json index e64ba77a7c..e1102db88c 100644 --- a/_schema/layers/policy.json +++ b/_schema/layers/policy.json @@ -796,6 +796,70 @@ "note": "kind=incompatible; layer=228; direction=profile-to-canonical; semantic=function:bots.setCustomVerification; wire=0x8b89dfbd-\u003e0xf4946757; field=custom_description-\u003ecustom_description; type=string-\u003eTextWithEntities; source_shape=8dbe65bea4ee0abe7e83c53b83e58674057a353efa71ec3d06ccf28a79ccca3b; target_shape=f2fe0042bab21d6203bd57cd9c82038f1737278bc13e0e0609da5c7a08d293ce" } }, + { + "key": "layer-obligation/v1/new-only/48cf1592bab384c078771998d489fd9e793d536cf038587ce7c98c558dcb94fc", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=225; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/5606c517427cdae430ba950680fa47f2c7969ab7a16e7b476db0db433278fe7c", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=232; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/62167c1a5cbd08e9220253c04cf408092e68326bec59ab1f47af3a65506201b8", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=230; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/7b7f67152e9d1b4811593bff8fa890e4768f6ef246a9d397f883959ccfe70921", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=231; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/975aaacb8e74e37b13a8eb886bd60f92be50b425b5837e14ceda975a8a4b301d", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=228; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/bda0208ba344039e3a0e01be032cc2964e242f2f97fda50b63a1f5604a81f8e2", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=226; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/bdd0c4d27164fe069302a61dbc4d54c168f9aea1032d064e365e9a055c26fe45", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=229; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, + { + "key": "layer-obligation/v1/new-only/d50e1746fc7b411accacaf1c57dae5eec66fe14e5dda255f008197cda8cc8a43", + "resolution": { + "action": "project", + "hook": "layerProjectLegacyWidgetMedia", + "note": "kind=new-only; layer=227; direction=canonical-to-profile; semantic=type:messageMediaWidget; wire=0x2238f214-\u003e0x00000000; type=MessageMedia-\u003e; source_shape=390976d23b5ffc231eeb226c4fecdc33fb72f315126c195823b0980db0478536; target_shape=0000000000000000000000000000000000000000000000000000000000000000" + } + }, { "key": "layer-obligation/v1/old-only/04095a246f363f365768d27cfea9ed4d959a1cff28664178e227bddfa5d2f9e5", "resolution": { diff --git a/gen/layer_codec_model.go b/gen/layer_codec_model.go index f24e701f7c..23ae266025 100644 --- a/gen/layer_codec_model.go +++ b/gen/layer_codec_model.go @@ -2332,8 +2332,15 @@ func (e *layerCodecEmitter) buildFamilies() error { return err } current.project = fmt.Sprintf("return %s(profile, value)\n", hook) - current.preflight = fmt.Sprintf("projected, keep, err := %s(profile, value); if err != nil { return 0, err }; if !keep { return 0, nil }; return layerPreflightDynamicObject(profile, projected, state)\n", hook) - current.encode = fmt.Sprintf("projected, keep, err := %s(profile, value); if err != nil { return err }; if !keep { return &LayerProjectionError{Profile: profile, Semantic: %s, Dropped: true, Reason: \"policy drops projected value\"} }; return layerEncodeObjectBody(profile, projected, b, state)\n", hook, semanticID) + // A class/object dispatcher applies the projection and then + // re-enters the family body of the *projected* constructor, so a + // projected value never reaches this body for an unavailable + // profile. Emitting a generic object encoder here would require + // runtime dynamic dispatch (the sparse codec forbids it). Keep the + // drop behavior: a value that reaches a family body directly for an + // unavailable profile has no encodable wire identity. + current.preflight = "return 0, nil\n" + current.encode = fmt.Sprintf("return &LayerProjectionError{Profile: profile, Semantic: %s, Dropped: true, Reason: \"policy drops projected value\"}\n", semanticID) default: reason := "semantic family is unavailable in exact profile" current.project = fmt.Sprintf("return nil, false, &LayerCodecError{Operation: \"project\", Profile: profile, Semantic: %s, Reason: %q}\n", semanticID, reason) diff --git a/gen/layer_real_policy_test.go b/gen/layer_real_policy_test.go index 1b34e5a698..ac834d481f 100644 --- a/gen/layer_real_policy_test.go +++ b/gen/layer_real_policy_test.go @@ -56,7 +56,7 @@ func TestRealLayerPolicy(t *testing.T) { if unresolved := resolved.LayerConversionPlan().Report.Unresolved(); len(unresolved) != 0 { t.Fatalf("real policy leaves %d unresolved obligations; first=%+v", len(unresolved), unresolved[0]) } - if got, want := len(document.Entries), 305; got != want { + if got, want := len(document.Entries), 313; got != want { t.Fatalf("reviewed policy entry count = %d, want %d", got, want) } codec, err := resolved.buildLayerCodecModel("tg") @@ -125,6 +125,7 @@ func assertRealLayerHookContracts(t *testing.T, codec, sparse []layerCodecHookCo "layerDefaultLegacyKeyboardButtonTypeDecode": "func(LayerProfile, *KeyboardButton) (ButtonTypeClass, error)", "layerProjectEphemeralBotCommandProject": "func(LayerProfile, *BotCommand, bool) (*BotCommand, bool, error)", "layerProjectLegacyDefaultKeyboardButtonProject": "func(LayerProfile, *KeyboardButton, ButtonTypeClass) (*KeyboardButton, bool, error)", + "layerProjectLegacyWidgetMediaProject": "func(LayerProfile, *MessageMediaWidget) (bin.Object, bool, error)", "layerRequireCapturedChatInviteJoinQueryIDDecode": "func(LayerProfile, *MessagesChatInviteJoinResultWebView) (int64, error)", "layerRequireLegacyEphemeralDeletePeerEncode": "func(LayerProfile, *EphemeralDeleteMessageRequest, bool, InputPeerClass) (InputPeerClass, error)", "layerRequireLegacyEphemeralMessagePeerEncode": "func(LayerProfile, *EphemeralMessage, bool, PeerClass) (PeerClass, error)", @@ -246,6 +247,13 @@ func realLayerResolution(obligation LayerObligation) (LayerObligationResolution, } return LayerObligationResolution{}, false, nil } + // A Layer 233 bot web widget has no wire identity before Layer 233. Dropping + // it would leave a text message with no media, so project it to + // messageMediaUnsupported for 225-232: the client then renders an explicit + // unsupported-media placeholder instead of a silently media-less message. + if obligation.Kind == LayerObligationNewOnly && obligation.Semantic.QName == "messageMediaWidget" { + return LayerObligationResolution{Action: LayerResolveProject, Hook: "layerProjectLegacyWidgetMedia"}, true, nil + } if obligation.Resolution.resolved() { return LayerObligationResolution{}, false, nil } diff --git a/telegram/message/entity/options.gen.go b/telegram/message/entity/options.gen.go index 6bc7cbe160..567d8436a2 100644 --- a/telegram/message/entity/options.gen.go +++ b/telegram/message/entity/options.gen.go @@ -480,3 +480,22 @@ func DiffDelete() Formatter { func (b *Builder) DiffDelete(s string) *Builder { return b.Format(s, DiffDelete()) } + +// TonAddress creates Formatter of TonAddress message entity. +// +// See https://core.telegram.org/constructor/messageEntityTonAddress. +func TonAddress() Formatter { + return func(offset, length int) tg.MessageEntityClass { + return &tg.MessageEntityTonAddress{ + Offset: offset, + Length: length, + } + } +} + +// TonAddress adds and formats message as TonAddress message entity. +// +// See https://core.telegram.org/constructor/messageEntityTonAddress. +func (b *Builder) TonAddress(s string) *Builder { + return b.Format(s, TonAddress()) +} diff --git a/telegram/message/styling/options.gen.go b/telegram/message/styling/options.gen.go index b91dbfda9e..d223ba1acf 100644 --- a/telegram/message/styling/options.gen.go +++ b/telegram/message/styling/options.gen.go @@ -251,3 +251,13 @@ func DiffDelete(s string) StyledTextOption { return nil }) } + +// TonAddress formats text as TonAddress entity. +// +// See https://core.telegram.org/constructor/messageEntityTonAddress. +func TonAddress(s string) StyledTextOption { + return styledTextOption(s, func(b *textBuilder) error { + b.TonAddress(s) + return nil + }) +} diff --git a/telegram/message/typing.gen.go b/telegram/message/typing.gen.go index 9a110531eb..80b787c0cd 100644 --- a/telegram/message/typing.gen.go +++ b/telegram/message/typing.gen.go @@ -121,25 +121,38 @@ func (b *TypingActionBuilder) EmojiInteractionSeen(ctx context.Context, emoticon } // TextDraft sends SendMessageTextDraftAction. -func (b *TypingActionBuilder) TextDraft(ctx context.Context, randomID int64, text tg.TextWithEntities) error { +func (b *TypingActionBuilder) TextDraft(ctx context.Context, canStop bool, keepOnStop bool, randomID int64, text tg.TextWithEntities) error { return b.send(ctx, &tg.SendMessageTextDraftAction{ - RandomID: randomID, - Text: text, + CanStop: canStop, + KeepOnStop: keepOnStop, + RandomID: randomID, + Text: text, }) } // InputSendMessageRichMessageDraft sends InputSendMessageRichMessageDraftAction. -func (b *TypingActionBuilder) InputSendMessageRichMessageDraft(ctx context.Context, randomID int64, richMessage tg.InputRichMessageClass) error { +func (b *TypingActionBuilder) InputSendMessageRichMessageDraft(ctx context.Context, canStop bool, keepOnStop bool, randomID int64, richMessage tg.InputRichMessageClass) error { return b.send(ctx, &tg.InputSendMessageRichMessageDraftAction{ + CanStop: canStop, + KeepOnStop: keepOnStop, RandomID: randomID, RichMessage: richMessage, }) } // RichMessageDraft sends SendMessageRichMessageDraftAction. -func (b *TypingActionBuilder) RichMessageDraft(ctx context.Context, randomID int64, richMessage tg.RichMessage) error { +func (b *TypingActionBuilder) RichMessageDraft(ctx context.Context, canStop bool, keepOnStop bool, randomID int64, richMessage tg.RichMessage) error { return b.send(ctx, &tg.SendMessageRichMessageDraftAction{ + CanStop: canStop, + KeepOnStop: keepOnStop, RandomID: randomID, RichMessage: richMessage, }) } + +// StopDraft sends SendMessageStopDraftAction. +func (b *TypingActionBuilder) StopDraft(ctx context.Context, randomID int64) error { + return b.send(ctx, &tg.SendMessageStopDraftAction{ + RandomID: randomID, + }) +} diff --git a/telegram/query/cached/queries.gen.go b/telegram/query/cached/queries.gen.go index d5c17660ca..7daa22b922 100644 --- a/telegram/query/cached/queries.gen.go +++ b/telegram/query/cached/queries.gen.go @@ -1362,6 +1362,94 @@ func (s *ContactsGetContacts) Fetch(ctx context.Context) (bool, error) { } } +type innerEphemeralGetWelcomeMessages struct { + // Last received hash. + hash int64 + // Last received result. + value *tg.EphemeralWelcomeMessages +} + +type EphemeralGetWelcomeMessages struct { + // Query to send. + req *tg.EphemeralGetWelcomeMessagesRequest + // Result state. + last atomic.Value + + // Reference to RPC client to make requests. + raw *tg.Client +} + +// NewEphemeralGetWelcomeMessages creates new EphemeralGetWelcomeMessages. +func NewEphemeralGetWelcomeMessages(raw *tg.Client, initial *tg.EphemeralGetWelcomeMessagesRequest) *EphemeralGetWelcomeMessages { + q := &EphemeralGetWelcomeMessages{ + req: initial, + raw: raw, + } + + return q +} + +func (s *EphemeralGetWelcomeMessages) store(v innerEphemeralGetWelcomeMessages) { + s.last.Store(v) +} + +func (s *EphemeralGetWelcomeMessages) load() (innerEphemeralGetWelcomeMessages, bool) { + v, ok := s.last.Load().(innerEphemeralGetWelcomeMessages) + return v, ok +} + +// Value returns last received result. +// NB: May be nil. Returned EphemeralWelcomeMessages must not be mutated. +func (s *EphemeralGetWelcomeMessages) Value() *tg.EphemeralWelcomeMessages { + inner, _ := s.load() + return inner.value +} + +// Hash returns last received hash. +func (s *EphemeralGetWelcomeMessages) Hash() int64 { + inner, _ := s.load() + return inner.hash +} + +// Get updates data if needed and returns it. +func (s *EphemeralGetWelcomeMessages) Get(ctx context.Context) (*tg.EphemeralWelcomeMessages, error) { + if _, err := s.Fetch(ctx); err != nil { + return nil, err + } + + return s.Value(), nil +} + +// Fetch updates data if needed and returns true if data was modified. +func (s *EphemeralGetWelcomeMessages) Fetch(ctx context.Context) (bool, error) { + lastHash := s.Hash() + + req := s.req + req.Hash = lastHash + result, err := s.raw.EphemeralGetWelcomeMessages(ctx, req) + if err != nil { + return false, errors.Wrap(err, "execute EphemeralGetWelcomeMessages") + } + + switch variant := result.(type) { + case *tg.EphemeralWelcomeMessages: + hash := variant.Hash + + s.store(innerEphemeralGetWelcomeMessages{ + hash: hash, + value: variant, + }) + return true, nil + case *tg.EphemeralWelcomeMessagesNotModified: + if lastHash == 0 { + return false, errors.Errorf("got unexpected %T result", result) + } + return false, nil + default: + return false, errors.Errorf("unexpected type %T", result) + } +} + type innerMessagesGetAllStickers struct { // Last received hash. hash int64 @@ -2642,6 +2730,94 @@ func (s *MessagesGetTopReactions) Fetch(ctx context.Context) (bool, error) { } } +type innerMessagesGetWidgetPublicData struct { + // Last received hash. + hash int64 + // Last received result. + value *tg.MessagesWidgetPublicData +} + +type MessagesGetWidgetPublicData struct { + // Query to send. + req *tg.MessagesGetWidgetPublicDataRequest + // Result state. + last atomic.Value + + // Reference to RPC client to make requests. + raw *tg.Client +} + +// NewMessagesGetWidgetPublicData creates new MessagesGetWidgetPublicData. +func NewMessagesGetWidgetPublicData(raw *tg.Client, initial *tg.MessagesGetWidgetPublicDataRequest) *MessagesGetWidgetPublicData { + q := &MessagesGetWidgetPublicData{ + req: initial, + raw: raw, + } + + return q +} + +func (s *MessagesGetWidgetPublicData) store(v innerMessagesGetWidgetPublicData) { + s.last.Store(v) +} + +func (s *MessagesGetWidgetPublicData) load() (innerMessagesGetWidgetPublicData, bool) { + v, ok := s.last.Load().(innerMessagesGetWidgetPublicData) + return v, ok +} + +// Value returns last received result. +// NB: May be nil. Returned MessagesWidgetPublicData must not be mutated. +func (s *MessagesGetWidgetPublicData) Value() *tg.MessagesWidgetPublicData { + inner, _ := s.load() + return inner.value +} + +// Hash returns last received hash. +func (s *MessagesGetWidgetPublicData) Hash() int64 { + inner, _ := s.load() + return inner.hash +} + +// Get updates data if needed and returns it. +func (s *MessagesGetWidgetPublicData) Get(ctx context.Context) (*tg.MessagesWidgetPublicData, error) { + if _, err := s.Fetch(ctx); err != nil { + return nil, err + } + + return s.Value(), nil +} + +// Fetch updates data if needed and returns true if data was modified. +func (s *MessagesGetWidgetPublicData) Fetch(ctx context.Context) (bool, error) { + lastHash := s.Hash() + + req := s.req + req.Hash = lastHash + result, err := s.raw.MessagesGetWidgetPublicData(ctx, req) + if err != nil { + return false, errors.Wrap(err, "execute MessagesGetWidgetPublicData") + } + + switch variant := result.(type) { + case *tg.MessagesWidgetPublicData: + hash := variant.Hash + + s.store(innerMessagesGetWidgetPublicData{ + hash: hash, + value: variant, + }) + return true, nil + case *tg.MessagesWidgetPublicDataNotModified: + if lastHash == 0 { + return false, errors.Errorf("got unexpected %T result", result) + } + return false, nil + default: + return false, errors.Errorf("unexpected type %T", result) + } +} + type innerMessagesSearchCustomEmoji struct { // Last received hash. hash int64 diff --git a/tlprofile/adapters.go b/tlprofile/adapters.go index 54afffb7dd..d5ebad1d1f 100644 --- a/tlprofile/adapters.go +++ b/tlprofile/adapters.go @@ -3,6 +3,7 @@ package tlprofile import ( "fmt" + "github.com/iamxvbaba/td/bin" "github.com/iamxvbaba/td/tg" ) @@ -86,6 +87,19 @@ func layerProjectEphemeralBotCommandProject( return value, true, nil } +// layerProjectLegacyWidgetMediaProject projects a Layer 233 bot web widget to +// messageMediaUnsupported for profiles that predate it. A dropped media field +// would otherwise reach an older client as an empty text message. +func layerProjectLegacyWidgetMediaProject(profile LayerProfile, value *tg.MessageMediaWidget) (bin.Object, bool, error) { + if value == nil { + return nil, false, fmt.Errorf("widget media is nil") + } + if profile >= LayerProfile233 { + return value, true, nil + } + return &tg.MessageMediaUnsupported{}, true, nil +} + func layerLegacyProjectionMiss(profile LayerProfile, kind string, value any) error { return &LayerProjectionError{ Profile: profile, diff --git a/tlprofile/layer233_widget_projection_test.go b/tlprofile/layer233_widget_projection_test.go new file mode 100644 index 0000000000..15ac90a4e7 --- /dev/null +++ b/tlprofile/layer233_widget_projection_test.go @@ -0,0 +1,37 @@ +package tlprofile + +import ( + "testing" + + "github.com/iamxvbaba/td/tg" +) + +// A Layer 233 bot web widget has no wire identity before Layer 233. Rather than +// dropping the media (which reaches an older client as an empty text message) it +// must project to messageMediaUnsupported#9f84f49e for profiles 225-232. +func TestLayer233BotWidgetProjectsToUnsupportedInHistoricalProfiles(t *testing.T) { + widget := &tg.MessageMediaWidget{Width: 320, Height: 200, Payload: []byte("x"), CanQuery: true} + widget.SetWidgetID(7) + message := func() *tg.Message { + return &tg.Message{ID: 1, PeerID: &tg.PeerUser{UserID: 2}, Date: 3, Message: "widget", Media: widget} + } + + for profile := Profile225; profile <= Profile232; profile++ { + got, ok := layer232RoundTrip(t, profile, message()).(*tg.Message) + if !ok { + t.Fatalf("profile %d round trip returned %T", profile, got) + } + if _, ok := got.Media.(*tg.MessageMediaUnsupported); !ok { + t.Fatalf("profile %d widget media = %T, want *tg.MessageMediaUnsupported", profile, got.Media) + } + } + + // The canonical profile keeps the widget unchanged. + got, ok := layer232RoundTrip(t, Profile233, message()).(*tg.Message) + if !ok { + t.Fatalf("Layer 233 round trip returned %T", got) + } + if _, ok := got.Media.(*tg.MessageMediaWidget); !ok { + t.Fatalf("Layer 233 widget media = %T, want *tg.MessageMediaWidget", got.Media) + } +} diff --git a/tlprofile/tl_profile_sparse_families_gen.go b/tlprofile/tl_profile_sparse_families_gen.go index ded5fca462..57cc041603 100644 --- a/tlprofile/tl_profile_sparse_families_gen.go +++ b/tlprofile/tl_profile_sparse_families_gen.go @@ -9152,7 +9152,7 @@ func layerEncodeFamilyMessageMediaWidgetBody(profile LayerProfile, value *tg.Mes } switch profile { case LayerProfile225, LayerProfile226, LayerProfile227, LayerProfile228, LayerProfile229, LayerProfile230, LayerProfile231, LayerProfile232: - return &LayerProjectionError{Profile: profile, Semantic: LayerSemanticTypeMessageMediaWidget, Dropped: true, Reason: "policy drops unavailable value"} + return &LayerProjectionError{Profile: profile, Semantic: LayerSemanticTypeMessageMediaWidget, Dropped: true, Reason: "policy drops projected value"} case LayerProfile233: b.PutID(0x2238f214) return layerEncodeWire2238f214BareBody(profile, value, b, state) @@ -25575,7 +25575,7 @@ func layerProjectFamilyMessageMediaWidget(profile LayerProfile, value *tg.Messag } switch profile { case LayerProfile225, LayerProfile226, LayerProfile227, LayerProfile228, LayerProfile229, LayerProfile230, LayerProfile231, LayerProfile232: - return nil, false, nil + return layerProjectLegacyWidgetMediaProject(profile, value) case LayerProfile233: return value, true, nil default: diff --git a/tlprofile/tl_profile_sparse_runtime_gen.go b/tlprofile/tl_profile_sparse_runtime_gen.go index 689052f577..4511363fcd 100644 --- a/tlprofile/tl_profile_sparse_runtime_gen.go +++ b/tlprofile/tl_profile_sparse_runtime_gen.go @@ -3178,6 +3178,11 @@ var _ func(LayerProfile, *tg.BotCommand, bool) (*tg.BotCommand, bool, error) = l // inside one transactional pass; hooks must not mutate their input value. var _ func(LayerProfile, *tg.KeyboardButton, tg.ButtonTypeClass) (*tg.KeyboardButton, bool, error) = layerProjectLegacyDefaultKeyboardButtonProject +// Static policy contract for layerProjectLegacyWidgetMediaProject. Missing hooks and signature drift +// intentionally fail compilation. Production encoding invokes each hook once +// inside one transactional pass; hooks must not mutate their input value. +var _ func(LayerProfile, *tg.MessageMediaWidget) (bin.Object, bool, error) = layerProjectLegacyWidgetMediaProject + // Static policy contract for layerRequireCapturedChatInviteJoinQueryIDDecode. Missing hooks and signature drift // intentionally fail compilation. Production encoding invokes each hook once // inside one transactional pass; hooks must not mutate their input value.