From 92fac1cd9f346e17db6fbce363faa97aa30ce647 Mon Sep 17 00:00:00 2001 From: Sol Fisher Romanoff Date: Thu, 16 Jun 2022 10:04:33 +0300 Subject: [PATCH] Allow removing accounts from list --- src/components/list_edit/list_edit.js | 15 +++++++++++---- src/services/api/api.service.js | 13 +++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/list_edit/list_edit.js b/src/components/list_edit/list_edit.js index 5c1b36f1..42316e03 100644 --- a/src/components/list_edit/list_edit.js +++ b/src/components/list_edit/list_edit.js @@ -94,14 +94,21 @@ const ListNew = { }) }, updateList () { - // the API has two different endpoints for "updating the list name" and - // "updating the accounts on the list". + // the API has three different endpoints: one for "updating the list name", + // one for "adding new accounts to the list" and one for "removing + // accounts from the list". this.$store.state.api.backendInteractor.updateList({ id: this.id, title: this.title }) this.$store.state.api.backendInteractor.addAccountsToList({ id: this.id, accountIds: this.selectedUserIds - }).then(() => { - this.$router.push({ name: 'list-timeline', params: { id: this.id } }) }) + this.$store.state.api.backendInteractor.getListAccounts({ id: this.id }) + .then((data) => { + this.$store.state.api.backendInteractor.removeAccountsFromList({ + id: this.id, accountIds: data.filter(x => !this.selectedUserIds.includes(x)) + }) + }).then(() => { + this.$router.push({ name: 'list-timeline', params: { id: this.id } }) + }) }, deleteList () { this.$store.state.api.backendInteractor.deleteList({ id: this.id }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 7f2fc5ac..fa3439e9 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -441,6 +441,18 @@ const addAccountsToList = ({ id, accountIds, credentials }) => { }) } +const removeAccountsFromList = ({ id, accountIds, credentials }) => { + const url = MASTODON_LIST_ACCOUNTS_URL(id) + const headers = authHeaders(credentials) + headers['Content-Type'] = 'application/json' + + return fetch(url, { + method: 'DELETE', + headers: headers, + body: JSON.stringify({ account_ids: accountIds }) + }) +} + const deleteList = ({ id, credentials }) => { const url = MASTODON_LIST_URL(id) return fetch(url, { @@ -1427,6 +1439,7 @@ const apiService = { updateList, getListAccounts, addAccountsToList, + removeAccountsFromList, deleteList, approveUser, denyUser,