1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-12 02:07:26 +01:00
Pinafore-Web-Client-Frontend/routes/_actions/reblog.js
2018-02-24 20:35:22 -08:00

28 lines
1.1 KiB
JavaScript

import { store } from '../_store/store'
import { database } from '../_database/database'
import { toast } from '../_utils/toast'
import { reblogStatus, unreblogStatus } from '../_api/reblog'
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')
try {
await (reblogged
? reblogStatus(instanceName, accessToken, statusId)
: unreblogStatus(instanceName, accessToken, statusId))
await database.setStatusReblogged(instanceName, statusId, reblogged)
let statusModifications = store.get('statusModifications')
let currentStatusModifications = statusModifications[instanceName] =
(statusModifications[instanceName] || {favorites: {}, reblogs: {}})
currentStatusModifications.reblogs[statusId] = reblogged
store.set({statusModifications: statusModifications})
} catch (e) {
console.error(e)
toast.say(`Failed to ${reblogged ? 'boost' : 'unboost'}. ` + (e.message || ''))
}
}