fix: properly build recipients... old logic was just plain wrong :shipit:

This commit is contained in:
Julian Lam
2024-03-09 21:09:50 -05:00
parent 66b4dc2c96
commit 1e6632392b

View File

@@ -70,13 +70,23 @@ activitypubApi.create = {};
// this might be better genericised... tbd. some of to/cc is built in mocks. // this might be better genericised... tbd. some of to/cc is built in mocks.
async function buildRecipients(object, uid) { async function buildRecipients(object, uid) {
const followers = await db.getSortedSetMembers(`followersRemote:${uid}`); const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
const { to } = object; let { to, cc } = object;
const targets = new Set(followers); to = new Set(to);
cc = new Set(cc);
// Directly address user if inReplyTo
const parentId = await posts.getPostField(object.inReplyTo, 'uid'); const parentId = await posts.getPostField(object.inReplyTo, 'uid');
if (activitypub.helpers.isUri(parentId)) { if (activitypub.helpers.isUri(parentId) && to.has(parentId)) {
to.unshift(parentId); to.add(parentId);
} }
const targets = new Set([...followers, ...to, ...cc]);
targets.delete(`${nconf.get('url')}/uid/${uid}/followers`); // followers URL not targeted
targets.delete(activitypub._constants.publicAddress); // public address not targeted
object.to = Array.from(to);
object.cc = Array.from(cc);
return { targets }; return { targets };
} }