2020-07-25 20:17:08 +02:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { toast } from '../_components/toast/toast'
|
|
|
|
import { bookmarkStatus, unbookmarkStatus } from '../_api/bookmark'
|
|
|
|
import { database } from '../_database/database'
|
|
|
|
|
|
|
|
export async function setStatusBookmarkedOrUnbookmarked (statusId, bookmarked) {
|
|
|
|
const { currentInstance, accessToken } = store.get()
|
|
|
|
try {
|
|
|
|
if (bookmarked) {
|
|
|
|
await bookmarkStatus(currentInstance, accessToken, statusId)
|
|
|
|
} else {
|
|
|
|
await unbookmarkStatus(currentInstance, accessToken, statusId)
|
|
|
|
}
|
|
|
|
if (bookmarked) {
|
2020-08-27 08:49:36 -07:00
|
|
|
toast.say('Bookmarked toot')
|
2020-07-25 20:17:08 +02:00
|
|
|
} else {
|
2020-08-27 08:49:36 -07:00
|
|
|
toast.say('Unbookmarked toot')
|
2020-07-25 20:17:08 +02:00
|
|
|
}
|
|
|
|
store.setStatusBookmarked(currentInstance, statusId, bookmarked)
|
|
|
|
await database.setStatusBookmarked(currentInstance, statusId, bookmarked)
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
2020-08-27 08:49:36 -07:00
|
|
|
toast.say(`Unable to ${bookmarked ? 'bookmark' : 'unbookmark'} toot: ` + (e.message || ''))
|
2020-07-25 20:17:08 +02:00
|
|
|
}
|
|
|
|
}
|