mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
fix: #9681, update posts in queue if target tid is merged
This commit is contained in:
@@ -48,9 +48,14 @@ module.exports = function (Posts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter by tid if present
|
// Filter by tid if present
|
||||||
if (isFinite(filter.tid)) {
|
if (utils.isNumber(filter.tid)) {
|
||||||
const tid = parseInt(filter.tid, 10);
|
const tid = parseInt(filter.tid, 10);
|
||||||
postData = postData.filter(item => item.data.tid && parseInt(item.data.tid, 10) === tid);
|
postData = postData.filter(item => item.data.tid && parseInt(item.data.tid, 10) === tid);
|
||||||
|
} else if (Array.isArray(filter.tid)) {
|
||||||
|
const tids = filter.tid.map(tid => parseInt(tid, 10));
|
||||||
|
postData = postData.filter(
|
||||||
|
item => item.data.tid && tids.includes(parseInt(item.data.tid, 10))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return postData;
|
return postData;
|
||||||
@@ -330,4 +335,18 @@ module.exports = function (Posts) {
|
|||||||
}
|
}
|
||||||
return isModerator && isModeratorOfTargetCid;
|
return isModerator && isModeratorOfTargetCid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Posts.updateQueuedPostsTopic = async function (newTid, tids) {
|
||||||
|
const postData = await Posts.getQueuedPosts({ tid: tids }, { metadata: false });
|
||||||
|
if (postData.length) {
|
||||||
|
postData.forEach((post) => {
|
||||||
|
post.data.tid = newTid;
|
||||||
|
});
|
||||||
|
await db.setObjectBulk(
|
||||||
|
postData.map(p => `post:queue:${p.id}`),
|
||||||
|
postData.map(p => ({ data: JSON.stringify(p.data) }))
|
||||||
|
);
|
||||||
|
cache.del('post-queue');
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ async function postReply(socket, data) {
|
|||||||
'downvote:disabled': meta.config['downvote:disabled'] === 1,
|
'downvote:disabled': meta.config['downvote:disabled'] === 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.emit('event:new_post', result);
|
if (socket.emit) {
|
||||||
|
socket.emit('event:new_post', result);
|
||||||
|
}
|
||||||
user.updateOnlineUsers(socket.uid);
|
user.updateOnlineUsers(socket.uid);
|
||||||
|
|
||||||
socketHelpers.notifyNew(socket.uid, 'newPost', result);
|
socketHelpers.notifyNew(socket.uid, 'newPost', result);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const posts = require('../posts');
|
||||||
|
|
||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
Topics.merge = async function (tids, uid, options) {
|
Topics.merge = async function (tids, uid, options) {
|
||||||
@@ -38,7 +39,10 @@ module.exports = function (Topics) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await updateViewCount(mergeIntoTid, tids);
|
await Promise.all([
|
||||||
|
posts.updateQueuedPostsTopic(mergeIntoTid, otherTids),
|
||||||
|
updateViewCount(mergeIntoTid, tids),
|
||||||
|
]);
|
||||||
|
|
||||||
plugins.hooks.fire('action:topic.merge', {
|
plugins.hooks.fire('action:topic.merge', {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
|
|||||||
@@ -1147,13 +1147,31 @@ describe('Post\'s', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should bypass post queue if user is in exempt group', (done) => {
|
it('should bypass post queue if user is in exempt group', async () => {
|
||||||
|
const oldValue = meta.config.groupsExemptFromPostQueue;
|
||||||
meta.config.groupsExemptFromPostQueue = ['registered-users'];
|
meta.config.groupsExemptFromPostQueue = ['registered-users'];
|
||||||
socketTopics.post({ uid: uid, emit: () => {} }, { title: 'should not be queued', content: 'topic content', cid: cid }, (err, result) => {
|
const uid = await user.create({ username: 'mergeexemptuser' });
|
||||||
assert.ifError(err);
|
const result = await socketTopics.post({ uid: uid, emit: () => {} }, { title: 'should not be queued', content: 'topic content', cid: cid });
|
||||||
assert.strictEqual(result.title, 'should not be queued');
|
assert.strictEqual(result.title, 'should not be queued');
|
||||||
done();
|
meta.config.groupsExemptFromPostQueue = oldValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update queued post\'s topic if target topic is merged', async () => {
|
||||||
|
const uid = await user.create({ username: 'mergetestsuser' });
|
||||||
|
const result1 = await socketTopics.post({ uid: globalModUid }, { title: 'topic A', content: 'topic A content', cid: cid });
|
||||||
|
const result2 = await socketTopics.post({ uid: globalModUid }, { title: 'topic B', content: 'topic B content', cid: cid });
|
||||||
|
|
||||||
|
const result = await socketPosts.reply({ uid: uid }, { content: 'the moved queued post', tid: result1.tid });
|
||||||
|
|
||||||
|
await topics.merge([
|
||||||
|
result1.tid, result2.tid,
|
||||||
|
], globalModUid, { mainTid: result2.tid });
|
||||||
|
|
||||||
|
let postData = await posts.getQueuedPosts();
|
||||||
|
postData = postData.filter(p => p.data.tid === result2.tid);
|
||||||
|
assert.strictEqual(postData.length, 1);
|
||||||
|
assert.strictEqual(postData[0].data.content, 'the moved queued post');
|
||||||
|
assert.strictEqual(postData[0].data.tid, result2.tid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user