/*
Template Name: Grenviro Monitoring
Author: Themesbrand
Website: https://Themesbrand.com/
Contact: Themesbrand@gmail.com
File: Chat init js
*/
(function () {
var dummyUserImage = "build/images/users/user-dummy-img.jpg";
var dummyMultiUserImage = "build/images/users/multi-user.jpg";
var isreplyMessage = false;
// favourite btn
document.querySelectorAll(".favourite-btn").forEach(function (item) {
item.addEventListener("click", function (event) {
this.classList.toggle("active");
});
});
// toggleSelected
function toggleSelected() {
var userChatElement = document.querySelectorAll(".user-chat");
Array.from(document.querySelectorAll(".chat-user-list li a")).forEach(function (item) {
item.addEventListener("click", function (event) {
userChatElement.forEach(function (elm) {
elm.classList.add("user-chat-show");
});
// chat user list link active
var chatUserList = document.querySelector(".chat-user-list li.active");
if (chatUserList) chatUserList.classList.remove("active");
this.parentNode.classList.add("active");
});
});
// user-chat-remove
document.querySelectorAll(".user-chat-remove").forEach(function (item) {
item.addEventListener("click", function (event) {
userChatElement.forEach(function (elm) {
elm.classList.remove("user-chat-show");
});
});
});
}
//User current Id
var currentChatId = "users-chat";
var currentSelectedChat = "users";
var url="build/json/";
var usersList = "";
var userChatId = 1;
scrollToBottom(currentChatId);
//user list by json
var getJSON = function (jsonurl, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url + jsonurl, true);
xhr.responseType = "json";
xhr.onload = function () {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
// get User list
getJSON("chat-users-list.json", function (err, data) {
if (err !== null) {
console.log("Something went wrong: " + err);
} else {
// set users message list
var users = data[0].users;
users.forEach(function (userData, index) {
var isUserProfile = userData.profile ? ''
: '
' + userData.name + "
\' + isChannel.name + "
\' + msg + "
\ ' + chatItems + '\
\\ ' + chatReplyItems + '\
\