diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 28c57a0f..108eaba7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,8 +31,7 @@ Lint: Automatically fix most linting issues: - npx standard --fix - npx standard --fix --plugin html 'routes/**/*.html' + npm run lint-fix ## Testing diff --git a/package.json b/package.json index f1045332..18ac3c12 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "version": "0.2.3", "scripts": { "lint": "standard && standard --plugin html 'routes/**/*.html'", + "lint-fix": "standard --fix && standard --fix --plugin html 'routes/**/*.html'", "dev": "run-s build-svg build-inline-script serve-dev", "serve-dev": "run-p --race build-sass-watch serve", "serve": "node server.js", diff --git a/routes/_actions/block.js b/routes/_actions/block.js index 850cce06..b6fb30f7 100644 --- a/routes/_actions/block.js +++ b/routes/_actions/block.js @@ -2,6 +2,7 @@ import { store } from '../_store/store' import { blockAccount, unblockAccount } from '../_api/block' import { toast } from '../_utils/toast' import { updateProfileAndRelationship } from './accounts' +import { emit } from '../_utils/eventBus' export async function setAccountBlocked (accountId, block, toastOnSuccess) { let { currentInstance, accessToken } = store.get() @@ -19,6 +20,7 @@ export async function setAccountBlocked (accountId, block, toastOnSuccess) { toast.say('Unblocked account') } } + emit('refreshAccountsList') } catch (e) { console.error(e) toast.say(`Unable to ${block ? 'block' : 'unblock'} account: ` + (e.message || '')) diff --git a/routes/_actions/mute.js b/routes/_actions/mute.js index ff6571f1..7b285419 100644 --- a/routes/_actions/mute.js +++ b/routes/_actions/mute.js @@ -2,6 +2,7 @@ import { store } from '../_store/store' import { muteAccount, unmuteAccount } from '../_api/mute' import { toast } from '../_utils/toast' import { updateProfileAndRelationship } from './accounts' +import { emit } from '../_utils/eventBus' export async function setAccountMuted (accountId, mute, toastOnSuccess) { let { currentInstance, accessToken } = store.get() @@ -19,6 +20,7 @@ export async function setAccountMuted (accountId, mute, toastOnSuccess) { toast.say('Unmuted account') } } + emit('refreshAccountsList') } catch (e) { console.error(e) toast.say(`Unable to ${mute ? 'mute' : 'unmute'} account: ` + (e.message || '')) diff --git a/routes/_actions/requests.js b/routes/_actions/requests.js new file mode 100644 index 00000000..6a9d1f3d --- /dev/null +++ b/routes/_actions/requests.js @@ -0,0 +1,29 @@ +import { store } from '../_store/store' +import { approveFollowRequest, rejectFollowRequest } from '../_api/requests' +import { emit } from '../_utils/eventBus' +import { toast } from '../_utils/toast' + +export async function setFollowRequestApprovedOrRejected (accountId, approved, toastOnSuccess) { + let { + currentInstance, + accessToken + } = store.get() + try { + if (approved) { + await approveFollowRequest(currentInstance, accessToken, accountId) + } else { + await rejectFollowRequest(currentInstance, accessToken, accountId) + } + if (toastOnSuccess) { + if (approved) { + toast.say('Approved follow request') + } else { + toast.say('Rejected follow request') + } + } + emit('refreshAccountsList') + } catch (e) { + console.error(e) + toast.say(`Unable to ${approved ? 'approve' : 'reject'} account: ` + (e.message || '')) + } +} diff --git a/routes/_api/requests.js b/routes/_api/requests.js new file mode 100644 index 00000000..394729e7 --- /dev/null +++ b/routes/_api/requests.js @@ -0,0 +1,12 @@ +import { postWithTimeout } from '../_utils/ajax' +import { auth, basename } from './utils' + +export async function approveFollowRequest (instanceName, accessToken, accountId) { + let url = `${basename(instanceName)}/api/v1/follow_requests/${accountId}/authorize` + return postWithTimeout(url, null, auth(accessToken)) +} + +export async function rejectFollowRequest (instanceName, accessToken, accountId) { + let url = `${basename(instanceName)}/api/v1/follow_requests/${accountId}/reject` + return postWithTimeout(url, null, auth(accessToken)) +} diff --git a/routes/_components/AccountsListPage.html b/routes/_components/AccountsListPage.html index 3d9a7847..c969e850 100644 --- a/routes/_components/AccountsListPage.html +++ b/routes/_components/AccountsListPage.html @@ -4,7 +4,11 @@ {{elseif accounts && accounts.length}}