Node.js based forum software built for the modern web
feat: send local posts out to established relays
Julian Lamaa26dfb372a2
diff --git a/src/activitypub/feps.js b/src/activitypub/feps.jsindex 7b7816516d..712126c506 100644--- a/src/activitypub/feps.js+++ b/src/activitypub/feps.js@@ -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}`,diff --git a/src/activitypub/relays.js b/src/activitypub/relays.jsindex 782d2d4b93..afaeaaa05f 100644--- a/src/activitypub/relays.js+++ b/src/activitypub/relays.js@@ -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;diff --git a/src/views/admin/settings/activitypub.tpl b/src/views/admin/settings/activitypub.tplindex 5fa72463a7..9a7e3493bf 100644--- a/src/views/admin/settings/activitypub.tpl+++ b/src/views/admin/settings/activitypub.tpl@@ -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 }}}