1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-23 11:08:36 +09:00
misskey/src/services/add-note-to-antenna.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Antenna } from '../models/entities/antenna';
import { Note } from '../models/entities/note';
import { AntennaNotes, Mutings, Notes } from '../models';
2021-03-23 17:43:07 +09:00
import { genId } from '@/misc/gen-id';
import { isMutedUserRelated } from '@/misc/is-muted-user-related';
import { publishAntennaStream, publishMainStream } from './stream';
import { User } from '../models/entities/user';
export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }) {
// 通知しない設定になっているか、自分自身の投稿なら既読にする
const read = !antenna.notify || (antenna.userId === noteUser.id);
2021-03-21 21:27:09 +09:00
AntennaNotes.insert({
id: genId(),
antennaId: antenna.id,
noteId: note.id,
read: read,
});
publishAntennaStream(antenna.id, 'note', note);
if (!read) {
const mutings = await Mutings.find({
where: {
muterId: antenna.userId
},
select: ['muteeId']
});
// Copy
const _note: Note = {
...note
};
if (note.replyId != null) {
2021-02-13 15:33:38 +09:00
_note.reply = await Notes.findOneOrFail(note.replyId);
}
if (note.renoteId != null) {
2021-02-13 15:33:38 +09:00
_note.renote = await Notes.findOneOrFail(note.renoteId);
}
if (isMutedUserRelated(_note, new Set<string>(mutings.map(x => x.muteeId)))) {
return;
}
// 2秒経っても既読にならなかったら通知
setTimeout(async () => {
const unread = await AntennaNotes.findOne({ antennaId: antenna.id, read: false });
if (unread) {
publishMainStream(antenna.userId, 'unreadAntenna', antenna);
}
}, 2000);
}
}