feed update: introduce reference point
This commit is contained in:
30
inc/Spot.php
30
inc/Spot.php
@@ -224,7 +224,7 @@ class Spot extends Main
|
||||
$oEmail->oTemplate->setTag('date_time', 'time:'.$asLastMessage['unix_time'], 'd/m/Y, H:i');
|
||||
|
||||
//Add latest news feed
|
||||
$asNews = $this->getNewsFeed(0, true);
|
||||
$asNews = $this->getNewsFeed(0, 0, true);
|
||||
$iPostCount = 0;
|
||||
foreach($asNews as $asPost) {
|
||||
if($asPost['type'] != 'message') {
|
||||
@@ -425,7 +425,7 @@ class Spot extends Main
|
||||
if($sTimeZone != '') $asData['formatted_time_local'] = $this->getTimeFormat($iTime, $sTimeZone);
|
||||
}
|
||||
|
||||
public function getNewsFeed($iChunk=0, $bInternal=false)
|
||||
public function getNewsFeed($iChunk=0, $iRefTimePoint=0, $bInternal=false)
|
||||
{
|
||||
$bHistoMode = ($this->oProject->getMode() == Project::MODE_HISTO);
|
||||
$asFeeds = array();
|
||||
@@ -448,25 +448,31 @@ class Spot extends Main
|
||||
);
|
||||
foreach($asFeedTypes as $sFeedType=>$asFeedTypeInfo) {
|
||||
foreach($asFeedTypeInfo['feed'] as $asFeed) {
|
||||
$sPriority = $asFeedTypeInfo['priority'];
|
||||
if($bHistoMode) $sPriority = count($asFeedTypes) - 1 - $asFeedTypeInfo['priority'];
|
||||
|
||||
$iTableId = $asFeed[Db::getId($asFeedTypeInfo['table'])];
|
||||
$iId = ($asFeed['unix_time'] * -1).'.'.$sPriority.$iTableId;
|
||||
$asFeeds[$iId] = $asFeed;
|
||||
$asFeeds[$iId]['type'] = $sFeedType;
|
||||
$asFeeds[$iId]['id'] = $iTableId;
|
||||
|
||||
//Build unique sorting ID
|
||||
$iSort = $asFeed['unix_time'].'.'.$asFeedTypeInfo['priority'].$iTableId;
|
||||
|
||||
//Build feed (not including new feeds added in between chunk by concurrent access)
|
||||
if($iChunk == 0 || $iSort <= $iRefTimePoint) {
|
||||
$asFeeds[$iSort] = $asFeed;
|
||||
$asFeeds[$iSort]['type'] = $sFeedType;
|
||||
$asFeeds[$iSort]['id'] = $iTableId;
|
||||
}
|
||||
|
||||
//Build Reference Time Point (latest item extracted by first chunk)
|
||||
if($iChunk == 0 && $iSort > $iRefTimePoint) $iRefTimePoint = $iSort;
|
||||
}
|
||||
}
|
||||
|
||||
//Sort by key
|
||||
if($bHistoMode) krsort($asFeeds);
|
||||
else ksort($asFeeds);
|
||||
if($bHistoMode) ksort($asFeeds); //Old first
|
||||
else krsort($asFeeds); //New first
|
||||
|
||||
//Split chunks
|
||||
$asFeeds = array_slice($asFeeds, $iChunk * self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE);
|
||||
|
||||
return $bInternal?$asFeeds:self::getJsonResult(true, '', $asFeeds);
|
||||
return $bInternal?$asFeeds:self::getJsonResult(true, '', array('ref_id'=>$iRefTimePoint, 'feed' => $asFeeds));
|
||||
}
|
||||
|
||||
public function syncMedias() {
|
||||
|
||||
@@ -45,7 +45,7 @@ if($sAction!='')
|
||||
$sResult = $oSpot->getMarkers();
|
||||
break;
|
||||
case 'feed':
|
||||
$sResult = $oSpot->getNewsFeed($iChunk);
|
||||
$sResult = $oSpot->getNewsFeed($iChunk, $iId);
|
||||
break;
|
||||
case 'add_post':
|
||||
$sResult = $oSpot->addPost($sName, $sContent);
|
||||
|
||||
@@ -720,6 +720,8 @@ function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
||||
bDiscrete = bDiscrete || false;
|
||||
fCallback = fCallback || function(){};
|
||||
|
||||
if(bFirstChunk) self.tmp('ref_id', 0);
|
||||
|
||||
if(self.tmp('updatable')) {
|
||||
if(!self.tmp('out-of-data') || bFirstChunk) {
|
||||
self.tmp('updatable', false);
|
||||
@@ -736,12 +738,14 @@ function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
||||
function(asData) {
|
||||
$('#loading').hide();
|
||||
|
||||
$.each(asData, function(iKey, asPost){
|
||||
self.tmp('ref_id', asData.ref_id);
|
||||
|
||||
$.each(asData.feed, function(iKey, asPost){
|
||||
$Posts.append(getPost(asPost));
|
||||
});
|
||||
|
||||
self.tmp('news_chunk', self.tmp('news_chunk') + 1);
|
||||
self.tmp('out-of-data', Object.keys(asData).length != self.vars('chunk_size'));
|
||||
self.tmp('out-of-data', Object.keys(asData.feed).length != self.vars('chunk_size'));
|
||||
|
||||
if(bFirstChunk===true) self.tmp('$PostList').empty();
|
||||
self.tmp('$PostList').append($Posts.children());
|
||||
@@ -751,7 +755,8 @@ function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
||||
self.tmp('updatable', true);
|
||||
}, {
|
||||
id_project: self.vars(['project', 'id']),
|
||||
chunk: self.tmp('news_chunk')
|
||||
chunk: self.tmp('news_chunk'),
|
||||
id: self.tmp('ref_id')
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user