-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline.go
95 lines (74 loc) 路 1.91 KB
/
timeline.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package mastodon
import (
"net/http"
"net/url"
"strconv"
"github.com/arrow2nd/nekomata/api/sharedapi"
)
func (m *Mastodon) getGlobalTimeline(sinceID string, limit int, local bool) ([]*sharedapi.Post, error) {
q := url.Values{}
q.Add("limit", strconv.Itoa(limit))
if local {
q.Add("local", "true")
} else {
q.Add("local", "false")
}
if sinceID != "" {
q.Add("since_id", sinceID)
}
opts := &requestOpts{
method: http.MethodGet,
url: endpointTimelinePublic.URL(m.user.Server, nil),
q: q,
isAuth: true,
}
res := []*status{}
if err := m.request(opts, &res); err != nil {
return nil, err
}
return statuses2SharedPosts(res), nil
}
func (m *Mastodon) GetGlobalTimeline(sinceID string, limit int) ([]*sharedapi.Post, error) {
return m.getGlobalTimeline(sinceID, limit, false)
}
func (m *Mastodon) GetLocalTimeline(sinceID string, limit int) ([]*sharedapi.Post, error) {
return m.getGlobalTimeline(sinceID, limit, true)
}
func (m *Mastodon) GetHomeTimeline(sinceID string, limit int) ([]*sharedapi.Post, error) {
q := url.Values{}
q.Add("limit", strconv.Itoa(limit))
if sinceID != "" {
q.Add("since_id", sinceID)
}
opts := &requestOpts{
method: http.MethodGet,
url: endpointTimelineHome.URL(m.user.Server, nil),
q: q,
isAuth: true,
}
res := []*status{}
if err := m.request(opts, &res); err != nil {
return nil, err
}
return statuses2SharedPosts(res), nil
}
func (m *Mastodon) GetListTimeline(listID, sinceID string, limit int) ([]*sharedapi.Post, error) {
p := url.Values{}
p.Add(":list_id", listID)
q := url.Values{}
q.Add("limit", strconv.Itoa(limit))
if sinceID != "" {
q.Add("since_id", sinceID)
}
opts := &requestOpts{
method: http.MethodGet,
url: endpointTimelineList.URL(m.user.Server, p),
q: q,
isAuth: true,
}
res := []*status{}
if err := m.request(opts, &res); err != nil {
return nil, err
}
return statuses2SharedPosts(res), nil
}