summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/ActivityPubServerService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-12-04 15:03:09 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-12-04 15:03:09 +0900
commitbbb49457f9fb5d46402e913c92ebf77722cad6ff (patch)
tree8ef285bcbab2c3a4a89d0a624a802d76a2864fed /packages/backend/src/server/ActivityPubServerService.ts
parent:art: (diff)
downloadsharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.gz
sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.tar.bz2
sharkey-bbb49457f9fb5d46402e913c92ebf77722cad6ff.zip
refactor: introduce bindThis decorator to bind this automaticaly
Diffstat (limited to 'packages/backend/src/server/ActivityPubServerService.ts')
-rw-r--r--packages/backend/src/server/ActivityPubServerService.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/packages/backend/src/server/ActivityPubServerService.ts b/packages/backend/src/server/ActivityPubServerService.ts
index 015c8f2b4c..94a277f4a4 100644
--- a/packages/backend/src/server/ActivityPubServerService.ts
+++ b/packages/backend/src/server/ActivityPubServerService.ts
@@ -18,6 +18,7 @@ import type { Note } from '@/models/entities/Note.js';
import { QueryService } from '@/core/QueryService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
+import { bindThis } from '@/decorators.js';
import type { FindOptionsWhere } from 'typeorm';
const ACTIVITY_JSON = 'application/activity+json; charset=utf-8';
@@ -57,9 +58,10 @@ export class ActivityPubServerService {
private userKeypairStoreService: UserKeypairStoreService,
private queryService: QueryService,
) {
- this.createServer = this.createServer.bind(this);
+ //this.createServer = this.createServer.bind(this);
}
+ @bindThis
private setResponseType(request: FastifyRequest, reply: FastifyReply): void {
const accept = request.accepts().type([ACTIVITY_JSON, LD_JSON]);
if (accept === LD_JSON) {
@@ -73,6 +75,7 @@ export class ActivityPubServerService {
* Pack Create<Note> or Announce Activity
* @param note Note
*/
+ @bindThis
private async packActivity(note: Note): Promise<any> {
if (note.renoteId && note.text == null && !note.hasPoll && (note.fileIds == null || note.fileIds.length === 0)) {
const renote = await this.notesRepository.findOneByOrFail({ id: note.renoteId });
@@ -82,6 +85,7 @@ export class ActivityPubServerService {
return this.apRendererService.renderCreate(await this.apRendererService.renderNote(note, false), note);
}
+ @bindThis
private inbox(request: FastifyRequest, reply: FastifyReply) {
let signature;
@@ -97,6 +101,7 @@ export class ActivityPubServerService {
reply.code(202);
}
+ @bindThis
private async followers(
request: FastifyRequest<{ Params: { user: string; }; Querystring: { cursor?: string; page?: string; }; }>,
reply: FastifyReply,
@@ -184,6 +189,7 @@ export class ActivityPubServerService {
}
}
+ @bindThis
private async following(
request: FastifyRequest<{ Params: { user: string; }; Querystring: { cursor?: string; page?: string; }; }>,
reply: FastifyReply,
@@ -271,6 +277,7 @@ export class ActivityPubServerService {
}
}
+ @bindThis
private async featured(request: FastifyRequest<{ Params: { user: string; }; }>, reply: FastifyReply) {
const userId = request.params.user;
@@ -304,6 +311,7 @@ export class ActivityPubServerService {
return (this.apRendererService.renderActivity(rendered));
}
+ @bindThis
private async outbox(
request: FastifyRequest<{
Params: { user: string; };
@@ -390,6 +398,7 @@ export class ActivityPubServerService {
}
}
+ @bindThis
private async userInfo(request: FastifyRequest, reply: FastifyReply, user: User | null) {
if (user == null) {
reply.code(404);
@@ -401,6 +410,7 @@ export class ActivityPubServerService {
return (this.apRendererService.renderActivity(await this.apRendererService.renderPerson(user as ILocalUser)));
}
+ @bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
fastify.addConstraintStrategy({
name: 'apOrHtml',