From 37c16e5b4536ea2db72b7853a8515df6ceb490a3 Mon Sep 17 00:00:00 2001 From: fuyu <54523771+mfmfuyu@users.noreply.github.com> Date: Sat, 4 Jul 2020 10:45:36 +0900 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E3=81=99=E3=81=B9=E3=81=A6=E6=97=A2?= =?UTF-8?q?=E8=AA=AD=E3=81=AB=E3=81=99=E3=82=8B=E3=80=8D=E3=81=A7=E3=82=B0?= =?UTF-8?q?=E3=83=AB=E3=83=BC=E3=83=97=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=81=8C=E6=97=A2=E8=AA=AD=E3=81=AB=E3=81=AA=E3=82=89?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20(#6476)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/i/read-all-messaging-messages.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/server/api/endpoints/i/read-all-messaging-messages.ts b/src/server/api/endpoints/i/read-all-messaging-messages.ts index 036ec02d6b..e47ef16bd9 100644 --- a/src/server/api/endpoints/i/read-all-messaging-messages.ts +++ b/src/server/api/endpoints/i/read-all-messaging-messages.ts @@ -1,6 +1,6 @@ import { publishMainStream } from '../../../../services/stream'; import define from '../../define'; -import { MessagingMessages } from '../../../../models'; +import { MessagingMessages, UserGroupJoinings } from '../../../../models'; export const meta = { desc: { @@ -27,5 +27,16 @@ export default define(meta, async (ps, user) => { 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'); });