inline token metadata into the notification instead of just storing the ID

This commit is contained in:
Hazelnoot 2025-06-22 12:02:31 -04:00
parent 156c7e9543
commit b62f6ca042
5 changed files with 16 additions and 37 deletions

View file

@ -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,
} : {}),
});
}

View file

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

View file

@ -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,
},
},
}, {

View file

@ -119,7 +119,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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);
}
}

View file

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