blob: 0fcb66bf98ce5d13270e0c79add146fcdd5f050b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import { publishMainStream } from '../stream';
import { Note } from '../../models/entities/note';
import { User } from '../../models/entities/user';
import { NoteUnreads } from '../../models';
import { In } from 'typeorm';
/**
* Mark a specified note as read
*/
export async function readSpecifiedNote(
userId: User['id'],
noteIds: Note['id'][]
) {
// Remove the records
await NoteUnreads.delete({
userId: userId,
noteId: In(noteIds),
});
const specifiedCount = await NoteUnreads.count({
userId: userId,
isSpecified: true
});
if (specifiedCount === 0) {
// 全て既読になったイベントを発行
publishMainStream(userId, 'readAllUnreadSpecifiedNotes');
}
}
|