diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-09-19 14:18:34 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-09-19 14:18:34 +0900 |
| commit | d9f0e158a35eec183da77e84a3b038fab645bf62 (patch) | |
| tree | a7cbad45883ff56d35771d849f95dbd911e3e45c /src/services/note/unread.ts | |
| parent | 8.55.0 (diff) | |
| download | sharkey-d9f0e158a35eec183da77e84a3b038fab645bf62.tar.gz sharkey-d9f0e158a35eec183da77e84a3b038fab645bf62.tar.bz2 sharkey-d9f0e158a35eec183da77e84a3b038fab645bf62.zip | |
Implement #2736
Diffstat (limited to 'src/services/note/unread.ts')
| -rw-r--r-- | src/services/note/unread.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/services/note/unread.ts b/src/services/note/unread.ts new file mode 100644 index 0000000000..6e10c8b248 --- /dev/null +++ b/src/services/note/unread.ts @@ -0,0 +1,47 @@ +import NoteUnread from '../../models/note-unread'; +import User, { IUser } from '../../models/user'; +import { INote } from '../../models/note'; +import Mute from '../../models/mute'; +import { publishUserStream } from '../../stream'; + +export default async function(user: IUser, note: INote, isSpecified = false) { + const unread = await NoteUnread.insert({ + noteId: note._id, + userId: user._id, + isSpecified, + _note: { + userId: note.userId + } + }); + + // 3秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する + setTimeout(async () => { + const exist = await NoteUnread.findOne({ _id: unread._id }); + if (exist == null) return; + + //#region ただしミュートされているなら発行しない + const mute = await Mute.find({ + muterId: user._id + }); + const mutedUserIds = mute.map(m => m.muteeId.toString()); + if (mutedUserIds.includes(note.userId.toString())) return; + //#endregion + + User.update({ + _id: user._id + }, { + $set: isSpecified ? { + hasUnreadSpecifiedNotes: true, + hasUnreadMentions: true + } : { + hasUnreadMentions: true + } + }); + + publishUserStream(user._id, 'unreadMention', note._id); + + if (isSpecified) { + publishUserStream(user._id, 'unreadSpecifiedNote', note._id); + } + }, 3000); +} |