diff --git a/public/language/en-GB/user.json b/public/language/en-GB/user.json index b010898322..e2bb9eeb4f 100644 --- a/public/language/en-GB/user.json +++ b/public/language/en-GB/user.json @@ -60,6 +60,7 @@ "chat-with": "Continue chat with %1", "new-chat-with": "Start new chat with %1", "flag-profile": "Flag Profile", + "profile-flagged": "Already flagged", "follow": "Follow", "unfollow": "Unfollow", "more": "More", diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js index 25ff7970a8..1d9884a8ca 100644 --- a/public/src/client/account/header.js +++ b/public/src/client/account/header.js @@ -56,6 +56,7 @@ define('forum/account/header', [ components.get('account/delete-content').on('click', () => AccountsDelete.content(ajaxify.data.theirid)); components.get('account/delete-all').on('click', () => AccountsDelete.purge(ajaxify.data.theirid)); components.get('account/flag').on('click', flagAccount); + components.get('account/already-flagged').on('click', rescindAccountFlag); components.get('account/block').on('click', () => toggleBlockAccount('block')); components.get('account/unblock').on('click', () => toggleBlockAccount('unblock')); }; @@ -130,6 +131,18 @@ define('forum/account/header', [ }); } + function rescindAccountFlag() { + const flagId = $(this).data('flag-id') + require(['flags'], function (flags) { + bootbox.confirm('[[flags:modal-confirm-rescind]]', function (confirm) { + if (!confirm) { + return; + } + flags.rescind(flagId); + }); + }); + } + function toggleBlockAccount(action) { socket.emit('user.toggleBlock', { blockeeUid: ajaxify.data.uid, diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js index 9e779a9a75..ca4fffb7ad 100644 --- a/src/controllers/accounts/helpers.js +++ b/src/controllers/accounts/helpers.js @@ -15,6 +15,7 @@ const messaging = require('../../messaging'); const categories = require('../../categories'); const posts = require('../../posts'); const activitypub = require('../../activitypub'); +const flags = require('../../flags'); const relative_path = nconf.get('relative_path'); @@ -26,7 +27,12 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {}) return null; } - const results = await getAllData(uid, callerUID); + const [results, canFlag, flagged, flagId] = await Promise.all([ + getAllData(uid, callerUID), + privileges.users.canFlag(callerUID, uid), + flags.exists('user', uid, callerUID), + flags.getFlagIdByTarget('user', uid), + ]); if (!results.userData) { throw new Error('[[error:invalid-uid]]'); } @@ -80,7 +86,9 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {}) userData.canEdit = results.canEdit; userData.canBan = results.canBanUser; userData.canMute = results.canMuteUser; - userData.canFlag = (await privileges.users.canFlag(callerUID, userData.uid)).flag; + userData.canFlag = canFlag.flag; + userData.flagged = flagged; + userData.flagId = flagId; userData.canChangePassword = isAdmin || (isSelf && !meta.config['password:disableEdit']); userData.isSelf = isSelf; userData.isFollowing = results.isFollowing;