diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 1c9ff7f285..c57ae3ed9a 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -91,7 +91,7 @@ Notes.assertTopic = async (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)); if (members.every(Boolean)) { @@ -118,6 +118,7 @@ Notes.assertTopic = async (uid, id) => { mainPid: tid, title: 'TBD', slug: `remote?resource=${encodeURIComponent(tid)}`, + timestamp, }), db.sortedSetAdd(`tidRemote:${tid}:posts`, timestamps, ids), Notes.assert(uid, unprocessed), @@ -125,6 +126,8 @@ Notes.assertTopic = async (uid, id) => { await Promise.all([ // must be done after .assert() Notes.assertParentChain(chain), Notes.updateTopicCounts(tid), + topics.updateLastPostTimeFromLastPid(tid), + topics.updateTeaser(tid), ]); return tid; diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.js index bc2152bb2a..aae87065e2 100644 --- a/src/controllers/activitypub/topics.js +++ b/src/controllers/activitypub/topics.js @@ -22,7 +22,7 @@ controller.get = async function (req, res, next) { 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 [ userPrivileges, settings, diff --git a/src/topics/data.js b/src/topics/data.js index 12bb949e8c..859de72395 100644 --- a/src/topics/data.js +++ b/src/topics/data.js @@ -64,11 +64,13 @@ module.exports = function (Topics) { }; 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) { - 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) { diff --git a/src/topics/posts.js b/src/topics/posts.js index 603bc465b9..6c9d53aee0 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -231,15 +231,16 @@ module.exports = function (Topics) { Topics.getLatestUndeletedReply = async function (tid) { let isDeleted = false; let index = 0; + const setPrefix = activitypub.helpers.isUri(tid) ? 'tidRemote' : 'tid'; do { /* 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) { return null; } isDeleted = await posts.getPostField(pids[0], 'deleted'); if (!isDeleted) { - return parseInt(pids[0], 10); + return pids[0]; } index += 1; } while (isDeleted);