mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #11981, post immediately when canceling scheduling
This commit is contained in:
@@ -186,7 +186,7 @@ module.exports = function (Posts) {
|
|||||||
throw new Error('[[error:no-privileges]]');
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
const isMain = parseInt(data.pid, 10) === parseInt(topicData.mainPid, 10);
|
const isMain = parseInt(data.pid, 10) === parseInt(topicData.mainPid, 10);
|
||||||
if (isMain && (isNaN(data.timestamp) || data.timestamp < Date.now())) {
|
if (isMain && isNaN(data.timestamp)) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ Scheduled.handleExpired = async function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await postTids(tids);
|
||||||
|
await db.sortedSetsRemoveRangeByScore([`topics:scheduled`], '-inf', now);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function postTids(tids) {
|
||||||
let topicsData = await topics.getTopicsData(tids);
|
let topicsData = await topics.getTopicsData(tids);
|
||||||
// Filter deleted
|
// Filter deleted
|
||||||
topicsData = topicsData.filter(topicData => Boolean(topicData));
|
topicsData = topicsData.filter(topicData => Boolean(topicData));
|
||||||
@@ -43,9 +48,8 @@ Scheduled.handleExpired = async function () {
|
|||||||
updateUserLastposttimes(uids, topicsData),
|
updateUserLastposttimes(uids, topicsData),
|
||||||
updateGroupPosts(uids, topicsData),
|
updateGroupPosts(uids, topicsData),
|
||||||
...topicsData.map(topicData => unpin(topicData.tid, topicData)),
|
...topicsData.map(topicData => unpin(topicData.tid, topicData)),
|
||||||
db.sortedSetsRemoveRangeByScore([`topics:scheduled`], '-inf', now)
|
|
||||||
));
|
));
|
||||||
};
|
}
|
||||||
|
|
||||||
// topics/tools.js#pin/unpin would block non-admins/mods, thus the local versions
|
// topics/tools.js#pin/unpin would block non-admins/mods, thus the local versions
|
||||||
Scheduled.pin = async function (tid, topicData) {
|
Scheduled.pin = async function (tid, topicData) {
|
||||||
@@ -62,23 +66,27 @@ Scheduled.pin = async function (tid, topicData) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Scheduled.reschedule = async function ({ cid, tid, timestamp, uid }) {
|
Scheduled.reschedule = async function ({ cid, tid, timestamp, uid }) {
|
||||||
const mainPid = await topics.getTopicField(tid, 'mainPid');
|
if (timestamp < Date.now()) {
|
||||||
await Promise.all([
|
await postTids([tid]);
|
||||||
db.sortedSetsAdd([
|
} else {
|
||||||
'topics:scheduled',
|
const mainPid = await topics.getTopicField(tid, 'mainPid');
|
||||||
`uid:${uid}:topics`,
|
await Promise.all([
|
||||||
'topics:tid',
|
db.sortedSetsAdd([
|
||||||
`cid:${cid}:uid:${uid}:tids`,
|
'topics:scheduled',
|
||||||
], timestamp, tid),
|
`uid:${uid}:topics`,
|
||||||
posts.setPostField(mainPid, 'timestamp', timestamp),
|
'topics:tid',
|
||||||
db.sortedSetsAdd([
|
`cid:${cid}:uid:${uid}:tids`,
|
||||||
'posts:pid',
|
], timestamp, tid),
|
||||||
`uid:${uid}:posts`,
|
posts.setPostField(mainPid, 'timestamp', timestamp),
|
||||||
`cid:${cid}:uid:${uid}:pids`,
|
db.sortedSetsAdd([
|
||||||
], timestamp, mainPid),
|
'posts:pid',
|
||||||
shiftPostTimes(tid, timestamp),
|
`uid:${uid}:posts`,
|
||||||
]);
|
`cid:${cid}:uid:${uid}:pids`,
|
||||||
return topics.updateLastPostTimeFromLastPid(tid);
|
], timestamp, mainPid),
|
||||||
|
shiftPostTimes(tid, timestamp),
|
||||||
|
]);
|
||||||
|
await topics.updateLastPostTimeFromLastPid(tid);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function unpin(tid, topicData) {
|
function unpin(tid, topicData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user