From b62f6ca0428735ad58db48e0b257697878f94bec Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 22 Jun 2025 12:02:31 -0400 Subject: [PATCH] inline token metadata into the notification instead of just storing the ID --- .../entities/NotificationEntityService.ts | 10 ++----- packages/backend/src/models/Notification.ts | 3 +- .../src/models/json-schema/notification.ts | 29 +++++-------------- .../server/api/endpoints/miauth/gen-token.ts | 2 +- packages/misskey-js/src/autogen/types.ts | 9 ++---- 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/packages/backend/src/core/entities/NotificationEntityService.ts b/packages/backend/src/core/entities/NotificationEntityService.ts index f56337a34c..45c55208a3 100644 --- a/packages/backend/src/core/entities/NotificationEntityService.ts +++ b/packages/backend/src/core/entities/NotificationEntityService.ts @@ -165,9 +165,6 @@ export class NotificationEntityService implements OnModuleInit { return null; } - const needsAccessToken = notification.type === 'sharedAccessGranted'; - const accessToken = (needsAccessToken && notification.tokenId) ? await this.accessTokensRepository.findOneBy({ id: notification.tokenId }) : null; - return await awaitAll({ id: notification.id, createdAt: new Date(notification.createdAt).toISOString(), @@ -208,11 +205,8 @@ export class NotificationEntityService implements OnModuleInit { } : {}), ...(notification.type === 'sharedAccessGranted' ? { tokenId: notification.tokenId, - token: accessToken ? { - id: accessToken.id, - permission: accessToken.permission, - rank: accessToken.rank, - } : null, + permCount: notification.permCount, + rank: notification.rank, } : {}), }); } diff --git a/packages/backend/src/models/Notification.ts b/packages/backend/src/models/Notification.ts index dbdaad7495..38773f828f 100644 --- a/packages/backend/src/models/Notification.ts +++ b/packages/backend/src/models/Notification.ts @@ -157,7 +157,8 @@ export type MiNotification = { id: string; createdAt: string; notifierId: MiUser['id']; - tokenId: MiAccessToken['id']; + permCount: number; + rank: 'user' | 'mod' | 'admin' | null; } | { type: 'sharedAccessRevoked'; id: string; diff --git a/packages/backend/src/models/json-schema/notification.ts b/packages/backend/src/models/json-schema/notification.ts index f314cec63f..7f05b75fd3 100644 --- a/packages/backend/src/models/json-schema/notification.ts +++ b/packages/backend/src/models/json-schema/notification.ts @@ -479,27 +479,14 @@ export const packedNotificationSchema = { optional: false, nullable: false, format: 'id', }, - token: { - type: 'object', - optional: false, nullable: true, - properties: { - id: { - type: 'string', - optional: false, nullable: false, - }, - permission: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'string', - }, - }, - rank: { - type: 'string', - enum: ['admin', 'mod', 'user'], - optional: false, nullable: true, - }, - }, + permCount: { + type: 'number', + optional: true, nullable: false, + }, + rank: { + type: 'string', + enum: ['admin', 'mod', 'user'], + optional: true, nullable: true, }, }, }, { diff --git a/packages/backend/src/server/api/endpoints/miauth/gen-token.ts b/packages/backend/src/server/api/endpoints/miauth/gen-token.ts index d1ac9db505..66146bc00c 100644 --- a/packages/backend/src/server/api/endpoints/miauth/gen-token.ts +++ b/packages/backend/src/server/api/endpoints/miauth/gen-token.ts @@ -119,7 +119,7 @@ export default class extends Endpoint { // eslint- if (ps.grantees) { for (const granteeId of ps.grantees) { - this.notificationService.createNotification(granteeId, 'sharedAccessGranted', { tokenId: accessTokenId }, me.id); + this.notificationService.createNotification(granteeId, 'sharedAccessGranted', { permCount: ps.permission.length, rank: ps.rank ?? null }, me.id); } } diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 3005d5cb62..ce61a76a7d 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -5032,12 +5032,9 @@ export type components = { user: components['schemas']['UserLite']; /** Format: id */ userId: string; - token: ({ - id: string; - permission: string[]; - /** @enum {string|null} */ - rank: 'admin' | 'mod' | 'user'; - }) | null; + permCount?: number; + /** @enum {string|null} */ + rank?: 'admin' | 'mod' | 'user'; }) | { /** Format: id */ id: string;