@@ -1175,8 +1175,9 @@ func mentions_timeline(c *fiber.Ctx) error {
11751175 }
11761176
11771177 // Handle pagination
1178- context := ""
11791178 max_id := c .Query ("max_id" )
1179+ context := ""
1180+
11801181 // Handle getting things in the past
11811182 if max_id != "" {
11821183 // Get the timeline context from the DB
@@ -1187,11 +1188,49 @@ func mentions_timeline(c *fiber.Ctx) error {
11871188 }
11881189 _ , date , _ , err := bridge .TwitterMsgIdToBluesky (& maxIDInt )
11891190 if err != nil {
1190- return ReturnError (c , "max_id was not found" , 144 , fiber .StatusForbidden )
1191+ tempId := maxIDInt - 1
1192+ _ , date , _ , err = bridge .TwitterMsgIdToBluesky (& tempId )
1193+ if err != nil {
1194+ tempId = maxIDInt + 1
1195+ _ , date , _ , err = bridge .TwitterMsgIdToBluesky (& tempId )
1196+ if err != nil {
1197+ return ReturnError (c , "max_id was not found" , 144 , fiber .StatusForbidden )
1198+
1199+ }
1200+ }
11911201 }
11921202 context = date .Format (time .RFC3339 )
11931203 }
11941204
1205+ since_id := c .Query ("since_id" )
1206+ since_date := time.Time {}
1207+ hasSinceDate := false
1208+
1209+ // Handle getting things in the past
1210+ if since_id != "" {
1211+ // Get the timeline context from the DB
1212+ sinceIdInt , err := strconv .ParseInt (since_id , 10 , 64 )
1213+ if err != nil {
1214+ return ReturnError (c , "Invalid since_id format" , 195 , fiber .StatusForbidden )
1215+ }
1216+ _ , tempDate , _ , err := bridge .TwitterMsgIdToBluesky (& sinceIdInt )
1217+ if err != nil {
1218+ // the offical twitter docs recommended you add one to the id. Because of... technical debt, our IDs do not support this, and thus this must be done
1219+ tempId := sinceIdInt - 1
1220+ _ , tempDate , _ , err = bridge .TwitterMsgIdToBluesky (& tempId )
1221+ if err != nil {
1222+ tempId = sinceIdInt + 1
1223+ _ , tempDate , _ , err = bridge .TwitterMsgIdToBluesky (& tempId )
1224+ if err != nil {
1225+ return ReturnError (c , "since_id was not found" , 144 , fiber .StatusForbidden )
1226+ }
1227+ }
1228+
1229+ }
1230+ since_date = * tempDate
1231+ hasSinceDate = true
1232+ }
1233+
11951234 // Handle count
11961235 count := 20
11971236 if countStr := c .Query ("count" ); countStr != "" {
@@ -1230,32 +1269,38 @@ func mentions_timeline(c *fiber.Ctx) error {
12301269 }
12311270
12321271 // Create thread-safe maps for results
1233- var userCache sync.Map
12341272 var postCache sync.Map
12351273
12361274 // Process in parallel
12371275 var wg sync.WaitGroup
12381276
12391277 // Fetch users in chunks
1240- wg .Add (1 )
1241- go func () {
1242- defer wg .Done ()
1243- users , err := blueskyapi .GetUsersInfo (* pds , * oauthToken , usersToLookUp , false )
1244- if err == nil {
1245- for _ , user := range users {
1246- userCache .Store (user .ScreenName [strings .LastIndex (user .ScreenName , "/" )+ 1 :], user )
1247- }
1248- }
1249- }()
1278+
1279+ userChunks := chunkSlice (usersToLookUp , 25 )
1280+ wg .Add (len (userChunks ))
1281+ for _ , chunk := range userChunks {
1282+ go func () {
1283+ defer wg .Done ()
1284+ blueskyapi .GetUsersInfo (* pds , * oauthToken , chunk , false )
1285+ }()
1286+ }
12501287
12511288 // Fetch posts in parallel chunks
1289+ var wgPosts sync.WaitGroup
12521290 postChunks := chunkSlice (postsToLookUp , 10 )
1291+
12531292 for _ , chunk := range postChunks {
1254- wg .Add (1 )
1255- go func (posts []string ) {
1256- defer wg .Done ()
1257- for _ , postID := range posts {
1293+ wgPosts .Add (len (chunk ))
1294+ for _ , postID := range chunk {
1295+ go func (postID string ) {
1296+ defer wgPosts .Done ()
1297+
12581298 if post , err := blueskyapi .GetPost (* pds , * oauthToken , postID , 0 , 1 ); err == nil {
1299+ if hasSinceDate {
1300+ if ! post .Thread .Post .IndexedAt .After (since_date ) {
1301+ return
1302+ }
1303+ }
12591304 tweet := TranslatePostToTweet (
12601305 post .Thread .Post ,
12611306 func () string {
@@ -1288,8 +1333,10 @@ func mentions_timeline(c *fiber.Ctx) error {
12881333 )
12891334 postCache .Store (postID , & tweet )
12901335 }
1291- }
1292- }(chunk )
1336+
1337+ }(postID )
1338+ }
1339+ wgPosts .Wait ()
12931340 }
12941341
12951342 wg .Wait ()
@@ -1299,6 +1346,7 @@ func mentions_timeline(c *fiber.Ctx) error {
12991346 for _ , notification := range bskyNotifications .Notifications {
13001347 if post , ok := postCache .Load (notification .URI ); ok {
13011348 tweet := post .(* bridge.Tweet )
1349+
13021350 tweets = append (tweets , * tweet )
13031351 }
13041352 }
0 commit comments