diff --git a/routes/_actions/statuses.js b/routes/_actions/statuses.js
index de07418..e7d3188 100644
--- a/routes/_actions/statuses.js
+++ b/routes/_actions/statuses.js
@@ -1,4 +1,8 @@
import { database } from '../_database/database'
+import { store } from '../_store/store'
+import { toast } from '../_utils/toast'
+import { postStatus as postStatusToServer } from '../_api/statuses'
+import { addStatusOrNotification } from './addStatusOrNotification'
export async function getIdThatThisStatusReblogged (instanceName, statusId) {
let status = await database.getStatus(instanceName, statusId)
@@ -19,3 +23,27 @@ export async function getIdsThatRebloggedThisStatus (instanceName, statusId) {
export async function getNotificationIdsForStatuses (instanceName, statusIds) {
return database.getNotificationIdsForStatuses(instanceName, statusIds)
}
+
+export async function postStatus(realm, text, inReplyToId, mediaIds,
+ 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})
+ }
+}
\ No newline at end of file
diff --git a/routes/_api/statuses.js b/routes/_api/statuses.js
new file mode 100644
index 0000000..bea4bb2
--- /dev/null
+++ b/routes/_api/statuses.js
@@ -0,0 +1,25 @@
+import { auth, basename } from './utils'
+import { postWithTimeout } from '../_utils/ajax'
+
+export async function postStatus(instanceName, accessToken, text, inReplyToId, mediaIds,
+ sensitive, spoilerText, visibility) {
+ let url = `${basename(instanceName)}/api/v1/statuses`
+
+ let body = {
+ status: text,
+ in_reply_to_id: inReplyToId,
+ media_ids: mediaIds,
+ sensitive: sensitive,
+ spoiler_text: spoilerText,
+ visibility: visibility
+ }
+
+ for (let key of Object.keys(body)) {
+ let value = body[key]
+ if (!value || (Array.isArray(value) && !value.length)) {
+ delete body[key]
+ }
+ }
+
+ return postWithTimeout(url, body, auth(accessToken))
+}
\ No newline at end of file
diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html
index 86647b5..c690af1 100644
--- a/routes/_components/compose/ComposeBox.html
+++ b/routes/_components/compose/ComposeBox.html
@@ -11,7 +11,7 @@
-
+
\ No newline at end of file
diff --git a/routes/_store/mixins/instanceMixins.js b/routes/_store/mixins/instanceMixins.js
index f74eac1..89076ba 100644
--- a/routes/_store/mixins/instanceMixins.js
+++ b/routes/_store/mixins/instanceMixins.js
@@ -14,4 +14,13 @@ export function instanceMixins (Store) {
composeData[instanceName][realm] &&
composeData[instanceName][realm][key]
}
+
+ Store.prototype.clearComposeData = function (realm) {
+ let composeData = this.get('composeData')
+ let instanceName = this.get('currentInstance')
+ if (composeData && composeData[instanceName]) {
+ delete composeData[instanceName][realm]
+ }
+ this.set({composeData})
+ }
}