
(function(){var ns=rx.namespace('stream.show.update');var stream=rx.stream.show.stream;ns.updating=false;ns.timeout=null;ns.queue=[];ns.queueupdate=function(up){ns.queue.push(up);if(ns.timeout){clearTimeout(ns.timeout);ns.timeout=null;}
ns.update();}
ns.update=function(){if(ns.updating)return;if(ns.queue.length){ns.process(ns.queue.shift());}
else if(ns.timeout===null&&!ns.disable_updates)
ns.timeout=setTimeout(function(){ns.process();},10000);};ns.process=function(up){if(!up)up={type:'update'};var params={type:'post',dataType:'json'};params.data={update_stream:ns.streamid,update_pos:ns.pos,update_ver:ns.version,update_filter:ns.filter};if(ns.view)params.data.update_view=ns.view;params.beforeSend=function(){if(up.type!='update')stream.trigger('sendstart');ns.updating=true;};params.complete=function(){if(up.type!='update')stream.trigger('sendfinish');ns.updating=false;ns.timeout=null;ns.update();};params.success=function(data){if(data.error)return location.reload();ns.pos=data.pos;stream.trigger('timeupdate',[data.stamp]);if(data.more)stream.trigger('more',[data.more]);if(data.moremore!==null)stream.trigger('morestate',[data.moremore]);if(data.updates)stream.trigger('queuerender',[data.updates]);stream.trigger('unread',[data.unread]);if(data.spa!==null)stream.trigger('spa',[data.spa]);up.cb&&up.cb({data:data.thru});};params.error=function(){up.cb&&up.cb({error:1});};if(ns.disable_updates)params.data.update_disable=1;else{var sids=[];var shareitems=stream.find('.shareitem');var oldest=null;shareitems.each(function(i){var $this=$(this);sids.push($this.attr('sid'));var st=$this.attr('stamp');if(!oldest||st<oldest)oldest=st;});params.data.update_sids=sids.join('\x01');if(shareitems.length>=rx.stream.show.render.perpage&&oldest)
params.data.update_oldest=oldest;}
params.url=rx.scripturl+'/stream.'+up.type;rx.util.update(params.data,up.data);if(ns.updateextras)rx.util.update(params.data,ns.updateextras);$.ajax(params);};})();