MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / convert_timeline

Function convert_timeline

twitterv1/post_viewing.go:93–169  ·  view source on GitHub ↗

https://web.archive.org/web/20120508224719/https://dev.twitter.com/docs/api/1/get/statuses/home_timeline

(c *fiber.Ctx, param string, requireAuth bool, fetcher func(string, string, string, string, int) (*blueskyapi.Timeline, error))

Source from the content-addressed store, hash-verified

91
92// https://web.archive.org/web/20120508224719/https://dev.twitter.com/docs/api/1/get/statuses/home_timeline
93func convert_timeline(c *fiber.Ctx, param string, requireAuth bool, fetcher func(string, string, string, string, int) (*blueskyapi.Timeline, error)) error {
94 // Get all of our keys, beeps, and bops
95 _, pds, _, oauthToken, err := GetAuthFromReq(c)
96
97 if err != nil && requireAuth {
98 return MissingAuth(c, err)
99 }
100
101 // Limits
102 limitStr := c.Query("count")
103 if limitStr == "" {
104 limitStr = "20"
105 }
106 limit, err := strconv.Atoi(limitStr)
107 if err != nil {
108 return ReturnError(c, "Invalid count provided", 195, fiber.StatusForbidden)
109 }
110 if limit > 100 {
111 limit = 100
112 }
113
114 // Check for context
115 max_id := c.Query("max_id")
116 context := ""
117
118 // Handle getting things in the past
119 if max_id != "" {
120 // Get the timeline context from the DB
121 maxIDInt, err := strconv.ParseInt(max_id, 10, 64)
122 fmt.Println("Max ID:", maxIDInt)
123 if err != nil {
124 return ReturnError(c, "Invalid max_id format", 195, fiber.StatusForbidden)
125 }
126 uri, date, _, err := bridge.TwitterMsgIdToBluesky(&maxIDInt)
127 fmt.Println("Max ID:", uri)
128 if err != nil {
129 return ReturnError(c, "max_id was not found", 144, fiber.StatusForbidden)
130 }
131 context = date.Format(time.RFC3339)
132 }
133
134 fmt.Println("Context:", context)
135 res, err := fetcher(*pds, *oauthToken, context, param, limit)
136 if err != nil {
137 return HandleBlueskyError(c, err.Error(), "app.bsky.feed.defs#timeline", func(c *fiber.Ctx) error { // dislike the "lexicon", but its fine.
138 return convert_timeline(c, param, requireAuth, fetcher)
139 })
140 }
141
142 // Caching the user DIDs efficiently
143 userDIDs := []string{}
144
145 for _, item := range res.Feed {
146 if !slices.Contains(userDIDs, item.Post.Author.DID) {
147 userDIDs = append(userDIDs, item.Post.Author.DID)
148 }
149 }
150

Callers 6

list_timelineFunction · 0.85
home_timelineFunction · 0.85
hot_post_timelineFunction · 0.85
user_timelineFunction · 0.85
media_timelineFunction · 0.85
likes_timelineFunction · 0.85

Calls 7

TwitterMsgIdToBlueskyFunction · 0.92
GetAuthFromReqFunction · 0.85
MissingAuthFunction · 0.85
ReturnErrorFunction · 0.85
HandleBlueskyErrorFunction · 0.85
TranslatePostToTweetFunction · 0.85
EncodeAndSendFunction · 0.85

Tested by

no test coverage detected