Skip to content

Commit

Permalink
just set mostRecentPostDate to now, not perfect but won't break
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerFisher committed Dec 31, 2024
1 parent 42d6276 commit 512e7aa
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions app/utils/bluesky.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const getBlueskyList = async (

let reachedEnd = false;
const newPosts: AppBskyFeedDefs.FeedViewPost[] = [];
for (const item of list) {
for (const [index, item] of list.entries()) {
if (item.post.author.handle === accountHandle) continue;
if (
AppBskyFeedDefs.isReasonRepost(item.reason) &&
Expand All @@ -104,7 +104,9 @@ export const getBlueskyList = async (
const postDate = AppBskyFeedDefs.isReasonRepost(item.reason)
? new Date(item.reason.indexedAt)
: new Date(item.post.indexedAt);
if (postDate <= checkDate && item.post.cid !== list[0].post.cid) {

// skip a few posts in case of pinned posts
if (postDate <= checkDate && index > 5) {
reachedEnd = true;
break;
}
Expand All @@ -121,30 +123,30 @@ export const getBlueskyList = async (
try {
const listTimeline = await getList();
if (listTimeline.length > 0) {
let firstPost = listTimeline[0];
let date = AppBskyFeedDefs.isReasonRepost(firstPost.reason)
? new Date(firstPost.reason.indexedAt)
: new Date(firstPost.post.indexedAt);

// Find first post that's within last 24 hours
let i = 0;
while (
i < listTimeline.length &&
Date.now() - date.getTime() > ONE_DAY_MS
) {
i++;
if (i < listTimeline.length) {
firstPost = listTimeline[i];
date = AppBskyFeedDefs.isReasonRepost(firstPost.reason)
? new Date(firstPost.reason.indexedAt)
: new Date(firstPost.post.indexedAt);
}
}
// let firstPost = listTimeline[0];
// let date = AppBskyFeedDefs.isReasonRepost(firstPost.reason)
// ? new Date(firstPost.reason.indexedAt)
// : new Date(firstPost.post.indexedAt);

// // Find first post that's within last 24 hours
// let i = 0;
// while (
// i < listTimeline.length &&
// Date.now() - date.getTime() > ONE_DAY_MS
// ) {
// i++;
// if (i < listTimeline.length) {
// firstPost = listTimeline[i];
// date = AppBskyFeedDefs.isReasonRepost(firstPost.reason)
// ? new Date(firstPost.reason.indexedAt)
// : new Date(firstPost.post.indexedAt);
// }
// }

await db
.update(list)
.set({
mostRecentPostDate: date,
mostRecentPostDate: new Date(),
})
.where(eq(list.uri, dbList.uri));
}
Expand Down

0 comments on commit 512e7aa

Please sign in to comment.