let LocalHistoryId = 0; let myChats = new Map(); let chatBoxes = new Map(); const roleDeleted = "not-a-member"; function convertStToBox(myMembershipSt){ let chatURI = "/user/" + myMembershipSt.chatNickname; let box = document.createElement("div"); chatBoxes.set(myMembershipSt.chatId, box); box.className = "dynamic-block-list-el CL-my-chat-box"; let inBoxNickname = document.createElement("a"); box.appendChild(inBoxNickname); inBoxNickname.className = "entity-nickname-txt CL-my-chat-box-nickname"; console.log(myMembershipSt); console.log(myMembershipSt.chatNickname); inBoxNickname.innerText = myMembershipSt.chatNickname; inBoxNickname.href = chatURI; let inBoxName = document.createElement("a"); box.appendChild(inBoxName); inBoxName.className = "entity-reg-field-txt CL-my-chat-box-name"; inBoxName.innerText = myMembershipSt.chatName; inBoxName.href = chatURI; let inBoxMyRoleHere = document.createElement("p"); box.appendChild(inBoxMyRoleHere); inBoxMyRoleHere.className = "entity-reg-field-txt CL-my-chat-box-my-role"; inBoxMyRoleHere.innerText = "You are " + myMembershipSt.myRoleHere + " here"; let ID = myMembershipSt.chatId; let inBoxLeaveBtn = document.createElement("img"); box.appendChild(inBoxLeaveBtn); inBoxLeaveBtn.className = "CL-my-chat-box-leave-btn"; inBoxLeaveBtn.src = "/assets/img/delete.svg"; inBoxLeaveBtn.onclick = function (ev) { if (ev.button !== 0) return; console.log("Tried to leave chat" + ID); activatePopupWindowById("chat-renunciation-win"); }; return box; } function configureChatCreationInterface(){ document.getElementById("chat-creation-win-yes").onclick = function (ev) { if (ev.button !== 0) return; deactivateActivePopup(); // todo: create chat, send request }; document.getElementById("chat-creation-win-no").onclick = function (ev) { if (ev.button !== 0) return; deactivateActivePopup(); } document.getElementById("CL-bacbe").onclick = function (ev){ if (ev.button !== 0) return; activatePopupWindowById("chat-creation-win"); console.log("Tried to show chat creation window"); }; } function configureChatRenunciationInterfaceWinPart(){ document.getElementById("chat-renunciation-win-yes").onclick = function (ev){ if (ev.button !== 0) return; deactivateActivePopup(); // todo: actually leave chat } document.getElementById("chat-renunciation-win-no").onclick = function(ev) { if (ev.button !== 0) return; deactivateActivePopup(); } } window.onload = function () { console.log("Loading complete"); LocalHistoryId = initial_chatListUpdResp.HistoryId; console.log(initial_chatListUpdResp); let literalChatList = document.getElementById("CL-dblec"); for (let myMembershipSt of initial_chatListUpdResp.myChats){ console.log(myMembershipSt); if (myMembershipSt.myRoleHere !== roleDeleted){ myChats.set(myMembershipSt.chatId, myMembershipSt); let box = convertStToBox(myMembershipSt) chatBoxes.set(myMembershipSt.chatId, box); literalChatList.appendChild(box); } } configureChatCreationInterface(); configureChatRenunciationInterfaceWinPart(); };