mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
feat: on post edit, also target anyone who announced the post and their followers
re: #12537
This commit is contained in:
@@ -94,13 +94,12 @@ activitypubApi.unfollow = enabledCheck(async (caller, { type, id, actor }) => {
|
|||||||
activitypubApi.create = {};
|
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, { pid, uid }) {
|
||||||
const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
|
const followers = await db.getSortedSetMembers(`followersRemote:${uid}`);
|
||||||
let { to, cc } = object;
|
let { to, cc } = object;
|
||||||
to = new Set(to);
|
to = new Set(to);
|
||||||
cc = new Set(cc);
|
cc = new Set(cc);
|
||||||
|
|
||||||
|
|
||||||
// Directly address user if inReplyTo
|
// 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) && to.has(parentId)) {
|
if (activitypub.helpers.isUri(parentId) && to.has(parentId)) {
|
||||||
@@ -111,6 +110,15 @@ async function buildRecipients(object, uid) {
|
|||||||
targets.delete(`${nconf.get('url')}/uid/${uid}/followers`); // followers URL not targeted
|
targets.delete(`${nconf.get('url')}/uid/${uid}/followers`); // followers URL not targeted
|
||||||
targets.delete(activitypub._constants.publicAddress); // public address not targeted
|
targets.delete(activitypub._constants.publicAddress); // public address not targeted
|
||||||
|
|
||||||
|
// Announcers and their followers
|
||||||
|
if (pid) {
|
||||||
|
const announcers = (await activitypub.notes.announce.list({ pid })).map(({ actor }) => actor);
|
||||||
|
const announcersFollowers = (await user.getUsersFields(announcers, ['followersUrl']))
|
||||||
|
.filter(o => o.hasOwnProperty('followersUrl'))
|
||||||
|
.map(({ followersUrl }) => followersUrl);
|
||||||
|
[...announcers, ...announcersFollowers].forEach(uri => targets.add(uri));
|
||||||
|
}
|
||||||
|
|
||||||
object.to = Array.from(to);
|
object.to = Array.from(to);
|
||||||
object.cc = Array.from(cc);
|
object.cc = Array.from(cc);
|
||||||
return { targets };
|
return { targets };
|
||||||
@@ -129,7 +137,7 @@ activitypubApi.create.post = enabledCheck(async (caller, { pid }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const object = await activitypub.mocks.note(post);
|
const object = await activitypub.mocks.note(post);
|
||||||
const { targets } = await buildRecipients(object, post.user.uid);
|
const { targets } = await buildRecipients(object, { uid: post.user.uid });
|
||||||
const { cid } = post.category;
|
const { cid } = post.category;
|
||||||
const followers = await activitypub.notes.getCategoryFollowers(cid);
|
const followers = await activitypub.notes.getCategoryFollowers(cid);
|
||||||
|
|
||||||
@@ -175,7 +183,7 @@ activitypubApi.update.profile = enabledCheck(async (caller, { uid }) => {
|
|||||||
|
|
||||||
activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
|
activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
|
||||||
const object = await activitypub.mocks.note(post);
|
const object = await activitypub.mocks.note(post);
|
||||||
const { targets } = await buildRecipients(object, post.user.uid);
|
const { targets } = await buildRecipients(object, { pid: post.pid, uid: post.user.uid });
|
||||||
|
|
||||||
const allowed = await privileges.posts.can('topics:read', post.pid, activitypub._constants.uid);
|
const allowed = await privileges.posts.can('topics:read', post.pid, activitypub._constants.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ module.exports = {
|
|||||||
|
|
||||||
let actorIds = await db.getSortedSetMembers('usersRemote:lastCrawled');
|
let actorIds = await db.getSortedSetMembers('usersRemote:lastCrawled');
|
||||||
progress.total = actorIds.length;
|
progress.total = actorIds.length;
|
||||||
const exists = await Promise.all(actorIds.map(async id => await db.isObjectField(`userRemote:${id}`, 'url')));
|
const exists = await Promise.all(actorIds.map(async id => await db.isObjectFields(`userRemote:${id}`, ['url', 'followersUrl'])));
|
||||||
actorIds = actorIds.filter((id, idx) => !exists[idx]);
|
actorIds = actorIds.filter((id, idx) => !exists[idx].every(Boolean));
|
||||||
|
|
||||||
// Increment ones that were already completed
|
// Increment ones that were already completed
|
||||||
progress.incr(progress.total - actorIds.length);
|
progress.incr(progress.total - actorIds.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user