aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-27 16:26:25 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commit594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (patch)
treebae28fa6215a3a3c6ccd78aea6ea7e75c500a96f /server/controllers/api
parent94148c9028829b5576a5dcbfba2c7fb9cf6443d3 (diff)
downloadPeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.gz
PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.zst
PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.zip
Add abuse messages/states notifications
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/abuse.ts23
-rw-r--r--server/controllers/api/users/my-notifications.ts4
2 files changed, 21 insertions, 6 deletions
diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.ts
index 72e62fc0b..03e6be8c8 100644
--- a/server/controllers/api/abuse.ts
+++ b/server/controllers/api/abuse.ts
@@ -25,6 +25,8 @@ import {
25 setDefaultSort 25 setDefaultSort
26} from '../../middlewares' 26} from '../../middlewares'
27import { AccountModel } from '../../models/account/account' 27import { AccountModel } from '../../models/account/account'
28import { Notifier } from '@server/lib/notifier'
29import { logger } from '@server/helpers/logger'
28 30
29const abuseRouter = express.Router() 31const abuseRouter = express.Router()
30 32
@@ -123,19 +125,28 @@ async function listAbusesForAdmins (req: express.Request, res: express.Response)
123 125
124async function updateAbuse (req: express.Request, res: express.Response) { 126async function updateAbuse (req: express.Request, res: express.Response) {
125 const abuse = res.locals.abuse 127 const abuse = res.locals.abuse
128 let stateUpdated = false
126 129
127 if (req.body.moderationComment !== undefined) abuse.moderationComment = req.body.moderationComment 130 if (req.body.moderationComment !== undefined) abuse.moderationComment = req.body.moderationComment
128 if (req.body.state !== undefined) abuse.state = req.body.state 131
132 if (req.body.state !== undefined) {
133 abuse.state = req.body.state
134 stateUpdated = true
135 }
129 136
130 await sequelizeTypescript.transaction(t => { 137 await sequelizeTypescript.transaction(t => {
131 return abuse.save({ transaction: t }) 138 return abuse.save({ transaction: t })
132 }) 139 })
133 140
134 // TODO: Notification 141 if (stateUpdated === true) {
142 AbuseModel.loadFull(abuse.id)
143 .then(abuseFull => Notifier.Instance.notifyOnAbuseStateChange(abuseFull))
144 .catch(err => logger.error('Cannot notify on abuse state change', { err }))
145 }
135 146
136 // Do not send the delete to other instances, we updated OUR copy of this abuse 147 // Do not send the delete to other instances, we updated OUR copy of this abuse
137 148
138 return res.type('json').status(204).end() 149 return res.sendStatus(204)
139} 150}
140 151
141async function deleteAbuse (req: express.Request, res: express.Response) { 152async function deleteAbuse (req: express.Request, res: express.Response) {
@@ -147,7 +158,7 @@ async function deleteAbuse (req: express.Request, res: express.Response) {
147 158
148 // Do not send the delete to other instances, we delete OUR copy of this abuse 159 // Do not send the delete to other instances, we delete OUR copy of this abuse
149 160
150 return res.type('json').status(204).end() 161 return res.sendStatus(204)
151} 162}
152 163
153async function reportAbuse (req: express.Request, res: express.Response) { 164async function reportAbuse (req: express.Request, res: express.Response) {
@@ -219,7 +230,9 @@ async function addAbuseMessage (req: express.Request, res: express.Response) {
219 abuseId: abuse.id 230 abuseId: abuse.id
220 }) 231 })
221 232
222 // TODO: Notification 233 AbuseModel.loadFull(abuse.id)
234 .then(abuseFull => Notifier.Instance.notifyOnAbuseMessage(abuseFull, abuseMessage))
235 .catch(err => logger.error('Cannot notify on new abuse message', { err }))
223 236
224 return res.json({ 237 return res.json({
225 abuseMessage: { 238 abuseMessage: {
diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts
index 0be51c128..050866960 100644
--- a/server/controllers/api/users/my-notifications.ts
+++ b/server/controllers/api/users/my-notifications.ts
@@ -77,7 +77,9 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
77 newUserRegistration: body.newUserRegistration, 77 newUserRegistration: body.newUserRegistration,
78 commentMention: body.commentMention, 78 commentMention: body.commentMention,
79 newInstanceFollower: body.newInstanceFollower, 79 newInstanceFollower: body.newInstanceFollower,
80 autoInstanceFollowing: body.autoInstanceFollowing 80 autoInstanceFollowing: body.autoInstanceFollowing,
81 abuseNewMessage: body.abuseNewMessage,
82 abuseStateChange: body.abuseStateChange
81 } 83 }
82 84
83 await UserNotificationSettingModel.update(values, query) 85 await UserNotificationSettingModel.update(values, query)