2018-04-29 21:28:44 +02:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { toast } from '../_utils/toast'
|
|
|
|
import { pinStatus, unpinStatus } from '../_api/pin'
|
2018-08-30 04:03:12 +02:00
|
|
|
import { database } from '../_database/database'
|
2018-04-29 21:28:44 +02:00
|
|
|
import { emit } from '../_utils/eventBus'
|
|
|
|
|
|
|
|
export async function setStatusPinnedOrUnpinned (statusId, pinned, toastOnSuccess) {
|
|
|
|
let { currentInstance, accessToken } = store.get()
|
|
|
|
try {
|
|
|
|
if (pinned) {
|
|
|
|
await pinStatus(currentInstance, accessToken, statusId)
|
|
|
|
} else {
|
|
|
|
await unpinStatus(currentInstance, accessToken, statusId)
|
|
|
|
}
|
|
|
|
if (toastOnSuccess) {
|
|
|
|
if (pinned) {
|
|
|
|
toast.say('Pinned status')
|
|
|
|
} else {
|
|
|
|
toast.say('Unpinned status')
|
|
|
|
}
|
|
|
|
}
|
2018-08-30 03:10:09 +02:00
|
|
|
store.setStatusPinned(currentInstance, statusId, pinned)
|
2018-08-30 04:03:12 +02:00
|
|
|
await database.setStatusPinned(currentInstance, statusId, pinned)
|
2018-04-29 21:28:44 +02:00
|
|
|
emit('updatePinnedStatuses')
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
toast.say(`Unable to ${pinned ? 'pin' : 'unpin'} status: ` + (e.message || ''))
|
|
|
|
}
|
|
|
|
}
|