feat: sync recent call and channel fixes

This commit is contained in:
A 2026-07-01 14:34:59 +08:00
parent e5e0080216
commit 866a87583e
65 changed files with 6680 additions and 229 deletions

View file

@ -10,9 +10,15 @@ import (
// Canonical ids used to synthesize converted/defaulted values.
const (
inputUserID = 0xf21158c6 // inputUser user_id:long access_hash:long
inputMessageID = 0xa676a322 // inputMessageID id:int
boolFalseID = 0xbc799737 // boolFalse
inputUserID = 0xf21158c6 // inputUser user_id:long access_hash:long
inputMessageID = 0xa676a322 // inputMessageID id:int
inputChannelEmptyID = 0xee8c1e86 // inputChannelEmpty
inputChannelID = 0xf35aec28 // inputChannel channel_id:long access_hash:long
inputChannelFromMessageID = 0x5b934f9d // inputChannelFromMessage peer:InputPeer msg_id:int channel_id:long
inputPeerEmptyID = 0x7f3b18ea // inputPeerEmpty
inputPeerChannelID = 0x27bcbbfc // inputPeerChannel channel_id:long access_hash:long
inputPeerChannelFromMessageID = 0xbd2a0840 // inputPeerChannelFromMessage peer:InputPeer msg_id:int channel_id:long
boolFalseID = 0xbc799737 // boolFalse
)
//go:embed schema/client-drift.tl
@ -34,7 +40,8 @@ func mustLoadDrift() *schemaModel {
// Pure schema diff cannot recover a rename, so it is declared here (data, not a
// transform). It is the only thing a structural rename needs.
var driftFieldRenames = map[string]string{
"bots.exportBotToken\x00bot": "bot_id",
"bots.exportBotToken\x00bot": "bot_id",
"messages.editChatCreator\x00peer": "channel",
}
// fieldConverter rewrites one field whose wire type changed between the old and
@ -73,6 +80,28 @@ var fieldConverters = map[string]fieldConverter{
out.PutLong(0)
return nil
},
// channel:InputChannel -> peer:InputPeer for the old channels.editCreator
// Android constructor. Concrete layouts are otherwise byte-compatible.
"InputChannel->InputPeer": func(raw []byte, out *bin.Buffer) error {
in := &bin.Buffer{Buf: raw}
id, err := in.ID()
if err != nil {
return err
}
switch id {
case inputChannelEmptyID:
out.PutID(inputPeerEmptyID)
case inputChannelID:
out.PutID(inputPeerChannelID)
out.Put(in.Buf)
case inputChannelFromMessageID:
out.PutID(inputPeerChannelFromMessageID)
out.Put(in.Buf)
default:
return bin.NewUnexpectedID(id)
}
return nil
},
}
// UpgradeInbound converts an old client's inbound request to canonical (227)

View file

@ -147,6 +147,34 @@ func TestInboundBodyTransforms(t *testing.T) {
}
validateMethodRequest(t, out, 0x42c6978f, "langpackGetLanguages")
})
t.Run("channelsEditCreatorToMessagesEditChatCreator", func(t *testing.T) {
var in bin.Buffer
in.PutID(0x8f38cd1f)
_ = (&tg.InputChannel{ChannelID: 132, AccessHash: 8956724956393200600}).Encode(&in)
_ = (&tg.InputUser{UserID: 1780243211, AccessHash: 42}).Encode(&in)
_ = (&tg.InputCheckPasswordEmpty{}).Encode(&in)
out, ok, err := UpgradeInbound(0x8f38cd1f, &in)
if !ok || err != nil {
t.Fatalf("upgrade: ok=%v err=%v", ok, err)
}
validateMethodRequest(t, out, 0xf743b857, "messagesEditChatCreator")
var req tg.MessagesEditChatCreatorRequest
if err := req.Decode(&bin.Buffer{Buf: append([]byte(nil), out.Buf...)}); err != nil {
t.Fatalf("decode upgraded editChatCreator: %v", err)
}
peer, ok := req.Peer.(*tg.InputPeerChannel)
if !ok || peer.ChannelID != 132 || peer.AccessHash != 8956724956393200600 {
t.Fatalf("upgraded peer = %T %+v, want inputPeerChannel", req.Peer, req.Peer)
}
user, ok := req.UserID.(*tg.InputUser)
if !ok || user.UserID != 1780243211 || user.AccessHash != 42 {
t.Fatalf("upgraded user = %T %+v, want inputUser", req.UserID, req.UserID)
}
if _, ok := req.Password.(*tg.InputCheckPasswordEmpty); !ok {
t.Fatalf("upgraded password = %T, want inputCheckPasswordEmpty", req.Password)
}
})
}
// TestInboundCRCSwaps covers the body-compatible client-drift methods that only

View file

@ -26,3 +26,7 @@ contacts.search#11f812d8 q:string limit:int = contacts.Found;
langpack.getLangPack#9ab5c58e lang_code:string = LangPackDifference;
langpack.getStrings#2e1ee318 lang_code:string keys:Vector<string> = Vector<LangPackString>;
langpack.getLanguages#800fd57d = Vector<LangPackLanguage>;
// DrKLO still emits old channels.editCreator#8f38cd1f; canonical 227 replaced
// that flow with messages.editChatCreator(peer:InputPeer,...). Keep the old
// constructor id here but target the canonical method name for generic upgrade.
messages.editChatCreator#8f38cd1f channel:InputChannel user_id:InputUser password:InputCheckPasswordSRP = Updates;