* Setup Pusher gem * Create ChatChannel and Message model * Create ChatChannelController * Add back fix-db-schema-conflicts gem * Add pusher-js package * Add validations on Message & ChatChannel models * Update Route * Create MessageController * Update ChatChannelController * Create Chat app WIP * Extract messenger render to Message Component * Implement live chat WIP * Implement live chat WIP (2) * Add style and scrollToBottom feature for chat * Create getUserDataAndCsrfToken function * Add feature toggle to the new live chat * Clean up ChatChannelsController & create spec * Update ChatChannel spec * Update Message spec * Create MessagesController spec & refactor * Clean up Chat app * Fix lint * Add character limit to Message
27 lines
732 B
JavaScript
27 lines
732 B
JavaScript
export function getAllMessages(successCb, failureCb) {
|
|
fetch('/chat_channels/1', {
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
}).then(response => response.json())
|
|
.then(successCb)
|
|
.catch(failureCb);
|
|
}
|
|
|
|
export function sendMessage(message, successCb, failureCb) {
|
|
fetch('/messages', {
|
|
method: 'POST',
|
|
headers: {
|
|
Accept: 'application/json',
|
|
'X-CSRF-Token': window.csrfToken,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
message_html: message,
|
|
user_id: window.currentUser.id,
|
|
chat_channel_id: '1',
|
|
}),
|
|
credentials: 'same-origin',
|
|
}).then(response => response.json())
|
|
.then(successCb)
|
|
.catch(failureCb);
|
|
}
|