src/services/api -> src/api
This commit is contained in:
parent
baf283123e
commit
c81813064b
50 changed files with 74 additions and 74 deletions
86
src/api/chats.js
Normal file
86
src/api/chats.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import { parseChat } from 'src/services/entity_normalizer/entity_normalizer.service.js'
|
||||
import { paramsString, promisedRequest } from './helpers.js'
|
||||
|
||||
const PLEROMA_CHATS_URL = '/api/v1/pleroma/chats'
|
||||
const PLEROMA_CHAT_URL = (id) => `/api/v1/pleroma/chats/by-account-id/${id}`
|
||||
const PLEROMA_CHAT_MESSAGES_URL = (id, { maxId, sinceId, limit }) =>
|
||||
`/api/v1/pleroma/chats/${id}/messages${paramsString({ maxId, sinceId, limit })}`
|
||||
const PLEROMA_CHAT_READ_URL = (id) => `/api/v1/pleroma/chats/${id}/read`
|
||||
const PLEROMA_DELETE_CHAT_MESSAGE_URL = (chatId, messageId) =>
|
||||
`/api/v1/pleroma/chats/${chatId}/messages/${messageId}`
|
||||
|
||||
export const chats = ({ credentials }) =>
|
||||
promisedRequest({
|
||||
url: PLEROMA_CHATS_URL,
|
||||
credentials,
|
||||
}).then((data) => ({
|
||||
chatList: data.map(parseChat).filter((c) => c),
|
||||
}))
|
||||
|
||||
export const getOrCreateChat = ({ accountId, credentials }) =>
|
||||
promisedRequest({
|
||||
url: PLEROMA_CHAT_URL(accountId),
|
||||
method: 'POST',
|
||||
credentials,
|
||||
})
|
||||
|
||||
export const chatMessages = ({
|
||||
id,
|
||||
credentials,
|
||||
maxId,
|
||||
sinceId,
|
||||
limit = 20,
|
||||
}) => {
|
||||
return promisedRequest({
|
||||
url: PLEROMA_CHAT_MESSAGES_URL(id, { maxId, sinceId, limit }),
|
||||
method: 'GET',
|
||||
credentials,
|
||||
})
|
||||
}
|
||||
|
||||
export const sendChatMessage = ({
|
||||
id,
|
||||
content,
|
||||
mediaId = null,
|
||||
idempotencyKey,
|
||||
credentials,
|
||||
}) => {
|
||||
const payload = {
|
||||
content,
|
||||
}
|
||||
|
||||
if (mediaId) {
|
||||
payload.media_id = mediaId
|
||||
}
|
||||
|
||||
const headers = {}
|
||||
|
||||
if (idempotencyKey) {
|
||||
headers['idempotency-key'] = idempotencyKey
|
||||
}
|
||||
|
||||
return promisedRequest({
|
||||
url: PLEROMA_CHAT_MESSAGES_URL(id),
|
||||
method: 'POST',
|
||||
payload,
|
||||
credentials,
|
||||
headers,
|
||||
})
|
||||
}
|
||||
|
||||
export const readChat = ({ id, lastReadId, credentials }) =>
|
||||
promisedRequest({
|
||||
url: PLEROMA_CHAT_READ_URL(id),
|
||||
method: 'POST',
|
||||
payload: {
|
||||
last_read_id: lastReadId,
|
||||
},
|
||||
credentials,
|
||||
})
|
||||
|
||||
export const deleteChatMessage = ({ chatId, messageId, credentials }) =>
|
||||
promisedRequest({
|
||||
url: PLEROMA_DELETE_CHAT_MESSAGE_URL(chatId, messageId),
|
||||
method: 'DELETE',
|
||||
credentials,
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue