v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
parent
a5955c1123
commit
f6154dc0af
871 changed files with 26140 additions and 71950 deletions
|
@ -1,7 +1,7 @@
|
|||
import { publishMainStream } from '../stream';
|
||||
import { Note } from '../../models/entities/note';
|
||||
import { User } from '../../models/entities/user';
|
||||
import { NoteUnreads } from '../../models';
|
||||
import { NoteUnreads, Antennas, AntennaNotes, Users } from '../../models';
|
||||
|
||||
/**
|
||||
* Mark a note as read
|
||||
|
@ -17,27 +17,54 @@ export default (
|
|||
});
|
||||
|
||||
// v11 TODO: https://github.com/typeorm/typeorm/issues/2415
|
||||
//if (res.affected == 0) {
|
||||
//if (res.affected === 0) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
const count1 = await NoteUnreads.count({
|
||||
userId: userId,
|
||||
isSpecified: false
|
||||
});
|
||||
const [count1, count2] = await Promise.all([
|
||||
NoteUnreads.count({
|
||||
userId: userId,
|
||||
isSpecified: false
|
||||
}),
|
||||
NoteUnreads.count({
|
||||
userId: userId,
|
||||
isSpecified: true
|
||||
})
|
||||
]);
|
||||
|
||||
const count2 = await NoteUnreads.count({
|
||||
userId: userId,
|
||||
isSpecified: true
|
||||
});
|
||||
|
||||
if (count1 == 0) {
|
||||
if (count1 === 0) {
|
||||
// 全て既読になったイベントを発行
|
||||
publishMainStream(userId, 'readAllUnreadMentions');
|
||||
}
|
||||
|
||||
if (count2 == 0) {
|
||||
if (count2 === 0) {
|
||||
// 全て既読になったイベントを発行
|
||||
publishMainStream(userId, 'readAllUnreadSpecifiedNotes');
|
||||
}
|
||||
|
||||
const antennas = await Antennas.find({ userId });
|
||||
|
||||
await Promise.all(antennas.map(async antenna => {
|
||||
await AntennaNotes.update({
|
||||
antennaId: antenna.id,
|
||||
noteId: noteId
|
||||
}, {
|
||||
read: true
|
||||
});
|
||||
|
||||
const count = await AntennaNotes.count({
|
||||
antennaId: antenna.id,
|
||||
read: false
|
||||
});
|
||||
|
||||
if (count === 0) {
|
||||
publishMainStream(userId, 'readAntenna', antenna);
|
||||
}
|
||||
}));
|
||||
|
||||
Users.getHasUnreadAntenna(userId).then(unread => {
|
||||
if (!unread) {
|
||||
publishMainStream(userId, 'readAllAntennas');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue