Skip to content

Commit 549429d

Browse files
committed
feat: add top tweets "timeline"
1 parent aa196c2 commit 549429d

5 files changed

Lines changed: 45 additions & 9 deletions

File tree

bluesky/blueskyapi.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,38 @@ func GetTimeline(pds string, token string, context string, feed string, limit in
714714
return nil, &feeds
715715
}
716716

717+
// https://docs.bsky.app/docs/api/app-bsky-feed-get-feed
718+
func GetHotPosts(pds string, token string, context string, feed string, limit int) (error, *Timeline) {
719+
url := pds + "/xrpc/app.bsky.feed.getFeed?feed=at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot&limit=" + fmt.Sprintf("%d", limit)
720+
// Context is removed, since how it gets context is witchcraft.
721+
722+
resp, err := SendRequest(&token, http.MethodGet, url, nil)
723+
if err != nil {
724+
return err, nil
725+
}
726+
defer resp.Body.Close()
727+
728+
// // Print the response body for debugging
729+
// bodyBytes, _ := io.ReadAll(resp.Body)
730+
// bodyString := string(bodyBytes)
731+
// fmt.Println("Response Body:", bodyString)
732+
733+
if resp.StatusCode != http.StatusOK {
734+
bodyBytes, _ := io.ReadAll(resp.Body)
735+
bodyString := string(bodyBytes)
736+
fmt.Println("Response Status:", resp.StatusCode)
737+
fmt.Println("Response Body:", bodyString)
738+
return errors.New("failed to fetch timeline"), nil
739+
}
740+
741+
feeds := Timeline{}
742+
if err := json.NewDecoder(resp.Body).Decode(&feeds); err != nil {
743+
return err, nil
744+
}
745+
746+
return nil, &feeds
747+
}
748+
717749
// https://docs.bsky.app/docs/api/app-bsky-feed-get-author-feed
718750
func GetUserTimeline(pds string, token string, context string, actor string, limit int) (error, *Timeline) {
719751
apiURL := pds + "/xrpc/app.bsky.feed.getAuthorFeed?actor=" + url.QueryEscape(actor) + "&limit=" + fmt.Sprintf("%d", limit)

twitterv1/discover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func GetTopicSuggestedUsers(c *fiber.Ctx) error {
238238
}
239239

240240
slug := c.Params("slug")
241-
if slug != "" {
241+
if slug == "" {
242242
return c.Status(fiber.StatusInternalServerError).SendString("Missing Slug")
243243
}
244244

twitterv1/lists.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func list_timeline(c *fiber.Ctx) error {
155155
list = *listPtr
156156
}
157157

158-
return convert_timeline(c, list, blueskyapi.GetListTimeline)
158+
return convert_timeline(c, list, false, blueskyapi.GetListTimeline)
159159
}
160160

161161
func GetListMembers(c *fiber.Ctx) error {

twitterv1/post_viewing.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ type TweetsRoot struct {
2222
}
2323

2424
func home_timeline(c *fiber.Ctx) error {
25-
return convert_timeline(c, "", blueskyapi.GetTimeline)
25+
return convert_timeline(c, "", true, blueskyapi.GetTimeline)
26+
}
27+
28+
func hot_post_timeline(c *fiber.Ctx) error {
29+
return convert_timeline(c, "", true, blueskyapi.GetHotPosts)
2630
}
2731

2832
func user_timeline(c *fiber.Ctx) error {
@@ -42,7 +46,7 @@ func user_timeline(c *fiber.Ctx) error {
4246
}
4347
actor = *actorPtr
4448
}
45-
return convert_timeline(c, actor, blueskyapi.GetUserTimeline)
49+
return convert_timeline(c, actor, false, blueskyapi.GetUserTimeline)
4650
}
4751

4852
func media_timeline(c *fiber.Ctx) error {
@@ -62,7 +66,7 @@ func media_timeline(c *fiber.Ctx) error {
6266
}
6367
actor = *actorPtr
6468
}
65-
return convert_timeline(c, actor, blueskyapi.GetMediaTimeline)
69+
return convert_timeline(c, actor, false, blueskyapi.GetMediaTimeline)
6670
}
6771

6872
func likes_timeline(c *fiber.Ctx) error {
@@ -78,11 +82,11 @@ func likes_timeline(c *fiber.Ctx) error {
7882
}
7983
actor = *actorPtr
8084

81-
return convert_timeline(c, actor, blueskyapi.GetActorLikes)
85+
return convert_timeline(c, actor, false, blueskyapi.GetActorLikes)
8286
}
8387

8488
// https://web.archive.org/web/20120508224719/https://dev.twitter.com/docs/api/1/get/statuses/home_timeline
85-
func convert_timeline(c *fiber.Ctx, param string, fetcher func(string, string, string, string, int) (error, *blueskyapi.Timeline)) error {
89+
func convert_timeline(c *fiber.Ctx, param string, requireAuth bool, fetcher func(string, string, string, string, int) (error, *blueskyapi.Timeline)) error {
8690
// Get all of our keys, beeps, and bops
8791
_, pds, _, oauthToken, err := GetAuthFromReq(c)
8892

twitterv1/twitterv1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func InitServer(config *config.Config) {
8484
// Posts
8585
app.Get("/1/statuses/home_timeline.:filetype", home_timeline)
8686
app.Get("/1/statuses/user_timeline.:filetype", user_timeline)
87+
app.Get("/1/favorites/toptweets.:filetype", hot_post_timeline)
8788
app.Get("/1/statuses/media_timeline.:filetype", media_timeline)
8889
app.Get("/1/statuses/show/:id.:filetype", GetStatusFromId)
8990
app.Get("/i/statuses/:id/activity/summary.:filetype", TweetInfo)
@@ -115,8 +116,7 @@ func InitServer(config *config.Config) {
115116
app.Get("/1/trends/:woeid.:filetype", trends_woeid)
116117
app.Get("/1/trends/current.:filetype", trends_woeid)
117118
app.Get("/1/users/suggestions.:filetype", SuggestedTopics)
118-
app.Get("/1/users/suggestions.:filetype", GetTopicSuggestedUsers)
119-
app.Get("/1/users/suggestions/:slug.:filetype", SuggestedTopics)
119+
app.Get("/1/users/suggestions/:slug.:filetype", GetTopicSuggestedUsers)
120120
app.Get("/i/search.:filetype", InternalSearch)
121121

122122
// Lists

0 commit comments

Comments
 (0)