do not create muted notification types in respective threads

This commit is contained in:
Johann150 2021-12-30 21:22:48 +01:00
parent 87411a6ed8
commit cc5a197785
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
4 changed files with 51 additions and 23 deletions

View file

@ -1,11 +1,11 @@
import { Not } from 'typeorm';
import { ArrayOverlap, Not } from 'typeorm';
import { publishNoteStream } from '@/services/stream.js';
import { createNotification } from '@/services/create-notification.js';
import { deliver } from '@/queue/index.js';
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import renderVote from '@/remote/activitypub/renderer/vote.js';
import { deliverQuestionUpdate } from '@/services/note/polls/update.js';
import { PollVotes, NoteWatchings, Users, Polls, Blockings } from '@/models/index.js';
import { PollVotes, NoteWatchings, Users, Polls, Blockings, NoteThreadMutings } from '@/models/index.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { genId } from '@/misc/gen-id.js';
import { getNote } from '../../../common/getters.js';
@ -136,14 +136,24 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
// Notify
createNotification(note.userId, 'pollVote', {
notifierId: user.id,
noteId: note.id,
choice: ps.choice,
// check if this thread and notification type is muted
const threadMuted = await NoteThreadMutings.findOne({
userId: note.userId,
threadId: note.threadId || note.id,
mutingNotificationTypes: ArrayOverlap(['pollVote']),
});
// Notify
if (!threadMuted) {
createNotification(note.userId, 'pollVote', {
notifierId: user.id,
noteId: note.id,
choice: ps.choice,
});
}
// Fetch watchers
// checking for mutes is not necessary here, as note watchings will be
// deleted when a thread is muted
NoteWatchings.findBy({
noteId: note.id,
userId: Not(user.id),

View file

@ -1,4 +1,4 @@
import { Not, In } from 'typeorm';
import { ArrayOverlap, Not, In } from 'typeorm';
import * as mfm from 'mfm-js';
import { db } from '@/db/postgre.js';
import es from '@/db/elasticsearch.js';
@ -80,15 +80,19 @@ class NotificationManager {
public async deliver() {
for (const x of this.queue) {
// ミュート情報を取得
const mentioneeMutes = await Mutings.findBy({
// check if the sender or thread are muted
const userMuted = await Mutings.findOneBy({
muterId: x.target,
muteeId: this.notifier.id,
});
const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId);
const threadMuted = await NoteThreadMutings.findOneBy({
userId: x.target,
threadId: this.note.threadId || this.note.id,
mutingNotificationTypes: ArrayOverlap([x.reason]),
});
// 通知される側のユーザーが通知する側のユーザーをミュートしていない限りは通知する
if (!mentioneesMutedUserIds.includes(this.notifier.id)) {
if (!userMuted && !threadMuted) {
createNotification(x.target, x.reason, {
notifierId: this.notifier.id,
noteId: this.note.id,

View file

@ -1,8 +1,8 @@
import { Not } from 'typeorm';
import { ArrayOverlap, Not } from 'typeorm';
import { publishNoteStream } from '@/services/stream.js';
import { CacheableUser } from '@/models/entities/user.js';
import { Note } from '@/models/entities/note.js';
import { PollVotes, NoteWatchings, Polls, Blockings } from '@/models/index.js';
import { PollVotes, NoteWatchings, Polls, Blockings, NoteThreadMutings } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js';
import { createNotification } from '../../create-notification.js';
@ -57,12 +57,20 @@ export default async function(user: CacheableUser, note: Note, choice: number) {
userId: user.id,
});
// Notify
createNotification(note.userId, 'pollVote', {
notifierId: user.id,
noteId: note.id,
choice,
// check if this thread and notification type is muted
const muted = await NoteThreadMutings.findOne({
userId: note.userId,
threadId: note.threadId || note.id,
mutingNotificationTypes: ArrayOverlap(['pollVote']),
});
// Notify
if (!muted) {
createNotification(note.userId, 'pollVote', {
notifierId: user.id,
noteId: note.id,
choice: choice,
});
}
// Fetch watchers
NoteWatchings.findBy({

View file

@ -1,4 +1,4 @@
import { IsNull, Not } from 'typeorm';
import { ArrayOverlap, IsNull, Not } from 'typeorm';
import { publishNoteStream } from '@/services/stream.js';
import { renderLike } from '@/remote/activitypub/renderer/like.js';
import DeliverManager from '@/remote/activitypub/deliver-manager.js';
@ -6,7 +6,7 @@ import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import { toDbReaction, decodeReaction } from '@/misc/reaction-lib.js';
import { User, IRemoteUser } from '@/models/entities/user.js';
import { Note } from '@/models/entities/note.js';
import { NoteReactions, Users, NoteWatchings, Notes, Emojis, Blockings } from '@/models/index.js';
import { NoteReactions, Users, NoteWatchings, Notes, Emojis, Blockings, NoteThreadMutings } from '@/models/index.js';
import { perUserReactionsChart } from '@/services/chart/index.js';
import { genId } from '@/misc/gen-id.js';
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js';
@ -98,8 +98,14 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note,
userId: user.id,
});
// check if this thread is muted
const threadMuted = await NoteThreadMutings.findOne({
userId: note.userId,
threadId: note.threadId || note.id,
mutingNotificationTypes: ArrayOverlap(['reaction']),
});
// リアクションされたユーザーがローカルユーザーなら通知を作成
if (note.userHost === null) {
if (note.userHost === null && !threadMuted) {
createNotification(note.userId, 'reaction', {
notifierId: user.id,
noteId: note.id,