add ability to mute conversation (#291)

fixes another thing from #6
This commit is contained in:
Nolan Lawson 2018-05-12 22:49:01 -07:00 committed by GitHub
parent 907e6b2e83
commit ad84adaf63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 1 deletions

View File

@ -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 || ''))
}
}

View File

@ -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))
}

View File

@ -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)
}
}
}

View File

@ -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
})
}