Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { publishMainStream } from "../stream.js";
|
||||
import { Mutings, NoteThreadMutings, NoteUnreads } from "../../models/index.js";
|
||||
import { genId } from "../../misc/gen-id.js";
|
||||
export async function insertNoteUnread(userId, note, params) {
|
||||
//#region ミュートしているなら無視
|
||||
// TODO: 現在の仕様ではChannelにミュートは適用されないのでよしなにケアする
|
||||
const mute = await Mutings.findBy({
|
||||
muterId: userId
|
||||
});
|
||||
if (mute.map((m)=>m.muteeId).includes(note.userId)) return;
|
||||
//#endregion
|
||||
// スレッドミュート
|
||||
const threadMute = await NoteThreadMutings.findOneBy({
|
||||
userId: userId,
|
||||
threadId: note.threadId || note.id
|
||||
});
|
||||
if (threadMute) return;
|
||||
const unread = {
|
||||
id: genId(),
|
||||
noteId: note.id,
|
||||
userId: userId,
|
||||
isSpecified: params.isSpecified,
|
||||
isMentioned: params.isMentioned,
|
||||
noteChannelId: note.channelId,
|
||||
noteUserId: note.userId
|
||||
};
|
||||
await NoteUnreads.insert(unread);
|
||||
// 2秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する
|
||||
setTimeout(async ()=>{
|
||||
const exist = await NoteUnreads.exist({
|
||||
where: {
|
||||
id: unread.id
|
||||
}
|
||||
});
|
||||
if (!exist) return;
|
||||
if (params.isMentioned) {
|
||||
publishMainStream(userId, "unreadMention", note.id);
|
||||
}
|
||||
if (params.isSpecified) {
|
||||
publishMainStream(userId, "unreadSpecifiedNote", note.id);
|
||||
}
|
||||
if (note.channelId) {
|
||||
publishMainStream(userId, "unreadChannel", note.id);
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
Reference in New Issue
Block a user