From 732d1fded469181e65a20bd03b2a1ba2b834bd73 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 14 Apr 2018 18:47:55 -0700 Subject: [PATCH] Block and unblock an account (#125) One of the many features listed in #6 --- routes/_actions/block.js | 27 +++++++++ routes/_api/block.js | 12 ++++ routes/_components/IconButton.html | 2 + .../AccountProfileOptionsDialog.html | 28 ++++++++- .../components/StatusOptionsDialog.html | 60 +++++++++++++------ .../showAccountProfileOptionsDialog.js | 5 +- .../_components/profile/AccountProfile.html | 2 +- .../profile/AccountProfileDetails.html | 3 +- .../profile/AccountProfileFollow.html | 28 ++++++--- .../profile/AccountProfileHeader.html | 4 +- tests/spec/113-block-unblock.js | 53 ++++++++++++++++ tests/utils.js | 10 ++++ 12 files changed, 201 insertions(+), 33 deletions(-) create mode 100644 routes/_actions/block.js create mode 100644 routes/_api/block.js create mode 100644 tests/spec/113-block-unblock.js diff --git a/routes/_actions/block.js b/routes/_actions/block.js new file mode 100644 index 00000000..07587757 --- /dev/null +++ b/routes/_actions/block.js @@ -0,0 +1,27 @@ +import { store } from '../_store/store' +import { blockAccount, unblockAccount } from '../_api/block' +import { toast } from '../_utils/toast' +import { updateProfileAndRelationship } from './accounts' + +export async function setAccountBlocked (accountId, block, toastOnSuccess) { + let instanceName = store.get('currentInstance') + let accessToken = store.get('accessToken') + try { + if (block) { + await blockAccount(instanceName, accessToken, accountId) + } else { + await unblockAccount(instanceName, accessToken, accountId) + } + await updateProfileAndRelationship(accountId) + if (toastOnSuccess) { + if (block) { + toast.say('Blocked account') + } else { + toast.say('Unblocked account') + } + } + } catch (e) { + console.error(e) + toast.say(`Unable to ${block ? 'block' : 'unblock'} account: ` + (e.message || '')) + } +} diff --git a/routes/_api/block.js b/routes/_api/block.js new file mode 100644 index 00000000..772444f6 --- /dev/null +++ b/routes/_api/block.js @@ -0,0 +1,12 @@ +import { auth, basename } from './utils' +import { postWithTimeout } from '../_utils/ajax' + +export async function blockAccount (instanceName, accessToken, accountId) { + let url = `${basename(instanceName)}/api/v1/accounts/${accountId}/block` + return postWithTimeout(url, null, auth(accessToken)) +} + +export async function unblockAccount (instanceName, accessToken, accountId) { + let url = `${basename(instanceName)}/api/v1/accounts/${accountId}/unblock` + return postWithTimeout(url, null, auth(accessToken)) +} diff --git a/routes/_components/IconButton.html b/routes/_components/IconButton.html index c4d09a96..02d4d9fa 100644 --- a/routes/_components/IconButton.html +++ b/routes/_components/IconButton.html @@ -1,5 +1,6 @@ {{#if delegateKey}}