-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
peer_unpack.go
71 lines (59 loc) · 1.68 KB
/
peer_unpack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package message
import (
"context"
"golang.org/x/xerrors"
"github.com/gotd/td/telegram/message/peer"
"github.com/gotd/td/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, xerrors.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, xerrors.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, xerrors.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, xerrors.Errorf("unexpected type %T", channel)
}
return channelID, nil
}