summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-29 01:49:42 +0000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-29 01:49:42 +0000
commita1b1f22705510b332fe95f6e3283c91e54aa27f5 (patch)
tree53bda166e96d4afaebf2e7df6f3a0df58d453a0d
parentsend Follow request to guild when remote invite code used (diff)
downloadserver-a1b1f22705510b332fe95f6e3283c91e54aa27f5.tar.xz
update activitypub-types package
-rw-r--r--package-lock.json4
-rw-r--r--package.json2
-rw-r--r--src/activitypub/federation/index.ts13
-rw-r--r--src/activitypub/federation/transforms.ts4
-rw-r--r--src/activitypub/federation/utils.ts48
5 files changed, 19 insertions, 52 deletions
diff --git a/package-lock.json b/package-lock.json
index 3ab0b712..f747e72d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2506,8 +2506,8 @@
 			}
 		},
 		"node_modules/activitypub-types": {
-			"version": "1.0.4",
-			"resolved": "git+ssh://git@github.com/spacebarchat/activitypub-types.git#67d3162d8a982f1d64c18412835b54169682b523",
+			"version": "1.1.1",
+			"resolved": "git+ssh://git@github.com/spacebarchat/activitypub-types.git#1270eaeaed5c1cb535b4b1da031160a4a21d2e00",
 			"license": "MIT"
 		},
 		"node_modules/addressparser": {
diff --git a/package.json b/package.json
index b2c6885c..5e316d2c 100644
--- a/package.json
+++ b/package.json
@@ -127,4 +127,4 @@
 		"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
 		"sqlite3": "^5.1.6"
 	}
-}
\ No newline at end of file
+}
diff --git a/src/activitypub/federation/index.ts b/src/activitypub/federation/index.ts
index a3504da6..449a3234 100644
--- a/src/activitypub/federation/index.ts
+++ b/src/activitypub/federation/index.ts
@@ -1,15 +1,10 @@
 import { MessageCreateEvent, emitEvent } from "@spacebar/util";
-import { APActivity } from "activitypub-types";
+import { APActivity, ActivityIsCreate, ObjectIsNote } from "activitypub-types";
 import { Request } from "express";
 import { HttpSig } from "./HttpSig";
 import { federationQueue } from "./queue";
 import { transformNoteToMessage } from "./transforms";
-import {
-	APActivityIsCreate,
-	APError,
-	APObjectIsNote,
-	hasAPContext,
-} from "./utils";
+import { APError, hasAPContext } from "./utils";
 
 export * from "./OrderedCollection";
 export * from "./transforms";
@@ -30,7 +25,7 @@ export class Federation {
 			throw new APError("Invalid signature");
 		}
 
-		if (!APActivityIsCreate(activity))
+		if (!ActivityIsCreate(activity))
 			throw new APError(
 				`activity of type ${activity.type} not implemented`,
 			);
@@ -39,7 +34,7 @@ export class Federation {
 			? activity.object[0]
 			: activity.object;
 
-		if (!object || typeof object == "string" || !APObjectIsNote(object))
+		if (!object || typeof object == "string" || !ObjectIsNote(object))
 			throw new APError("not implemented");
 
 		const message = await transformNoteToMessage(object);
diff --git a/src/activitypub/federation/transforms.ts b/src/activitypub/federation/transforms.ts
index fd347116..41b76148 100644
--- a/src/activitypub/federation/transforms.ts
+++ b/src/activitypub/federation/transforms.ts
@@ -18,13 +18,13 @@ import {
 	APNote,
 	APOrganization,
 	APPerson,
+	ObjectIsPerson,
 } from "activitypub-types";
 import TurndownService from "turndown";
 import { In } from "typeorm";
 import {
 	ACTIVITYSTREAMS_CONTEXT,
 	APError,
-	APObjectIsPerson,
 	fetchFederatedUser,
 	resolveAPObject,
 } from "./utils";
@@ -117,7 +117,7 @@ export const transformNoteToMessage = async (note: APNote) => {
 			: note.attributedTo,
 	);
 
-	if (!APObjectIsPerson(attrib))
+	if (!ObjectIsPerson(attrib))
 		throw new APError("Note must be attributedTo a Person");
 
 	const user = await transformPersonToUser(attrib);
diff --git a/src/activitypub/federation/utils.ts b/src/activitypub/federation/utils.ts
index 4bb9279c..366a5d5d 100644
--- a/src/activitypub/federation/utils.ts
+++ b/src/activitypub/federation/utils.ts
@@ -11,13 +11,12 @@ import {
 	WebfingerResponse,
 } from "@spacebar/util";
 import {
-	APActivity,
-	APAnnounce,
-	APCreate,
 	APFollow,
-	APNote,
 	APPerson,
 	AnyAPObject,
+	ObjectIsGroup,
+	ObjectIsOrganization,
+	ObjectIsPerson,
 } from "activitypub-types";
 import { HTTPError } from "lambert-server";
 import fetch from "node-fetch";
@@ -145,9 +144,9 @@ export const fetchFederatedUser = async (actorId: string) => {
 	const remoteActor = await resolveWebfinger(actorId);
 
 	let type: ActorType;
-	if (APObjectIsPerson(remoteActor)) type = ActorType.USER;
-	else if (APObjectIsGroup(remoteActor)) type = ActorType.CHANNEL;
-	else if (APObjectIsOrganisation(remoteActor)) type = ActorType.GUILD;
+	if (ObjectIsPerson(remoteActor)) type = ActorType.USER;
+	else if (ObjectIsGroup(remoteActor)) type = ActorType.CHANNEL;
+	else if (ObjectIsOrganization(remoteActor)) type = ActorType.GUILD;
 	else
 		throw new APError(
 			`The remote actor '${actorId}' is not a Person, Group, or Organisation`,
@@ -205,7 +204,7 @@ export const fetchFederatedUser = async (actorId: string) => {
 
 export const tryFederatedGuildJoin = async (code: string, user_id: string) => {
 	const guild = await tryResolveWebfinger(code);
-	if (!guild || !APObjectIsOrganisation(guild))
+	if (!guild || !ObjectIsOrganization(guild))
 		throw new APError(
 			`Invite code did not produce Guild on remote server ${code}`,
 		);
@@ -224,39 +223,12 @@ export const tryFederatedGuildJoin = async (code: string, user_id: string) => {
 	await Federation.distribute(follow.toJSON());
 };
 
-// fetch from remote server?
-export const APObjectIsPerson = (object: AnyAPObject): object is APPerson => {
-	return "type" in object && object.type == "Person";
-};
-
-export const APObjectIsGroup = (object: AnyAPObject): object is APPerson => {
-	return "type" in object && object.type == "Group";
-};
-
-export const APObjectIsOrganisation = (
-	object: AnyAPObject,
-): object is APPerson => {
-	return "type" in object && object.type == "Organization";
-};
-
 export const APObjectIsSpacebarActor = (
 	object: AnyAPObject,
 ): object is APPerson => {
 	return (
-		APObjectIsGroup(object) ||
-		APObjectIsOrganisation(object) ||
-		APObjectIsPerson(object)
+		ObjectIsPerson(object) ||
+		ObjectIsGroup(object) ||
+		ObjectIsOrganization(object)
 	);
 };
-
-export const APActivityIsCreate = (act: APActivity): act is APCreate => {
-	return act.type == "Create";
-};
-
-export const APActivityIsAnnounce = (act: APActivity): act is APAnnounce => {
-	return act.type == "Announce";
-};
-
-export const APObjectIsNote = (obj: AnyAPObject): obj is APNote => {
-	return obj.type == "Note";
-};