diff --git a/interface_common.js b/interface_common.js index 2329862..a26914b 100644 --- a/interface_common.js +++ b/interface_common.js @@ -181,6 +181,8 @@ function openMentionsModal(e) //título do modal $( "."+hashtagModalClass + " h3" ).text( polyglot.t("users_mentions", { username: username }) ); + // obtain already cached mention posts from twister_newmsgs.js + processHashtag(hashtagModalContent.find(".postboard-posts"), defaultScreenName, getMentionsData() ); resetMentionsCount(); } @@ -458,4 +460,4 @@ function initInterfaceCommon() { $( ".open-hashtag-modal").bind( "click", openHashtagModal ); $( ".open-following-modal").bind( "click", openFollowingModal ); $( ".userMenu-connections a").bind( "click", openMentionsModal ); -} \ No newline at end of file +} diff --git a/tmobile.js b/tmobile.js index 2f41670..21765bb 100644 --- a/tmobile.js +++ b/tmobile.js @@ -530,6 +530,10 @@ function setupHashtagOrMention( ulElem, tag, res) { $.MAL.setPostTemplate( $("#post-template-home") ); $.mobile.showPageLoadingMsg(); clearHashtagProcessed(); + if( tag == defaultScreenName && res == "mention" ) { + // obtain already cached mention posts from twister_newmsgs.js + processHashtag(hashtag_elem, defaultScreenName, getMentionsData() ); + } requestHashtag(hashtag_elem,hashtag_tag,hashtag_res); } diff --git a/twister_newmsgs.js b/twister_newmsgs.js index 90b597b..c5287e8 100644 --- a/twister_newmsgs.js +++ b/twister_newmsgs.js @@ -9,23 +9,24 @@ var _knownMentions = {} var _lastMentionTime = 0; var _newMentions = 0; +var PURGE_OLD_MENTIONS_TIMEOUT = 3600 * 24 * 30; // one month // process a mention received to check if it is really new -function processMention(user, mentionTime) { +function processMention(user, mentionTime, data) { var key = user + ";" + mentionTime; var curTime = new Date().getTime() / 1000; if( mentionTime > curTime + 3600 ) { console.log("mention from the future will be ignored"); } else { - // mention must be somewhat newer compared to last known one to be considered - if( mentionTime + 3600 > _lastMentionTime ) { - if( !(key in _knownMentions) ) { - _knownMentions[key] = mentionTime; - _lastMentionTime = mentionTime; + if( !(key in _knownMentions) ) { + // mention must be somewhat recent compared to last known one to be considered new + if( mentionTime + 3600 > _lastMentionTime ) { _newMentions++; - purgeOldMentions(); - saveMentionsToStorage(); + _lastMentionTime = mentionTime; } + _knownMentions[key] = {mentionTime:mentionTime, data:data}; + purgeOldMentions(); + saveMentionsToStorage(); } } } @@ -33,7 +34,8 @@ function processMention(user, mentionTime) { function purgeOldMentions() { for( var key in _knownMentions ) { if( _knownMentions.hasOwnProperty(key) ) { - if( _knownMentions[key] + 3600 < _lastMentionTime ) { + if( !_knownMentions[key].mentionTime || !_knownMentions[key].data || + _knownMentions[key].mentionTime + PURGE_OLD_MENTIONS_TIMEOUT < _lastMentionTime ) { delete _knownMentions[key]; } } @@ -63,7 +65,7 @@ function requestMentionsCount() { if( data ) { for( var i = 0; i < data.length; i++ ) { var userpost = data[i]["userpost"]; - processMention( userpost["n"], userpost["time"]); + processMention( userpost["n"], userpost["time"], data[i]); } $.MAL.updateNewMentionsUI(_newMentions); } @@ -84,6 +86,16 @@ function initMentionsCount() { setInterval("requestMentionsCount()", 10000); } +function getMentionsData() { + mentions = [] + for( var key in _knownMentions ) { + if( _knownMentions.hasOwnProperty(key) && _knownMentions[key].data ) { + mentions.push(_knownMentions[key].data); + } + } + return mentions; +} + // --- direct messages --- var _lastDMIdPerUser = {};