mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #11530, fix topic rescheduling
don't display scheduled posts in group page when topic is rescheduled update post sorted sets with new timestamp when post is published update group posts zset fix markTopicRead if topic was read while it was still hidden
This commit is contained in:
@@ -6,7 +6,7 @@ const posts = require('../posts');
|
||||
|
||||
module.exports = function (Groups) {
|
||||
Groups.onNewPostMade = async function (postData) {
|
||||
if (!parseInt(postData.uid, 10)) {
|
||||
if (!parseInt(postData.uid, 10) || postData.timestamp > Date.now()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ module.exports = function (Groups) {
|
||||
};
|
||||
|
||||
async function truncateMemberPosts(groupName) {
|
||||
let lastPid = await db.getSortedSetRevRange(`group:${groupName}:member:pids`, 10, 10);
|
||||
let lastPid = await db.getSortedSetRevRangeByScore(`group:${groupName}:member:pids`, 10, 1, Date.now(), '-inf');
|
||||
lastPid = lastPid[0];
|
||||
if (!parseInt(lastPid, 10)) {
|
||||
return;
|
||||
@@ -37,7 +37,7 @@ module.exports = function (Groups) {
|
||||
|
||||
Groups.getLatestMemberPosts = async function (groupName, max, uid) {
|
||||
const [allPids, groupData] = await Promise.all([
|
||||
db.getSortedSetRevRange(`group:${groupName}:member:pids`, 0, max - 1),
|
||||
db.getSortedSetRevRangeByScore(`group:${groupName}:member:pids`, 0, max, Date.now(), '-inf'),
|
||||
Groups.getGroupFields(groupName, ['memberPostCids']),
|
||||
]);
|
||||
const cids = groupData.memberPostCidsArray;
|
||||
|
||||
@@ -8,6 +8,7 @@ const db = require('../database');
|
||||
const posts = require('../posts');
|
||||
const socketHelpers = require('../socket.io/helpers');
|
||||
const topics = require('./index');
|
||||
const groups = require('../groups');
|
||||
const user = require('../user');
|
||||
|
||||
const Scheduled = module.exports;
|
||||
@@ -40,6 +41,7 @@ Scheduled.handleExpired = async function () {
|
||||
await Promise.all([].concat(
|
||||
sendNotifications(uids, topicsData),
|
||||
updateUserLastposttimes(uids, topicsData),
|
||||
updateGroupPosts(uids, topicsData),
|
||||
...topicsData.map(topicData => unpin(topicData.tid, topicData)),
|
||||
db.sortedSetsRemoveRangeByScore([`topics:scheduled`], '-inf', now)
|
||||
));
|
||||
@@ -69,6 +71,11 @@ Scheduled.reschedule = async function ({ cid, tid, timestamp, uid }) {
|
||||
`cid:${cid}:uid:${uid}:tids`,
|
||||
], timestamp, tid),
|
||||
posts.setPostField(mainPid, 'timestamp', timestamp),
|
||||
db.sortedSetsAdd([
|
||||
'posts:pid',
|
||||
`uid:${uid}:posts`,
|
||||
`cid:${cid}:uid:${uid}:pids`,
|
||||
], timestamp, mainPid),
|
||||
shiftPostTimes(tid, timestamp),
|
||||
]);
|
||||
return topics.updateLastPostTimeFromLastPid(tid);
|
||||
@@ -124,6 +131,16 @@ async function updateUserLastposttimes(uids, topicsData) {
|
||||
return Promise.all(uidsToUpdate.map(uid => user.setUserField(uid, 'lastposttime', tstampByUid[uid])));
|
||||
}
|
||||
|
||||
async function updateGroupPosts(uids, topicsData) {
|
||||
const postsData = await posts.getPostsData(topicsData.map(t => t && t.mainPid));
|
||||
await Promise.all(postsData.map(async (post, i) => {
|
||||
if (topicsData[i]) {
|
||||
post.cid = topicsData[i].cid;
|
||||
await groups.onNewPostMade(post);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async function shiftPostTimes(tid, timestamp) {
|
||||
const pids = (await posts.getPidsFromSet(`tid:${tid}:posts`, 0, -1, false));
|
||||
// Leaving other related score values intact, since they reflect post order correctly, and it seems that's good enough
|
||||
|
||||
@@ -291,14 +291,16 @@ module.exports = function (Topics) {
|
||||
db.sortedSetScores(`uid:${uid}:tids_read`, tids),
|
||||
]);
|
||||
|
||||
const topics = topicScores.filter((t, i) => t.lastposttime && (!userScores[i] || userScores[i] < t.lastposttime));
|
||||
const now = Date.now();
|
||||
const topics = topicScores.filter(
|
||||
(t, i) => t.lastposttime && (!userScores[i] || userScores[i] < t.lastposttime || userScores[i] > now)
|
||||
);
|
||||
tids = topics.map(t => t.tid);
|
||||
|
||||
if (!tids.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const scores = topics.map(topic => (topic.scheduled ? topic.lastposttime : now));
|
||||
const [topicData] = await Promise.all([
|
||||
Topics.getTopicsFields(tids, ['cid']),
|
||||
|
||||
Reference in New Issue
Block a user