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) { switch (true) {
case isNote: { case isNote: {
const postData = await activitypub.mocks.post(object); const postData = await activitypub.mocks.post(object);
postData.tags = await activitypub.notes._normalizeTags(postData._activitypub.tag, postData.cid);
await posts.edit(postData); await posts.edit(postData);
const isDeleted = await posts.getPostField(object.id, 'deleted'); const isDeleted = await posts.getPostField(object.id, 'deleted');
if (isDeleted) { if (isDeleted) {

View File

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

View File

@@ -27,6 +27,24 @@ async function unlock(value) {
await db.deleteObjectField('locks', 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 }) => { Notes.assert = async (uid, input, options = { skipChecks: false }) => {
/** /**
* Given the id or object of any as:Note, either retrieves the full context (if resolvable), * 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; const count = unprocessed.length;
activitypub.helpers.log(`[notes/assert] ${count} new note(s) found.`); activitypub.helpers.log(`[notes/assert] ${count} new note(s) found.`);
let tags;
if (!hasTid) { if (!hasTid) {
const { to, cc, attachment } = mainPost._activitypub; const { to, cc, attachment } = mainPost._activitypub;
const systemTags = (meta.config.systemTags || '').split(','); const tags = Notes._normalizeTags(mainPost._activitypub.tag || []);
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;
}
await Promise.all([ await Promise.all([
topics.post({ topics.post({

View File

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