From 6f336256504f2678168dcb587989663be837d494 Mon Sep 17 00:00:00 2001 From: Tag Date: Wed, 30 Nov 2022 17:36:14 -0800 Subject: [PATCH] More chat code --- package.nw/gt_chat.html | 76 ++++++++++++++++++++++++----------------- package.nw/lib/gt.js | 14 ++++++-- package.nw/lib/gtws.js | 7 ++-- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/package.nw/gt_chat.html b/package.nw/gt_chat.html index c2ef12a..7ac2f63 100644 --- a/package.nw/gt_chat.html +++ b/package.nw/gt_chat.html @@ -267,7 +267,6 @@ function updateCallsign(id) { - var count = parseInt(userCount.innerHTML); if (id in window.opener.g_gtFlagPins) { var obj = window.opener.g_gtFlagPins[id]; @@ -288,10 +287,7 @@ if (obj.canmsg == false) show = false; - if (makeCallsignRow(obj, show) && show) - { - count++; - } + makeCallsignRow(obj, show); if (obj.cid == g_currentId && messageInput.disabled == true && obj.live == true) { @@ -312,19 +308,44 @@ var obj = document.getElementById(id); if (obj) { - if (obj.style.display == "") - { - count--; - } allCallDiv.removeChild(obj); } } + updateCount(); + } + + function updateCount() + { + var count = 0; + if(allCallDiv.childElementCount > 0) + { + for (var x = allCallDiv.childNodes.length-1; x > -1; x--) + { + if (allCallDiv.childNodes[x].style.display != "none") + { + count++; + } + } + } userCount.innerHTML = count; } - function showAllCallsigns() + function removeAllChildNodes(parent) { - var count = 0; + while (parent.firstChild) + { + parent.removeChild(parent.firstChild); + } + } + + function showAllCallsigns(justSearching = false) + { + allCallDiv.style.display = "none"; + if (justSearching == false) + { + removeAllChildNodes(allCallDiv); + } + for (const x in window.opener.g_gtFlagPins) { var obj = window.opener.g_gtFlagPins[x]; @@ -345,11 +366,6 @@ if (obj.canmsg == false) show = false; - if (show) - { - count++; - } - makeCallsignRow(obj, show); if (obj.cid == g_currentId && messageInput.disabled == true && obj.live == true) @@ -362,19 +378,8 @@ } } - if(allCallDiv.childElementCount > 0) - { - for (var x = allCallDiv.childNodes.length-1; x > -1; x--) - { - if (!(allCallDiv.childNodes[x].id in window.opener.g_gtFlagPins)) - { - allCallDiv.removeChild(allCallDiv.childNodes[x]); - } - } - } - updateBar(g_currentId); - userCount.innerHTML = count; + updateCount(); if (g_viewBand) { @@ -394,6 +399,13 @@ viewMode.innerHTML = "All"; } + allCallDiv.style.display = ""; + + messagesRedraw(); + } + + function messagesRedraw() + { showAllMessages(); Resize(); } @@ -443,8 +455,7 @@ g_currentId = ""; openId(what); } - showAllMessages(); - Resize(); + messagesRedraw(); } function updateEverything() @@ -548,7 +559,8 @@ if (id in window.opener.g_gtUnread) { delete window.opener.g_gtUnread[id]; - showAllCallsigns(); + updateCallsign(id); + showAllMessages(); } } messageTextDiv.innerHTML = worker; @@ -613,7 +625,7 @@ } else { clearSearch.style.display = "none"; } - showAllCallsigns(); + showAllCallsigns(true); } function doLookup(what) diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index ef04ae1..9acbacc 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -10638,22 +10638,30 @@ function setGtShareButtons() g_layerVectors.gtflags.setVisible(false); clearGtFlags(); // Clear list - g_gtFlagPins = {}; + g_gtFlagPins = Object() + g_gtMessages = Object(); + g_gtUnread = Object(); + g_gtIdToCid = Object(); + g_gtCallsigns = Object(); + g_gtSentAwayToCid = Object(); + if (g_chatWindowHandle != null) { try { g_chatWindowHandle.hide(); + g_chatWindowHandle.window.allCallDiv.innerHTML = ""; + g_chatWindowHandle.window.updateCount(); } catch (e) { console.error(e); } } + goProcessRoster(); } - gtShareFlagImg.src = - g_gtShareFlagImageArray[g_appSettings.gtShareEnable == false ? 0 : 1]; + gtShareFlagImg.src = g_gtShareFlagImageArray[g_appSettings.gtShareEnable == false ? 0 : 1]; } function setMulticastIp() diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index 3cc9dfa..8438ff3 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -54,7 +54,7 @@ var g_gtLiveStatusUpdate = false; var myChatId = 0; var myRoom = 0; -var g_gtChatlistChangeCount = 0; + var g_gtCurrentMessageCount = 0; function gtConnectChat() @@ -352,7 +352,6 @@ function gtChatUpdateCall(jsmesg) g_layerSources.gtflags.addFeature(g_gtFlagPins[cid].pin); } } - g_gtChatlistChangeCount++; g_gtCallsigns[g_gtFlagPins[cid].call] = cid; updateChatWindow(cid); } @@ -476,7 +475,6 @@ function gtChatNewList(jsmesg) } } } - g_gtChatlistChangeCount++; updateChatWindow(); } @@ -608,7 +606,6 @@ function gtChatStateMachine() { g_getEngineWasRunning = false; closeGtSocket(); - g_gtChatlistChangeCount = 0; g_lastGtStatus = ""; } } @@ -730,9 +727,9 @@ function newChatMessage(id, jsmesg) try { hasFocus = g_chatWindowHandle.window.newChatMessage(id, jsmesg); + g_chatWindowHandle.window.messagesRedraw(); } catch (e) {} - updateChatWindow(); } return hasFocus; }