Browse Source

cache your own mentions locally. much better user experience imho (the old thing was annoying me!). please test.

master
Miguel Freitas 11 years ago
parent
commit
ecc498967e
  1. 2
      interface_common.js
  2. 4
      tmobile.js
  3. 32
      twister_newmsgs.js

2
interface_common.js

@ -196,6 +196,8 @@ function openMentionsModal(e)
//título do modal //título do modal
$( "."+hashtagModalClass + " h3" ).text( "Mentions of @" + username ); $( "."+hashtagModalClass + " h3" ).text( "Mentions of @" + username );
// obtain already cached mention posts from twister_newmsgs.js
processHashtag(hashtagModalContent.find(".postboard-posts"), defaultScreenName, getMentionsData() );
resetMentionsCount(); resetMentionsCount();
} }

4
tmobile.js

@ -530,6 +530,10 @@ function setupHashtagOrMention( ulElem, tag, res) {
$.MAL.setPostTemplate( $("#post-template-home") ); $.MAL.setPostTemplate( $("#post-template-home") );
$.mobile.showPageLoadingMsg(); $.mobile.showPageLoadingMsg();
clearHashtagProcessed(); 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); requestHashtag(hashtag_elem,hashtag_tag,hashtag_res);
} }

32
twister_newmsgs.js

@ -9,23 +9,24 @@
var _knownMentions = {} var _knownMentions = {}
var _lastMentionTime = 0; var _lastMentionTime = 0;
var _newMentions = 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 // 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 key = user + ";" + mentionTime;
var curTime = new Date().getTime() / 1000; var curTime = new Date().getTime() / 1000;
if( mentionTime > curTime + 3600 ) { if( mentionTime > curTime + 3600 ) {
console.log("mention from the future will be ignored"); console.log("mention from the future will be ignored");
} else { } else {
// mention must be somewhat newer compared to last known one to be considered if( !(key in _knownMentions) ) {
if( mentionTime + 3600 > _lastMentionTime ) { // mention must be somewhat recent compared to last known one to be considered new
if( !(key in _knownMentions) ) { if( mentionTime + 3600 > _lastMentionTime ) {
_knownMentions[key] = mentionTime;
_lastMentionTime = mentionTime;
_newMentions++; _newMentions++;
purgeOldMentions(); _lastMentionTime = mentionTime;
saveMentionsToStorage();
} }
_knownMentions[key] = {mentionTime:mentionTime, data:data};
purgeOldMentions();
saveMentionsToStorage();
} }
} }
} }
@ -33,7 +34,8 @@ function processMention(user, mentionTime) {
function purgeOldMentions() { function purgeOldMentions() {
for( var key in _knownMentions ) { for( var key in _knownMentions ) {
if( _knownMentions.hasOwnProperty(key) ) { 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]; delete _knownMentions[key];
} }
} }
@ -63,7 +65,7 @@ function requestMentionsCount() {
if( data ) { if( data ) {
for( var i = 0; i < data.length; i++ ) { for( var i = 0; i < data.length; i++ ) {
var userpost = data[i]["userpost"]; var userpost = data[i]["userpost"];
processMention( userpost["n"], userpost["time"]); processMention( userpost["n"], userpost["time"], data[i]);
} }
$.MAL.updateNewMentionsUI(_newMentions); $.MAL.updateNewMentionsUI(_newMentions);
} }
@ -84,6 +86,16 @@ function initMentionsCount() {
setInterval("requestMentionsCount()", 10000); 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 --- // --- direct messages ---
var _lastDMIdPerUser = {}; var _lastDMIdPerUser = {};

Loading…
Cancel
Save