From ad84adaf63a46296affdef9b322fbcc6050a4140 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 12 May 2018 22:49:01 -0700 Subject: [PATCH] add ability to mute conversation (#291) fixes another thing from #6 --- routes/_actions/muteConversation.js | 26 +++++++++++++++++++ routes/_api/muteConversation.js | 12 +++++++++ .../components/StatusOptionsDialog.html | 21 ++++++++++++++- routes/_database/timelines/updateStatus.js | 6 +++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 routes/_actions/muteConversation.js create mode 100644 routes/_api/muteConversation.js diff --git a/routes/_actions/muteConversation.js b/routes/_actions/muteConversation.js new file mode 100644 index 00000000..1e5c1d4f --- /dev/null +++ b/routes/_actions/muteConversation.js @@ -0,0 +1,26 @@ +import { store } from '../_store/store' +import { muteConversation, unmuteConversation } from '../_api/muteConversation' +import { toast } from '../_utils/toast' +import { setStatusMuted as setStatusMutedInDatabase } from '../_database/timelines/updateStatus' + +export async function setConversationMuted (statusId, mute, toastOnSuccess) { + let { currentInstance, accessToken } = store.get() + try { + if (mute) { + await muteConversation(currentInstance, accessToken, statusId) + } else { + await unmuteConversation(currentInstance, accessToken, statusId) + } + await setStatusMutedInDatabase(currentInstance, statusId, mute) + if (toastOnSuccess) { + if (mute) { + toast.say('Muted conversation') + } else { + toast.say('Unmuted conversation') + } + } + } catch (e) { + console.error(e) + toast.say(`Unable to ${mute ? 'mute' : 'unmute'} conversation: ` + (e.message || '')) + } +} diff --git a/routes/_api/muteConversation.js b/routes/_api/muteConversation.js new file mode 100644 index 00000000..a006e73e --- /dev/null +++ b/routes/_api/muteConversation.js @@ -0,0 +1,12 @@ +import { auth, basename } from './utils' +import { postWithTimeout } from '../_utils/ajax' + +export async function muteConversation (instanceName, accessToken, statusId) { + let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/mute` + return postWithTimeout(url, null, auth(accessToken)) +} + +export async function unmuteConversation (instanceName, accessToken, statusId) { + let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/unmute` + return postWithTimeout(url, null, auth(accessToken)) +} diff --git a/routes/_components/dialog/components/StatusOptionsDialog.html b/routes/_components/dialog/components/StatusOptionsDialog.html index 635a39f5..d8394e6a 100644 --- a/routes/_components/dialog/components/StatusOptionsDialog.html +++ b/routes/_components/dialog/components/StatusOptionsDialog.html @@ -19,6 +19,7 @@ import { setAccountBlocked } from '../../../_actions/block' import { setAccountMuted } from '../../../_actions/mute' import { setStatusPinnedOrUnpinned } from '../../../_actions/pin' import { importShowCopyDialog } from '../asyncDialogs' +import { setConversationMuted } from '../../../_actions/muteConversation' export default { oncreate, @@ -63,9 +64,15 @@ export default { // pinLabel: ({pinned, isUser}) => isUser ? (pinned ? 'Unpin from profile' : 'Pin to profile') : '', visibility: ({status}) => status.visibility, + mentions: ({status}) => status.mentions || [], + mentionsUser: ({mentions, verifyCredentialsId}) => !!mentions.find(_ => _.id === verifyCredentialsId), + mutingConversation: ({status}) => !!status.muted, + muteConversationLabel: ({mutingConversation}) => mutingConversation ? `Unmute conversation` : `Mute conversation`, + muteConversationIcon: ({mutingConversation}) => mutingConversation ? '#fa-volume-up' : '#fa-volume-off', items: ({ blockLabel, blocking, blockIcon, muteLabel, muteIcon, followLabel, followIcon, - following, followRequested, pinLabel, isUser, visibility + following, followRequested, pinLabel, isUser, visibility, mentionsUser, mutingConversation, + muteConversationLabel, muteConversationIcon }) => ([ isUser && { key: 'delete', @@ -92,6 +99,11 @@ export default { label: muteLabel, icon: muteIcon }, + (isUser || mentionsUser) && { + key: 'muteConversation', + label: muteConversationLabel, + icon: muteConversationIcon + }, { key: 'copy', label: 'Copy link to toot', @@ -121,6 +133,8 @@ export default { return this.onMuteClicked() case 'copy': return this.onCopyClicked() + case 'muteConversation': + return this.onMuteConversationClicked() } }, async onDeleteClicked () { @@ -153,6 +167,11 @@ export default { let { url } = status let showCopyDialog = await importShowCopyDialog() showCopyDialog(url) + }, + async onMuteConversationClicked () { + let { statusId, mutingConversation } = this.get() + this.close() + await setConversationMuted(statusId, !mutingConversation, true) } } } diff --git a/routes/_database/timelines/updateStatus.js b/routes/_database/timelines/updateStatus.js index 33a1af9f..71dc8774 100644 --- a/routes/_database/timelines/updateStatus.js +++ b/routes/_database/timelines/updateStatus.js @@ -45,3 +45,9 @@ export async function setStatusPinned (instanceName, statusId, pinned) { status.pinned = pinned }) } + +export async function setStatusMuted (instanceName, statusId, muted) { + return updateStatus(instanceName, statusId, status => { + status.muted = muted + }) +}