From 26f919b9ced0b65e55de600c083f7a550aa3359d Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 21:08:19 +0100 Subject: [PATCH 01/33] chat: define atomic markup rendering --- core/code/chat.js | 75 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index ca4f7d988..4b6097649 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -380,30 +380,17 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is break; case 'TEXT': - msg += $('
').text(markup[1].plain).html().autoLink(); + msg += chat.renderText(markup[1]); break; case 'AT_PLAYER': var thisToPlayer = (markup[1].plain == ('@'+window.PLAYER.nickname)); - var spanClass = thisToPlayer ? "pl_nudge_me" : (markup[1].team + " pl_nudge_player"); - var atPlayerName = markup[1].plain.replace(/^@/, ""); - msg += $('
').html($('') - .attr('class', spanClass) - .attr('onclick',"window.chat.nicknameClicked(event, '"+atPlayerName+"')") - .text(markup[1].plain)).html(); + msg += chat.renderPlayer(markup[1], true); msgToPlayer = msgToPlayer || thisToPlayer; break; case 'PORTAL': - var lat = markup[1].latE6/1E6, lng = markup[1].lngE6/1E6; - var perma = window.makePermalink([lat,lng]); - var js = 'window.selectPortalByLatLng('+lat+', '+lng+');return false'; - - msg += '' - + window.chat.getChatPortalName(markup[1]) - + ''; + msg += chat.renderPortal(markup[1]); break; case 'SECURE': @@ -413,7 +400,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is default: //handle unknown types by outputting the plain text version, marked with it's type - msg += $('
').text(markup[0]+':<'+markup[1].plain+'>').html(); + msg += chat.renderMarkupEntity(markup); break; } }); @@ -452,6 +439,60 @@ window.chat.getChatPortalName = function(markup) { return name; } +window.chat.renderText = function (text) { + return $('
').text(text.plain).html().autoLink(); +} + +window.chat.renderPortal = function (portal) { + var lat = portal.latE6/1E6, lng = portal.lngE6/1E6; + var perma = window.makePermalink([lat,lng]); + var js = 'window.selectPortalByLatLng('+lat+', '+lng+');return false'; + return '' + + window.chat.getChatPortalName(portal) + + ''; +} + +window.chat.renderFactionEnt = function (faction) { + var name = faction.team == "ENLIGHTENED" ? "Enlightened" : "Resistance"; + var spanClass = faction.team == "ENLIGHTENED" ? TEAM_ENL : TEAM_RES; + return $('
').html($('') + .attr('class', spanClass) + .text(name)).html(); +} + +window.chat.renderPlayer = function (player, at, sender) { + var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; + var thisToPlayer = name == window.PLAYER.nickname; + var spanClass = thisToPlayer ? "pl_nudge_me" : (player.team + " pl_nudge_player"); + return $('
').html($('') + .attr('class', spanClass) + .attr('onclick',"window.chat.nicknameClicked(event, '"+name+"')") + .text((at ? '@' : '') + name)).html(); +} + +window.chat.renderMarkupEntity = function (ent) { + switch (ent[0]) { + case 'TEXT': + return chat.renderText(ent[1]); + case 'PORTAL': + return chat.renderPortal(ent[1]); + case 'FACTION': + return chat.renderFactionEnt(ent[1]); + case 'SENDER': + return chat.renderPlayer(ent[1], false, true); + case 'PLAYER': + return chat.renderPlayer(ent[1]); + case 'AT_PLAYER': + return chat.renderPlayer(ent[1], true); + case 'TEXT': + return $('
').text(ent[1].plain).html().autoLink(); + default: + } + return $('
').text(ent[0]+':<'+ent[1].plain+'>').html(); +} + // renders data from the data-hash to the element defined by the given // ID. Set 3rd argument to true if it is likely that old data has been // added. Latter is only required for scrolling. From 0e0d0afa176b51dc07c7c51f8a29efcc6d0560e3 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 21:53:00 +0100 Subject: [PATCH 02/33] chat: use plext.categories --- core/code/chat.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 4b6097649..37ead80d8 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -355,8 +355,12 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // avoid duplicates if(json[0] in storageHash.data) return true; - var isSecureMessage = false; - var msgToPlayer = false; + var categories = json[2].plext.categories; + var isPublic = (categories & 1) == 1; + var isSecure = (categories & 2) == 2; + var msgAlert = (categories & 4) == 4; + + var msgToPlayer = msgAlert && (isPublic || isSecure); var time = json[1]; var team = json[2].plext.team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; @@ -384,9 +388,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is break; case 'AT_PLAYER': - var thisToPlayer = (markup[1].plain == ('@'+window.PLAYER.nickname)); msg += chat.renderPlayer(markup[1], true); - msgToPlayer = msgToPlayer || thisToPlayer; break; case 'PORTAL': @@ -395,7 +397,6 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is case 'SECURE': //NOTE: we won't add the '[secure]' string here - it'll be handled below instead - isSecureMessage = true; break; default: @@ -418,9 +419,9 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is //both the public and private channels //we don't include this '[secure]' text above, as it's redundant in the faction-only channel //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one - if (!auto && !(isPublicChannel===false) && isSecureMessage) msg = '[faction] ' + msg; + if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; //and, add the reverse - a 'public' marker to messages in the private channel - if (!auto && !(isPublicChannel===true) && (!isSecureMessage)) msg = '[public] ' + msg; + if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; // format: timestamp, autogenerated, HTML message From 96e457cc45a4232a0257e5312fe7b45c1083457b Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 21:58:58 +0100 Subject: [PATCH 03/33] chat: use renderMarkupEntity for some refactor --- core/code/chat.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 37ead80d8..ef6302113 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -383,24 +383,12 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is if(ind > 0) msg += nick; // don’t repeat nick directly break; - case 'TEXT': - msg += chat.renderText(markup[1]); - break; - - case 'AT_PLAYER': - msg += chat.renderPlayer(markup[1], true); - break; - - case 'PORTAL': - msg += chat.renderPortal(markup[1]); - break; - case 'SECURE': //NOTE: we won't add the '[secure]' string here - it'll be handled below instead break; default: - //handle unknown types by outputting the plain text version, marked with it's type + // add other enitities whatever the type msg += chat.renderMarkupEntity(markup); break; } From 6fc7c70e4135d44f82a495b3362ac4bedff84a0e Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 23:46:19 +0100 Subject: [PATCH 04/33] chat: use css for [public]/[faction] --- core/code/chat.js | 23 ++++++++++++----------- core/style.css | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index ef6302113..1b69c555d 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -402,18 +402,18 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // if ((!isPublicChannel) && (!isSecureMessage)) return true; - //NOTE: these two are redundant with the above two tests in place - but things have changed... - //from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in - //both the public and private channels - //we don't include this '[secure]' text above, as it's redundant in the faction-only channel - //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one - if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; - //and, add the reverse - a 'public' marker to messages in the private channel - if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; + // //NOTE: these two are redundant with the above two tests in place - but things have changed... + // //from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in + // //both the public and private channels + // //we don't include this '[secure]' text above, as it's redundant in the faction-only channel + // //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one + // if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; + // //and, add the reverse - a 'public' marker to messages in the private channel + // if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; // format: timestamp, autogenerated, HTML message - storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast), nick]; + storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert), nick]; }); } @@ -517,7 +517,7 @@ window.chat.renderDivider = function(text) { } -window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { +window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); //add tags around the milliseconds @@ -537,7 +537,8 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro if (nick === window.PLAYER.nickname) color = '#fd6'; //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) var s = 'style="cursor:pointer; color:'+color+'"'; var i = ['<', '>']; - return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; + var className = (isPublic) ? 'public' : (isSecure) ? 'faction' : ''; + return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; } window.chat.addNickname= function(nick) { diff --git a/core/style.css b/core/style.css index 8e515b8ed..b30588eec 100644 --- a/core/style.css +++ b/core/style.css @@ -342,6 +342,22 @@ em { color: #f66 !important; } +#chatall tr.faction td:nth-child(3):before, +#chatalerts tr.faction td:nth-child(3):before { + content: '[faction]'; + color: #f88; + background-color: #500; + margin-right: .5rem; +} + +#chatfaction tr.public td:nth-child(3):before, +#chatalerts tr.public td:nth-child(3):before { + content: '[public]'; + color: #ff6; + background-color: #550; + margin-right: .5rem; +} + mark { background: transparent; } From aa166bf4636f4ff8781e5348406c9964840fd1fd Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 00:09:08 +0100 Subject: [PATCH 05/33] chat: move message rendering to renderMsg --- core/code/chat.js | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 1b69c555d..aa88fd6ae 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -311,7 +311,7 @@ window.chat.renderAlerts = function(oldMsgsWereAdded) { window.chat.nicknameClicked = function(event, nickname) { var hookData = { event: event, nickname: nickname }; - + if (window.runHooks('nicknameClicked', hookData)) { window.chat.addNickname('@' + nickname); } @@ -367,11 +367,13 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is var auto = json[2].plext.plextType !== 'PLAYER_GENERATED'; var systemNarrowcast = json[2].plext.plextType === 'SYSTEM_NARROWCAST'; + var markup = json[2].plext.markup; + //remove "Your X on Y was destroyed by Z" from the faction channel // if (systemNarrowcast && !isPublicChannel) return true; - var msg = '', nick = ''; - $.each(json[2].plext.markup, function(ind, markup) { + var nick = ''; + $.each(markup, function(ind, markup) { switch(markup[0]) { case 'SENDER': // user generated messages nick = markup[1].plain.slice(0, -2); // cut “: ” at end @@ -380,21 +382,13 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is case 'PLAYER': // automatically generated messages nick = markup[1].plain; team = markup[1].team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; - if(ind > 0) msg += nick; // don’t repeat nick directly - break; - - case 'SECURE': - //NOTE: we won't add the '[secure]' string here - it'll be handled below instead break; default: - // add other enitities whatever the type - msg += chat.renderMarkupEntity(markup); break; } }); - // //skip secure messages on the public channel // if (isPublicChannel && isSecureMessage) return true; @@ -411,6 +405,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // //and, add the reverse - a 'public' marker to messages in the private channel // if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; + var msg = chat.renderMarkup(markup); // format: timestamp, autogenerated, HTML message storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert), nick]; @@ -482,6 +477,28 @@ window.chat.renderMarkupEntity = function (ent) { return $('
').text(ent[0]+':<'+ent[1].plain+'>').html(); } +window.chat.renderMarkup = function (markup) { + var msg = ''; + $.each(markup, function(ind, markup) { + switch(markup[0]) { + case 'SENDER': + case 'SECURE': + // skip as already handled + break; + + case 'PLAYER': // automatically generated messages + if(ind > 0) msg += chat.renderMarkupEntity(markup); // don’t repeat nick directly + break; + + default: + // add other enitities whatever the type + msg += chat.renderMarkupEntity(markup); + break; + } + }); + return msg; +} + // renders data from the data-hash to the element defined by the given // ID. Set 3rd argument to true if it is likely that old data has been // added. Latter is only required for scrolling. @@ -629,7 +646,7 @@ window.chat.needMoreMessages = function() { var hasScrollbar = scrollBottom(activeChat) !== 0 || activeChat.scrollTop() !== 0; var nearTop = activeChat.scrollTop() <= CHAT_REQUEST_SCROLL_TOP; if(hasScrollbar && !nearTop) return; - + if(activeTab === 'faction') chat.requestFaction(true); else From 471d43f77a4d122f91b1426193cd2e35d69cf586 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 00:23:46 +0100 Subject: [PATCH 06/33] chat: remove outdated comment --- core/code/chat.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index aa88fd6ae..a1929ed43 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -323,8 +323,8 @@ window.chat.nicknameClicked = function(event, nickname) { window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { + //track oldest + newest timestamps/GUID if (newData.result.length > 0) { - //track oldest + newest timestamps/GUID var first = { guid: newData.result[0][0], time: newData.result[0][1] @@ -369,9 +369,6 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is var markup = json[2].plext.markup; - //remove "Your X on Y was destroyed by Z" from the faction channel -// if (systemNarrowcast && !isPublicChannel) return true; - var nick = ''; $.each(markup, function(ind, markup) { switch(markup[0]) { @@ -389,22 +386,6 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is } }); -// //skip secure messages on the public channel -// if (isPublicChannel && isSecureMessage) return true; - -// //skip public messages (e.g. @player mentions) on the secure channel -// if ((!isPublicChannel) && (!isSecureMessage)) return true; - - - // //NOTE: these two are redundant with the above two tests in place - but things have changed... - // //from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in - // //both the public and private channels - // //we don't include this '[secure]' text above, as it's redundant in the faction-only channel - // //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one - // if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; - // //and, add the reverse - a 'public' marker to messages in the private channel - // if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; - var msg = chat.renderMarkup(markup); // format: timestamp, autogenerated, HTML message From ebfee74b5e3d74691a934bcf3e43b55635ed1718 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 09:53:58 +0100 Subject: [PATCH 07/33] chat: use time.pl_nudge_date:after --- core/code/chat.js | 12 ++++++------ core/style.css | 27 +++++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index a1929ed43..639f62c51 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -521,12 +521,12 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro //add tags around the milliseconds tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); - // help cursor via “#chat time” - var t = ''; - if ( msgToPlayer ) - { - t = '
' + t + '
'; - } + var timeClass = (msgToPlayer) ? 'pl_nudge_date' : ''; + var t = ''; + // if ( msgToPlayer ) + // { + // t = '
' + t + '
'; + // } if (systemNarrowcast) { msg = '
' + msg + '
'; diff --git a/core/style.css b/core/style.css index b30588eec..7f5ff8e56 100644 --- a/core/style.css +++ b/core/style.css @@ -1123,25 +1123,28 @@ td + td { } */ +.pl_nudge_date:after { + background: no-repeat url(//commondatastorage.googleapis.com/ingress.com/img/nudge_pointy.png); + position:absolute; + content:""; + height:20px; + width: 5px; + right:-5px; + top:-1px +} + .pl_nudge_date { background-color: #724510; border-left: 1px solid #ffd652; border-bottom: 1px solid #ffd652; border-top: 1px solid #ffd652; color: #ffd652; - display: inline-block; - float: left; + display: block; + position:relative; height: 18px; - text-align: center; -} - -.pl_nudge_pointy_spacer { - background: no-repeat url(//commondatastorage.googleapis.com/ingress.com/img/nudge_pointy.png); - display: inline-block; - float: left; - height: 20px; - left: 47px; - width: 5px; + width: 36px; + padding-left: 2px; + left: -2px; } .pl_nudge_player { From 5244ea710ed17a9a2e1a91309a9c6c379faacda0 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 13:39:34 +0100 Subject: [PATCH 08/33] at: remove obsolete desiredNum --- core/code/chat.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 639f62c51..d4690c4be 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -99,7 +99,6 @@ window.chat.genPostData = function(channel, storageHash, getOlderMsgs) { var ne = b.getNorthEast(); var sw = b.getSouthWest(); var data = { -// desiredNumItems: isFaction ? CHAT_FACTION_ITEMS : CHAT_PUBLIC_ITEMS , minLatE6: Math.round(sw.lat*1E6), minLngE6: Math.round(sw.lng*1E6), maxLatE6: Math.round(ne.lat*1E6), @@ -119,18 +118,14 @@ window.chat.genPostData = function(channel, storageHash, getOlderMsgs) { // ask for newer chat var min = storageHash.newestTimestamp; // the initial request will have both timestamp values set to -1, - // thus we receive the newest desiredNumItems. After that, we will - // only receive messages with a timestamp greater or equal to min - // above. + // thus we receive the newest 50. After that, we will only receive + // messages with a timestamp greater or equal to min above. // After resuming from idle, there might be more new messages than // desiredNumItems. So on the first request, we are not really up to // date. We will eventually catch up, as long as there are less new - // messages than desiredNumItems per each refresh cycle. + // messages than 50 per each refresh cycle. // A proper solution would be to query until no more new results are - // returned. Another way would be to set desiredNumItems to a very - // large number so we really get all new messages since the last - // request. Setting desiredNumItems to -1 does unfortunately not - // work. + // returned. // Currently this edge case is not handled. Let’s see if this is a // problem in crowded areas. $.extend(data, { From bb6e52d04a6d5bc3e77913f1f5b6ce9d08e98203 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 13:51:22 +0100 Subject: [PATCH 09/33] chat: narrowcast as td class --- core/code/chat.js | 11 ++++++----- core/style.css | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index d4690c4be..4ea68b500 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -522,16 +522,17 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro // { // t = '
' + t + '
'; // } - if (systemNarrowcast) - { - msg = '
' + msg + '
'; - } + var msgClass = (systemNarrowcast) ? 'system_narrowcast' : ''; var color = COLORS[team]; if (nick === window.PLAYER.nickname) color = '#fd6'; //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) var s = 'style="cursor:pointer; color:'+color+'"'; var i = ['<', '>']; var className = (isPublic) ? 'public' : (isSecure) ? 'faction' : ''; - return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; + return '' + + ''+t+'' + + ''+i[0]+''+ nick+''+i[1]+'' + + ''+msg+'' + + ''; } window.chat.addNickname= function(nick) { diff --git a/core/style.css b/core/style.css index 7f5ff8e56..ff37d5ee6 100644 --- a/core/style.css +++ b/core/style.css @@ -338,7 +338,7 @@ em { white-space: nowrap; } -#chat td .system_narrowcast { +#chat td.system_narrowcast { color: #f66 !important; } From 40f844356564f95e67d312acec43e4847325c92d Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:06:57 +0100 Subject: [PATCH 10/33] chat: use style.css for nick color --- core/code/chat.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 4ea68b500..8d8b131b4 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -523,14 +523,14 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro // t = '
' + t + '
'; // } var msgClass = (systemNarrowcast) ? 'system_narrowcast' : ''; - var color = COLORS[team]; - if (nick === window.PLAYER.nickname) color = '#fd6'; //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) - var s = 'style="cursor:pointer; color:'+color+'"'; + var nickClasses = ['nickname']; + if (team == TEAM_ENL || team == TEAM_RES) nickClasses.push(TEAM_TO_CSS[team]); + if (nick === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) var i = ['<', '>']; var className = (isPublic) ? 'public' : (isSecure) ? 'faction' : ''; return '' + ''+t+'' - + ''+i[0]+''+ nick+''+i[1]+'' + + ''+i[0]+''+ nick+''+i[1]+'' + ''+msg+'' + ''; } From 07aec11d6f6c8682fcef2fafc367412266b13dba Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 12 Dec 2020 14:08:24 +0100 Subject: [PATCH 11/33] style: remove unwanted !important --- core/style.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/style.css b/core/style.css index ff37d5ee6..501d71578 100644 --- a/core/style.css +++ b/core/style.css @@ -99,11 +99,11 @@ i.large { font-size: 6rem; } } .enl { - color: #03fe03 !important; + color: #03fe03; } .res { - color: #00c5ff !important; + color: #00c5ff; } .none { @@ -111,7 +111,7 @@ i.large { font-size: 6rem; } } .nickname { - cursor: pointer !important; + cursor: pointer; } a { @@ -208,7 +208,7 @@ a:hover { #chatcontrols a:first-child { letter-spacing:-1px; - text-decoration: none !important; + text-decoration: none; } #chatcontrols a.active { @@ -339,7 +339,7 @@ em { } #chat td.system_narrowcast { - color: #f66 !important; + color: #f66; } #chatall tr.faction td:nth-child(3):before, From 2de2a594d9657bb90b37ecc86ff1c2bf41642f76 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:56:51 +0100 Subject: [PATCH 12/33] chat: add raw data in channel.data --- core/code/chat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 8d8b131b4..57944dcd4 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -383,8 +383,8 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is var msg = chat.renderMarkup(markup); - // format: timestamp, autogenerated, HTML message - storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert), nick]; + // format: timestamp, autogenerated, HTML message, nick, additional data (raw, plugin specific data...) + storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert), nick, { raw: json }]; }); } From dcc56aa57ea460ad8513154f3489d62f0a77b2cd Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 17:11:48 +0100 Subject: [PATCH 13/33] chat: cut renderMsg in small pieces --- core/code/chat.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 57944dcd4..72008609a 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -509,30 +509,37 @@ window.chat.renderDivider = function(text) { return '─ ' + text + d + ''; } - -window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert) { +window.chat.renderTimeCell = function(time, classNames) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); //add tags around the milliseconds tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); + return ''; +} + +window.chat.renderNickCell = function(nick, classNames) { + var i = ['<', '>']; + return ''+i[0]+''+ nick+''+i[1]+''; +} + +window.chat.renderMsgCell = function(msg, classNames) { + return ''+msg+''; +} +window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert) { var timeClass = (msgToPlayer) ? 'pl_nudge_date' : ''; - var t = ''; - // if ( msgToPlayer ) - // { - // t = '
' + t + '
'; - // } - var msgClass = (systemNarrowcast) ? 'system_narrowcast' : ''; + var timeCell = chat.renderTimeCell(time, timeClass); + var nickClasses = ['nickname']; if (team == TEAM_ENL || team == TEAM_RES) nickClasses.push(TEAM_TO_CSS[team]); if (nick === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) - var i = ['<', '>']; + var nickCell = chat.renderNickCell(nick, nickClasses.join(' ')); + + var msgClass = (systemNarrowcast) ? 'system_narrowcast' : ''; + var msgCell = chat.renderMsgCell(msg, msgClass); + var className = (isPublic) ? 'public' : (isSecure) ? 'faction' : ''; - return '' - + ''+t+'' - + ''+i[0]+''+ nick+''+i[1]+'' - + ''+msg+'' - + ''; + return '' + timeCell + nickCell + msgCell + ''; } window.chat.addNickname= function(nick) { From f7dd72be98e40deb0a87c4472594e5ebd9b562a3 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 18:41:58 +0100 Subject: [PATCH 14/33] chat: introduce renderMsgRow & restore renderMsg --- core/code/chat.js | 62 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 72008609a..75e1d521f 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -381,11 +381,25 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is } }); - var msg = chat.renderMarkup(markup); - - // format: timestamp, autogenerated, HTML message, nick, additional data (raw, plugin specific data...) - storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert), nick, { raw: json }]; + var parsedData = { + guid: json[0], + time: time, + public: isPublic, + secure: isSecure, + alert: msgAlert, + msgToPlayer: msgToPlayer, + type: json[2].plext.plextType, + narrowcast: systemNarrowcast, + auto: auto, + player: { + name: nick, + team: team, + }, + markup: markup, + }; + // format: timestamp, autogenerated, HTML message, nick, additional data (parsed, plugin specific data...) + storageHash.data[json[0]] = [json[1], auto, chat.renderMsgRow(parsedData), nick, parsedData]; }); } @@ -526,22 +540,46 @@ window.chat.renderMsgCell = function(msg, classNames) { return ''+msg+''; } -window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert) { - var timeClass = (msgToPlayer) ? 'pl_nudge_date' : ''; - var timeCell = chat.renderTimeCell(time, timeClass); +window.chat.renderMsgRow = function(data) { + var timeClass = (data.msgToPlayer) ? 'pl_nudge_date' : ''; + var timeCell = chat.renderTimeCell(data.time, timeClass); var nickClasses = ['nickname']; - if (team == TEAM_ENL || team == TEAM_RES) nickClasses.push(TEAM_TO_CSS[team]); - if (nick === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) - var nickCell = chat.renderNickCell(nick, nickClasses.join(' ')); + if (data.player.team == TEAM_ENL || data.player.team == TEAM_RES) nickClasses.push(TEAM_TO_CSS[data.player.team]); + if (data.player.name === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) + var nickCell = chat.renderNickCell(data.player.name, nickClasses.join(' ')); - var msgClass = (systemNarrowcast) ? 'system_narrowcast' : ''; + var msg = chat.renderMarkup(data.markup) + var msgClass = (data.narrowcast) ? 'system_narrowcast' : ''; var msgCell = chat.renderMsgCell(msg, msgClass); - var className = (isPublic) ? 'public' : (isSecure) ? 'faction' : ''; + var className = (data.public) ? 'public' : (data.secure) ? 'faction' : ''; return '' + timeCell + nickCell + msgCell + ''; } +window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { + var ta = unixTimeToHHmm(time); + var tb = unixTimeToDateTimeString(time, true); + //add tags around the milliseconds + tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); + + // help cursor via “#chat time” + var t = ''; + if ( msgToPlayer ) + { + t = '
' + t + '
'; + } + if (systemNarrowcast) + { + msg = '
' + msg + '
'; + } + var color = COLORS[team]; + if (nick === window.PLAYER.nickname) color = '#fd6'; //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) + var s = 'style="cursor:pointer; color:'+color+'"'; + var i = ['<', '>']; + return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; +} + window.chat.addNickname= function(nick) { var c = document.getElementById("chattext"); c.value = [c.value.trim(), nick].join(" ").trim() + " "; From b5736a35a4acadcc15d7c0999336095b18690900 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 18:56:34 +0100 Subject: [PATCH 15/33] chat: add guid in row html data --- core/code/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/code/chat.js b/core/code/chat.js index 75e1d521f..a1d4e6b66 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -554,7 +554,7 @@ window.chat.renderMsgRow = function(data) { var msgCell = chat.renderMsgCell(msg, msgClass); var className = (data.public) ? 'public' : (data.secure) ? 'faction' : ''; - return '' + timeCell + nickCell + msgCell + ''; + return '' + timeCell + nickCell + msgCell + ''; } window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { From 933ae249203757ef2ca8cb7da1d2f54764a23119 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 18:59:37 +0100 Subject: [PATCH 16/33] comment spacing --- core/code/chat.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index a1d4e6b66..e73fde8f0 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -317,8 +317,7 @@ window.chat.nicknameClicked = function(event, nickname) { } window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { - - //track oldest + newest timestamps/GUID + // track oldest + newest timestamps/GUID if (newData.result.length > 0) { var first = { guid: newData.result[0][0], @@ -526,7 +525,7 @@ window.chat.renderDivider = function(text) { window.chat.renderTimeCell = function(time, classNames) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); - //add tags around the milliseconds + // add tags around the milliseconds tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); return ''; } @@ -546,7 +545,8 @@ window.chat.renderMsgRow = function(data) { var nickClasses = ['nickname']; if (data.player.team == TEAM_ENL || data.player.team == TEAM_RES) nickClasses.push(TEAM_TO_CSS[data.player.team]); - if (data.player.name === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) + // highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) + if (data.player.name === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); var nickCell = chat.renderNickCell(data.player.name, nickClasses.join(' ')); var msg = chat.renderMarkup(data.markup) @@ -560,7 +560,7 @@ window.chat.renderMsgRow = function(data) { window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); - //add tags around the milliseconds + // add tags around the milliseconds tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); // help cursor via “#chat time” @@ -574,7 +574,8 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro msg = '
' + msg + '
'; } var color = COLORS[team]; - if (nick === window.PLAYER.nickname) color = '#fd6'; //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) + // highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) + if (nick === window.PLAYER.nickname) color = '#fd6'; var s = 'style="cursor:pointer; color:'+color+'"'; var i = ['<', '>']; return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; From 2fad7bc5ab7b49b4102c0757fe8f66261cf983b0 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 19:02:26 +0100 Subject: [PATCH 17/33] chat: move oldest/newest msg update --- core/code/chat.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/code/chat.js b/core/code/chat.js index e73fde8f0..19a227528 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -316,7 +316,7 @@ window.chat.nicknameClicked = function(event, nickname) { return false; } -window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { +window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAscendingOrder) { // track oldest + newest timestamps/GUID if (newData.result.length > 0) { var first = { @@ -345,6 +345,11 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is } } } +} + +window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { + window.chat.updateOldNewHash(newData, storageHash, isOldMsgs, isAscendingOrder); + $.each(newData.result, function(ind, json) { // avoid duplicates if(json[0] in storageHash.data) return true; From 8407a424197c6eb3af175b0d14f66a131edfc620 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 19:13:23 +0100 Subject: [PATCH 18/33] chat: move message data parsing --- core/code/chat.js | 96 ++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 19a227528..d774d0d2c 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -347,63 +347,67 @@ window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAsc } } -window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { - window.chat.updateOldNewHash(newData, storageHash, isOldMsgs, isAscendingOrder); +window.chat.parseMsgData = function(data) { + var categories = data[2].plext.categories; + var isPublic = (categories & 1) == 1; + var isSecure = (categories & 2) == 2; + var msgAlert = (categories & 4) == 4; - $.each(newData.result, function(ind, json) { - // avoid duplicates - if(json[0] in storageHash.data) return true; + var msgToPlayer = msgAlert && (isPublic || isSecure); + + var time = data[1]; + var team = data[2].plext.team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; + var auto = data[2].plext.plextType !== 'PLAYER_GENERATED'; + var systemNarrowcast = data[2].plext.plextType === 'SYSTEM_NARROWCAST'; - var categories = json[2].plext.categories; - var isPublic = (categories & 1) == 1; - var isSecure = (categories & 2) == 2; - var msgAlert = (categories & 4) == 4; + var markup = data[2].plext.markup; - var msgToPlayer = msgAlert && (isPublic || isSecure); + var nick = ''; + $.each(markup, function(ind, markup) { + switch(markup[0]) { + case 'SENDER': // user generated messages + nick = markup[1].plain.slice(0, -2); // cut “: ” at end + break; - var time = json[1]; - var team = json[2].plext.team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; - var auto = json[2].plext.plextType !== 'PLAYER_GENERATED'; - var systemNarrowcast = json[2].plext.plextType === 'SYSTEM_NARROWCAST'; + case 'PLAYER': // automatically generated messages + nick = markup[1].plain; + team = markup[1].team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; + break; - var markup = json[2].plext.markup; + default: + break; + } + }); - var nick = ''; - $.each(markup, function(ind, markup) { - switch(markup[0]) { - case 'SENDER': // user generated messages - nick = markup[1].plain.slice(0, -2); // cut “: ” at end - break; + return { + guid: data[0], + time: time, + public: isPublic, + secure: isSecure, + alert: msgAlert, + msgToPlayer: msgToPlayer, + type: data[2].plext.plextType, + narrowcast: systemNarrowcast, + auto: auto, + player: { + name: nick, + team: team, + }, + markup: markup, + }; +} - case 'PLAYER': // automatically generated messages - nick = markup[1].plain; - team = markup[1].team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; - break; +window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { + window.chat.updateOldNewHash(newData, storageHash, isOlderMsgs, isAscendingOrder); - default: - break; - } - }); + $.each(newData.result, function(ind, json) { + // avoid duplicates + if(json[0] in storageHash.data) return true; - var parsedData = { - guid: json[0], - time: time, - public: isPublic, - secure: isSecure, - alert: msgAlert, - msgToPlayer: msgToPlayer, - type: json[2].plext.plextType, - narrowcast: systemNarrowcast, - auto: auto, - player: { - name: nick, - team: team, - }, - markup: markup, - }; + var parsedData = chat.parseMsgData(json); // format: timestamp, autogenerated, HTML message, nick, additional data (parsed, plugin specific data...) - storageHash.data[json[0]] = [json[1], auto, chat.renderMsgRow(parsedData), nick, parsedData]; + storageHash.data[parsedData.guid] = [parsedData.time, parsedData.auto, chat.renderMsgRow(parsedData), parsedData.player.name, parsedData]; }); } From 29f91d6a119deb5c05de9e871383504ad44fbae3 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 19:18:04 +0100 Subject: [PATCH 19/33] chat: group related functions --- core/code/chat.js | 86 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index d774d0d2c..a409c732c 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -304,6 +304,12 @@ window.chat.renderAlerts = function(oldMsgsWereAdded) { // common // +window.chat.addNickname= function(nick) { + var c = document.getElementById("chattext"); + c.value = [c.value.trim(), nick].join(" ").trim() + " "; + c.focus() +} + window.chat.nicknameClicked = function(event, nickname) { var hookData = { event: event, nickname: nickname }; @@ -411,6 +417,14 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is }); } +// +// Rendering primitive for markup, chat cells (td) and chat row (tr) +// + +window.chat.renderText = function (text) { + return $('
').text(text.plain).html().autoLink(); +} + // Override portal names that are used over and over, such as 'US Post Office' window.chat.getChatPortalName = function(markup) { var name = markup.name; @@ -421,10 +435,6 @@ window.chat.getChatPortalName = function(markup) { return name; } -window.chat.renderText = function (text) { - return $('
').text(text.plain).html().autoLink(); -} - window.chat.renderPortal = function (portal) { var lat = portal.latE6/1E6, lng = portal.lngE6/1E6; var perma = window.makePermalink([lat,lng]); @@ -497,40 +507,6 @@ window.chat.renderMarkup = function (markup) { return msg; } -// renders data from the data-hash to the element defined by the given -// ID. Set 3rd argument to true if it is likely that old data has been -// added. Latter is only required for scrolling. -window.chat.renderData = function(data, element, likelyWereOldMsgs) { - var elm = $('#'+element); - if(elm.is(':hidden')) return; - - // discard guids and sort old to new -//TODO? stable sort, to preserve server message ordering? or sort by GUID if timestamps equal? - var vals = $.map(data, function(v, k) { return [v]; }); - vals = vals.sort(function(a, b) { return a[0]-b[0]; }); - - // render to string with date separators inserted - var msgs = ''; - var prevTime = null; - $.each(vals, function(ind, msg) { - var nextTime = new Date(msg[0]).toLocaleDateString(); - if(prevTime && prevTime !== nextTime) - msgs += chat.renderDivider(nextTime); - msgs += msg[2]; - prevTime = nextTime; - }); - - var scrollBefore = scrollBottom(elm); - elm.html('' + msgs + '
'); - chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); -} - - -window.chat.renderDivider = function(text) { - var d = ' ──────────────────────────────────────────────────────────────────────────'; - return '─ ' + text + d + ''; -} - window.chat.renderTimeCell = function(time, classNames) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); @@ -566,6 +542,7 @@ window.chat.renderMsgRow = function(data) { return '' + timeCell + nickCell + msgCell + ''; } +// legacy rendering, not used internaly, but left there for backward compatibilty in case a plugin uses it directly window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); @@ -590,13 +567,38 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; } -window.chat.addNickname= function(nick) { - var c = document.getElementById("chattext"); - c.value = [c.value.trim(), nick].join(" ").trim() + " "; - c.focus() +window.chat.renderDivider = function(text) { + var d = ' ──────────────────────────────────────────────────────────────────────────'; + return '─ ' + text + d + ''; } +// renders data from the data-hash to the element defined by the given +// ID. Set 3rd argument to true if it is likely that old data has been +// added. Latter is only required for scrolling. +window.chat.renderData = function(data, element, likelyWereOldMsgs) { + var elm = $('#'+element); + if(elm.is(':hidden')) return; + + // discard guids and sort old to new +//TODO? stable sort, to preserve server message ordering? or sort by GUID if timestamps equal? + var vals = $.map(data, function(v, k) { return [v]; }); + vals = vals.sort(function(a, b) { return a[0]-b[0]; }); + // render to string with date separators inserted + var msgs = ''; + var prevTime = null; + $.each(vals, function(ind, msg) { + var nextTime = new Date(msg[0]).toLocaleDateString(); + if(prevTime && prevTime !== nextTime) + msgs += chat.renderDivider(nextTime); + msgs += msg[2]; + prevTime = nextTime; + }); + + var scrollBefore = scrollBottom(elm); + elm.html('' + msgs + '
'); + chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); +} window.chat.getActive = function() { From 5a9e6fe0a9886402e8de5418d92ea8ef760add47 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 19:29:27 +0100 Subject: [PATCH 20/33] chat: comply with eqeqeq --- core/code/chat.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index a409c732c..eefa16f6d 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -339,13 +339,13 @@ window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAsc last = temp; } if (storageHash.oldestTimestamp === -1 || storageHash.oldestTimestamp >= last.time) { - if (isOlderMsgs || storageHash.oldestTimestamp != last.time) { + if (isOlderMsgs || storageHash.oldestTimestamp !== last.time) { storageHash.oldestTimestamp = last.time; storageHash.oldestGUID = last.guid; } } if (storageHash.newestTimestamp === -1 || storageHash.newestTimestamp <= first.time) { - if (!isOlderMsgs || storageHash.newestTimestamp != first.time) { + if (!isOlderMsgs || storageHash.newestTimestamp !== first.time) { storageHash.newestTimestamp = first.time; storageHash.newestGUID = first.guid; } @@ -355,9 +355,9 @@ window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAsc window.chat.parseMsgData = function(data) { var categories = data[2].plext.categories; - var isPublic = (categories & 1) == 1; - var isSecure = (categories & 2) == 2; - var msgAlert = (categories & 4) == 4; + var isPublic = (categories & 1) === 1; + var isSecure = (categories & 2) === 2; + var msgAlert = (categories & 4) === 4; var msgToPlayer = msgAlert && (isPublic || isSecure); @@ -447,8 +447,8 @@ window.chat.renderPortal = function (portal) { } window.chat.renderFactionEnt = function (faction) { - var name = faction.team == "ENLIGHTENED" ? "Enlightened" : "Resistance"; - var spanClass = faction.team == "ENLIGHTENED" ? TEAM_ENL : TEAM_RES; + var name = faction.team === "ENLIGHTENED" ? "Enlightened" : "Resistance"; + var spanClass = faction.team === "ENLIGHTENED" ? TEAM_ENL : TEAM_RES; return $('
').html($('') .attr('class', spanClass) .text(name)).html(); @@ -456,7 +456,7 @@ window.chat.renderFactionEnt = function (faction) { window.chat.renderPlayer = function (player, at, sender) { var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; - var thisToPlayer = name == window.PLAYER.nickname; + var thisToPlayer = name === window.PLAYER.nickname; var spanClass = thisToPlayer ? "pl_nudge_me" : (player.team + " pl_nudge_player"); return $('
').html($('') .attr('class', spanClass) @@ -529,7 +529,7 @@ window.chat.renderMsgRow = function(data) { var timeCell = chat.renderTimeCell(data.time, timeClass); var nickClasses = ['nickname']; - if (data.player.team == TEAM_ENL || data.player.team == TEAM_RES) nickClasses.push(TEAM_TO_CSS[data.player.team]); + if (data.player.team === TEAM_ENL || data.player.team === TEAM_RES) nickClasses.push(TEAM_TO_CSS[data.player.team]); // highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) if (data.player.name === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); var nickCell = chat.renderNickCell(data.player.name, nickClasses.join(' ')); From d982ab77bf22d2918a9d4049231ee53c887fcd8c Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Dec 2020 20:36:30 +0100 Subject: [PATCH 21/33] chat: scroll down on first rendering --- core/code/chat.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/code/chat.js b/core/code/chat.js index eefa16f6d..cdd0a7812 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -595,9 +595,14 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs) { prevTime = nextTime; }); + var firstRender = elm.is(':empty'); var scrollBefore = scrollBottom(elm); elm.html('' + msgs + '
'); - chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); + + if (firstRender) + elm.data('needsScrollTop', 99999999); + else + chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); } From 936042a75cfec7ecffc99fb2affdb6b625926c1f Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Thu, 24 Dec 2020 11:17:32 +0100 Subject: [PATCH 22/33] chat: use server order --- core/code/chat.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index cdd0a7812..79b55d17c 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -76,18 +76,21 @@ window.chat.genPostData = function(channel, storageHash, getOlderMsgs) { // after the request is finished – i.e. there would be one almost // useless request. chat._faction.data = {}; + chat._faction.guids = []; chat._faction.oldestTimestamp = -1; chat._faction.newestTimestamp = -1; delete chat._faction.oldestGUID; delete chat._faction.newestGUID; chat._public.data = {}; + chat._public.guids = []; chat._public.oldestTimestamp = -1; chat._public.newestTimestamp = -1; delete chat._public.oldestGUID; delete chat._public.newestGUID; chat._alerts.data = {}; + chat._alerts.guids = []; chat._alerts.oldestTimestamp = -1; chat._alerts.newestTimestamp = -1; delete chat._alerts.oldestGUID; @@ -164,7 +167,7 @@ window.chat.requestFaction = function(getOlderMsgs, isRetry) { } -window.chat._faction = {data:{}, oldestTimestamp:-1, newestTimestamp:-1}; +window.chat._faction = {data:{}, guids: [], oldestTimestamp:-1, newestTimestamp:-1}; window.chat.handleFaction = function(data, olderMsgs, ascendingTimestampOrder) { chat._requestFactionRunning = false; $("#chatcontrols a:contains('faction')").removeClass('loading'); @@ -191,7 +194,7 @@ window.chat.handleFaction = function(data, olderMsgs, ascendingTimestampOrder) { } window.chat.renderFaction = function(oldMsgsWereAdded) { - chat.renderData(chat._faction.data, 'chatfaction', oldMsgsWereAdded); + chat.renderData(chat._faction.data, 'chatfaction', oldMsgsWereAdded, chat._faction.guids); } @@ -217,7 +220,7 @@ window.chat.requestPublic = function(getOlderMsgs, isRetry) { ); } -window.chat._public = {data:{}, oldestTimestamp:-1, newestTimestamp:-1}; +window.chat._public = {data:{}, guids: [], oldestTimestamp:-1, newestTimestamp:-1}; window.chat.handlePublic = function(data, olderMsgs, ascendingTimestampOrder) { chat._requestPublicRunning = false; $("#chatcontrols a:contains('all')").removeClass('loading'); @@ -245,7 +248,7 @@ window.chat.handlePublic = function(data, olderMsgs, ascendingTimestampOrder) { } window.chat.renderPublic = function(oldMsgsWereAdded) { - chat.renderData(chat._public.data, 'chatall', oldMsgsWereAdded); + chat.renderData(chat._public.data, 'chatall', oldMsgsWereAdded, chat._public.guids); } @@ -272,7 +275,7 @@ window.chat.requestAlerts = function(getOlderMsgs, isRetry) { } -window.chat._alerts = {data:{}, oldestTimestamp:-1, newestTimestamp:-1}; +window.chat._alerts = {data:{}, guids: [], oldestTimestamp:-1, newestTimestamp:-1}; window.chat.handleAlerts = function(data, olderMsgs, ascendingTimestampOrder) { chat._requestAlertsRunning = false; $("#chatcontrols a:contains('alerts')").removeClass('loading'); @@ -295,7 +298,7 @@ window.chat.handleAlerts = function(data, olderMsgs, ascendingTimestampOrder) { } window.chat.renderAlerts = function(oldMsgsWereAdded) { - chat.renderData(chat._alerts.data, 'chatalerts', oldMsgsWereAdded); + chat.renderData(chat._alerts.data, 'chatalerts', oldMsgsWereAdded, chat._alerts.guids); } @@ -414,6 +417,10 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // format: timestamp, autogenerated, HTML message, nick, additional data (parsed, plugin specific data...) storageHash.data[parsedData.guid] = [parsedData.time, parsedData.auto, chat.renderMsgRow(parsedData), parsedData.player.name, parsedData]; + if (isAscendingOrder) + storageHash.guids.push(parsedData.guid); + else + storageHash.guids.unshift(parsedData.guid); }); } @@ -575,19 +582,24 @@ window.chat.renderDivider = function(text) { // renders data from the data-hash to the element defined by the given // ID. Set 3rd argument to true if it is likely that old data has been // added. Latter is only required for scrolling. -window.chat.renderData = function(data, element, likelyWereOldMsgs) { +window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) { var elm = $('#'+element); if(elm.is(':hidden')) return; // discard guids and sort old to new //TODO? stable sort, to preserve server message ordering? or sort by GUID if timestamps equal? - var vals = $.map(data, function(v, k) { return [v]; }); - vals = vals.sort(function(a, b) { return a[0]-b[0]; }); + var vals = sortedGuids; + if (vals === undefined) { + vals = $.map(data, function(v, k) { return [[v[0], k]]; }); + vals = vals.sort(function(a, b) { return a[0]-b[0]; }); + vals = vals.map(function(v) { return v[1]}); + } // render to string with date separators inserted var msgs = ''; var prevTime = null; - $.each(vals, function(ind, msg) { + vals.forEach(function(guid) { + var msg = data[guid]; var nextTime = new Date(msg[0]).toLocaleDateString(); if(prevTime && prevTime !== nextTime) msgs += chat.renderDivider(nextTime); From 2b549a166d8358a07649fc2a05f8d927c370e2d2 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Thu, 24 Dec 2020 17:51:26 +0100 Subject: [PATCH 23/33] chat: tr.class on chat message only plextType === PLAYER_GENERATED --- core/code/chat.js | 6 +++++- core/style.css | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 79b55d17c..f93f7fd2b 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -545,7 +545,11 @@ window.chat.renderMsgRow = function(data) { var msgClass = (data.narrowcast) ? 'system_narrowcast' : ''; var msgCell = chat.renderMsgCell(msg, msgClass); - var className = (data.public) ? 'public' : (data.secure) ? 'faction' : ''; + var className = ''; + if (!data.auto && data.public) + className = 'public'; + else if (!data.auto && data.secure) + className = 'faction'; return '' + timeCell + nickCell + msgCell + ''; } diff --git a/core/style.css b/core/style.css index 501d71578..6ceccde78 100644 --- a/core/style.css +++ b/core/style.css @@ -350,7 +350,7 @@ em { margin-right: .5rem; } -#chatfaction tr.public td:nth-child(3):before, +#chatall tr.public td:nth-child(3):before, #chatalerts tr.public td:nth-child(3):before { content: '[public]'; color: #ff6; From e09984ec8dad03eb57108266463de52b92a71fe5 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 30 Dec 2020 22:41:30 +0100 Subject: [PATCH 24/33] chat: lint changes --- core/code/chat.js | 88 +++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index f93f7fd2b..acd0b406c 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -109,9 +109,9 @@ window.chat.genPostData = function(channel, storageHash, getOlderMsgs) { minTimestampMs: -1, maxTimestampMs: -1, tab: channel, - } + }; - if(getOlderMsgs) { + if (getOlderMsgs) { // ask for older chat when scrolling up data = $.extend(data, { maxTimestampMs: storageHash.oldestTimestamp, @@ -140,7 +140,7 @@ window.chat.genPostData = function(channel, storageHash, getOlderMsgs) { if (min > -1) $.extend(data, {ascendingTimestampOrder: true}); } return data; -} +}; @@ -354,7 +354,7 @@ window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAsc } } } -} +}; window.chat.parseMsgData = function(data) { var categories = data[2].plext.categories; @@ -372,15 +372,15 @@ window.chat.parseMsgData = function(data) { var markup = data[2].plext.markup; var nick = ''; - $.each(markup, function(ind, markup) { - switch(markup[0]) { + markup.forEach(function(ent) { + switch (ent[0]) { case 'SENDER': // user generated messages - nick = markup[1].plain.slice(0, -2); // cut “: ” at end + nick = ent[1].plain.slice(0, -2); // cut “: ” at end break; case 'PLAYER': // automatically generated messages - nick = markup[1].plain; - team = markup[1].team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; + nick = ent[1].plain; + team = ent[1].team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; break; default: @@ -404,14 +404,14 @@ window.chat.parseMsgData = function(data) { }, markup: markup, }; -} +}; window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, isOlderMsgs, isAscendingOrder) { window.chat.updateOldNewHash(newData, storageHash, isOlderMsgs, isAscendingOrder); - $.each(newData.result, function(ind, json) { + newData.result.forEach(function(json) { // avoid duplicates - if(json[0] in storageHash.data) return true; + if (json[0] in storageHash.data) return true; var parsedData = chat.parseMsgData(json); @@ -422,7 +422,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is else storageHash.guids.unshift(parsedData.guid); }); -} +}; // // Rendering primitive for markup, chat cells (td) and chat row (tr) @@ -430,17 +430,17 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is window.chat.renderText = function (text) { return $('
').text(text.plain).html().autoLink(); -} +}; // Override portal names that are used over and over, such as 'US Post Office' window.chat.getChatPortalName = function(markup) { var name = markup.name; - if(name === 'US Post Office') { + if (name === 'US Post Office') { var address = markup.address.split(','); name = 'USPS: ' + address[0]; } return name; -} +}; window.chat.renderPortal = function (portal) { var lat = portal.latE6/1E6, lng = portal.lngE6/1E6; @@ -451,25 +451,25 @@ window.chat.renderPortal = function (portal) { + ' href="'+perma+'" class="help">' + window.chat.getChatPortalName(portal) + ''; -} +}; window.chat.renderFactionEnt = function (faction) { - var name = faction.team === "ENLIGHTENED" ? "Enlightened" : "Resistance"; - var spanClass = faction.team === "ENLIGHTENED" ? TEAM_ENL : TEAM_RES; + var name = faction.team === 'ENLIGHTENED' ? 'Enlightened' : 'Resistance'; + var spanClass = faction.team === 'ENLIGHTENED' ? TEAM_ENL : TEAM_RES; return $('
').html($('') - .attr('class', spanClass) - .text(name)).html(); -} + .attr('class', spanClass) + .text(name)).html(); +}; window.chat.renderPlayer = function (player, at, sender) { var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; var thisToPlayer = name === window.PLAYER.nickname; - var spanClass = thisToPlayer ? "pl_nudge_me" : (player.team + " pl_nudge_player"); + var spanClass = thisToPlayer ? 'pl_nudge_me' : (player.team + 'pl_nudge_player'); return $('
').html($('') - .attr('class', spanClass) - .attr('onclick',"window.chat.nicknameClicked(event, '"+name+"')") - .text((at ? '@' : '') + name)).html(); -} + .attr('class', spanClass) + .attr('onclick',"window.chat.nicknameClicked(event, '"+name+"')") + .text((at ? '@' : '') + name)).html(); +}; window.chat.renderMarkupEntity = function (ent) { switch (ent[0]) { @@ -485,34 +485,32 @@ window.chat.renderMarkupEntity = function (ent) { return chat.renderPlayer(ent[1]); case 'AT_PLAYER': return chat.renderPlayer(ent[1], true); - case 'TEXT': - return $('
').text(ent[1].plain).html().autoLink(); default: } return $('
').text(ent[0]+':<'+ent[1].plain+'>').html(); -} +}; window.chat.renderMarkup = function (markup) { var msg = ''; - $.each(markup, function(ind, markup) { - switch(markup[0]) { + markup.forEach(function(ent, ind) { + switch (ent[0]) { case 'SENDER': case 'SECURE': // skip as already handled break; case 'PLAYER': // automatically generated messages - if(ind > 0) msg += chat.renderMarkupEntity(markup); // don’t repeat nick directly + if (ind > 0) msg += chat.renderMarkupEntity(ent); // don’t repeat nick directly break; default: // add other enitities whatever the type - msg += chat.renderMarkupEntity(markup); + msg += chat.renderMarkupEntity(ent); break; } }); return msg; -} +}; window.chat.renderTimeCell = function(time, classNames) { var ta = unixTimeToHHmm(time); @@ -520,16 +518,16 @@ window.chat.renderTimeCell = function(time, classNames) { // add tags around the milliseconds tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); return ''; -} +}; window.chat.renderNickCell = function(nick, classNames) { var i = ['<', '>']; return ''+i[0]+''+ nick+''+i[1]+''; -} +}; window.chat.renderMsgCell = function(msg, classNames) { return ''+msg+''; -} +}; window.chat.renderMsgRow = function(data) { var timeClass = (data.msgToPlayer) ? 'pl_nudge_date' : ''; @@ -541,7 +539,7 @@ window.chat.renderMsgRow = function(data) { if (data.player.name === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); var nickCell = chat.renderNickCell(data.player.name, nickClasses.join(' ')); - var msg = chat.renderMarkup(data.markup) + var msg = chat.renderMarkup(data.markup); var msgClass = (data.narrowcast) ? 'system_narrowcast' : ''; var msgCell = chat.renderMsgCell(msg, msgClass); @@ -551,7 +549,7 @@ window.chat.renderMsgRow = function(data) { else if (!data.auto && data.secure) className = 'faction'; return '' + timeCell + nickCell + msgCell + ''; -} +}; // legacy rendering, not used internaly, but left there for backward compatibilty in case a plugin uses it directly window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { @@ -581,14 +579,14 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro window.chat.renderDivider = function(text) { var d = ' ──────────────────────────────────────────────────────────────────────────'; return '─ ' + text + d + ''; -} +}; // renders data from the data-hash to the element defined by the given // ID. Set 3rd argument to true if it is likely that old data has been // added. Latter is only required for scrolling. window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) { var elm = $('#'+element); - if(elm.is(':hidden')) return; + if (elm.is(':hidden')) return; // discard guids and sort old to new //TODO? stable sort, to preserve server message ordering? or sort by GUID if timestamps equal? @@ -596,7 +594,7 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) if (vals === undefined) { vals = $.map(data, function(v, k) { return [[v[0], k]]; }); vals = vals.sort(function(a, b) { return a[0]-b[0]; }); - vals = vals.map(function(v) { return v[1]}); + vals = vals.map(function(v) { return v[1]; }); } // render to string with date separators inserted @@ -605,7 +603,7 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) vals.forEach(function(guid) { var msg = data[guid]; var nextTime = new Date(msg[0]).toLocaleDateString(); - if(prevTime && prevTime !== nextTime) + if (prevTime && prevTime !== nextTime) msgs += chat.renderDivider(nextTime); msgs += msg[2]; prevTime = nextTime; @@ -619,7 +617,7 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) elm.data('needsScrollTop', 99999999); else chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); -} +}; window.chat.getActive = function() { From cbcbb4f78aaa4daee98dd9931fb15a3c24c2992d Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 12 Jan 2021 10:45:34 +0100 Subject: [PATCH 25/33] fix: @player not colorized --- core/code/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/code/chat.js b/core/code/chat.js index acd0b406c..f09cfc1af 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -464,7 +464,7 @@ window.chat.renderFactionEnt = function (faction) { window.chat.renderPlayer = function (player, at, sender) { var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; var thisToPlayer = name === window.PLAYER.nickname; - var spanClass = thisToPlayer ? 'pl_nudge_me' : (player.team + 'pl_nudge_player'); + var spanClass = thisToPlayer ? 'pl_nudge_me' : (player.team + ' pl_nudge_player'); return $('
').html($('') .attr('class', spanClass) .attr('onclick',"window.chat.nicknameClicked(event, '"+name+"')") From 859163dd49e8d705ff06b09d10bdf4ffecb9edc2 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Thu, 18 Feb 2021 23:37:01 +0100 Subject: [PATCH 26/33] reduce margin for [public]/[faction] --- core/style.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/style.css b/core/style.css index 6ceccde78..0bfb3ad78 100644 --- a/core/style.css +++ b/core/style.css @@ -347,7 +347,7 @@ em { content: '[faction]'; color: #f88; background-color: #500; - margin-right: .5rem; + margin-right: .2rem; } #chatall tr.public td:nth-child(3):before, @@ -355,7 +355,7 @@ em { content: '[public]'; color: #ff6; background-color: #550; - margin-right: .5rem; + margin-right: .2rem; } mark { From a04697628cf4248b02e3bd300c78cba89e4d3a7a Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 19 Feb 2021 00:17:49 +0100 Subject: [PATCH 27/33] fix: first render not scrolled to last msg --- core/code/chat.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index f09cfc1af..93487fad3 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -617,6 +617,12 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) elm.data('needsScrollTop', 99999999); else chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); + + if(elm.data('needsScrollTop')) { + elm.data('ignoreNextScroll', true); + elm.scrollTop(elm.data('needsScrollTop')); + elm.data('needsScrollTop', null); + } }; @@ -758,12 +764,6 @@ window.chat.chooseTab = function(tab) { default: throw new Error('chat.chooser was asked to handle unknown button: ' + tt); } - - if(elm.data('needsScrollTop')) { - elm.data('ignoreNextScroll', true); - elm.scrollTop(elm.data('needsScrollTop')); - elm.data('needsScrollTop', null); - } } window.chat.show = function(name) { From 21aebe0ed96ffe0bfb27ef204407bd148a5e844b Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 19 Feb 2021 14:26:51 +0100 Subject: [PATCH 28/33] enable alertsChatDataAvailable hook --- core/code/chat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 93487fad3..cba854829 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -291,8 +291,8 @@ window.chat.handleAlerts = function(data, olderMsgs, ascendingTimestampOrder) { chat.writeDataToHash(data, chat._alerts, undefined, olderMsgs, ascendingTimestampOrder); //NOTE: isPublic passed as undefined - it's nether public or private! var oldMsgsWereAdded = old !== chat._alerts.oldestTimestamp; -// no hoot for alerts - API change planned here... -// runHooks('alertsChatDataAvailable', {raw: data, result: data.result, processed: chat._alerts.data}); + // hook for alerts - API change planned here for next refactor + runHooks('alertsChatDataAvailable', {raw: data, result: data.result, processed: chat._alerts.data}); window.chat.renderAlerts(oldMsgsWereAdded); } From 36b3496649691cd4462d62c4b0691da7e7dd43e8 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Mon, 8 Mar 2021 22:49:06 +0100 Subject: [PATCH 29/33] unify divider using 3 columns --- core/code/chat.js | 3 +-- core/style.css | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index cba854829..f0307aaa2 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -577,8 +577,7 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro } window.chat.renderDivider = function(text) { - var d = ' ──────────────────────────────────────────────────────────────────────────'; - return '─ ' + text + d + ''; + return '
' + text + '
'; }; // renders data from the data-hash to the element defined by the given diff --git a/core/style.css b/core/style.css index 0bfb3ad78..b7d923ddc 100644 --- a/core/style.css +++ b/core/style.css @@ -317,6 +317,14 @@ em { padding-bottom: 3px; } +#chat .divider { + color: #bbb; +} + +#chat .divider td:nth-child(2) { + text-align: center; +} + /* time */ #chat td:first-child, #chatinput td:first-child { width: 44px; From 7ced0ec12aa738885380ba0a9c9de321aeed1031 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 1 Dec 2021 21:20:25 +0100 Subject: [PATCH 30/33] fixup! enable alertsChatDataAvailable hook --- core/code/hooks.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/code/hooks.js b/core/code/hooks.js index 047876544..85f68d91b 100644 --- a/core/code/hooks.js +++ b/core/code/hooks.js @@ -45,6 +45,13 @@ // displayed. The data hash contains both the unprocessed // raw ajax response as well as the processed chat data // that is going to be used for display. +// alertsChatDataAvailable: this hook runs after data for the alerts +// chat has been received and processed, but not yet been +// displayed. The data hash contains both the unprocessed +// raw ajax response as well as the processed chat data +// that is going to be used for display. +// WARNING: this hook was disabled in earlier versions +// sideeffects possible but unknown. Use with care! // requestFinished: DEPRECATED: best to use mapDataRefreshEnd instead // called after each map data request finished. Argument is // {success: boolean} indicated the request success or fail. From cd1545d60d5c6b550819417bbdeff69101d46b46 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 1 Dec 2021 22:06:45 +0100 Subject: [PATCH 31/33] apply suggestion --- core/code/chat.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index f0307aaa2..346f91ddb 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -417,10 +417,11 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // format: timestamp, autogenerated, HTML message, nick, additional data (parsed, plugin specific data...) storageHash.data[parsedData.guid] = [parsedData.time, parsedData.auto, chat.renderMsgRow(parsedData), parsedData.player.name, parsedData]; - if (isAscendingOrder) + if (isAscendingOrder) { storageHash.guids.push(parsedData.guid); - else + } else { storageHash.guids.unshift(parsedData.guid); + } }); }; @@ -429,7 +430,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // window.chat.renderText = function (text) { - return $('
').text(text.plain).html().autoLink(); + return $('
').text(text.plain).html().autoLink(); }; // Override portal names that are used over and over, such as 'US Post Office' @@ -456,7 +457,7 @@ window.chat.renderPortal = function (portal) { window.chat.renderFactionEnt = function (faction) { var name = faction.team === 'ENLIGHTENED' ? 'Enlightened' : 'Resistance'; var spanClass = faction.team === 'ENLIGHTENED' ? TEAM_ENL : TEAM_RES; - return $('
').html($('') + return $('
').html($('') .attr('class', spanClass) .text(name)).html(); }; @@ -465,7 +466,7 @@ window.chat.renderPlayer = function (player, at, sender) { var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; var thisToPlayer = name === window.PLAYER.nickname; var spanClass = thisToPlayer ? 'pl_nudge_me' : (player.team + ' pl_nudge_player'); - return $('
').html($('') + return $('
').html($('') .attr('class', spanClass) .attr('onclick',"window.chat.nicknameClicked(event, '"+name+"')") .text((at ? '@' : '') + name)).html(); @@ -487,7 +488,7 @@ window.chat.renderMarkupEntity = function (ent) { return chat.renderPlayer(ent[1], true); default: } - return $('
').text(ent[0]+':<'+ent[1].plain+'>').html(); + return $('
').text(ent[0]+':<'+ent[1].plain+'>').html(); }; window.chat.renderMarkup = function (markup) { @@ -534,20 +535,26 @@ window.chat.renderMsgRow = function(data) { var timeCell = chat.renderTimeCell(data.time, timeClass); var nickClasses = ['nickname']; - if (data.player.team === TEAM_ENL || data.player.team === TEAM_RES) nickClasses.push(TEAM_TO_CSS[data.player.team]); - // highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) - if (data.player.name === window.PLAYER.nickname) nickClasses.push('pl_nudge_me'); + if (data.player.team === TEAM_ENL || data.player.team === TEAM_RES) { + nickClasses.push(TEAM_TO_CSS[data.player.team]); + } + // highlight things said/done by the player in a unique colour + // (similar to @player mentions from others in the chat text itself) + if (data.player.name === window.PLAYER.nickname) { + nickClasses.push('pl_nudge_me'); + } var nickCell = chat.renderNickCell(data.player.name, nickClasses.join(' ')); var msg = chat.renderMarkup(data.markup); - var msgClass = (data.narrowcast) ? 'system_narrowcast' : ''; + var msgClass = data.narrowcast ? 'system_narrowcast' : ''; var msgCell = chat.renderMsgCell(msg, msgClass); var className = ''; - if (!data.auto && data.public) + if (!data.auto && data.public) { className = 'public'; - else if (!data.auto && data.secure) + } else if (!data.auto && data.secure) { className = 'faction'; + } return '' + timeCell + nickCell + msgCell + ''; }; @@ -612,10 +619,11 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) var scrollBefore = scrollBottom(elm); elm.html('' + msgs + '
'); - if (firstRender) + if (firstRender) { elm.data('needsScrollTop', 99999999); - else + } else { chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); + } if(elm.data('needsScrollTop')) { elm.data('ignoreNextScroll', true); @@ -705,10 +713,11 @@ window.chat.needMoreMessages = function() { var nearTop = activeChat.scrollTop() <= CHAT_REQUEST_SCROLL_TOP; if(hasScrollbar && !nearTop) return; - if(activeTab === 'faction') + if(activeTab === 'faction') { chat.requestFaction(true); - else + } else chat.requestPublic(true); + } }; From 95b0c263a5776a47c0b870267e280a42ef3710ba Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 8 Dec 2021 20:23:43 +0100 Subject: [PATCH 32/33] fixup! apply suggestion --- core/code/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/code/chat.js b/core/code/chat.js index 346f91ddb..4e5b587a7 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -715,7 +715,7 @@ window.chat.needMoreMessages = function() { if(activeTab === 'faction') { chat.requestFaction(true); - } else + } else { chat.requestPublic(true); } }; From 175fdd765523da23bea3a524f0979d4a24d22f46 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Thu, 5 May 2022 22:45:45 +0200 Subject: [PATCH 33/33] apply some coding style --- core/code/chat.js | 46 +++++++++++++++++++++++++++++++--------------- core/code/hooks.js | 5 ++--- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 4e5b587a7..c0d690cf5 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -375,7 +375,7 @@ window.chat.parseMsgData = function(data) { markup.forEach(function(ent) { switch (ent[0]) { case 'SENDER': // user generated messages - nick = ent[1].plain.slice(0, -2); // cut “: ” at end + nick = ent[1].plain.replace(/: $/, ''); // cut “: ” at end break; case 'PLAYER': // automatically generated messages @@ -411,7 +411,9 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is newData.result.forEach(function(json) { // avoid duplicates - if (json[0] in storageHash.data) return true; + if (json[0] in storageHash.data) { + return true; + } var parsedData = chat.parseMsgData(json); @@ -456,14 +458,19 @@ window.chat.renderPortal = function (portal) { window.chat.renderFactionEnt = function (faction) { var name = faction.team === 'ENLIGHTENED' ? 'Enlightened' : 'Resistance'; - var spanClass = faction.team === 'ENLIGHTENED' ? TEAM_ENL : TEAM_RES; + var spanClass = faction.team === 'ENLIGHTENED' ? TEAM_TO_CSS[TEAM_ENL] : TEAM_TO_CSS[TEAM_RES]; return $('
').html($('') .attr('class', spanClass) .text(name)).html(); }; window.chat.renderPlayer = function (player, at, sender) { - var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; + var name = player.plain; + if (sender) { + name = player.plain.replace(/: $/, ''); + } else if (at) { + name = player.plain.replace(/^@/, ''); + } var thisToPlayer = name === window.PLAYER.nickname; var spanClass = thisToPlayer ? 'pl_nudge_me' : (player.team + ' pl_nudge_player'); return $('
').html($('') @@ -517,7 +524,10 @@ window.chat.renderTimeCell = function(time, classNames) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); // add tags around the milliseconds - tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); + tb = (tb.slice(0,19)+''+tb.slice(19)+'') + .replace(//g,'>') + .replace(/"/g,'"'); return ''; }; @@ -563,21 +573,24 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); // add tags around the milliseconds - tb = (tb.slice(0,19)+''+tb.slice(19)+'').replace(//g,'>').replace(/"/g,'"'); + tb = (tb.slice(0,19)+''+tb.slice(19)+'') + .replace(//g,'>') + .replace(/"/g,'"'); // help cursor via “#chat time” var t = ''; - if ( msgToPlayer ) - { + if (msgToPlayer) { t = '
' + t + '
'; } - if (systemNarrowcast) - { + if (systemNarrowcast) { msg = '
' + msg + '
'; } var color = COLORS[team]; // highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) - if (nick === window.PLAYER.nickname) color = '#fd6'; + if (nick === window.PLAYER.nickname) { + color = '#fd6'; + } var s = 'style="cursor:pointer; color:'+color+'"'; var i = ['<', '>']; return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+''; @@ -592,10 +605,12 @@ window.chat.renderDivider = function(text) { // added. Latter is only required for scrolling. window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) { var elm = $('#'+element); - if (elm.is(':hidden')) return; + if (elm.is(':hidden')) { + return; + } - // discard guids and sort old to new -//TODO? stable sort, to preserve server message ordering? or sort by GUID if timestamps equal? + // if sortedGuids is not specified (legacy), sort old to new + // (disregarding server order) var vals = sortedGuids; if (vals === undefined) { vals = $.map(data, function(v, k) { return [[v[0], k]]; }); @@ -609,8 +624,9 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs, sortedGuids) vals.forEach(function(guid) { var msg = data[guid]; var nextTime = new Date(msg[0]).toLocaleDateString(); - if (prevTime && prevTime !== nextTime) + if (prevTime && prevTime !== nextTime) { msgs += chat.renderDivider(nextTime); + } msgs += msg[2]; prevTime = nextTime; }); diff --git a/core/code/hooks.js b/core/code/hooks.js index 85f68d91b..8625c4355 100644 --- a/core/code/hooks.js +++ b/core/code/hooks.js @@ -18,7 +18,8 @@ // portalSelected: called when portal on map is selected/unselected. // Provide guid of selected and unselected portal. // mapDataRefreshStart: called when we start refreshing map data -// mapDataEntityInject: called just as we start to render data. has callback to inject cached entities into the map render +// mapDataEntityInject: called just as we start to render data. has callback to +// Sinject cached entities into the map render // mapDataRefreshEnd: called when we complete the map data load // portalAdded: called when a portal has been received and is about to // be added to its layer group. Note that this does NOT @@ -50,8 +51,6 @@ // displayed. The data hash contains both the unprocessed // raw ajax response as well as the processed chat data // that is going to be used for display. -// WARNING: this hook was disabled in earlier versions -// sideeffects possible but unknown. Use with care! // requestFinished: DEPRECATED: best to use mapDataRefreshEnd instead // called after each map data request finished. Argument is // {success: boolean} indicated the request success or fail.