From 594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Jul 2020 16:26:25 +0200 Subject: Add abuse messages/states notifications --- server/controllers/api/abuse.ts | 23 ++++++++++++++++++----- server/controllers/api/users/my-notifications.ts | 4 +++- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'server/controllers') 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 { setDefaultSort } from '../../middlewares' import { AccountModel } from '../../models/account/account' +import { Notifier } from '@server/lib/notifier' +import { logger } from '@server/helpers/logger' const abuseRouter = express.Router() @@ -123,19 +125,28 @@ async function listAbusesForAdmins (req: express.Request, res: express.Response) async function updateAbuse (req: express.Request, res: express.Response) { const abuse = res.locals.abuse + let stateUpdated = false if (req.body.moderationComment !== undefined) abuse.moderationComment = req.body.moderationComment - if (req.body.state !== undefined) abuse.state = req.body.state + + if (req.body.state !== undefined) { + abuse.state = req.body.state + stateUpdated = true + } await sequelizeTypescript.transaction(t => { return abuse.save({ transaction: t }) }) - // TODO: Notification + if (stateUpdated === true) { + AbuseModel.loadFull(abuse.id) + .then(abuseFull => Notifier.Instance.notifyOnAbuseStateChange(abuseFull)) + .catch(err => logger.error('Cannot notify on abuse state change', { err })) + } // Do not send the delete to other instances, we updated OUR copy of this abuse - return res.type('json').status(204).end() + return res.sendStatus(204) } async function deleteAbuse (req: express.Request, res: express.Response) { @@ -147,7 +158,7 @@ async function deleteAbuse (req: express.Request, res: express.Response) { // Do not send the delete to other instances, we delete OUR copy of this abuse - return res.type('json').status(204).end() + return res.sendStatus(204) } async function reportAbuse (req: express.Request, res: express.Response) { @@ -219,7 +230,9 @@ async function addAbuseMessage (req: express.Request, res: express.Response) { abuseId: abuse.id }) - // TODO: Notification + AbuseModel.loadFull(abuse.id) + .then(abuseFull => Notifier.Instance.notifyOnAbuseMessage(abuseFull, abuseMessage)) + .catch(err => logger.error('Cannot notify on new abuse message', { err })) return res.json({ 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 newUserRegistration: body.newUserRegistration, commentMention: body.commentMention, newInstanceFollower: body.newInstanceFollower, - autoInstanceFollowing: body.autoInstanceFollowing + autoInstanceFollowing: body.autoInstanceFollowing, + abuseNewMessage: body.abuseNewMessage, + abuseStateChange: body.abuseStateChange } await UserNotificationSettingModel.update(values, query) -- cgit v1.2.3