From ea3674d04dd0a67962224073256dc7d4173527a5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Nov 2020 11:13:01 +0100 Subject: Remove notifications of muted accounts/servers --- server/controllers/api/server/server-blocklist.ts | 22 ++++++++++++++++++---- server/controllers/api/users/my-blocklist.ts | 14 ++++++++++++++ server/controllers/api/users/my-subscriptions.ts | 3 +++ 3 files changed, 35 insertions(+), 4 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/server/server-blocklist.ts b/server/controllers/api/server/server-blocklist.ts index f849b15c7..78e8a7e09 100644 --- a/server/controllers/api/server/server-blocklist.ts +++ b/server/controllers/api/server/server-blocklist.ts @@ -1,6 +1,11 @@ -import * as express from 'express' import 'multer' +import * as express from 'express' +import { logger } from '@server/helpers/logger' +import { UserNotificationModel } from '@server/models/account/user-notification' +import { getServerActor } from '@server/models/application/application' +import { UserRight } from '../../../../shared/models/users' import { getFormattedObjects } from '../../../helpers/utils' +import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -19,10 +24,7 @@ import { unblockServerByServerValidator } from '../../../middlewares/validators' import { AccountBlocklistModel } from '../../../models/account/account-blocklist' -import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' import { ServerBlocklistModel } from '../../../models/server/server-blocklist' -import { UserRight } from '../../../../shared/models/users' -import { getServerActor } from '@server/models/application/application' const serverBlocklistRouter = express.Router() @@ -100,6 +102,12 @@ async function blockAccount (req: express.Request, res: express.Response) { await addAccountInBlocklist(serverActor.Account.id, accountToBlock.id) + UserNotificationModel.removeNotificationsOf({ + id: accountToBlock.id, + type: 'account', + forUserId: null // For all users + }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) + return res.status(204).end() } @@ -131,6 +139,12 @@ async function blockServer (req: express.Request, res: express.Response) { await addServerInBlocklist(serverActor.Account.id, serverToBlock.id) + UserNotificationModel.removeNotificationsOf({ + id: serverToBlock.id, + type: 'server', + forUserId: null // For all users + }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) + return res.status(204).end() } diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts index 3a44376f2..6eba22d52 100644 --- a/server/controllers/api/users/my-blocklist.ts +++ b/server/controllers/api/users/my-blocklist.ts @@ -20,6 +20,8 @@ import { import { AccountBlocklistModel } from '../../../models/account/account-blocklist' import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' import { ServerBlocklistModel } from '../../../models/server/server-blocklist' +import { UserNotificationModel } from '@server/models/account/user-notification' +import { logger } from '@server/helpers/logger' const myBlocklistRouter = express.Router() @@ -91,6 +93,12 @@ async function blockAccount (req: express.Request, res: express.Response) { await addAccountInBlocklist(user.Account.id, accountToBlock.id) + UserNotificationModel.removeNotificationsOf({ + id: accountToBlock.id, + type: 'account', + forUserId: user.id + }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) + return res.status(204).end() } @@ -122,6 +130,12 @@ async function blockServer (req: express.Request, res: express.Response) { await addServerInBlocklist(user.Account.id, serverToBlock.id) + UserNotificationModel.removeNotificationsOf({ + id: serverToBlock.id, + type: 'server', + forUserId: user.id + }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) + return res.status(204).end() } diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index b8c234eef..66b33c477 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts @@ -26,6 +26,7 @@ import { } from '../../../middlewares/validators' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { VideoModel } from '../../../models/video/video' +import { sendUndoFollow } from '@server/lib/activitypub/send' const mySubscriptionsRouter = express.Router() @@ -138,6 +139,8 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon const subscription = res.locals.subscription await sequelizeTypescript.transaction(async t => { + if (subscription.state === 'accepted') await sendUndoFollow(subscription, t) + return subscription.destroy({ transaction: t }) }) -- cgit v1.2.3