let LocalHistoryId = 0; function genSentBase(){ return { 'chatUpdReq': { 'LocalHistoryId': LocalHistoryId } }; } let members = new Map(); let memberBoxes = new Map(); let myRoleHere = null; // Dung local state updates should be updated first let userDeletionWinStoredUId = -1; function shouldShowDeleteButton(memberSt){ return userinfo.uid !== memberSt.userId && myRoleHere === userChatRoleAdmin; } function updateBoxWithSt(box, memberSt){ let ID = memberSt.userId; let roleP = box.querySelector(".CM-member-box-role"); roleP.innerText = memberSt.roleHere; box.style.backgroundColor = roleToColor(memberSt.roleHere); box.querySelector(".CM-member-box-leave-btn").style.display = (shouldShowDeleteButton(memberSt) ? "block" : "none"); } function convertMemberStToBox(memberSt){ let ID = memberSt.userId; let userProfileURI = "/user/" + memberSt.nickname; let box = document.createElement("div"); box.className = "dynamic-block-list-el CM-member-box"; box.style.backgroundColor = roleToColor(memberSt.roleHere); let inBoxNickname = document.createElement("a"); box.appendChild(inBoxNickname); inBoxNickname.className = "entity-nickname-txt CM-member-box-nickname"; inBoxNickname.innerText = memberSt.nickname; inBoxNickname.href = userProfileURI; let inBoxName = document.createElement("a"); box.appendChild(inBoxName); inBoxName.className = "entity-reg-field-txt CM-member-box-name"; inBoxName.innerText = memberSt.name; inBoxName.href = userProfileURI; let inBoxUserRoleHere = document.createElement("p"); box.appendChild(inBoxUserRoleHere); inBoxUserRoleHere.className = "entity-reg-field-txt CM-member-box-role"; inBoxUserRoleHere.innerText = memberSt.roleHere; let inBoxLeaveBtn = document.createElement("img"); box.appendChild(inBoxLeaveBtn); inBoxLeaveBtn.className = "CM-member-box-leave-btn"; inBoxLeaveBtn.src = "/assets/img/delete.svg"; inBoxLeaveBtn.onclick = function (ev) { if (ev.button !== 0) return; userDeletionWinStoredUId = ID; activatePopupWindowById("user-deletion-win"); document.getElementById("user-deletion-win-title").innerText = "Do you really want to kick user " + memberSt.nickname + "?"; }; box.querySelector(".CM-member-box-leave-btn").style.display = (shouldShowDeleteButton(memberSt) ? "block" : "none"); return box; } function updateLocalStateFromChatUpdResp(chatUpdResp){ LocalHistoryId = chatUpdResp.HistoryId; // If my role is updated, we need to update all the boes of already set users (kick button can appear and disappear) let literalMemberList = document.getElementById("CM-list"); // We ignore messages and everything related to them. Dang, I really should add an argument to disable message lookup here // let haveToUpdateAllBoxes = false; for (let memberSt of chatUpdResp.members){ if (memberSt.id === userinfo.uid && myRoleHere !== memberSt.roleHere){ myRoleHere = memberSt.roleHere; // haveToUpdateAllBoxes = true; for (let [id, memberSt] of members){ let box = memberBoxes.get(id); updateBoxWithSt(box, memberSt); } break; } } for (let memberSt of chatUpdResp.members){ let id = memberSt.userId; // todo: CONTINUE FROM HERE WHEN YOU WAKE UP } } __mainloopDelayMS = 5000; __guestMainloopPollerAction = function (){ console.log("Hello, world"); } window.onload = function(){ console.log("Page loaded"); updateLocalStateFromChatUpdResp(initial_chatUpdResp); mainloopPoller(); }