-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchat_info.go
More file actions
83 lines (66 loc) · 1.8 KB
/
Copy pathchat_info.go
File metadata and controls
83 lines (66 loc) · 1.8 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
package botapi
import (
"context"
"github.com/gotd/td/tg"
)
// GetChat returns up-to-date information about a chat.
func (b *Bot) GetChat(ctx context.Context, chat ChatID) (*Chat, error) {
p, err := b.resolvePeer(ctx, chat)
if err != nil {
return nil, err
}
c := chatFromPeer(p)
return &c, nil
}
// GetUserProfilePhotosOption configures a GetUserProfilePhotos call.
type GetUserProfilePhotosOption func(*userPhotosConfig)
type userPhotosConfig struct {
offset int
limit int
}
// WithProfilePhotosOffset sets the number of photos to skip.
func WithProfilePhotosOffset(offset int) GetUserProfilePhotosOption {
return func(c *userPhotosConfig) { c.offset = offset }
}
// WithProfilePhotosLimit caps the number of photos returned (1-100).
func WithProfilePhotosLimit(limit int) GetUserProfilePhotosOption {
return func(c *userPhotosConfig) { c.limit = limit }
}
// GetUserProfilePhotos returns a user's profile photos.
func (b *Bot) GetUserProfilePhotos(ctx context.Context, userID int64, opts ...GetUserProfilePhotosOption) (*UserProfilePhotos, error) {
cfg := userPhotosConfig{limit: 100}
for _, o := range opts {
o(&cfg)
}
user, err := b.resolveInputUser(ctx, userID)
if err != nil {
return nil, err
}
res, err := b.raw.PhotosGetUserPhotos(ctx, &tg.PhotosGetUserPhotosRequest{
UserID: user,
Offset: cfg.offset,
Limit: cfg.limit,
})
if err != nil {
return nil, asAPIError(err)
}
var (
photos []tg.PhotoClass
total int
)
switch p := res.(type) {
case *tg.PhotosPhotos:
photos = p.Photos
total = len(p.Photos)
case *tg.PhotosPhotosSlice:
photos = p.Photos
total = p.Count
}
out := &UserProfilePhotos{TotalCount: total}
for _, ph := range photos {
if photo, ok := ph.(*tg.Photo); ok {
out.Photos = append(out.Photos, photoSizesFromTg(photo))
}
}
return out, nil
}