mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: saving teaserPid, timestamp, lastposttime in topic, fixed post index issue in loading topics
This commit is contained in:
@@ -91,7 +91,7 @@ Notes.assertTopic = async (uid, id) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const chain = Array.from(await Notes.getParentChain(uid, id));
|
const chain = Array.from(await Notes.getParentChain(uid, id));
|
||||||
const { pid: tid, uid: authorId } = chain[chain.length - 1];
|
const { pid: tid, uid: authorId, timestamp } = chain[chain.length - 1];
|
||||||
|
|
||||||
const members = await db.isSortedSetMembers(`tidRemote:${tid}:posts`, chain.map(p => p.pid));
|
const members = await db.isSortedSetMembers(`tidRemote:${tid}:posts`, chain.map(p => p.pid));
|
||||||
if (members.every(Boolean)) {
|
if (members.every(Boolean)) {
|
||||||
@@ -118,6 +118,7 @@ Notes.assertTopic = async (uid, id) => {
|
|||||||
mainPid: tid,
|
mainPid: tid,
|
||||||
title: 'TBD',
|
title: 'TBD',
|
||||||
slug: `remote?resource=${encodeURIComponent(tid)}`,
|
slug: `remote?resource=${encodeURIComponent(tid)}`,
|
||||||
|
timestamp,
|
||||||
}),
|
}),
|
||||||
db.sortedSetAdd(`tidRemote:${tid}:posts`, timestamps, ids),
|
db.sortedSetAdd(`tidRemote:${tid}:posts`, timestamps, ids),
|
||||||
Notes.assert(uid, unprocessed),
|
Notes.assert(uid, unprocessed),
|
||||||
@@ -125,6 +126,8 @@ Notes.assertTopic = async (uid, id) => {
|
|||||||
await Promise.all([ // must be done after .assert()
|
await Promise.all([ // must be done after .assert()
|
||||||
Notes.assertParentChain(chain),
|
Notes.assertParentChain(chain),
|
||||||
Notes.updateTopicCounts(tid),
|
Notes.updateTopicCounts(tid),
|
||||||
|
topics.updateLastPostTimeFromLastPid(tid),
|
||||||
|
topics.updateTeaser(tid),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return tid;
|
return tid;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ controller.get = async function (req, res, next) {
|
|||||||
|
|
||||||
const tid = await notes.assertTopic(req.uid, req.query.resource);
|
const tid = await notes.assertTopic(req.uid, req.query.resource);
|
||||||
|
|
||||||
let postIndex = await db.sortedSetRank(`tidRemote:${tid}:posts`, req.query.resource);
|
let postIndex = Math.max(1, await db.sortedSetRank(`tidRemote:${tid}:posts`, req.query.resource));
|
||||||
const [
|
const [
|
||||||
userPrivileges,
|
userPrivileges,
|
||||||
settings,
|
settings,
|
||||||
|
|||||||
@@ -64,11 +64,13 @@ module.exports = function (Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.setTopicField = async function (tid, field, value) {
|
Topics.setTopicField = async function (tid, field, value) {
|
||||||
await db.setObjectField(`topic:${tid}`, field, value);
|
const setPrefix = activitypub.helpers.isUri(tid) ? 'topicRemote' : 'topic';
|
||||||
|
await db.setObjectField(`${setPrefix}:${tid}`, field, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.setTopicFields = async function (tid, data) {
|
Topics.setTopicFields = async function (tid, data) {
|
||||||
await db.setObject(`topic:${tid}`, data);
|
const setPrefix = activitypub.helpers.isUri(tid) ? 'topicRemote' : 'topic';
|
||||||
|
await db.setObject(`${setPrefix}:${tid}`, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.deleteTopicField = async function (tid, field) {
|
Topics.deleteTopicField = async function (tid, field) {
|
||||||
|
|||||||
@@ -231,15 +231,16 @@ module.exports = function (Topics) {
|
|||||||
Topics.getLatestUndeletedReply = async function (tid) {
|
Topics.getLatestUndeletedReply = async function (tid) {
|
||||||
let isDeleted = false;
|
let isDeleted = false;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
const setPrefix = activitypub.helpers.isUri(tid) ? 'tidRemote' : 'tid';
|
||||||
do {
|
do {
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
const pids = await db.getSortedSetRevRange(`tid:${tid}:posts`, index, index);
|
const pids = await db.getSortedSetRevRange(`${setPrefix}:${tid}:posts`, index, index);
|
||||||
if (!pids.length) {
|
if (!pids.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
isDeleted = await posts.getPostField(pids[0], 'deleted');
|
isDeleted = await posts.getPostField(pids[0], 'deleted');
|
||||||
if (!isDeleted) {
|
if (!isDeleted) {
|
||||||
return parseInt(pids[0], 10);
|
return pids[0];
|
||||||
}
|
}
|
||||||
index += 1;
|
index += 1;
|
||||||
} while (isDeleted);
|
} while (isDeleted);
|
||||||
|
|||||||
Reference in New Issue
Block a user