1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-25 11:43:07 +01:00

Accept Follow for federated guild joins. TODO: Channels and role federation

This commit is contained in:
Madeline 2023-09-29 07:38:07 +00:00
parent b993216651
commit 4cc297cc10

View File

@ -12,6 +12,7 @@ import {
APAccept,
APCreate,
APFollow,
ActivityIsFollow,
AnyAPObject,
ObjectIsNote,
} from "activitypub-types";
@ -63,8 +64,6 @@ const handlers = {
},
Follow: async (activity: APFollow) => {
// dummy: send back Accept regardless
if (typeof activity.object != "string")
throw new APError("not implemented");
const mention = splitQualifiedMention(activity.object);
@ -82,6 +81,39 @@ const handlers = {
throw new APError("not implemented");
}
},
Accept: async (activity: APAccept) => {
// check what this accept is for
if (!activity.object)
throw new APError(
"Received Accept activity without object, what was accepted?",
);
const inner = await resolveAPObject(
Array.isArray(activity.object)
? activity.object[0]
: activity.object,
);
if (!ActivityIsFollow(inner))
throw new APError(
"Accept received for activity other than Follow, ignoring",
);
// if it's for a guild join,
if (typeof inner.object != "string")
throw new APError("not implemented");
const guild = await fetchFederatedUser(inner.object);
if (typeof inner.actor != "string")
throw new APError("not implemented");
const { user } = splitQualifiedMention(inner.actor);
Member.addToGuild(user, guild.entity.id);
},
} as Record<string, (activity: AnyAPObject) => Promise<unknown>>;
export const genericInboxHandler = async (req: Request) => {