summaryrefslogtreecommitdiff
path: root/src/services/note/read-mention.ts
blob: 2a668ecd6cf278884a60edfbdac304e409b70c1d (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 mention note as read
 */
export async function readMention(
	userId: User['id'],
	noteIds: Note['id'][]
) {
	// Remove the records
	await NoteUnreads.delete({
		userId: userId,
		noteId: In(noteIds),
	});

	const mentionsCount = await NoteUnreads.count({
		userId: userId,
		isMentioned: true
	});

	if (mentionsCount === 0) {
		// 全て既読になったイベントを発行
		publishMainStream(userId, 'readAllUnreadMentions');
	}
}