update - chat inserted in member-chat view and nowhere else

This commit is contained in:
Alexandre Bourlier
2018-07-11 20:43:18 +02:00
parent f29e3c829d
commit ae0ab04570
5 changed files with 16 additions and 83 deletions

View File

@ -40,56 +40,5 @@
<?php require_once('src/html/channel-creation.html'); ?>
<?php require_once('src/html/search.html'); ?>
</main>
<!-- This is a hack : https://git.happy-dev.fr/happy-dev/xmpp-chat-component/issues/24 -->
<sib-chat
id="chat-singleton"
data-src="https://djangoldp.happy-dev.fr/users/1"
data-authentication="login"
data-auto-login="true"
data-bosh-service-url="http://jabber.happy-dev.fr/http-bind/" // FIXME: make HTTPS
data-debug="false"
data-locales-url="node_modules/converse.js/locale/{{{locale}}}/LC_MESSAGES/converse.json"
bind-resources>
</sib-chat>
<script>
// Store url on load
var currentRoute = getCurrentRoute();
var previousRoute = "";
var chatSingleton = document.querySelector("#chat-singleton");
var body = document.querySelector("body");
function getCurrentRoute() {
var pathnameSegments = window.location.pathname.split("/");
return pathnameSegments[pathnameSegments.length - 1];
}
// Listen for changes
setInterval(function() {
previousRoute = currentRoute;
currentRoute = getCurrentRoute();
if (previousRoute !== currentRoute) {
insertChatIfNeeded();
}
}, 250);
// Inserts a chat in the current view if needed
function insertChatIfNeeded() {
console.log(currentRoute);
if (["project-chat", "channel-chat", "member-chat"].indexOf(currentRoute) > -1) {
var currentView = document.querySelector("#" + currentRoute);
if (currentView.querySelector("sib-chat") == null) {
currentView.appendChild(chatSingleton);
}
}
else {
body.appendChild(chatSingleton);
}
}
insertChatIfNeeded();
</script>
</body>
</html>