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:
parent
c82b71695d
commit
a1b1f22705
4
package-lock.json
generated
4
package-lock.json
generated
@ -2506,8 +2506,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/activitypub-types": {
|
"node_modules/activitypub-types": {
|
||||||
"version": "1.0.4",
|
"version": "1.1.1",
|
||||||
"resolved": "git+ssh://git@github.com/spacebarchat/activitypub-types.git#67d3162d8a982f1d64c18412835b54169682b523",
|
"resolved": "git+ssh://git@github.com/spacebarchat/activitypub-types.git#1270eaeaed5c1cb535b4b1da031160a4a21d2e00",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/addressparser": {
|
"node_modules/addressparser": {
|
||||||
|
@ -127,4 +127,4 @@
|
|||||||
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
|
"nodemailer-sendgrid-transport": "github:Maria-Golomb/nodemailer-sendgrid-transport",
|
||||||
"sqlite3": "^5.1.6"
|
"sqlite3": "^5.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
import { MessageCreateEvent, emitEvent } from "@spacebar/util";
|
import { MessageCreateEvent, emitEvent } from "@spacebar/util";
|
||||||
import { APActivity } from "activitypub-types";
|
import { APActivity, ActivityIsCreate, ObjectIsNote } from "activitypub-types";
|
||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
import { HttpSig } from "./HttpSig";
|
import { HttpSig } from "./HttpSig";
|
||||||
import { federationQueue } from "./queue";
|
import { federationQueue } from "./queue";
|
||||||
import { transformNoteToMessage } from "./transforms";
|
import { transformNoteToMessage } from "./transforms";
|
||||||
import {
|
import { APError, hasAPContext } from "./utils";
|
||||||
APActivityIsCreate,
|
|
||||||
APError,
|
|
||||||
APObjectIsNote,
|
|
||||||
hasAPContext,
|
|
||||||
} from "./utils";
|
|
||||||
|
|
||||||
export * from "./OrderedCollection";
|
export * from "./OrderedCollection";
|
||||||
export * from "./transforms";
|
export * from "./transforms";
|
||||||
@ -30,7 +25,7 @@ export class Federation {
|
|||||||
throw new APError("Invalid signature");
|
throw new APError("Invalid signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!APActivityIsCreate(activity))
|
if (!ActivityIsCreate(activity))
|
||||||
throw new APError(
|
throw new APError(
|
||||||
`activity of type ${activity.type} not implemented`,
|
`activity of type ${activity.type} not implemented`,
|
||||||
);
|
);
|
||||||
@ -39,7 +34,7 @@ export class Federation {
|
|||||||
? activity.object[0]
|
? activity.object[0]
|
||||||
: activity.object;
|
: activity.object;
|
||||||
|
|
||||||
if (!object || typeof object == "string" || !APObjectIsNote(object))
|
if (!object || typeof object == "string" || !ObjectIsNote(object))
|
||||||
throw new APError("not implemented");
|
throw new APError("not implemented");
|
||||||
|
|
||||||
const message = await transformNoteToMessage(object);
|
const message = await transformNoteToMessage(object);
|
||||||
|
@ -18,13 +18,13 @@ import {
|
|||||||
APNote,
|
APNote,
|
||||||
APOrganization,
|
APOrganization,
|
||||||
APPerson,
|
APPerson,
|
||||||
|
ObjectIsPerson,
|
||||||
} from "activitypub-types";
|
} from "activitypub-types";
|
||||||
import TurndownService from "turndown";
|
import TurndownService from "turndown";
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import {
|
import {
|
||||||
ACTIVITYSTREAMS_CONTEXT,
|
ACTIVITYSTREAMS_CONTEXT,
|
||||||
APError,
|
APError,
|
||||||
APObjectIsPerson,
|
|
||||||
fetchFederatedUser,
|
fetchFederatedUser,
|
||||||
resolveAPObject,
|
resolveAPObject,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
@ -117,7 +117,7 @@ export const transformNoteToMessage = async (note: APNote) => {
|
|||||||
: note.attributedTo,
|
: note.attributedTo,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!APObjectIsPerson(attrib))
|
if (!ObjectIsPerson(attrib))
|
||||||
throw new APError("Note must be attributedTo a Person");
|
throw new APError("Note must be attributedTo a Person");
|
||||||
|
|
||||||
const user = await transformPersonToUser(attrib);
|
const user = await transformPersonToUser(attrib);
|
||||||
|
@ -11,13 +11,12 @@ import {
|
|||||||
WebfingerResponse,
|
WebfingerResponse,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import {
|
import {
|
||||||
APActivity,
|
|
||||||
APAnnounce,
|
|
||||||
APCreate,
|
|
||||||
APFollow,
|
APFollow,
|
||||||
APNote,
|
|
||||||
APPerson,
|
APPerson,
|
||||||
AnyAPObject,
|
AnyAPObject,
|
||||||
|
ObjectIsGroup,
|
||||||
|
ObjectIsOrganization,
|
||||||
|
ObjectIsPerson,
|
||||||
} from "activitypub-types";
|
} from "activitypub-types";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
@ -145,9 +144,9 @@ export const fetchFederatedUser = async (actorId: string) => {
|
|||||||
const remoteActor = await resolveWebfinger(actorId);
|
const remoteActor = await resolveWebfinger(actorId);
|
||||||
|
|
||||||
let type: ActorType;
|
let type: ActorType;
|
||||||
if (APObjectIsPerson(remoteActor)) type = ActorType.USER;
|
if (ObjectIsPerson(remoteActor)) type = ActorType.USER;
|
||||||
else if (APObjectIsGroup(remoteActor)) type = ActorType.CHANNEL;
|
else if (ObjectIsGroup(remoteActor)) type = ActorType.CHANNEL;
|
||||||
else if (APObjectIsOrganisation(remoteActor)) type = ActorType.GUILD;
|
else if (ObjectIsOrganization(remoteActor)) type = ActorType.GUILD;
|
||||||
else
|
else
|
||||||
throw new APError(
|
throw new APError(
|
||||||
`The remote actor '${actorId}' is not a Person, Group, or Organisation`,
|
`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) => {
|
export const tryFederatedGuildJoin = async (code: string, user_id: string) => {
|
||||||
const guild = await tryResolveWebfinger(code);
|
const guild = await tryResolveWebfinger(code);
|
||||||
if (!guild || !APObjectIsOrganisation(guild))
|
if (!guild || !ObjectIsOrganization(guild))
|
||||||
throw new APError(
|
throw new APError(
|
||||||
`Invite code did not produce Guild on remote server ${code}`,
|
`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());
|
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 = (
|
export const APObjectIsSpacebarActor = (
|
||||||
object: AnyAPObject,
|
object: AnyAPObject,
|
||||||
): object is APPerson => {
|
): object is APPerson => {
|
||||||
return (
|
return (
|
||||||
APObjectIsGroup(object) ||
|
ObjectIsPerson(object) ||
|
||||||
APObjectIsOrganisation(object) ||
|
ObjectIsGroup(object) ||
|
||||||
APObjectIsPerson(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";
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user