Close #934. Remove feed item read state syncing
This commit is contained in:
parent
fabc2ba6a2
commit
2b41f7af1d
7 changed files with 22 additions and 125 deletions
|
@ -331,33 +331,14 @@ Zotero.Feed.prototype.erase = Zotero.Promise.coroutine(function* (options = {})
|
|||
yield Zotero.Feed._super.prototype.erase.call(this, options);
|
||||
});
|
||||
|
||||
Zotero.Feed.prototype.getSyncedSettings = function () {
|
||||
if (!this._syncedSettings) {
|
||||
Zotero.Feed.prototype.storeSyncedSettings = Zotero.Promise.coroutine(function* () {
|
||||
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds') || {};
|
||||
this._syncedSettings = syncedFeeds[this.url];
|
||||
}
|
||||
if (!this._syncedSettings) {
|
||||
this._syncedSettings = {
|
||||
syncedFeeds[this.url] = {
|
||||
url: this.url,
|
||||
name: this.name,
|
||||
cleanupAfter: this.cleanupAfter,
|
||||
refreshInterval: this.refreshInterval,
|
||||
markedAsRead: {}
|
||||
refreshInterval: this.refreshInterval
|
||||
};
|
||||
}
|
||||
return this._syncedSettings;
|
||||
};
|
||||
|
||||
Zotero.Feed.prototype.setSyncedSettings = Zotero.Promise.coroutine(function* (syncedSettings, store=false) {
|
||||
this._syncedSettings = syncedSettings;
|
||||
if (store) {
|
||||
return this.storeSyncedSettings();
|
||||
}
|
||||
});
|
||||
|
||||
Zotero.Feed.prototype.storeSyncedSettings = Zotero.Promise.coroutine(function* () {
|
||||
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds') || {};
|
||||
syncedFeeds[this.url] = this.getSyncedSettings();
|
||||
return Zotero.SyncedSettings.set(Zotero.Libraries.userLibraryID, 'feeds', syncedFeeds);
|
||||
});
|
||||
|
||||
|
@ -405,7 +386,6 @@ Zotero.Feed.prototype.clearExpiredItems = Zotero.Promise.coroutine(function* (it
|
|||
Zotero.debug("Error clearing expired feed items");
|
||||
Zotero.debug(e);
|
||||
}
|
||||
return this.storeSyncedSettings();
|
||||
});
|
||||
|
||||
Zotero.Feed.prototype._updateFeed = Zotero.Promise.coroutine(function* () {
|
||||
|
@ -534,9 +514,3 @@ Zotero.Feed.prototype.updateUnreadCount = Zotero.Promise.coroutine(function* ()
|
|||
Zotero.Notifier.trigger('unreadCountUpdated', 'feed', this.id);
|
||||
}
|
||||
});
|
||||
|
||||
Zotero.Feed.prototype.updateFromJSON = Zotero.Promise.coroutine(function* (json) {
|
||||
yield this.updateFeed();
|
||||
yield Zotero.FeedItems.markAsReadByGUID(Object.keys(json.markedAsRead));
|
||||
yield this.updateUnreadCount();
|
||||
});
|
||||
|
|
|
@ -182,9 +182,6 @@ Zotero.FeedItem.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
Zotero.FeedItem.prototype._finalizeErase = Zotero.Promise.coroutine(function* () {
|
||||
// Set for syncing
|
||||
let feed = Zotero.Feeds.get(this.libraryID);
|
||||
let syncedSettings = feed.getSyncedSettings();
|
||||
delete syncedSettings.markedAsRead[this.guid];
|
||||
yield feed.setSyncedSettings(syncedSettings);
|
||||
|
||||
return Zotero.FeedItem._super.prototype._finalizeErase.apply(this, arguments);
|
||||
});
|
||||
|
@ -195,18 +192,9 @@ Zotero.FeedItem.prototype.toggleRead = Zotero.Promise.coroutine(function* (state
|
|||
if (changed) {
|
||||
this.isRead = state;
|
||||
|
||||
// Set for syncing
|
||||
let feed = Zotero.Feeds.get(this.libraryID);
|
||||
let syncedSettings = feed.getSyncedSettings();
|
||||
if (state) {
|
||||
syncedSettings.markedAsRead[this.guid] = true;
|
||||
} else {
|
||||
delete syncedSettings.markedAsRead[this.guid];
|
||||
}
|
||||
yield feed.setSyncedSettings(syncedSettings, true);
|
||||
|
||||
yield this.saveTx();
|
||||
|
||||
let feed = Zotero.Feeds.get(this.libraryID);
|
||||
yield feed.updateUnreadCount();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -109,7 +109,7 @@ Zotero.FeedItems = new Proxy(function() {
|
|||
});
|
||||
|
||||
/**
|
||||
* Used on restore from sync
|
||||
* Currently not used
|
||||
*/
|
||||
this.markAsReadByGUID = Zotero.Promise.coroutine(function* (guids) {
|
||||
if (! Array.isArray(guids)) {
|
||||
|
@ -152,17 +152,8 @@ Zotero.FeedItems = new Proxy(function() {
|
|||
for (let i=0; i<items.length; i++) {
|
||||
items[i].isRead = state;
|
||||
|
||||
// Set for syncing
|
||||
yield items[i].save();
|
||||
let feed = Zotero.Feeds.get(items[i].libraryID);
|
||||
let syncedSettings = feed.getSyncedSettings();
|
||||
if (state) {
|
||||
syncedSettings.markedAsRead[items[i].guid] = true;
|
||||
} else {
|
||||
delete syncedSettings.markedAsRead[items[i].guid];
|
||||
}
|
||||
yield feed.setSyncedSettings(syncedSettings);
|
||||
|
||||
yield items[i].save({skipEditCheck: true});
|
||||
feedsToUpdate.add(feed);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -93,12 +93,10 @@ Zotero.Feeds = new function() {
|
|||
json = syncedFeeds;
|
||||
}
|
||||
yield Zotero.SyncedSettings.set(Zotero.Libraries.userLibraryID, 'feeds', json);
|
||||
//
|
||||
let feeds = Zotero.Feeds.getAll();
|
||||
for (let feed of feeds) {
|
||||
if (json[feed.url]) {
|
||||
Zotero.debug("Feed " + feed.url + " is being updated from remote JSON");
|
||||
yield feed.updateFromJSON(json[feed.url]);
|
||||
Zotero.debug("Feed " + feed.url + " exists remotely and locally");
|
||||
delete json[feed.url];
|
||||
} else {
|
||||
Zotero.debug("Feed " + feed.url + " does not exist in remote JSON. Deleting");
|
||||
|
@ -107,10 +105,10 @@ Zotero.Feeds = new function() {
|
|||
}
|
||||
// Because existing json[feed.url] got deleted, `json` now only contains new feeds
|
||||
for (let url in json) {
|
||||
Zotero.debug("Feed " + url + " is being created from remote JSON");
|
||||
Zotero.debug("Feed " + url + " exists remotely but not locally. Creating");
|
||||
let feed = new Zotero.Feed(json[url]);
|
||||
yield feed.saveTx();
|
||||
yield feed.updateFromJSON(json[url]);
|
||||
yield feed.updateFeed();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -180,18 +180,6 @@ describe("Zotero.FeedItem", function () {
|
|||
|
||||
//yield assert.isRejected(feedItem.EraseTx(), "does not allow erasing twice");
|
||||
});
|
||||
it("should remove synced setting if exists", function* () {
|
||||
let item = yield createDataObject('feedItem', { libraryID });
|
||||
|
||||
yield item.toggleRead();
|
||||
let syncedSettings = feed.getSyncedSettings();
|
||||
assert.ok(syncedSettings.markedAsRead[item.guid]);
|
||||
|
||||
yield item.eraseTx();
|
||||
|
||||
syncedSettings = feed.getSyncedSettings();
|
||||
assert.notOk(syncedSettings.markedAsRead[item.guid]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#toggleRead()", function() {
|
||||
|
@ -217,17 +205,6 @@ describe("Zotero.FeedItem", function () {
|
|||
yield item.toggleRead(true);
|
||||
assert.isFalse(item.save.called, "item was not saved on toggle read to same state");
|
||||
});
|
||||
it('should set relevant synced settings', function* () {
|
||||
let item = yield createDataObject('feedItem', { libraryID });
|
||||
item.isRead = false;
|
||||
yield item.saveTx();
|
||||
|
||||
yield item.toggleRead();
|
||||
|
||||
let feed = Zotero.Feeds.get(item.libraryID);
|
||||
let syncedSettings = feed.getSyncedSettings();
|
||||
assert.ok(syncedSettings.markedAsRead[item.guid], "item marked as read stored in synced settings");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#translate()', function() {
|
||||
|
|
|
@ -138,15 +138,5 @@ describe("Zotero.FeedItems", function () {
|
|||
assert.isFalse(save.thisValues[i].isRead, "#toggleRead called with true");
|
||||
}
|
||||
});
|
||||
|
||||
it('should set relevant sync settings', function* () {
|
||||
items[0].isRead = false;
|
||||
yield items[0].saveTx();
|
||||
yield Zotero.FeedItems.toggleReadByID(ids);
|
||||
|
||||
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
||||
let markedAsRead = Object.keys(syncedFeeds[feed.url].markedAsRead);
|
||||
assert.deepEqual(markedAsRead, Object.keys(items).map((k) => items[k].guid));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -199,39 +199,18 @@ describe("Zotero.Feed", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#getSyncedSettings", function() {
|
||||
it("should return correct synced settings for the feed", function* () {
|
||||
let url = 'http://' + Zotero.Utilities.randomString(10, 'abcde') + '.com/feed.rss';
|
||||
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
||||
assert.notOk(syncedFeeds[url]);
|
||||
|
||||
let feed = yield createFeed({url});
|
||||
|
||||
syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
||||
assert.ok(syncedFeeds[url]);
|
||||
|
||||
let syncedData = feed.getSyncedSettings();
|
||||
|
||||
assert.deepEqual(syncedData, syncedFeeds[url]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#storeSyncedSettings", function() {
|
||||
it("should store updated settings for the feed", function* () {
|
||||
let guid = Zotero.Utilities.randomString();
|
||||
let feed = yield createFeed();
|
||||
let settings = {
|
||||
name: Zotero.Utilities.randomString(),
|
||||
url: 'http://' + Zotero.Utilities.randomString().toLowerCase() + '.com/feed.rss',
|
||||
refreshInterval: 1,
|
||||
cleanupAfter: 1
|
||||
};
|
||||
let feed = yield createFeed(settings);
|
||||
|
||||
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
||||
assert.notOk(syncedFeeds[feed.url].markedAsRead[guid]);
|
||||
|
||||
let syncedData = feed.getSyncedSettings();
|
||||
syncedData.markedAsRead[guid] = true;
|
||||
yield feed.setSyncedSettings(syncedData);
|
||||
yield feed.storeSyncedSettings();
|
||||
|
||||
syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
||||
|
||||
assert.isTrue(syncedFeeds[feed.url].markedAsRead[guid]);
|
||||
assert.deepEqual(syncedFeeds[feed.url], settings);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue