1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 02:12:40 +01:00

update activitypub-types package

This commit is contained in:
Madeline 2023-09-29 01:49:42 +00:00
parent c82b71695d
commit a1b1f22705
5 changed files with 19 additions and 52 deletions

4
package-lock.json generated
View File

@ -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": {

View File

@ -127,4 +127,4 @@
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
"sqlite3": "^5.1.6"
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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";
};