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,71 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-faster/errors"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/message/peer"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
// AsInputPeer returns resolve result as InputPeerClass.
|
||||
func (b *RequestBuilder) AsInputPeer(ctx context.Context) (tg.InputPeerClass, error) {
|
||||
return b.peer(ctx)
|
||||
}
|
||||
|
||||
// AsInputUserClass returns resolve result as InputUserClass.
|
||||
func (b *RequestBuilder) AsInputUserClass(ctx context.Context) (tg.InputUserClass, error) {
|
||||
p, err := b.peer(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
user, ok := peer.ToInputUser(p)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("unexpected type %T", p)
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// AsInputUser returns resolve result as InputUser.
|
||||
func (b *RequestBuilder) AsInputUser(ctx context.Context) (*tg.InputUser, error) {
|
||||
user, err := b.AsInputUserClass(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userID, ok := user.(*tg.InputUser)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("unexpected type %T", user)
|
||||
}
|
||||
return userID, nil
|
||||
}
|
||||
|
||||
// AsInputChannelClass returns resolve result as tg.NotEmptyInputChannel.
|
||||
func (b *RequestBuilder) AsInputChannelClass(ctx context.Context) (tg.InputChannelClass, error) {
|
||||
p, err := b.peer(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channel, ok := peer.ToInputChannel(p)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("unexpected type %T", p)
|
||||
}
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
// AsInputChannel returns resolve result as InputChannel.
|
||||
func (b *RequestBuilder) AsInputChannel(ctx context.Context) (*tg.InputChannel, error) {
|
||||
channel, err := b.AsInputChannelClass(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelID, ok := channel.(*tg.InputChannel)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("unexpected type %T", channel)
|
||||
}
|
||||
return channelID, nil
|
||||
}
|
||||
Reference in New Issue
Block a user