fix: more duplicate detection in to/cc

This commit is contained in:
Julian Lam
2024-03-11 11:40:24 -04:00
parent 17c55922d4
commit ceab77e43b

View File

@@ -208,8 +208,8 @@ Mocks.note = async (post) => {
const raw = await posts.getPostField(post.pid, 'content'); const raw = await posts.getPostField(post.pid, 'content');
// todo: post visibility // todo: post visibility
const to = [activitypub._constants.publicAddress]; const to = new Set([activitypub._constants.publicAddress]);
const cc = [`${nconf.get('url')}/uid/${post.user.uid}/followers`]; const cc = new Set([`${nconf.get('url')}/uid/${post.user.uid}/followers`]);
let inReplyTo = null; let inReplyTo = null;
let name = null; let name = null;
@@ -217,10 +217,10 @@ Mocks.note = async (post) => {
if (post.toPid) { // direct reply if (post.toPid) { // direct reply
inReplyTo = utils.isNumber(post.toPid) ? `${nconf.get('url')}/post/${post.toPid}` : post.toPid; inReplyTo = utils.isNumber(post.toPid) ? `${nconf.get('url')}/post/${post.toPid}` : post.toPid;
const parentId = await posts.getPostField(post.toPid, 'uid'); const parentId = await posts.getPostField(post.toPid, 'uid');
to.unshift(utils.isNumber(parentId) ? `${nconf.get('url')}/uid/${parentId}` : parentId); to.add(utils.isNumber(parentId) ? `${nconf.get('url')}/uid/${parentId}` : parentId);
} else if (!post.isMainPost) { // reply to OP } else if (!post.isMainPost) { // reply to OP
inReplyTo = utils.isNumber(post.topic.mainPid) ? `${nconf.get('url')}/post/${post.topic.mainPid}` : post.topic.mainPid; inReplyTo = utils.isNumber(post.topic.mainPid) ? `${nconf.get('url')}/post/${post.topic.mainPid}` : post.topic.mainPid;
to.unshift(utils.isNumber(post.topic.uid) ? `${nconf.get('url')}/uid/${post.topic.uid}` : post.topic.uid); to.add(utils.isNumber(post.topic.uid) ? `${nconf.get('url')}/uid/${post.topic.uid}` : post.topic.uid);
} else { // new topic } else { // new topic
name = await topics.getTitleByPid(post.pid); name = await topics.getTitleByPid(post.pid);
tag = post.topic.tags.map(tag => ({ tag = post.topic.tags.map(tag => ({
@@ -251,13 +251,15 @@ Mocks.note = async (post) => {
}; };
})); }));
to.push(...Array.from(matches).reduce((ids, { id }) => { Array.from(matches)
if (!utils.isNumber(id)) { .reduce((ids, { id }) => {
ids.push(id); if (!utils.isNumber(id) && !to.has(id) && !cc.has(id)) {
} ids.push(id);
}
return ids; return ids;
}, [])); }, [])
.forEach(id => cc.add(id));
} }
} }
@@ -265,8 +267,8 @@ Mocks.note = async (post) => {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
id, id,
type: 'Note', type: 'Note',
to, to: Array.from(to),
cc, cc: Array.from(cc),
inReplyTo, inReplyTo,
published, published,
url: id, url: id,