「すべて既読にする」でグループメッセージが既読にならない問題を修正 (#6476)

This commit is contained in:
fuyu 2020-07-04 10:45:36 +09:00 committed by GitHub
parent ca25b9acc1
commit 37c16e5b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import { publishMainStream } from '../../../../services/stream'; import { publishMainStream } from '../../../../services/stream';
import define from '../../define'; import define from '../../define';
import { MessagingMessages } from '../../../../models'; import { MessagingMessages, UserGroupJoinings } from '../../../../models';
export const meta = { export const meta = {
desc: { desc: {
@ -27,5 +27,16 @@ export default define(meta, async (ps, user) => {
isRead: true isRead: true
}); });
const joinings = await UserGroupJoinings.find({ userId: user.id });
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()));
publishMainStream(user.id, 'readAllMessagingMessages'); publishMainStream(user.id, 'readAllMessagingMessages');
}); });