fix: #8286, rescind notif when its resolved/rejected

v1.18.x
Barış Soner Uşaklı 5 years ago
parent c0e441d3b2
commit 0391856d7d

@ -363,7 +363,7 @@ Flags.getTargetCid = async function (type, id) {
};
Flags.update = async function (flagId, uid, changeset) {
const current = await db.getObjectFields('flag:' + flagId, ['state', 'assignee', 'type', 'targetId']);
const current = await db.getObjectFields('flag:' + flagId, ['uid', 'state', 'assignee', 'type', 'targetId']);
const now = changeset.datetime || Date.now();
const notifyAssignee = async function (assigneeId) {
if (assigneeId === '' || parseInt(uid, 10) === parseInt(assigneeId, 10)) {
@ -404,6 +404,9 @@ Flags.update = async function (flagId, uid, changeset) {
} else {
tasks.push(db.sortedSetAdd('flags:byState:' + changeset[prop], now, flagId));
tasks.push(db.sortedSetRemove('flags:byState:' + current[prop], flagId));
if (changeset[prop] === 'resolved' || changeset[prop] === 'rejected') {
tasks.push(notifications.rescind('flag:' + current.type + ':' + current.targetId + ':uid:' + current.uid));
}
}
} else if (prop === 'assignee') {
/* eslint-disable-next-line */

@ -1,17 +1,19 @@
'use strict';
var assert = require('assert');
var async = require('async');
var db = require('./mocks/databasemock');
var Flags = require('../src/flags');
var Categories = require('../src/categories');
var Topics = require('../src/topics');
var Posts = require('../src/posts');
var User = require('../src/user');
var Groups = require('../src/groups');
var Meta = require('../src/meta');
var Privileges = require('../src/privileges');
const assert = require('assert');
const async = require('async');
const util = require('util');
const sleep = util.promisify(setTimeout);
const db = require('./mocks/databasemock');
const Flags = require('../src/flags');
const Categories = require('../src/categories');
const Topics = require('../src/topics');
const Posts = require('../src/posts');
const User = require('../src/user');
const Groups = require('../src/groups');
const Meta = require('../src/meta');
const Privileges = require('../src/privileges');
describe('Flags', function () {
let uid1;
@ -363,6 +365,28 @@ describe('Flags', function () {
const state = await db.getObjectField('flag:1', 'state');
assert.strictEqual('wip', state);
});
it('should rescind notification if flag is resolved', async () => {
const SocketFlags = require('../src/socket.io/flags.js');
const result = await Topics.post({
cid: category.cid,
uid: uid3,
title: 'Topic to flag',
content: 'This is flaggable content',
});
const flagId = await SocketFlags.create({ uid: uid1 }, { type: 'post', id: result.postData.pid, reason: 'spam' });
await sleep(2000);
let userNotifs = await User.notifications.getAll(adminUid);
assert(userNotifs.includes('flag:post:' + result.postData.pid + ':uid:' + uid1));
await Flags.update(flagId, adminUid, {
state: 'resolved',
});
userNotifs = await User.notifications.getAll(adminUid);
assert(!userNotifs.includes('flag:post:' + result.postData.pid + ':uid:' + uid1));
});
});
describe('.getTarget()', function () {

Loading…
Cancel
Save