Skip to content

Commit

Permalink
fix: also wait when posting split posts
Browse files Browse the repository at this point in the history
  • Loading branch information
thilobillerbeck committed Nov 18, 2024
1 parent c4f3bfa commit ba36e60
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions lib/tasks/mastodonToBluesky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default async function taskMastodonToBluesky() {

const repostsInThisRun: { [tootId: string]: ReplyRef } = {};

for (const post of posts) {
for (const [postIdx, post] of posts.entries()) {
try {
if (
post.in_reply_to_account_id !== user.mastodonUid &&
Expand Down Expand Up @@ -132,7 +132,17 @@ export default async function taskMastodonToBluesky() {
}
}

for (const postBsky of postsBsky) {

for (const [postBskyIdx, postBsky] of postsBsky.entries()) {
if(postsBsky.length > 1) {
logSchedulerEvent(
user.name,
user.mastodonInstance.url,
"REPOSTER",
`posting ${postBskyIdx + 1}/${postsBsky.length} (${post.id})`
);
}

if (repRef.parent !== undefined) {
const discoveredParents = await blueskyClient.getPosts({
uris: [repRef.parent?.uri],
Expand Down Expand Up @@ -190,12 +200,30 @@ export default async function taskMastodonToBluesky() {
return;
}
}

if(postBskyIdx < postsBsky.length - 1) {
logSchedulerEvent(
user.name,
user.mastodonInstance.url,
"REPOSTER",
`waiting ${getBlueskyApiWaittime()}ms for next post (split post)`
);
await new Promise((resolve) => setTimeout(resolve, getBlueskyApiWaittime()));
}
}

repostsInThisRun[post.id] = repRef;
await storeRepostRecord(user.id, post.id, repRef);
await updateLastPostTime(user.id, new Date(post.created_at));
await new Promise((resolve) => setTimeout(resolve, getBlueskyApiWaittime()));
if(postIdx < posts.length - 1) {
logSchedulerEvent(
user.name,
user.mastodonInstance.url,
"REPOSTER",
`waiting ${getBlueskyApiWaittime()}ms for next post (thread)`
);
await new Promise((resolve) => setTimeout(resolve, getBlueskyApiWaittime()));
}
} catch (err) {
logSchedulerEvent(
user.name,
Expand Down

0 comments on commit ba36e60

Please sign in to comment.