summary refs log tree commit diff
path: root/src/activitypub/federation
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-10-26 05:39:22 +0000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-10-26 05:39:22 +0000
commitcc48f595fdecfdb2825f4023fb157ff5f0e8ded6 (patch)
tree974b4612b87bf5b3fc04933f2c731d83f1ee083c /src/activitypub/federation
parentbasic channel federation (diff)
downloadserver-cc48f595fdecfdb2825f4023fb157ff5f0e8ded6.tar.xz
bug fixes and improvements (i wrote this code a week ago and forgot what it does) feat/federation2
Diffstat (limited to 'src/activitypub/federation')
-rw-r--r--src/activitypub/federation/OrderedCollection.ts6
-rw-r--r--src/activitypub/federation/inbox/index.ts2
-rw-r--r--src/activitypub/federation/transforms.ts17
-rw-r--r--src/activitypub/federation/utils.ts6
4 files changed, 21 insertions, 10 deletions
diff --git a/src/activitypub/federation/OrderedCollection.ts b/src/activitypub/federation/OrderedCollection.ts
index f3b8feea..aa462e64 100644
--- a/src/activitypub/federation/OrderedCollection.ts
+++ b/src/activitypub/federation/OrderedCollection.ts
@@ -1,7 +1,9 @@
-import { APOrderedCollection, AnyAPObject } from "activitypub-types";
+import { APOrderedCollection, CollectionCurrentField } from "activitypub-types";
 import { ACTIVITYSTREAMS_CONTEXT } from "./utils";
 
-export const makeOrderedCollection = async <T extends AnyAPObject>(opts: {
+export const makeOrderedCollection = async <
+	T extends CollectionCurrentField,
+>(opts: {
 	page: boolean;
 	min_id?: string;
 	max_id?: string;
diff --git a/src/activitypub/federation/inbox/index.ts b/src/activitypub/federation/inbox/index.ts
index 079c13de..3fbdfc4a 100644
--- a/src/activitypub/federation/inbox/index.ts
+++ b/src/activitypub/federation/inbox/index.ts
@@ -192,7 +192,7 @@ const addRemoteUserToGuild = async (
 		},
 	});
 
-	const { entity, keys } = await fetchFederatedUser(actor);
+	const { entity } = await fetchFederatedUser(actor);
 
 	await Member.addToGuild(entity.id, guild.actorId);
 
diff --git a/src/activitypub/federation/transforms.ts b/src/activitypub/federation/transforms.ts
index a11cc62b..b11005eb 100644
--- a/src/activitypub/federation/transforms.ts
+++ b/src/activitypub/federation/transforms.ts
@@ -211,13 +211,13 @@ export const transformUserToPerson = async (user: User): Promise<APPerson> => {
 	const { host, accountDomain } = Config.get().federation;
 
 	const keys = await FederationKey.findOneOrFail({
-		where: { actorId: user.id, domain: accountDomain },
+		where: { actorId: user.id },
 	});
 
 	return {
 		"@context": ACTIVITYSTREAMS_CONTEXT,
 		type: "Person",
-		id: `https://${host}/federation/users/${user.id}`,
+		id: keys.federatedId,
 
 		name: user.username,
 		preferredUsername: user.id,
@@ -232,9 +232,10 @@ export const transformUserToPerson = async (user: User): Promise<APPerson> => {
 			  ]
 			: undefined,
 
-		inbox: `https://${host}/federation/users/${user.id}/inbox`,
-		outbox: `https://${host}/federation/users/${user.id}/outbox`,
-		followers: `https://${host}/federation/users/${user.id}/followers`,
+		inbox: keys.inbox,
+		outbox: keys.outbox,
+		followers: keys.followers,
+		following: keys.following,
 		publicKey: {
 			id: `https://${host}/federation/users/${user.id}#main-key`,
 			owner: `https://${host}/federation/users/${user.id}`,
@@ -266,6 +267,8 @@ export const transformPersonToUser = async (person: APPerson) => {
 		type: ActorType.USER,
 		inbox: person.inbox.toString(),
 		outbox: person.outbox.toString(),
+		followers: person.followers?.toString(),
+		following: person.following?.toString(),
 	}).save();
 
 	return await User.create({
@@ -332,6 +335,8 @@ export const transformOrganisationToGuild = async (org: APOrganization) => {
 		type: ActorType.GUILD,
 		inbox: org.inbox.toString(),
 		outbox: org.outbox.toString(),
+		followers: org.followers?.toString(),
+		following: org.following?.toString(),
 	});
 
 	if (typeof org.attributedTo != "string")
@@ -423,6 +428,8 @@ export const transformGroupToChannel = async (
 		type: ActorType.CHANNEL,
 		inbox: group.inbox.toString(),
 		outbox: group.outbox.toString(),
+		followers: group.followers?.toString(),
+		following: group.following?.toString(),
 	});
 
 	const channel = Channel.create({
diff --git a/src/activitypub/federation/utils.ts b/src/activitypub/federation/utils.ts
index e879e863..4a56c67d 100644
--- a/src/activitypub/federation/utils.ts
+++ b/src/activitypub/federation/utils.ts
@@ -191,8 +191,10 @@ export const fetchFederatedUser = async (
 		domain: mention.domain,
 		publicKey: remoteActor.publicKey?.publicKeyPem,
 		type,
-		inbox: remoteActor.inbox,
-		outbox: remoteActor.outbox,
+		inbox: remoteActor.inbox?.toString(),
+		outbox: remoteActor.outbox?.toString(),
+		following: remoteActor.following?.toString(),
+		followers: remoteActor.followers?.toString(),
 	});
 
 	let entity: BaseClass | undefined = undefined;