fix: filter out system tags and prune extra tags beyond number allowed, when creating topic from remote data

This commit is contained in:
Julian Lam
2024-03-14 13:17:26 -04:00
parent e389aec288
commit 7aa56c727b

View File

@@ -6,6 +6,7 @@ const crypto = require('crypto');
const db = require('../database'); const db = require('../database');
const meta = require('../meta'); const meta = require('../meta');
const privileges = require('../privileges'); const privileges = require('../privileges');
const categories = require('../categories');
const user = require('../user'); const user = require('../user');
const topics = require('../topics'); const topics = require('../topics');
const posts = require('../posts'); const posts = require('../posts');
@@ -192,10 +193,16 @@ Notes.assertTopic = async (uid, id) => {
let tags; let tags;
if (!hasTid) { if (!hasTid) {
const systemTags = (meta.config.systemTags || '').split(',');
const maxTags = cid > 0 ? await categories.getCategoryField(cid, 'maxTags') : null;
tags = (mainPost._activitypub.tag || []) tags = (mainPost._activitypub.tag || [])
.filter(o => o.type === 'Hashtag') .filter(o => o.type === 'Hashtag' && !systemTags.include(o.name.slice(1)))
.map(o => o.name.slice(1)); .map(o => o.name.slice(1));
if (maxTags) {
tags.length = maxTags;
}
await topics.post({ await topics.post({
tid, tid,
uid: authorId, uid: authorId,