2018-03-09 17:45:12 +01:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { toast } from '../_utils/toast'
|
2018-03-10 07:31:26 +01:00
|
|
|
import { postStatus as postStatusToServer } from '../_api/statuses'
|
2018-03-09 17:45:12 +01:00
|
|
|
import { addStatusOrNotification } from './addStatusOrNotification'
|
2018-04-17 05:56:21 +02:00
|
|
|
import { getStatus as getStatusFromDatabase } from '../_database/timelines/getStatusOrNotification'
|
2018-04-09 00:08:32 +02:00
|
|
|
import { emit } from '../_utils/eventBus'
|
2018-04-10 03:30:15 +02:00
|
|
|
import { putMediaDescription } from '../_api/media'
|
2018-03-09 17:45:12 +01:00
|
|
|
|
|
|
|
export async function insertHandleForReply (statusId) {
|
2018-04-19 18:37:05 +02:00
|
|
|
let { currentInstance } = store.get()
|
|
|
|
let status = await getStatusFromDatabase(currentInstance, statusId)
|
|
|
|
let { currentVerifyCredentials } = store.get()
|
2018-03-09 17:45:12 +01:00
|
|
|
let originalStatus = status.reblog || status
|
|
|
|
let accounts = [originalStatus.account].concat(originalStatus.mentions || [])
|
2018-04-19 18:37:05 +02:00
|
|
|
.filter(account => account.id !== currentVerifyCredentials.id)
|
2018-03-09 17:45:12 +01:00
|
|
|
if (!store.getComposeData(statusId, 'text') && accounts.length) {
|
|
|
|
store.setComposeData(statusId, {
|
|
|
|
text: accounts.map(account => `@${account.acct} `).join('')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function postStatus (realm, text, inReplyToId, mediaIds,
|
2018-04-19 05:43:13 +02:00
|
|
|
sensitive, spoilerText, visibility,
|
|
|
|
mediaDescriptions = [], inReplyToUuid) {
|
2018-04-19 18:37:05 +02:00
|
|
|
let { currentInstance, accessToken, online } = store.get()
|
2018-03-09 17:45:12 +01:00
|
|
|
|
|
|
|
if (!online) {
|
|
|
|
toast.say('You cannot post while offline')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
store.set({
|
2018-04-09 00:08:32 +02:00
|
|
|
postingStatus: true
|
2018-03-09 17:45:12 +01:00
|
|
|
})
|
|
|
|
try {
|
2018-04-10 03:30:15 +02:00
|
|
|
await Promise.all(mediaDescriptions.map(async (description, i) => {
|
2018-04-19 18:37:05 +02:00
|
|
|
return description && putMediaDescription(currentInstance, accessToken, mediaIds[i], description)
|
2018-04-10 03:30:15 +02:00
|
|
|
}))
|
2018-04-19 18:37:05 +02:00
|
|
|
let status = await postStatusToServer(currentInstance, accessToken, text,
|
2018-03-09 17:45:12 +01:00
|
|
|
inReplyToId, mediaIds, sensitive, spoilerText, visibility)
|
2018-04-19 18:37:05 +02:00
|
|
|
addStatusOrNotification(currentInstance, 'home', status)
|
2018-03-09 17:45:12 +01:00
|
|
|
store.clearComposeData(realm)
|
2018-04-13 06:18:14 +02:00
|
|
|
emit('postedStatus', realm, inReplyToUuid)
|
2018-03-09 17:45:12 +01:00
|
|
|
} catch (e) {
|
2018-04-05 03:33:31 +02:00
|
|
|
console.error(e)
|
2018-03-09 17:45:12 +01:00
|
|
|
toast.say('Unable to post status: ' + (e.message || ''))
|
|
|
|
} finally {
|
|
|
|
store.set({postingStatus: false})
|
|
|
|
}
|
|
|
|
}
|
2018-03-25 03:04:54 +02:00
|
|
|
|
2018-04-03 18:45:17 +02:00
|
|
|
export function setReplySpoiler (realm, spoiler) {
|
|
|
|
let contentWarning = store.getComposeData(realm, 'contentWarning')
|
|
|
|
let contentWarningShown = store.getComposeData(realm, 'contentWarningShown')
|
2018-04-08 22:42:31 +02:00
|
|
|
if (typeof contentWarningShown !== 'undefined' || contentWarning) {
|
|
|
|
return // user has already interacted with the CW
|
2018-04-03 18:45:17 +02:00
|
|
|
}
|
2018-04-08 22:42:31 +02:00
|
|
|
store.setComposeData(realm, {
|
|
|
|
contentWarning: spoiler,
|
|
|
|
contentWarningShown: true
|
|
|
|
})
|
2018-04-03 18:45:17 +02:00
|
|
|
}
|
2018-04-04 02:50:48 +02:00
|
|
|
|
|
|
|
const PRIVACY_LEVEL = {
|
|
|
|
'direct': 1,
|
|
|
|
'private': 2,
|
|
|
|
'unlisted': 3,
|
|
|
|
'public': 4
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setReplyVisibility (realm, replyVisibility) {
|
|
|
|
// return the most private between the user's preferred default privacy
|
|
|
|
// and the privacy of the status they're replying to
|
2018-04-08 22:42:31 +02:00
|
|
|
let postPrivacy = store.getComposeData(realm, 'postPrivacy')
|
|
|
|
if (typeof postPrivacy !== 'undefined') {
|
|
|
|
return // user has already set the postPrivacy
|
|
|
|
}
|
2018-04-19 18:37:05 +02:00
|
|
|
let { currentVerifyCredentials } = store.get()
|
|
|
|
let defaultVisibility = currentVerifyCredentials.source.privacy
|
2018-04-04 02:50:48 +02:00
|
|
|
let visibility = PRIVACY_LEVEL[replyVisibility] < PRIVACY_LEVEL[defaultVisibility]
|
|
|
|
? replyVisibility
|
|
|
|
: defaultVisibility
|
|
|
|
store.setComposeData(realm, {postPrivacy: visibility})
|
|
|
|
}
|