diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-18 11:13:01 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-18 11:32:57 +0100 |
commit | ea3674d04dd0a67962224073256dc7d4173527a5 (patch) | |
tree | 7a1936b088509b88157e6493c8fb897f06bd29cb /server/controllers | |
parent | aa9cf3b98d5db85fefce918bb29840d0cdcb84c4 (diff) | |
download | PeerTube-ea3674d04dd0a67962224073256dc7d4173527a5.tar.gz PeerTube-ea3674d04dd0a67962224073256dc7d4173527a5.tar.zst PeerTube-ea3674d04dd0a67962224073256dc7d4173527a5.zip |
Remove notifications of muted accounts/servers
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/server/server-blocklist.ts | 22 | ||||
-rw-r--r-- | server/controllers/api/users/my-blocklist.ts | 14 | ||||
-rw-r--r-- | server/controllers/api/users/my-subscriptions.ts | 3 |
3 files changed, 35 insertions, 4 deletions
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 @@ | |||
1 | import * as express from 'express' | ||
2 | import 'multer' | 1 | import 'multer' |
2 | import * as express from 'express' | ||
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { UserNotificationModel } from '@server/models/account/user-notification' | ||
5 | import { getServerActor } from '@server/models/application/application' | ||
6 | import { UserRight } from '../../../../shared/models/users' | ||
3 | import { getFormattedObjects } from '../../../helpers/utils' | 7 | import { getFormattedObjects } from '../../../helpers/utils' |
8 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | ||
4 | import { | 9 | import { |
5 | asyncMiddleware, | 10 | asyncMiddleware, |
6 | asyncRetryTransactionMiddleware, | 11 | asyncRetryTransactionMiddleware, |
@@ -19,10 +24,7 @@ import { | |||
19 | unblockServerByServerValidator | 24 | unblockServerByServerValidator |
20 | } from '../../../middlewares/validators' | 25 | } from '../../../middlewares/validators' |
21 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' | 26 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' |
22 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | ||
23 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' | 27 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' |
24 | import { UserRight } from '../../../../shared/models/users' | ||
25 | import { getServerActor } from '@server/models/application/application' | ||
26 | 28 | ||
27 | const serverBlocklistRouter = express.Router() | 29 | const serverBlocklistRouter = express.Router() |
28 | 30 | ||
@@ -100,6 +102,12 @@ async function blockAccount (req: express.Request, res: express.Response) { | |||
100 | 102 | ||
101 | await addAccountInBlocklist(serverActor.Account.id, accountToBlock.id) | 103 | await addAccountInBlocklist(serverActor.Account.id, accountToBlock.id) |
102 | 104 | ||
105 | UserNotificationModel.removeNotificationsOf({ | ||
106 | id: accountToBlock.id, | ||
107 | type: 'account', | ||
108 | forUserId: null // For all users | ||
109 | }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) | ||
110 | |||
103 | return res.status(204).end() | 111 | return res.status(204).end() |
104 | } | 112 | } |
105 | 113 | ||
@@ -131,6 +139,12 @@ async function blockServer (req: express.Request, res: express.Response) { | |||
131 | 139 | ||
132 | await addServerInBlocklist(serverActor.Account.id, serverToBlock.id) | 140 | await addServerInBlocklist(serverActor.Account.id, serverToBlock.id) |
133 | 141 | ||
142 | UserNotificationModel.removeNotificationsOf({ | ||
143 | id: serverToBlock.id, | ||
144 | type: 'server', | ||
145 | forUserId: null // For all users | ||
146 | }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) | ||
147 | |||
134 | return res.status(204).end() | 148 | return res.status(204).end() |
135 | } | 149 | } |
136 | 150 | ||
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 { | |||
20 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' | 20 | import { AccountBlocklistModel } from '../../../models/account/account-blocklist' |
21 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' | 21 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' |
22 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' | 22 | import { ServerBlocklistModel } from '../../../models/server/server-blocklist' |
23 | import { UserNotificationModel } from '@server/models/account/user-notification' | ||
24 | import { logger } from '@server/helpers/logger' | ||
23 | 25 | ||
24 | const myBlocklistRouter = express.Router() | 26 | const myBlocklistRouter = express.Router() |
25 | 27 | ||
@@ -91,6 +93,12 @@ async function blockAccount (req: express.Request, res: express.Response) { | |||
91 | 93 | ||
92 | await addAccountInBlocklist(user.Account.id, accountToBlock.id) | 94 | await addAccountInBlocklist(user.Account.id, accountToBlock.id) |
93 | 95 | ||
96 | UserNotificationModel.removeNotificationsOf({ | ||
97 | id: accountToBlock.id, | ||
98 | type: 'account', | ||
99 | forUserId: user.id | ||
100 | }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) | ||
101 | |||
94 | return res.status(204).end() | 102 | return res.status(204).end() |
95 | } | 103 | } |
96 | 104 | ||
@@ -122,6 +130,12 @@ async function blockServer (req: express.Request, res: express.Response) { | |||
122 | 130 | ||
123 | await addServerInBlocklist(user.Account.id, serverToBlock.id) | 131 | await addServerInBlocklist(user.Account.id, serverToBlock.id) |
124 | 132 | ||
133 | UserNotificationModel.removeNotificationsOf({ | ||
134 | id: serverToBlock.id, | ||
135 | type: 'server', | ||
136 | forUserId: user.id | ||
137 | }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) | ||
138 | |||
125 | return res.status(204).end() | 139 | return res.status(204).end() |
126 | } | 140 | } |
127 | 141 | ||
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 { | |||
26 | } from '../../../middlewares/validators' | 26 | } from '../../../middlewares/validators' |
27 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 27 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
28 | import { VideoModel } from '../../../models/video/video' | 28 | import { VideoModel } from '../../../models/video/video' |
29 | import { sendUndoFollow } from '@server/lib/activitypub/send' | ||
29 | 30 | ||
30 | const mySubscriptionsRouter = express.Router() | 31 | const mySubscriptionsRouter = express.Router() |
31 | 32 | ||
@@ -138,6 +139,8 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon | |||
138 | const subscription = res.locals.subscription | 139 | const subscription = res.locals.subscription |
139 | 140 | ||
140 | await sequelizeTypescript.transaction(async t => { | 141 | await sequelizeTypescript.transaction(async t => { |
142 | if (subscription.state === 'accepted') await sendUndoFollow(subscription, t) | ||
143 | |||
141 | return subscription.destroy({ transaction: t }) | 144 | return subscription.destroy({ transaction: t }) |
142 | }) | 145 | }) |
143 | 146 | ||