pinafore/routes/_actions/statuses.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-02-17 04:38:21 +01:00
import { database } from '../_database/database'
2018-03-05 01:27:15 +01:00
import { store } from '../_store/store'
import { toast } from '../_utils/toast'
import { postStatus as postStatusToServer } from '../_api/statuses'
import { addStatusOrNotification } from './addStatusOrNotification'
2018-02-17 04:38:21 +01:00
export async function getIdThatThisStatusReblogged (instanceName, statusId) {
let status = await database.getStatus(instanceName, statusId)
return status.reblog && status.reblog.id
}
export async function getIdsThatTheseStatusesReblogged (instanceName, statusIds) {
let reblogIds = await Promise.all(statusIds.map(async statusId => {
return getIdThatThisStatusReblogged(instanceName, statusId)
}))
return reblogIds.filter(Boolean)
2018-02-17 04:38:21 +01:00
}
export async function getIdsThatRebloggedThisStatus (instanceName, statusId) {
return database.getReblogsForStatus(instanceName, statusId)
}
export async function getNotificationIdsForStatuses (instanceName, statusIds) {
return database.getNotificationIdsForStatuses(instanceName, statusIds)
}
2018-03-05 01:27:15 +01:00
2018-03-05 02:16:33 +01:00
export async function postStatus (realm, text, inReplyToId, mediaIds,
2018-03-05 01:27:15 +01:00
sensitive, spoilerText, visibility) {
let instanceName = store.get('currentInstance')
let accessToken = store.get('accessToken')
let online = store.get('online')
if (!online) {
toast.say('You cannot post while offline')
return
}
store.set({postingStatus: true})
try {
let status = await postStatusToServer(instanceName, accessToken, text,
inReplyToId, mediaIds, sensitive, spoilerText, visibility)
addStatusOrNotification(instanceName, 'home', status)
store.clearComposeData(realm)
} catch (e) {
toast.say('Unable to post status: ' + (e.message || ''))
} finally {
store.set({postingStatus: false})
}
2018-03-05 02:16:33 +01:00
}