Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync client from server using last update timestamp #846

Merged
merged 15 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controllers/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function sync() {
$last_update = new \DateTime($itemsDao->lastUpdate());

$sync = array(
'last_update' => $last_update->format(\DateTime::ISO8601),
'last_update' => $last_update->format(\DateTime::ATOM),
);

if( $last_update > $since ) {
Expand All @@ -208,7 +208,7 @@ public function sync() {

$wantItemsStatuses = array_key_exists('items_statuses', $_GET) && $_GET['items_statuses'] == 'true';
if( $wantItemsStatuses ) {
$sync['items'] = $itemsDao->statuses($since->format(\DateTime::ISO8601));
$sync['items'] = $itemsDao->statuses($since->format(\DateTime::ATOM));
}
}
$this->view->jsonSuccess($sync);
Expand Down
2 changes: 1 addition & 1 deletion helpers/ViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function dateago($datestr) {
*/
public static function date_iso8601($datestr) {
$date = new \DateTime($datestr);
return $date->format(\DateTime::ISO8601);
return $date->format(\DateTime::ATOM);
}


Expand Down
5 changes: 4 additions & 1 deletion public/js/selfoss-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,17 @@ var selfoss = {
*
* @return void
*/
sync: function(force=false) {
sync: function(force) {
var force = (typeof force !== 'undefined') ? force : false;

if( !force && (selfoss.lastUpdate == null ||
Date.now() - selfoss.lastSync < 5*60*1000) )
return;

$.ajax({
url: 'items/sync',
type: 'GET',
dataType: 'json',
data: {
since: selfoss.lastUpdate.toISOString(),
tags: true,
Expand Down
2 changes: 1 addition & 1 deletion public/js/selfoss-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ selfoss.db = {
return !isValid; // break the loop if valid
});
return isValid;
},
}


};
10 changes: 8 additions & 2 deletions public/js/selfoss-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ selfoss.events = {

processHashChange: true,

processHash: function(hash=false) {
processHash: function(hash) {
var hash = (typeof hash != 'undefined') ? hash : false;

var done = function() {
selfoss.events.processHashChange = true;
};
Expand Down Expand Up @@ -176,7 +178,11 @@ selfoss.events = {
},


setHash: function(section='same', subsection='same', entryId=false) {
setHash: function(section, subsection, entryId) {
var section = (typeof section !== 'undefined') ? section : 'same';
var subsection = (typeof subsection !== 'undefined') ? subsection : 'same';
var entryId = (typeof entryId !== 'undefined') ? entryId : false;

if( section == 'same' )
section = selfoss.events.section;
newHash = new Array(section);
Expand Down
22 changes: 14 additions & 8 deletions public/js/selfoss-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,28 @@ selfoss.ui = {
},


refreshItemStatuses: function(entry_statuses) {
refreshItemStatuses: function(entryStatuses) {
$('.entry').each(function(index, item) {
var id = $(this).data(('entry-id'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous parentheses.

new_status = entry_statuses.find(function(entry_status) {
return entry_status.id == id;
var newStatus = false;
entryStatuses.some(function(entryStatus) {
if( entryStatus.id == id )
newStatus = entryStatus.id;
Copy link
Member

@jtojnar jtojnar Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not this be just newStatus = entryStatus? And since you are actually trying to find some entryStatus, why do you use Array.prototype.some? Weird, I have been using Array.prototype.find for ages, never knew it was ES6 feature.

return newStatus;
});
if( new_status ) {
selfoss.ui.entryStarr(id, new_status.starr);
selfoss.ui.entryMark(id, new_status.unread);
if( newStatus ) {
selfoss.ui.entryStarr(id, newStatus.starr);
selfoss.ui.entryMark(id, newStatus.unread);
}
});
},


refreshStreamButtons: function(entries=false,
hasEntries=false, hasMore=false) {
refreshStreamButtons: function(entries, hasEntries, hasMore) {
var entries = (typeof entries !== 'undefined') ? entries : false;
var hasEntries = (typeof hasEntries !== 'undefined') ? hasEntries : false;
var hasMore = (typeof hasMore !== 'undefined') ? hasMore : false;

$('.stream-button, .stream-empty').css('display', 'block').hide();
if( entries ) {
if( hasEntries ) {
Expand Down