aboutsummaryrefslogtreecommitdiff
path: root/src/services/api/api.service.js
diff options
context:
space:
mode:
authoreugenijm <eugenijm@protonmail.com>2020-10-29 13:33:06 +0300
committereugenijm <eugenijm@protonmail.com>2020-11-01 23:36:58 +0300
commite798e9a4177f025dda2b40d109fa40c2ebfd814e (patch)
treee9916a0cf615fbff6cc5296494476cea89ac7996 /src/services/api/api.service.js
parent148789767a28a988751af9635cd53fe6d85a4c75 (diff)
Optimistic message sending for chat
Diffstat (limited to 'src/services/api/api.service.js')
-rw-r--r--src/services/api/api.service.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 1a3495d4..22b5e8ba 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -129,7 +129,11 @@ const promisedRequest = ({ method, url, params, payload, credentials, headers =
return reject(new StatusCodeError(response.status, json, { url, options }, response))
}
return resolve(json)
- }))
+ })
+ .catch((error) => {
+ return reject(new StatusCodeError(response.status, error, { url, options }, response))
+ })
+ )
})
}
@@ -1210,7 +1214,7 @@ const chatMessages = ({ id, credentials, maxId, sinceId, limit = 20 }) => {
})
}
-const sendChatMessage = ({ id, content, mediaId = null, credentials }) => {
+const sendChatMessage = ({ id, content, mediaId = null, idempotencyKey, credentials }) => {
const payload = {
'content': content
}
@@ -1219,11 +1223,18 @@ const sendChatMessage = ({ id, content, mediaId = null, credentials }) => {
payload['media_id'] = mediaId
}
+ const headers = {}
+
+ if (idempotencyKey) {
+ headers['idempotency-key'] = idempotencyKey
+ }
+
return promisedRequest({
url: PLEROMA_CHAT_MESSAGES_URL(id),
method: 'POST',
payload: payload,
- credentials
+ credentials,
+ headers
})
}