Hack to display the chat

This commit is contained in:
Alexandre Bourlier
2018-05-03 21:02:37 +02:00
parent b1f25e2d65
commit 1f148c416b
6 changed files with 72 additions and 22 deletions

View File

@ -34,5 +34,57 @@
<?php require_once('src/html/channels.html'); ?>
<?php require_once('src/html/channel.html'); ?>
</main>
<!-- This is a hack : https://git.happy-dev.fr/happy-dev/xmpp-chat-component/issues/24 -->
<hd-chat-window
id="chat-singleton"
data-authentication="anonymous"
data-auto-login="true"
data-bosh-service-url="https://conversejs.org/http-bind/"
data-debug="true"
data-jid="nomnom.im"
data-locales-url="http://hd-app.local/dist/lib/xmpp-chat-component/node_modules/converse.js/locale/{{{locale}}}/LC_MESSAGES/converse.json",
data-room-jid="anonymous@conference.nomnom.im">
</hd-chat-window>
<script>
// Store url on load
var currentRoute = getCurrentRoute();
console.log(currentRoute);
var chatSingleton = document.querySelector("#chat-singleton");
var body = document.querySelector("body");
function getCurrentRoute() {
var pathnameSegments = window.location.pathname.split("/");
return pathnameSegments[1];
}
// Listen for changes
setInterval(function() {
if (currentRoute != window.location.href) {
currentRoute = getCurrentRoute();
insertChatIfNeeded();
}
}, 150);
// Inserts a chat in the current view if needed
function insertChatIfNeeded() {
if (["project", "project-chat", "channel", "channel-chat", "member", "member-chat"].indexOf(currentRoute) > -1) {
if (currentRoute.indexOf("chat") == -1) {
currentRoute += "-chat";
}
console.log(currentRoute);
var currentView = document.querySelector("#" + currentRoute);
if (currentView.querySelector("hd-chat-window") == null) {
currentView.appendChild(chatSingleton);
currentView.style.display = 'block';
}
}
else {
body.appendChild(chatSingleton);
}
}
</script>
</body>
</html>