docbrown/app/javascript/packs/chat.jsx
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

36 lines
1 KiB
JavaScript

import { h, render } from 'preact';
import { getUserDataAndCsrfToken } from '../chat/util';
import Chat from '../chat/chat';
HTMLDocument.prototype.ready = new Promise(resolve => {
if (document.readyState !== 'loading') {
return resolve();
}
document.addEventListener('DOMContentLoaded', () => resolve());
return null;
});
document.ready.then(
getUserDataAndCsrfToken().then(currentUser => {
if (document.getElementById('chat')) {
const { chatChannels, pusherKey, chatOptions } = document.getElementById(
'chat',
).dataset;
window.currentUser = currentUser;
window.csrfToken = document.querySelector(
"meta[name='csrf-token']",
).content;
const root = render(
<Chat
pusherKey={pusherKey}
chatChannels={chatChannels}
chatOptions={chatOptions}
/>,
document.getElementById('chat'),
);
window.InstantClick.on('change', () => {
render('', document.body, root);
});
}
}),
);