diff options
| author | Shpuld Shpludson <shp@cock.li> | 2020-11-02 05:36:42 +0000 |
|---|---|---|
| committer | Shpuld Shpludson <shp@cock.li> | 2020-11-02 05:36:42 +0000 |
| commit | 5254fdba75fc8d645c2235902a39b79c45f9aa6f (patch) | |
| tree | ac329a5fc0448d804d5aa8d77e137b00e64a4491 /src/services/api/api.service.js | |
| parent | 590f8e17544969b1fc2456b3724e85b16cf81bdd (diff) | |
| parent | 78e5a639228ba846e38ae722590aec1310275c79 (diff) | |
Merge branch 'optimistic-chat-posting' into 'develop'
Optimistic / nonblocking message posting for chats
See merge request pleroma/pleroma-fe!1228
Diffstat (limited to 'src/services/api/api.service.js')
| -rw-r--r-- | src/services/api/api.service.js | 17 |
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 }) } |
