mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: relay handshake logic, handle Follow/Accept, send back Accept.
This commit is contained in:
@@ -198,6 +198,9 @@ Helpers.resolveLocalId = async (input) => {
|
||||
|
||||
case 'message':
|
||||
return { type: 'message', id: value, ...activityData };
|
||||
|
||||
case 'actor':
|
||||
return { type: 'application', id: null };
|
||||
}
|
||||
|
||||
return { type: null, id: null, ...activityData };
|
||||
|
||||
@@ -367,9 +367,12 @@ inbox.announce = async (req) => {
|
||||
|
||||
inbox.follow = async (req) => {
|
||||
const { actor, object, id: followId } = req.body;
|
||||
|
||||
// Sanity checks
|
||||
const { type, id } = await helpers.resolveLocalId(object.id);
|
||||
if (!['category', 'user'].includes(type)) {
|
||||
if (type === 'application') {
|
||||
return activitypub.relays.handshake(req.body);
|
||||
} else if (!['category', 'user'].includes(type)) {
|
||||
throw new Error('[[error:activitypub.invalid-id]]');
|
||||
}
|
||||
|
||||
@@ -454,7 +457,9 @@ inbox.accept = async (req) => {
|
||||
const { type } = object;
|
||||
|
||||
const { type: localType, id } = await helpers.resolveLocalId(object.actor);
|
||||
if (!['user', 'category'].includes(localType)) {
|
||||
if (object.id === `${nconf.get('url')}/actor`) {
|
||||
return activitypub.relays.handshake(req.body);
|
||||
} else if (!['user', 'category'].includes(localType)) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,32 @@ Relays.remove = async (url) => {
|
||||
]);
|
||||
};
|
||||
|
||||
Relays.handshake = async (activity) => {
|
||||
console.log(activity);
|
||||
Relays.handshake = async (object) => {
|
||||
const now = new Date();
|
||||
const { type, actor } = object;
|
||||
|
||||
// Confirm relay was added
|
||||
const exists = await db.isSortedSetMember('relays:createtime', actor);
|
||||
if (!exists) {
|
||||
throw new Error('[[error:api.400]]');
|
||||
}
|
||||
|
||||
if (type === 'Follow') {
|
||||
await db.sortedSetIncrBy('relays:state', 1, actor);
|
||||
await activitypub.send('uid', 0, actor, {
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://pleroma.example/schemas/litepub-0.1.jsonld',
|
||||
],
|
||||
id: `${nconf.get('url')}/actor#activity/accept/${encodeURIComponent(actor)}/${now.getTime()}`,
|
||||
type: 'Accept',
|
||||
to: [actor],
|
||||
published: now.toISOString(),
|
||||
object,
|
||||
});
|
||||
} else if (type === 'Accept') {
|
||||
await db.sortedSetIncrBy('relays:state', 1, actor);
|
||||
} else {
|
||||
throw new Error('[[error:api.400]]');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user