2019-02-05 06:14:23 +01:00
|
|
|
import { publishMainStream } from '../../../../services/stream';
|
2018-12-27 21:06:25 +01:00
|
|
|
import define from '../../define';
|
2020-07-04 03:45:36 +02:00
|
|
|
import { MessagingMessages, UserGroupJoinings } from '../../../../models';
|
2018-12-27 21:06:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
|
|
|
'ja-JP': 'トークメッセージをすべて既読にします。',
|
|
|
|
'en-US': 'Mark all talk messages as read.'
|
|
|
|
},
|
|
|
|
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['account', 'messaging'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2018-12-27 21:06:25 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
kind: 'write:account',
|
2018-12-27 21:06:25 +01:00
|
|
|
|
|
|
|
params: {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, user) => {
|
2018-12-27 21:06:25 +01:00
|
|
|
// Update documents
|
2019-04-07 14:50:36 +02:00
|
|
|
await MessagingMessages.update({
|
|
|
|
recipientId: user.id,
|
2018-12-27 21:06:25 +01:00
|
|
|
isRead: false
|
|
|
|
}, {
|
2019-04-07 14:50:36 +02:00
|
|
|
isRead: true
|
2018-12-27 21:06:25 +01:00
|
|
|
});
|
|
|
|
|
2020-07-04 03:45:36 +02:00
|
|
|
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()));
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
publishMainStream(user.id, 'readAllMessagingMessages');
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|