2018-02-25 02:20:33 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { toast } from '../_utils/toast'
|
|
|
|
import { reblogStatus, unreblogStatus } from '../_api/reblog'
|
2018-04-17 03:56:21 +00:00
|
|
|
import { setStatusReblogged as setStatusRebloggedInDatabase } from '../_database/timelines/updateStatus'
|
2018-02-25 02:20:33 +00:00
|
|
|
|
|
|
|
export async function setReblogged (statusId, reblogged) {
|
|
|
|
if (!store.get('online')) {
|
|
|
|
toast.say(`You cannot ${reblogged ? 'boost' : 'unboost'} while offline.`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let instanceName = store.get('currentInstance')
|
|
|
|
let accessToken = store.get('accessToken')
|
2018-03-21 00:41:39 +00:00
|
|
|
let networkPromise = reblogged
|
|
|
|
? reblogStatus(instanceName, accessToken, statusId)
|
|
|
|
: unreblogStatus(instanceName, accessToken, statusId)
|
|
|
|
store.setStatusReblogged(instanceName, statusId, reblogged) // optimistic update
|
2018-02-25 02:20:33 +00:00
|
|
|
try {
|
2018-03-21 00:41:39 +00:00
|
|
|
await networkPromise
|
2018-04-17 03:56:21 +00:00
|
|
|
await setStatusRebloggedInDatabase(instanceName, statusId, reblogged)
|
2018-02-25 02:20:33 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
toast.say(`Failed to ${reblogged ? 'boost' : 'unboost'}. ` + (e.message || ''))
|
2018-03-21 00:41:39 +00:00
|
|
|
store.setStatusReblogged(instanceName, statusId, !reblogged) // undo optimistic update
|
2018-02-25 02:20:33 +00:00
|
|
|
}
|
|
|
|
}
|