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
|
|
|
|
2019-10-27 13:31:59 +00:00
|
|
|
create({ conversationId, message, private: isPrivate }) {
|
|
|
|
return axios.post(`${this.url}/${conversationId}/messages`, {
|
|
|
|
message,
|
|
|
|
private: isPrivate,
|
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-04-02 06:58:38 +00:00
|
|
|
sendAttachment([conversationId, { file }]) {
|
2020-03-22 10:24:36 +00:00
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('attachment[file]', file);
|
|
|
|
return axios({
|
|
|
|
method: 'post',
|
|
|
|
url: `${this.url}/${conversationId}/messages`,
|
|
|
|
data: formData,
|
|
|
|
});
|
|
|
|
}
|
2019-10-27 13:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new MessageApi();
|