diff --git a/code/chat.js b/code/chat.js index 67c23ed8..f6716a0d 100644 --- a/code/chat.js +++ b/code/chat.js @@ -241,12 +241,12 @@ window.chat.renderFull = function(oldMsgsWereAdded) { // common // -window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) { +window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel) { $.each(newData.result, function(ind, json) { // avoid duplicates if(json[0] in storageHash.data) return true; - var skipThisEntry = false; + var isSecureMessage = false; var msgToPlayer = false; var time = json[1]; @@ -259,10 +259,7 @@ window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) { if (storageHash.newestTimestamp === -1 || storageHash.newestTimestamp < time) storageHash.newestTimestamp = time; //remove "Your X on Y was destroyed by Z" from the faction channel - if (systemNarrowcast && !skipSecureMsgs) { - //NOTE: skipSecureMsgs is being used as a "is public channel" flag here - return true; - } + if (systemNarrowcast && !isPublicChannel) return true; var msg = '', nick = '', pguid; $.each(json[2].plext.markup, function(ind, markup) { @@ -306,13 +303,34 @@ window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) { break; case 'SECURE': - if(skipSecureMsgs) { - skipThisEntry = true; - return false; // breaks $.each - } + //NOTE: we won't add the '[secure]' string here - it'll be handled below instead + isSecureMessage = true; + break; + + default: + //handle unknown types by outputting the plain text version, marked with it's type + msg += $('
').text(markup[0]+':<'+markup[1].plain+'>').html(); + break; } }); - if(skipThisEntry) return true; + + + //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 currently redundant with the above two tests - but code can change... + //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 (isPublicChannel && isSecureMessage) msg = '[secure] ' + msg; + //and, add the reverse - a 'public' marker to messages in the private channel + if ((!isPublicChannel) && (!isSecureMessage)) msg = '[public] ' + msg; + // format: timestamp, autogenerated, HTML message, player guid storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast), pguid]; @@ -378,7 +396,9 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro { msg = '
' + msg + '
'; } - var s = 'style="cursor:pointer; color:'+COLORS[team]+'"'; + 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 title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : ''; var i = ['<', '>']; return ''+t+''+i[0]+''+ nick+''+i[1]+''+msg+'';