Skip to content
Permalink
Browse files

add ability to mute conversation

fixes another thing from #6
  • Loading branch information...
nolanlawson committed May 12, 2018
1 parent 3d8cdcd commit d3dfefbe45cef149e57f134236e1b1bbedde1985
@@ -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 || ''))
}
}
@@ -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))
}
@@ -19,6 +19,7 @@
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 @@
//
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 @@
label: muteLabel,
icon: muteIcon
},
(isUser || mentionsUser) && {
key: 'muteConversation',
label: muteConversationLabel,
icon: muteConversationIcon
},
{
key: 'copy',
label: 'Copy link to toot',
@@ -121,6 +133,8 @@
return this.onMuteClicked()
case 'copy':
return this.onCopyClicked()
case 'muteConversation':
return this.onMuteConversationClicked()
}
},
async onDeleteClicked () {
@@ -153,6 +167,11 @@
let { url } = status
let showCopyDialog = await importShowCopyDialog()
showCopyDialog(url)
},
async onMuteConversationClicked () {
let { statusId, mutingConversation } = this.get()
this.close()
await setConversationMuted(statusId, !mutingConversation, true)
}
}
}
@@ -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
})
}

0 comments on commit d3dfefb

Please sign in to comment.
You can’t perform that action at this time.