mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
feat: send local posts out to established relays
This commit is contained in:
@@ -4,6 +4,7 @@ const nconf = require('nconf');
|
||||
|
||||
const posts = require('../posts');
|
||||
const utils = require('../utils');
|
||||
const { default: PG } = require('pg');
|
||||
|
||||
const activitypub = module.parent.exports;
|
||||
const Feps = module.exports;
|
||||
@@ -18,21 +19,29 @@ Feps.announce = async function announce(id, activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
let relays = await activitypub.relays.list();
|
||||
relays = relays.reduce((memo, { state, url }) => {
|
||||
if (state === 2) {
|
||||
memo.push(url);
|
||||
}
|
||||
return memo;
|
||||
}, []);
|
||||
const followers = await activitypub.notes.getCategoryFollowers(cid);
|
||||
if (!followers.length) {
|
||||
const targets = relays.concat(followers);
|
||||
if (!targets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { actor } = activity;
|
||||
if (actor && !actor.startsWith(nconf.get('url'))) {
|
||||
followers.unshift(actor);
|
||||
targets.unshift(actor);
|
||||
}
|
||||
const now = Date.now();
|
||||
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, {
|
||||
activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing plain object (${activity.id}) to followers of cid ${cid} and ${relays.length} relays`);
|
||||
await activitypub.send('cid', cid, targets, {
|
||||
id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${now}`,
|
||||
type: 'Announce',
|
||||
actor: `${nconf.get('url')}/category/${cid}`,
|
||||
@@ -43,8 +52,8 @@ Feps.announce = async function announce(id, activity) {
|
||||
}
|
||||
}
|
||||
|
||||
activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing ${activity.type} (${activity.id}) to followers of cid ${cid}`);
|
||||
await activitypub.send('cid', cid, followers, {
|
||||
activitypub.helpers.log(`[activitypub/inbox.announce(1b12)] Announcing ${activity.type} (${activity.id}) to followers of cid ${cid} and ${relays.length} relays`);
|
||||
await activitypub.send('cid', cid, targets, {
|
||||
id: `${nconf.get('url')}/post/${encodeURIComponent(id)}#activity/announce/${now + 1}`,
|
||||
type: 'Announce',
|
||||
actor: `${nconf.get('url')}/category/${cid}`,
|
||||
|
||||
@@ -14,22 +14,23 @@ Relays.is = async (actor) => {
|
||||
Relays.list = async () => {
|
||||
let relays = await db.getSortedSetMembersWithScores('relays:state');
|
||||
relays = relays.reduce((memo, { value, score }) => {
|
||||
let state = '[[admin/settings/activitypub:relays.state-0]]';
|
||||
let label = '[[admin/settings/activitypub:relays.state-0]]';
|
||||
switch(score) {
|
||||
case 1: {
|
||||
state = '[[admin/settings/activitypub:relays.state-1]]';
|
||||
label = '[[admin/settings/activitypub:relays.state-1]]';
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
state = '[[admin/settings/activitypub:relays.state-2]]';
|
||||
label = '[[admin/settings/activitypub:relays.state-2]]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memo.push({
|
||||
url: value,
|
||||
state,
|
||||
state: score,
|
||||
label,
|
||||
});
|
||||
|
||||
return memo;
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
{{{ each relays }}}
|
||||
<tr data-url="{./url}">
|
||||
<td>{./url}</td>
|
||||
<td>{./state}</td>
|
||||
<td>{./label}</td>
|
||||
<td><a href="#" data-action="relays.remove"><i class="fa fa-trash link-danger"></i></a></td>
|
||||
</tr>
|
||||
{{{ end }}}
|
||||
|
||||
Reference in New Issue
Block a user