なんかもうめっちゃ変えた
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { publishMainStream } from '@/services/stream.js';
|
||||
import define from '../../define.js';
|
||||
import { MessagingMessages, UserGroupJoinings } from '@/models/index.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { MessagingMessagesRepository, UserGroupJoiningsRepository } from '@/models/index.js';
|
||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['account', 'messaging'],
|
||||
@@ -17,25 +19,38 @@ export const paramDef = {
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Update documents
|
||||
await MessagingMessages.update({
|
||||
recipientId: user.id,
|
||||
isRead: false,
|
||||
}, {
|
||||
isRead: true,
|
||||
});
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.messagingMessagesRepository)
|
||||
private messagingMessagesRepository: MessagingMessagesRepository,
|
||||
|
||||
const joinings = await UserGroupJoinings.findBy({ userId: user.id });
|
||||
@Inject(DI.userGroupJoiningsRepository)
|
||||
private userGroupJoiningsRepository: UserGroupJoiningsRepository,
|
||||
|
||||
await Promise.all(joinings.map(j => MessagingMessages.createQueryBuilder().update()
|
||||
.set({
|
||||
reads: (() => `array_append("reads", '${user.id}')`) as any,
|
||||
})
|
||||
.where(`groupId = :groupId`, { groupId: j.userGroupId })
|
||||
.andWhere('userId != :userId', { userId: user.id })
|
||||
.andWhere('NOT (:userId = ANY(reads))', { userId: user.id })
|
||||
.execute()));
|
||||
private globalEventService: GlobalEventService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
// Update documents
|
||||
await this.messagingMessagesRepository.update({
|
||||
recipientId: me.id,
|
||||
isRead: false,
|
||||
}, {
|
||||
isRead: true,
|
||||
});
|
||||
|
||||
publishMainStream(user.id, 'readAllMessagingMessages');
|
||||
});
|
||||
const joinings = await this.userGroupJoiningsRepository.findBy({ userId: me.id });
|
||||
|
||||
await Promise.all(joinings.map(j => this.messagingMessagesRepository.createQueryBuilder().update()
|
||||
.set({
|
||||
reads: (() => `array_append("reads", '${me.id}')`) as any,
|
||||
})
|
||||
.where('groupId = :groupId', { groupId: j.userGroupId })
|
||||
.andWhere('userId != :userId', { userId: me.id })
|
||||
.andWhere('NOT (:userId = ANY(reads))', { userId: me.id })
|
||||
.execute()));
|
||||
|
||||
this.globalEventService.publishMainStream(me.id, 'readAllMessagingMessages');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user