Prevent notifications if the notification is for a note that is muted (#9323)

This commit is contained in:
Kainoa Kanter 2022-12-29 11:36:57 +00:00
commit fd180ab642
3 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import { publishMainStream } from '@/services/stream.js';
import { pushNotification } from '@/services/push-notification.js';
import { Notifications, Mutings, UserProfiles, Users } from '@/models/index.js';
import { Notifications, Mutings, NoteThreadMutings, UserProfiles, Users } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js';
import { User } from '@/models/entities/user.js';
import { Notification } from '@/models/entities/notification.js';
@ -19,6 +19,17 @@ export async function createNotification(
const isMuted = profile?.mutingNotificationTypes.includes(type);
if (data.note != null) {
const threadMute = await NoteThreadMutings.findOneBy({
userId: notifieeId,
threadId: data.note.threadId || data.note.id,
});
if (threadMute) {
return null;
}
}
// Create notification
const notification = await Notifications.insert({
id: genId(),

View File

@ -92,6 +92,7 @@ class NotificationManager {
createNotification(x.target, x.reason, {
notifierId: this.notifier.id,
noteId: this.note.id,
note: this.note,
});
}
}
@ -394,8 +395,15 @@ export default async (user: { id: User['id']; username: User['username']; host:
// Notify
if (data.renote.userHost === null) {
const threadMuted = await NoteThreadMutings.findOneBy({
userId: data.renote.userId,
threadId: data.renote.threadId || data.renote.id,
});
if (!threadMuted) {
nm.push(data.renote.userId, type);
}
}
// Fetch watchers
nmRelatedPromises.push(notifyToWatchersOfRenotee(data.renote, user, nm, type));

View File

@ -102,6 +102,7 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note,
if (note.userHost === null) {
createNotification(note.userId, 'reaction', {
notifierId: user.id,
note: note,
noteId: note.id,
reaction: reaction,
});
@ -115,6 +116,7 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note,
for (const watcher of watchers) {
createNotification(watcher.userId, 'reaction', {
notifierId: user.id,
note: note,
noteId: note.id,
reaction: reaction,
});