inline token metadata into the notification instead of just storing the ID
This commit is contained in:
parent
156c7e9543
commit
b62f6ca042
5 changed files with 16 additions and 37 deletions
|
|
@ -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,
|
||||
} : {}),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue