chat - oldest/newest timestamp handling rewrite

this fixes an issue that, in theory, could have occured with the public chat fetching and over 200 sequential skipped ([secure]) messages. the recent change to skip SYSTEM_NARROWCAST for faction chat was much more likely to trigger the same issue
also
- lighten the red colour used in public chat - was almost impossible to read before
- set the faction chat message count to 100 (it was 50, then bumpped to 200 briefly to work around chat issues)
This commit is contained in:
Jon Atkins 2013-04-05 00:07:54 +01:00
parent e5e4a00589
commit 3a37667a7c
2 changed files with 36 additions and 41 deletions

View File

@ -33,26 +33,12 @@ window.chat.handleTabCompletion = function() {
} }
// //
// timestamp and clear management // clear management
// //
window.chat.getTimestamps = function(isFaction) {
var storage = isFaction ? chat._factionData : chat._publicData;
return $.map(storage, function(v, k) { return [v[0]]; });
}
window.chat.getOldestTimestamp = function(isFaction) {
var t = Math.min.apply(null, chat.getTimestamps(isFaction));
return t === Infinity ? -1 : t;
}
window.chat.getNewestTimestamp = function(isFaction) {
var t = Math.max.apply(null, chat.getTimestamps(isFaction));
return t === -1*Infinity ? -1 : t;
}
window.chat._oldBBox = null; window.chat._oldBBox = null;
window.chat.genPostData = function(isFaction, getOlderMsgs) { window.chat.genPostData = function(isFaction, storageHash, getOlderMsgs) {
if(typeof isFaction !== 'boolean') throw('Need to know if public or faction chat.'); if(typeof isFaction !== 'boolean') throw('Need to know if public or faction chat.');
chat._localRangeCircle.setLatLng(map.getCenter()); chat._localRangeCircle.setLatLng(map.getCenter());
@ -68,8 +54,13 @@ window.chat.genPostData = function(isFaction, getOlderMsgs) {
// need to reset these flags now because clearing will only occur // need to reset these flags now because clearing will only occur
// after the request is finished i.e. there would be one almost // after the request is finished i.e. there would be one almost
// useless request. // useless request.
chat._factionData = {}; chat._faction.data = {};
chat._publicData = {}; chat._faction.oldestTimestamp = -1;
chat._faction.newestTimestamp = -1;
chat._public.data = {};
chat._public.oldestTimestamp = -1;
chat._public.newestTimestamp = -1;
} }
chat._oldBBox = bbs; chat._oldBBox = bbs;
@ -88,10 +79,10 @@ window.chat.genPostData = function(isFaction, getOlderMsgs) {
if(getOlderMsgs) { if(getOlderMsgs) {
// ask for older chat when scrolling up // ask for older chat when scrolling up
data = $.extend(data, {maxTimestampMs: chat.getOldestTimestamp(isFaction)}); data = $.extend(data, {maxTimestampMs: storageHash.oldestTimestamp});
} else { } else {
// ask for newer chat // ask for newer chat
var min = chat.getNewestTimestamp(isFaction); var min = storageHash.newestTimestamp;
// the inital request will have both timestamp values set to -1, // the inital request will have both timestamp values set to -1,
// thus we receive the newest desiredNumItems. After that, we will // thus we receive the newest desiredNumItems. After that, we will
// only receive messages with a timestamp greater or equal to min // only receive messages with a timestamp greater or equal to min
@ -124,7 +115,7 @@ window.chat.requestFaction = function(getOlderMsgs, isRetry) {
if(isIdle()) return renderUpdateStatus(); if(isIdle()) return renderUpdateStatus();
chat._requestFactionRunning = true; chat._requestFactionRunning = true;
var d = chat.genPostData(true, getOlderMsgs); var d = chat.genPostData(true, chat._faction, getOlderMsgs);
var r = window.postAjax( var r = window.postAjax(
'getPaginatedPlextsV2', 'getPaginatedPlextsV2',
d, d,
@ -138,7 +129,7 @@ window.chat.requestFaction = function(getOlderMsgs, isRetry) {
} }
window.chat._factionData = {}; window.chat._faction = {data:{}, oldestTimestamp:-1, newestTimestamp:-1};
window.chat.handleFaction = function(data, textStatus, jqXHR) { window.chat.handleFaction = function(data, textStatus, jqXHR) {
chat._requestFactionRunning = false; chat._requestFactionRunning = false;
@ -149,11 +140,11 @@ window.chat.handleFaction = function(data, textStatus, jqXHR) {
if(data.result.length === 0) return; if(data.result.length === 0) return;
var old = chat.getOldestTimestamp(true); var old = chat._faction.oldestTimestamp;
chat.writeDataToHash(data, chat._factionData, false); chat.writeDataToHash(data, chat._faction, false);
var oldMsgsWereAdded = old !== chat.getOldestTimestamp(true); var oldMsgsWereAdded = old !== chat._faction.oldestTimestamp;
runHooks('factionChatDataAvailable', {raw: data, processed: chat._factionData}); runHooks('factionChatDataAvailable', {raw: data, processed: chat._faction.data});
window.chat.renderFaction(oldMsgsWereAdded); window.chat.renderFaction(oldMsgsWereAdded);
@ -161,7 +152,7 @@ window.chat.handleFaction = function(data, textStatus, jqXHR) {
} }
window.chat.renderFaction = function(oldMsgsWereAdded) { window.chat.renderFaction = function(oldMsgsWereAdded) {
chat.renderData(chat._factionData, 'chatfaction', oldMsgsWereAdded); chat.renderData(chat._faction.data, 'chatfaction', oldMsgsWereAdded);
} }
@ -175,7 +166,7 @@ window.chat.requestPublic = function(getOlderMsgs, isRetry) {
if(isIdle()) return renderUpdateStatus(); if(isIdle()) return renderUpdateStatus();
chat._requestPublicRunning = true; chat._requestPublicRunning = true;
var d = chat.genPostData(false, getOlderMsgs); var d = chat.genPostData(false, chat._public, getOlderMsgs);
var r = window.postAjax( var r = window.postAjax(
'getPaginatedPlextsV2', 'getPaginatedPlextsV2',
d, d,
@ -188,7 +179,7 @@ window.chat.requestPublic = function(getOlderMsgs, isRetry) {
requests.add(r); requests.add(r);
} }
window.chat._publicData = {}; window.chat._public = {data:{}, oldestTimestamp:-1, newestTimestamp:-1};
window.chat.handlePublic = function(data, textStatus, jqXHR) { window.chat.handlePublic = function(data, textStatus, jqXHR) {
chat._requestPublicRunning = false; chat._requestPublicRunning = false;
@ -199,11 +190,11 @@ window.chat.handlePublic = function(data, textStatus, jqXHR) {
if(data.result.length === 0) return; if(data.result.length === 0) return;
var old = chat.getOldestTimestamp(false); var old = chat._public.oldestTimestamp;
chat.writeDataToHash(data, chat._publicData, true); chat.writeDataToHash(data, chat._public, true);
var oldMsgsWereAdded = old !== chat.getOldestTimestamp(false); var oldMsgsWereAdded = old !== chat._public.oldestTimestamp;
runHooks('publicChatDataAvailable', {raw: data, processed: chat._publicData}); runHooks('publicChatDataAvailable', {raw: data, processed: chat._public.data});
switch(chat.getActive()) { switch(chat.getActive()) {
case 'public': window.chat.renderPublic(oldMsgsWereAdded); break; case 'public': window.chat.renderPublic(oldMsgsWereAdded); break;
@ -216,7 +207,7 @@ window.chat.handlePublic = function(data, textStatus, jqXHR) {
window.chat.renderPublic = function(oldMsgsWereAdded) { window.chat.renderPublic = function(oldMsgsWereAdded) {
// only keep player data // only keep player data
var data = $.map(chat._publicData, function(entry) { var data = $.map(chat._public.data, function(entry) {
if(!entry[1]) return [entry]; if(!entry[1]) return [entry];
}); });
chat.renderData(data, 'chatpublic', oldMsgsWereAdded); chat.renderData(data, 'chatpublic', oldMsgsWereAdded);
@ -224,7 +215,7 @@ window.chat.renderPublic = function(oldMsgsWereAdded) {
window.chat.renderCompact = function(oldMsgsWereAdded) { window.chat.renderCompact = function(oldMsgsWereAdded) {
var data = {}; var data = {};
$.each(chat._publicData, function(guid, entry) { $.each(chat._public.data, function(guid, entry) {
// skip player msgs // skip player msgs
if(!entry[1]) return true; if(!entry[1]) return true;
var pguid = entry[3]; var pguid = entry[3];
@ -239,7 +230,7 @@ window.chat.renderCompact = function(oldMsgsWereAdded) {
window.chat.renderFull = function(oldMsgsWereAdded) { window.chat.renderFull = function(oldMsgsWereAdded) {
// only keep automatically generated data // only keep automatically generated data
var data = $.map(chat._publicData, function(entry) { var data = $.map(chat._public.data, function(entry) {
if(entry[1]) return [entry]; if(entry[1]) return [entry];
}); });
chat.renderData(data, 'chatfull', oldMsgsWereAdded); chat.renderData(data, 'chatfull', oldMsgsWereAdded);
@ -253,7 +244,7 @@ window.chat.renderFull = function(oldMsgsWereAdded) {
window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) { window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) {
$.each(newData.result, function(ind, json) { $.each(newData.result, function(ind, json) {
// avoid duplicates // avoid duplicates
if(json[0] in storageHash) return true; if(json[0] in storageHash.data) return true;
var skipThisEntry = false; var skipThisEntry = false;
var msgToPlayer = false; var msgToPlayer = false;
@ -263,6 +254,10 @@ window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) {
var auto = json[2].plext.plextType !== 'PLAYER_GENERATED'; var auto = json[2].plext.plextType !== 'PLAYER_GENERATED';
var systemNarrowcast = json[2].plext.plextType === 'SYSTEM_NARROWCAST'; var systemNarrowcast = json[2].plext.plextType === 'SYSTEM_NARROWCAST';
//track oldest + newest timestamps
if (storageHash.oldestTimestamp === -1 || storageHash.oldestTimestamp > time) storageHash.oldestTimestamp = time;
if (storageHash.newestTimestamp === -1 || storageHash.newestTimestamp < time) storageHash.newestTimestamp = time;
//remove "Your X on Y was destroyed by Z" from the faction channel //remove "Your X on Y was destroyed by Z" from the faction channel
if (systemNarrowcast && !skipSecureMsgs) { if (systemNarrowcast && !skipSecureMsgs) {
//NOTE: skipSecureMsgs is being used as a "is public channel" flag here //NOTE: skipSecureMsgs is being used as a "is public channel" flag here
@ -320,7 +315,7 @@ window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) {
if(skipThisEntry) return true; if(skipThisEntry) return true;
// format: timestamp, autogenerated, HTML message, player guid // format: timestamp, autogenerated, HTML message, player guid
storageHash[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer), pguid]; storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer), pguid];
window.setPlayerName(pguid, nick); // free nick name resolves window.setPlayerName(pguid, nick); // free nick name resolves
}); });
@ -468,8 +463,8 @@ window.chat.chooser = function(event) {
break; break;
case 'public': case 'public':
input.css('cssText', 'color: red !important'); input.css('cssText', 'color: #f66 !important');
mark.css('cssText', 'color: red !important'); mark.css('cssText', 'color: #f66 !important');
mark.text('broadcast:'); mark.text('broadcast:');
break; break;

View File

@ -129,7 +129,7 @@ window.VIEWPORT_PAD_RATIO = 0.3;
// how many items to request each query // how many items to request each query
window.CHAT_PUBLIC_ITEMS = 200; window.CHAT_PUBLIC_ITEMS = 200;
window.CHAT_FACTION_ITEMS = 200; window.CHAT_FACTION_ITEMS = 100;
// how many pixels to the top before requesting new data // how many pixels to the top before requesting new data
window.CHAT_REQUEST_SCROLL_TOP = 200; window.CHAT_REQUEST_SCROLL_TOP = 200;
window.CHAT_SHRINKED = 60; window.CHAT_SHRINKED = 60;