2025-02-07 08:21:41 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const nconf = require('nconf');
|
|
|
|
|
|
|
|
|
|
const posts = require('../posts');
|
|
|
|
|
|
|
|
|
|
const activitypub = module.parent.exports;
|
|
|
|
|
const Feps = module.exports;
|
|
|
|
|
|
|
|
|
|
Feps.announce = async function announce(id, activity) {
|
|
|
|
|
let localId;
|
|
|
|
|
if (String(id).startsWith(nconf.get('url'))) {
|
|
|
|
|
({ id: localId } = await activitypub.helpers.resolveLocalId(id));
|
|
|
|
|
}
|
|
|
|
|
const cid = await posts.getCidByPid(localId || id);
|
2025-02-14 21:12:18 -05:00
|
|
|
if (cid === -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-07 08:21:41 -05:00
|
|
|
|
|
|
|
|
const followers = await activitypub.notes.getCategoryFollowers(cid);
|
|
|
|
|
if (!followers.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { actor } = activity;
|
|
|
|
|
if (actor && !actor.startsWith(nconf.get('url'))) {
|
|
|
|
|
followers.unshift(actor);
|
|
|
|
|
}
|
2025-04-04 10:45:05 -04:00
|
|
|
const now = Date.now();
|
2025-02-20 15:07:45 -05:00
|
|
|
if (activity.type === 'Create') {
|
|
|
|
|
const isMain = await posts.isMain(localId || id);
|
|
|
|
|
if (isMain) {
|
|
|
|
|
activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing plain object (${activity.id}) to followers of cid ${cid}`);
|
|
|
|
|
await activitypub.send('cid', cid, followers, {
|
2025-04-04 10:45:05 -04:00
|
|
|
id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${now}`,
|
2025-02-20 15:07:45 -05:00
|
|
|
type: 'Announce',
|
|
|
|
|
actor: `${nconf.get('url')}/category/${cid}`,
|
|
|
|
|
to: [`${nconf.get('url')}/category/${cid}/followers`],
|
|
|
|
|
cc: [actor, activitypub._constants.publicAddress],
|
|
|
|
|
object: activity.object,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-14 21:07:23 -05:00
|
|
|
activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing ${activity.type} (${activity.id}) to followers of cid ${cid}`);
|
2025-02-20 15:07:45 -05:00
|
|
|
await activitypub.send('cid', cid, followers, {
|
2025-04-04 10:45:05 -04:00
|
|
|
id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${now + 1}`,
|
2025-02-20 15:07:45 -05:00
|
|
|
type: 'Announce',
|
|
|
|
|
actor: `${nconf.get('url')}/category/${cid}`,
|
|
|
|
|
to: [`${nconf.get('url')}/category/${cid}/followers`],
|
|
|
|
|
cc: [actor, activitypub._constants.publicAddress],
|
|
|
|
|
object: activity,
|
|
|
|
|
});
|
2025-02-07 08:21:41 -05:00
|
|
|
};
|