mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: followers url filtering logic, #12834
This commit is contained in:
@@ -195,27 +195,26 @@ Notes.assertPrivate = async (object) => {
|
|||||||
// Given an object, adds it to an existing chat or creates a new chat otherwise
|
// Given an object, adds it to an existing chat or creates a new chat otherwise
|
||||||
// todo: context stuff
|
// todo: context stuff
|
||||||
|
|
||||||
const recipients = new Set([...object.to, ...object.cc]);
|
|
||||||
|
|
||||||
// Remove follower urls
|
|
||||||
const isFollowerUrl = await db.isObjectFields('followersUrl:uid', Array.from(recipients));
|
|
||||||
Array.from(recipients).forEach((id, idx) => {
|
|
||||||
if (isFollowerUrl[idx]) {
|
|
||||||
recipients.delete(id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const localUids = [];
|
const localUids = [];
|
||||||
const recipientsResolved = new Set([...recipients]);
|
const recipients = new Set([...object.to, ...object.cc]);
|
||||||
await Promise.all(Array.from(recipients).map(async (value) => {
|
await Promise.all(Array.from(recipients).map(async (value) => {
|
||||||
const { type, id } = await activitypub.helpers.resolveLocalId(value);
|
const { type, id } = await activitypub.helpers.resolveLocalId(value);
|
||||||
if (type === 'user') {
|
if (type === 'user') {
|
||||||
localUids.push(id);
|
localUids.push(id);
|
||||||
recipientsResolved.delete(value);
|
recipients.delete(value);
|
||||||
recipientsResolved.add(parseInt(id, 10));
|
recipients.add(parseInt(id, 10));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Trim recipient list down to asserted actors (and local users) only
|
||||||
|
await activitypub.actors.assert([...recipients]);
|
||||||
|
const exists = await user.exists([...recipients]);
|
||||||
|
Array.from(recipients).forEach((uid, idx) => {
|
||||||
|
if (!exists[idx]) {
|
||||||
|
recipients.delete(uid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Locate the roomId based on `inReplyTo`
|
// Locate the roomId based on `inReplyTo`
|
||||||
let roomId;
|
let roomId;
|
||||||
const resolved = await activitypub.helpers.resolveLocalId(object.inReplyTo);
|
const resolved = await activitypub.helpers.resolveLocalId(object.inReplyTo);
|
||||||
@@ -229,9 +228,7 @@ Notes.assertPrivate = async (object) => {
|
|||||||
const participantUids = participants.map(user => user.uid);
|
const participantUids = participants.map(user => user.uid);
|
||||||
if (roomId) {
|
if (roomId) {
|
||||||
const omitted = participants.filter((user) => {
|
const omitted = participants.filter((user) => {
|
||||||
// todo: this could use recipientsResolved
|
const { uid } = user;
|
||||||
let { uid } = user;
|
|
||||||
uid = utils.isNumber(uid) ? `${nconf.get('url')}/uid/${uid}` : uid;
|
|
||||||
return !recipients.has(uid) && uid !== object.attributedTo;
|
return !recipients.has(uid) && uid !== object.attributedTo;
|
||||||
});
|
});
|
||||||
if (omitted.length) {
|
if (omitted.length) {
|
||||||
@@ -248,11 +245,11 @@ Notes.assertPrivate = async (object) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!roomId) {
|
if (!roomId) {
|
||||||
roomId = await messaging.newRoom(object.attributedTo, { uids: [...recipientsResolved] });
|
roomId = await messaging.newRoom(object.attributedTo, { uids: [...recipients] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add any new members to the chat
|
// Add any new members to the chat
|
||||||
const added = Array.from(recipientsResolved).filter(uid => !participantUids.includes(uid));
|
const added = Array.from(recipients).filter(uid => !participantUids.includes(uid));
|
||||||
const assertion = await activitypub.actors.assert(added);
|
const assertion = await activitypub.actors.assert(added);
|
||||||
if (assertion) {
|
if (assertion) {
|
||||||
await messaging.addUsersToRoom(object.attributedTo, added, roomId);
|
await messaging.addUsersToRoom(object.attributedTo, added, roomId);
|
||||||
|
|||||||
Reference in New Issue
Block a user