move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package tgtest
|
||||
|
||||
import (
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
// UnpackInvoke is a simple Handler middleware to unpack some Invoke*-like requests.
|
||||
// Including:
|
||||
//
|
||||
// tg.InvokeWithLayerRequest
|
||||
// tg.InitConnectionRequest
|
||||
// tg.InvokeWithoutUpdatesRequest
|
||||
func UnpackInvoke(next Handler) Handler {
|
||||
return HandlerFunc(func(srv *Server, req *Request) error {
|
||||
id, err := req.Buf.PeekID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO(tdakkota): handle more Invoke* requests.
|
||||
var (
|
||||
obj = peekIDObject{}
|
||||
r bin.Decoder
|
||||
)
|
||||
for {
|
||||
switch id {
|
||||
case tg.InvokeWithLayerRequestTypeID:
|
||||
r = &tg.InvokeWithLayerRequest{
|
||||
Query: &obj,
|
||||
}
|
||||
// TODO(tdakkota): pass Layer to session.
|
||||
case tg.InitConnectionRequestTypeID:
|
||||
r = &tg.InitConnectionRequest{
|
||||
Query: &obj,
|
||||
}
|
||||
// TODO(tdakkota): pass DeviceInfo to session.
|
||||
case tg.InvokeWithoutUpdatesRequestTypeID:
|
||||
r = &tg.InvokeWithoutUpdatesRequest{
|
||||
Query: &obj,
|
||||
}
|
||||
// TODO(tdakkota): pass NoUpdates flag to session.
|
||||
default:
|
||||
return next.OnMessage(srv, req)
|
||||
}
|
||||
|
||||
if err := r.Decode(req.Buf); err != nil {
|
||||
return err
|
||||
}
|
||||
id = obj.TypeID
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type peekIDObject struct {
|
||||
TypeID uint32
|
||||
}
|
||||
|
||||
func (t *peekIDObject) Decode(b *bin.Buffer) error {
|
||||
id, err := b.PeekID()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "peek id")
|
||||
}
|
||||
t.TypeID = id
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *peekIDObject) Encode(*bin.Buffer) error {
|
||||
return errors.New("peekIDObject must not be encoded")
|
||||
}
|
||||
Reference in New Issue
Block a user