-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
48 lines (40 loc) · 1.14 KB
/
user.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
package botapi
import (
"context"
"github.com/go-faster/errors"
"github.com/gotd/td/tg"
"github.com/gotd/botapi/internal/oas"
)
// GetUserProfilePhotos implements oas.Handler.
func (b *BotAPI) GetUserProfilePhotos(ctx context.Context, req *oas.GetUserProfilePhotos) (*oas.ResultUserProfilePhotos, error) {
userID, err := b.resolveUserID(ctx, req.UserID)
if err != nil {
return nil, errors.Wrap(err, "resolve userID")
}
response, err := b.raw.PhotosGetUserPhotos(ctx, &tg.PhotosGetUserPhotosRequest{
UserID: userID.InputUser(),
Offset: req.Offset.Value,
Limit: req.Limit.Or(100),
})
if err != nil {
return nil, errors.Wrap(err, "get photos")
}
var totalCount int
switch response := response.(type) {
case *tg.PhotosPhotos:
totalCount = len(response.Photos)
case *tg.PhotosPhotosSlice:
totalCount = response.Count
}
var photos [][]oas.PhotoSize
for _, p := range response.MapPhotos() {
photos = append(photos, b.convertToBotAPIPhotoSizes(p))
}
return &oas.ResultUserProfilePhotos{
Result: oas.NewOptUserProfilePhotos(oas.UserProfilePhotos{
TotalCount: totalCount,
Photos: photos,
}),
Ok: true,
}, nil
}