1
0
Files
pawkey-sk/src/services/note/read-mention.ts
T
2021-03-19 20:43:24 +09:00

30 lines
675 B
TypeScript

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');
}
}