-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathshared_locations.go
More file actions
71 lines (56 loc) · 1.84 KB
/
Copy pathshared_locations.go
File metadata and controls
71 lines (56 loc) · 1.84 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
package stream_chat
import (
"context"
"errors"
"net/http"
"net/url"
"path"
"time"
)
type SharedLocation struct {
MessageID string `json:"message_id"`
ChannelCID string `json:"channel_cid"`
UserID string `json:"user_id"`
Latitude *float64 `json:"latitude,omitempty"`
Longitude *float64 `json:"longitude,omitempty"`
CreatedByDeviceID string `json:"created_by_device_id"`
EndAt *time.Time `json:"end_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ActiveLiveLocationsResponse struct {
ActiveLiveLocations []*SharedLocation `json:"active_live_locations"`
Response
}
type SharedLocationResponse struct {
SharedLocation
Message *MessageResponse `json:"message,omitempty"`
Channel *Channel `json:"channel,omitempty"`
}
// GetUserActiveLocations returns all active live locations for a user
func (c *Client) GetUserActiveLocations(ctx context.Context, userID string) (*ActiveLiveLocationsResponse, error) {
path := path.Join("users", "live_locations")
var resp ActiveLiveLocationsResponse
if userID == "" {
return nil, errors.New("user ID is empty")
}
if userID == "" {
return nil, errors.New("user ID is empty")
}
params := url.Values{}
params.Set("user_id", userID)
err := c.makeRequest(ctx, http.MethodGet, path, params, nil, &resp)
return &resp, err
}
// UpdateUserActiveLocation updates a location
func (c *Client) UpdateUserActiveLocation(ctx context.Context, userID string, location *SharedLocation) (*SharedLocationResponse, error) {
path := path.Join("users", "live_locations")
var resp SharedLocationResponse
if userID == "" {
return nil, errors.New("user ID is empty")
}
params := url.Values{}
params.Set("user_id", userID)
err := c.makeRequest(ctx, http.MethodPut, path, params, location, &resp)
return &resp, err
}