/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  December 17th 2009 3:48:07 PM PST                            */
/*      Machine:  10.16.139.103                                                */
/*       Source:  Global Cache                                                 */
/*     Location:  js/stream/UIIntentionalStreamRefresh.js h:5vjds43u           */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/stream/UIIntentionalStreamRefresh.js                      */

if (window.CavalryLogger) { CavalryLogger.start_js(["js\/stream\/UIIntentionalStreamRefresh.js"]); }

function UIIntentionalStreamRefresh(a,b){copy_properties(this,{isAutoRefreshing:false,lastRefresh:new Date().getTime()});UIIntentionalStreamRefresh.instance=this;this.setAutoRefreshConfig(a);this.updateConfigHandler=Arbiter.subscribe(UIIntentionalStreamMessage.UPDATE_AUTOREFRESH_CONFIG,this.updateAutoRefreshConfig.bind(this));onunloadRegister(this.unload.bind(this));this.userActivity();this.uaToken=UserActivity.subscribe(this.userActivity.bind(this));this.autoRefreshInterval=setInterval(this.checkAutoPageRefresh.bind(this),this.checkAutoRefreshTimeInterval);this.enableAutoRefresh(b);if(this.usePresence)UIIntentionalStreamRefresh.presenceRegister();}copy_properties(UIIntentionalStreamRefresh,{_presenceInit:false,DISABLE_AUTOREFRESH_TIME:4*60*1000,CHECK_AUTOREFRESH_INTERVAL:5*60*1000,AUTOREFRESH_INACTIVE_TIME:30*60*1000,HIGHLIGHTS_OVERRIDE_TIME:360*60*1000});UIIntentionalStreamRefresh.presenceRegister=function(){if(UIIntentionalStreamRefresh._presenceInit)return true;Arbiter.subscribe(PresenceMessage.getArbiterMessageType('feedpub'),UIIntentionalStreamRefresh.handleNewStoryMessage);UIIntentionalStreamRefresh._presenceInit=true;};UIIntentionalStreamRefresh.prototype.updateAutoRefreshConfig=function(b,a){if(b!=UIIntentionalStreamMessage.UPDATE_AUTOREFRESH_CONFIG)return;this.setAutoRefreshConfig(a);};UIIntentionalStreamRefresh.prototype.setAutoRefreshConfig=function(a){a=a||{};var b=24*60*60*1000;if(!this.storyInterval)this.storyInterval=coalesce(a.story_interval,null);this.allowAutoRefresh=coalesce(a.allow_auto_refresh,false);this.inactiveThreshold=coalesce(a.inactive_threshold,0);this.activeRefreshTime=coalesce(a.fast_refresh_rate,b);this.inactiveRefreshTime=coalesce(a.slow_refresh_rate,b);this.allowPolling=coalesce(a.allow_polling,false);this.refreshFactor=coalesce(a.refresh_factor,10);this.minRefreshInterval=coalesce(a.min_refresh_interval,60*1000);this.usePresence=coalesce(a.use_presence,false);this.disableAutoRefreshTime=coalesce(a.disable_autorefresh_time,UIIntentionalStreamRefresh.DISABLE_AUTOREFRESH_TIME);this.checkAutoRefreshTimeInterval=coalesce(a.check_autorefresh_time_interval,UIIntentionalStreamRefresh.CHECK_AUTOREFRESH_INTERVAL);this.autoRefreshInactiveTime=coalesce(a.autorefresh_inactive_time,UIIntentionalStreamRefresh.AUTOREFRESH_INACTIVE_TIME);this.highlightsOverrideTime=coalesce(a.highlights_override_time,UIIntentionalStreamRefresh.HIGHLIGHTS_OVERRIDE_TIME);return this;};UIIntentionalStreamRefresh.prototype.unload=function(){this.enableAutoRefresh(false);this.cleanupRefreshInterval();UserActivity.unsubscribe(this.uaToken);this.updateConfigHandler&&Arbiter.unsubscribe(this.updateConfigHandler);};UIIntentionalStreamRefresh.prototype.userActivity=function(){if(this.getMSSinceLastActivity()>this.autoRefreshInactiveTime)Arbiter.inform(UIIntentionalStreamMessage.SAVE_PENDING_HIGHLIGHTS);var a=this.isInactive();this.lastActivity=(new Date().getTime());this.isAutoRefreshing=true;if(a&&this.shouldAutoRefresh()){Arbiter.inform(UIIntentionalStreamMessage.UPDATE_STREAM);this.schedulePoll(this.getRefreshInterval());}return true;};UIIntentionalStreamRefresh.prototype.isInactive=function(){return this.getMSSinceLastActivity()>this.inactiveThreshold;};UIIntentionalStreamRefresh.prototype.getMSSinceLastActivity=function(){return (new Date().getTime())-this.lastActivity;};UIIntentionalStreamRefresh.prototype.getMSSinceLastRefresh=function(){return (new Date().getTime())-this.lastRefresh;};UIIntentionalStreamRefresh.prototype.getRefreshInterval=function(){if(this.isInactive()){return this.inactiveRefreshTime;}else if(this.storyInterval!=null){var a=this.storyInterval*this.refreshFactor;return Math.max(a,this.activeRefreshTime);}else return this.activeRefreshTime;};UIIntentionalStreamRefresh.prototype.shouldAutoRefresh=function(){return this.isAutoRefreshing&&this.allowAutoRefresh&&(this.getMSSinceLastRefresh()>this.minRefreshInterval);};UIIntentionalStreamRefresh.handleNewStoryMessage=function(b,a){if(b!=PresenceMessage.getArbiterMessageType('feedpub'))return;Arbiter.inform(UIIntentionalStreamMessage.UPDATE_STREAM);};UIIntentionalStreamRefresh.prototype.cancelUpdate=function(){if(this.updateTask){clearTimeout(this.updateTask);this.updateTask=null;}};UIIntentionalStreamRefresh.prototype.runUpdatePoll=function(){this.updateTask=null;if(!this.shouldAutoRefresh())return;Arbiter.inform(UIIntentionalStreamMessage.UPDATE_STREAM);this.schedulePoll(this.getRefreshInterval());};UIIntentionalStreamRefresh.prototype.schedulePoll=function(a){this.cancelUpdate();if(this.allowPolling)this.updateTask=setTimeout(this.runUpdatePoll.bind(this),a);};UIIntentionalStreamRefresh.prototype.enableAutoRefresh=function(b,c){this.isAutoRefreshing=b;if(b){var a=c?0:this.getRefreshInterval();this.schedulePoll(a);}else this.cancelUpdate();};UIIntentionalStreamRefresh.prototype.checkAutoPageRefresh=function(){if(!this.allowAutoRefresh)return;if(this.isAutoRefreshing&&(this.getMSSinceLastActivity()>this.disableAutoRefreshTime))this.isAutoRefreshing=false;if(this.getMSSinceLastRefresh()<this.autoRefreshInactiveTime)return;var a=this.getMSSinceLastActivity();if(a>this.autoRefreshInactiveTime){var b=(a>this.highlightsOverrideTime);Arbiter.inform(UIIntentionalStreamMessage.REFRESH_STREAM,{shouldOverride:b});}};UIIntentionalStreamRefresh.prototype.cleanupRefreshInterval=function(){if(this.autoRefreshInterval){clearInterval(this.autoRefreshInterval);this.autoRefreshInterval=null;}};

if (window.Bootloader) { Bootloader.done(["js\/stream\/UIIntentionalStreamRefresh.js"]); }