2019-08-14 09:48:44 +00:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
/* global axios */
|
2019-10-27 13:31:59 +00:00
|
|
|
import ApiClient from '../ApiClient';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-27 13:31:59 +00:00
|
|
|
class MessageApi extends ApiClient {
|
|
|
|
constructor() {
|
2020-03-09 17:57:10 +00:00
|
|
|
super('conversations', { accountScoped: true });
|
2019-10-27 13:31:59 +00:00
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-08-11 04:27:42 +00:00
|
|
|
create({ conversationId, message, private: isPrivate, contentAttributes }) {
|
2019-10-27 13:31:59 +00:00
|
|
|
return axios.post(`${this.url}/${conversationId}/messages`, {
|
2020-04-10 11:12:37 +00:00
|
|
|
content: message,
|
2019-10-27 13:31:59 +00:00
|
|
|
private: isPrivate,
|
2020-08-11 04:27:42 +00:00
|
|
|
content_attributes: contentAttributes,
|
2019-08-14 09:48:44 +00:00
|
|
|
});
|
2019-10-27 13:31:59 +00:00
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2019-10-27 13:31:59 +00:00
|
|
|
getPreviousMessages({ conversationId, before }) {
|
2020-03-08 16:38:25 +00:00
|
|
|
return axios.get(`${this.url}/${conversationId}/messages`, {
|
2019-10-27 13:31:59 +00:00
|
|
|
params: { before },
|
2019-08-14 09:48:44 +00:00
|
|
|
});
|
2019-10-27 13:31:59 +00:00
|
|
|
}
|
2020-03-22 10:24:36 +00:00
|
|
|
|
2020-07-25 17:24:45 +00:00
|
|
|
sendAttachment([conversationId, { file, isPrivate = false }]) {
|
2020-03-22 10:24:36 +00:00
|
|
|
const formData = new FormData();
|
2020-04-17 15:45:20 +00:00
|
|
|
formData.append('attachments[]', file, file.name);
|
2020-07-25 17:24:45 +00:00
|
|
|
formData.append('private', isPrivate);
|
2020-03-22 10:24:36 +00:00
|
|
|
return axios({
|
|
|
|
method: 'post',
|
|
|
|
url: `${this.url}/${conversationId}/messages`,
|
|
|
|
data: formData,
|
|
|
|
});
|
|
|
|
}
|
2019-10-27 13:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new MessageApi();
|