Skip to content

Commit 51f9ab4

Browse files
committed
fix: rethink logic for scheduled posts
This makes things cleaner and shows the right “time since” for scheduled posts.
1 parent c9a1283 commit 51f9ab4

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

api/resolvers/item.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ export const muteClause = me =>
260260

261261
export const scheduledOrMine = (me) => {
262262
return me
263-
? `("Item"."scheduledAt" IS NULL OR "Item"."userId" = ${me.id})`
264-
: '"Item"."scheduledAt" IS NULL'
263+
? `("Item"."scheduledAt" IS NULL OR "Item"."scheduledAt" <= now() OR "Item"."userId" = ${me.id})`
264+
: '("Item"."scheduledAt" IS NULL OR "Item"."scheduledAt" <= now())'
265265
}
266266

267267
const HIDE_NSFW_CLAUSE = '("Sub"."nsfw" = FALSE OR "Sub"."nsfw" IS NULL)'
@@ -1125,12 +1125,10 @@ export default {
11251125

11261126
const publishTime = new Date()
11271127

1128-
// Publish immediately with current timestamp
1128+
// Publish immediately - keep original createdAt and scheduledAt
11291129
const updatedItem = await models.item.update({
11301130
where: { id: Number(id) },
11311131
data: {
1132-
scheduledAt: null,
1133-
createdAt: publishTime,
11341132
updatedAt: publishTime
11351133
}
11361134
})

lib/apollo.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ function getClient (uri) {
332332

333333
return reactiveVar()
334334
}
335+
},
336+
// Ensure scheduled post state changes are properly reflected in cache
337+
scheduledAt: {
338+
merge (existing, incoming) {
339+
return incoming
340+
}
335341
}
336342
}
337343
}

worker/publishScheduledPosts.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ export async function publishScheduledPost ({ data: { itemId }, models, lnd }) {
1919

2020
const publishTime = new Date()
2121

22-
// Update the item to be published with new timestamp
22+
// Update the item to be published - keep original createdAt and scheduledAt
2323
await models.item.update({
2424
where: { id: itemId },
2525
data: {
26-
scheduledAt: null,
27-
createdAt: publishTime,
2826
updatedAt: publishTime
2927
}
3028
})

0 commit comments

Comments
 (0)