docbrown/app/javascript/chat/actions.js
Mac Siri b4292ade33 Implement chatroom (#308)
* Fix multiple chat loading bug

* Open profile links in chat via new tab

* Add unmount handling for chat

* Add overscroll property to chat

* Add channel_name to ChatChannel model

* Create route and page for chatroom WIP

* Expose ChatChannel id to live page

* Implement multichannel support WIP

* Implement chatroom page WIP

* Add css for chatroom

* Update chat's moderation

* Refactor chat's message type

* Swap the use of :message_markdown & :message_html

* Add channel permissions WIP

* Fix failing specs

* Adjust json reponses

* Add empty message prevention

* Update participant error message

* Change Workshop channel to General
2018-05-14 12:50:32 -04:00

56 lines
1.3 KiB
JavaScript

export function getAllMessages(channelId, successCb, failureCb) {
fetch(`/chat_channels/${channelId}`, {
Accept: 'application/json',
'Content-Type': 'application/json',
})
.then(response => response.json())
.then(successCb)
.catch(failureCb);
}
export function sendMessage(activeChannelId, message, successCb, failureCb) {
fetch('/messages', {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
message_markdown: message,
user_id: window.currentUser.id,
chat_channel_id: activeChannelId,
},
}),
credentials: 'same-origin',
})
.then(response => response.json())
.then(successCb)
.catch(failureCb);
}
export function conductModeration(
activeChannelId,
message,
successCb,
failureCb,
) {
fetch(`/chat_channels/${activeChannelId}/moderate`, {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
chat_channel: {
command: message,
},
}),
credentials: 'same-origin',
})
.then(response => response.json())
.then(successCb)
.catch(failureCb);
}