From b8d1ccb33928ffd6fd6d9e602c871b3d21a255e6 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Wed, 14 Mar 2018 08:36:12 -0700 Subject: [PATCH] add ability to delete a status --- bin/svgs.js | 3 ++- routes/_actions/delete.js | 15 +++++++++++++ .../dialog/StatusOptionsDialog.html | 22 +++++++++++++++---- templates/2xx.html | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 routes/_actions/delete.js diff --git a/bin/svgs.js b/bin/svgs.js index ea9a48a4..cbf13f9f 100644 --- a/bin/svgs.js +++ b/bin/svgs.js @@ -29,5 +29,6 @@ module.exports = [ {id: 'fa-camera', src: 'node_modules/font-awesome-svg-png/white/svg/camera.svg', title: 'Add media'}, {id: 'fa-smile', src: 'node_modules/font-awesome-svg-png/white/svg/smile-o.svg', title: 'Custom emoji'}, {id: 'fa-exclamation-triangle', src: 'node_modules/font-awesome-svg-png/white/svg/exclamation-triangle.svg', title: 'Content warning'}, - {id: 'fa-check', src: 'node_modules/font-awesome-svg-png/white/svg/check.svg', title: 'Check'} + {id: 'fa-check', src: 'node_modules/font-awesome-svg-png/white/svg/check.svg', title: 'Check'}, + {id: 'fa-trash', src: 'node_modules/font-awesome-svg-png/white/svg/trash-o.svg', title: 'Delete'} ] diff --git a/routes/_actions/delete.js b/routes/_actions/delete.js new file mode 100644 index 00000000..a127b45b --- /dev/null +++ b/routes/_actions/delete.js @@ -0,0 +1,15 @@ +import { store } from '../_store/store' +import { deleteStatus } from '../_api/delete' +import { toast } from '../_utils/toast' + +export async function doDeleteStatus (statusId) { + let instanceName = store.get('currentInstance') + let accessToken = store.get('accessToken') + try { + await deleteStatus(instanceName, accessToken, statusId) + toast.say('Status deleted.') + } catch (e) { + console.error(e) + toast.say('Unable to delete status: ' + (e.message || '')) + } +} diff --git a/routes/_components/dialog/StatusOptionsDialog.html b/routes/_components/dialog/StatusOptionsDialog.html index 56017548..1a4efac5 100644 --- a/routes/_components/dialog/StatusOptionsDialog.html +++ b/routes/_components/dialog/StatusOptionsDialog.html @@ -6,11 +6,14 @@ import ModalDialog from './ModalDialog.html' import { store } from '../../_store/store' import GenericDialogList from './GenericDialogList.html' import { setAccountFollowed } from '../../_actions/follow' +import { doDeleteStatus } from '../../_actions/delete' export default { computed: { relationship: ($currentAccountRelationship) => $currentAccountRelationship, account: ($currentAccountProfile) => $currentAccountProfile, + verifyCredentials: ($currentVerifyCredentials) => $currentVerifyCredentials, + verifyCredentialsId: (verifyCredentials) => verifyCredentials.id, following: (relationship) => relationship && !!relationship.following, accountName: (account) => account && (account.display_name || account.acct), accountId: (account) => account && account.id, @@ -20,15 +23,22 @@ export default { } return following ? `Unfollow ${accountName}` : `Follow ${accountName}` }, - items: (followLabel, following) => { - return [ + items: (followLabel, following, accountId, verifyCredentialsId) => ( + [ + accountId !== verifyCredentialsId && { key: 'follow', label: followLabel, icon: following ? '#fa-user-times' : '#fa-user-plus' + }, + accountId === verifyCredentialsId && + { + key: 'delete', + label: 'Delete', + icon: '#fa-trash' } - ] - } + ].filter(Boolean) + ) }, components: { ModalDialog, @@ -45,6 +55,10 @@ export default { let following = this.get('following') await setAccountFollowed(accountId, !following, true) this.set({closed: true}) + } else if (item.key === 'delete') { + let statusId = this.get('statusId') + await doDeleteStatus(statusId) + this.set({closed: true}) } } } diff --git a/templates/2xx.html b/templates/2xx.html index a0cbb3fb..1d8a1340 100644 --- a/templates/2xx.html +++ b/templates/2xx.html @@ -95,6 +95,7 @@ body.offline,body.theme-hotpants.offline,body.theme-majesty.offline,body.theme-o Custom emoji Content warning Check +Delete