fix: #13374, updates to posts.edit to handle remote content updates better

This commit is contained in:
Julian Lam
2025-05-06 10:44:47 -04:00
parent 625ce96f94
commit b433848971
4 changed files with 25 additions and 17 deletions

View File

@@ -95,6 +95,7 @@ inbox.update = async (req) => {
switch (true) {
case isNote: {
const postData = await activitypub.mocks.post(object);
postData.tags = await activitypub.notes._normalizeTags(postData._activitypub.tag, postData.cid);
await posts.edit(postData);
const isDeleted = await posts.getPostField(object.id, 'deleted');
if (isDeleted) {

View File

@@ -355,12 +355,13 @@ Mocks.post = async (objects) => {
uid,
pid,
// tid, --> purposely omitted
name,
content,
sourceContent,
timestamp,
toPid,
title: name, // used in post.edit
edited,
editor: edited ? uid : undefined,
_activitypub: { to, cc, audience, attachment, tag, url, image },

View File

@@ -27,6 +27,24 @@ async function unlock(value) {
await db.deleteObjectField('locks', value);
}
Notes._normalizeTags = async (tag, cid) => {
const systemTags = (meta.config.systemTags || '').split(',');
const maxTags = await categories.getCategoryField(cid, 'maxTags');
const tags = (tag || [])
.map((tag) => {
tag.name = tag.name.startsWith('#') ? tag.name.slice(1) : tag.name;
return tag;
})
.filter(o => o.type === 'Hashtag' && !systemTags.includes(o.name))
.map(t => t.name);
if (tags.length > maxTags) {
tags.length = maxTags;
}
return tags;
};
Notes.assert = async (uid, input, options = { skipChecks: false }) => {
/**
* Given the id or object of any as:Note, either retrieves the full context (if resolvable),
@@ -166,22 +184,9 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
const count = unprocessed.length;
activitypub.helpers.log(`[notes/assert] ${count} new note(s) found.`);
let tags;
if (!hasTid) {
const { to, cc, attachment } = mainPost._activitypub;
const systemTags = (meta.config.systemTags || '').split(',');
const maxTags = await categories.getCategoryField(cid, 'maxTags');
tags = (mainPost._activitypub.tag || [])
.map((tag) => {
tag.name = tag.name.startsWith('#') ? tag.name.slice(1) : tag.name;
return tag;
})
.filter(o => o.type === 'Hashtag' && !systemTags.includes(o.name))
.map(t => t.name);
if (tags.length > maxTags) {
tags.length = maxTags;
}
const tags = Notes._normalizeTags(mainPost._activitypub.tag || []);
await Promise.all([
topics.post({

View File

@@ -35,7 +35,7 @@ module.exports = function (Posts) {
await scheduledTopicCheck(data, topicData);
data.content = data.content === null ? postData.content : data.content;
const oldContent = postData.content; // for diffing purposes
const oldContent = postData.sourceContent || postData.content; // for diffing purposes
const editPostData = getEditPostData(data, topicData, postData);
if (data.handle) {
@@ -55,7 +55,7 @@ module.exports = function (Posts) {
]);
await Posts.setPostFields(data.pid, result.post);
const contentChanged = data.content !== oldContent ||
const contentChanged = ((data.sourceContent || data.content) !== oldContent) ||
topic.renamed ||
topic.tagsupdated;
@@ -194,6 +194,7 @@ module.exports = function (Posts) {
function getEditPostData(data, topicData, postData) {
const editPostData = {
content: data.content,
sourceContent: data.sourceContent,
editor: data.uid,
};