[uniques] make sync work (hopefully)
If it doesn't work, try to delete the file "uniques[uniques]" in your Google Drive. Be sure to delete it from the trash as well.
This commit is contained in:
parent
e81dead91f
commit
b4053c2800
@ -23,11 +23,12 @@ window.plugin.uniques = function() {};
|
|||||||
//delay in ms
|
//delay in ms
|
||||||
window.plugin.uniques.SYNC_DELAY = 10000;
|
window.plugin.uniques.SYNC_DELAY = 10000;
|
||||||
|
|
||||||
window.plugin.uniques.LOCAL_STORAGE_KEY = 'plugin-uniques-data';
|
// maps the JS property names to localStorage keys
|
||||||
|
window.plugin.uniques.FIELDS = {
|
||||||
window.plugin.uniques.KEY = {key: window.plugin.uniques.LOCAL_STORAGE_KEY, field: 'uniques'};
|
'uniques': 'plugin-uniques-data',
|
||||||
window.plugin.uniques.UPDATE_QUEUE = {key: 'plugin-uniques-data-queue', field: 'updateQueue'};
|
'updateQueue': 'plugin-uniques-data-queue',
|
||||||
window.plugin.uniques.UPDATING_QUEUE = {key: 'plugin-uniques-data-updating-queue', field: 'updatingQueue'};
|
'updatingQueue': 'plugin-uniques-data-updating-queue',
|
||||||
|
};
|
||||||
|
|
||||||
window.plugin.uniques.uniques = {};
|
window.plugin.uniques.uniques = {};
|
||||||
window.plugin.uniques.updateQueue = {};
|
window.plugin.uniques.updateQueue = {};
|
||||||
@ -187,9 +188,7 @@ window.plugin.uniques.setPortalVisited = function(guid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.uniques.updateCheckedAndHighlight(guid);
|
plugin.uniques.updateCheckedAndHighlight(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.KEY);
|
plugin.uniques.sync(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATE_QUEUE);
|
|
||||||
plugin.uniques.delaySync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.setPortalCaptured = function(guid) {
|
window.plugin.uniques.setPortalCaptured = function(guid) {
|
||||||
@ -205,9 +204,7 @@ window.plugin.uniques.setPortalCaptured = function(guid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.uniques.updateCheckedAndHighlight(guid);
|
plugin.uniques.updateCheckedAndHighlight(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.KEY);
|
plugin.uniques.sync(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATE_QUEUE);
|
|
||||||
plugin.uniques.delaySync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.updateVisited = function(visited) {
|
window.plugin.uniques.updateVisited = function(visited) {
|
||||||
@ -228,9 +225,7 @@ window.plugin.uniques.updateVisited = function(visited) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.uniques.updateCheckedAndHighlight(guid);
|
plugin.uniques.updateCheckedAndHighlight(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.KEY);
|
plugin.uniques.sync(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATE_QUEUE);
|
|
||||||
plugin.uniques.delaySync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.updateCaptured = function(captured) {
|
window.plugin.uniques.updateCaptured = function(captured) {
|
||||||
@ -251,32 +246,35 @@ window.plugin.uniques.updateCaptured = function(captured) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.uniques.updateCheckedAndHighlight(guid);
|
plugin.uniques.updateCheckedAndHighlight(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.KEY);
|
plugin.uniques.sync(guid);
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATE_QUEUE);
|
|
||||||
plugin.uniques.delaySync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delay the syncing to group a few updates in a single request
|
// stores the gived GUID for sync
|
||||||
window.plugin.uniques.delaySync = function() {
|
plugin.uniques.sync = function(guid) {
|
||||||
|
plugin.uniques.updatingQueue[guid] = true;
|
||||||
|
plugin.uniques.storeLocal('uniques');
|
||||||
|
plugin.uniques.storeLocal('updateQueue');
|
||||||
|
plugin.uniques.syncQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// sync the queue, but delay the actual sync to group a few updates in a single request
|
||||||
|
window.plugin.uniques.syncQueue = function() {
|
||||||
if(!plugin.uniques.enableSync) return;
|
if(!plugin.uniques.enableSync) return;
|
||||||
clearTimeout(plugin.uniques.delaySync.timer);
|
|
||||||
plugin.uniques.delaySync.timer = setTimeout(function() {
|
clearTimeout(plugin.uniques.syncTimer);
|
||||||
plugin.uniques.delaySync.timer = null;
|
|
||||||
window.plugin.uniques.syncNow();
|
plugin.uniques.syncTimer = setTimeout(function() {
|
||||||
|
plugin.uniques.syncTimer = null;
|
||||||
|
|
||||||
|
$.extend(plugin.uniques.updatingQueue, plugin.uniques.updateQueue);
|
||||||
|
plugin.uniques.updateQueue = {};
|
||||||
|
plugin.uniques.storeLocal('updatingQueue');
|
||||||
|
plugin.uniques.storeLocal('updateQueue');
|
||||||
|
|
||||||
|
plugin.sync.updateMap('uniques', 'uniques', Object.keys(plugin.uniques.updatingQueue));
|
||||||
}, plugin.uniques.SYNC_DELAY);
|
}, plugin.uniques.SYNC_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Store the updateQueue in updatingQueue and upload
|
|
||||||
window.plugin.uniques.syncNow = function() {
|
|
||||||
if(!plugin.uniques.enableSync) return;
|
|
||||||
$.extend(plugin.uniques.updatingQueue, plugin.uniques.updateQueue);
|
|
||||||
plugin.uniques.updateQueue = {};
|
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATING_QUEUE);
|
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATE_QUEUE);
|
|
||||||
|
|
||||||
plugin.sync.updateMap('uniques', 'uniques', plugin.uniques.updatingQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Call after IITC and all plugin loaded
|
//Call after IITC and all plugin loaded
|
||||||
window.plugin.uniques.registerFieldForSyncing = function() {
|
window.plugin.uniques.registerFieldForSyncing = function() {
|
||||||
if(!window.plugin.sync) return;
|
if(!window.plugin.sync) return;
|
||||||
@ -286,7 +284,7 @@ window.plugin.uniques.registerFieldForSyncing = function() {
|
|||||||
//Call after local or remote change uploaded
|
//Call after local or remote change uploaded
|
||||||
window.plugin.uniques.syncCallback = function(pluginName, fieldName, e, fullUpdated) {
|
window.plugin.uniques.syncCallback = function(pluginName, fieldName, e, fullUpdated) {
|
||||||
if(fieldName === 'uniques') {
|
if(fieldName === 'uniques') {
|
||||||
plugin.uniques.storeLocal(plugin.uniques.KEY);
|
plugin.uniques.storeLocal('uniques');
|
||||||
// All data is replaced if other client update the data during this client
|
// All data is replaced if other client update the data during this client
|
||||||
// offline,
|
// offline,
|
||||||
// fire 'pluginUniquesRefreshAll' to notify a full update
|
// fire 'pluginUniquesRefreshAll' to notify a full update
|
||||||
@ -311,7 +309,7 @@ window.plugin.uniques.syncCallback = function(pluginName, fieldName, e, fullUpda
|
|||||||
} else {
|
} else {
|
||||||
// Remote update
|
// Remote update
|
||||||
delete plugin.uniques.updateQueue[e.property];
|
delete plugin.uniques.updateQueue[e.property];
|
||||||
plugin.uniques.storeLocal(plugin.uniques.UPDATE_QUEUE);
|
plugin.uniques.storeLocal('updateQueue');
|
||||||
plugin.uniques.updateCheckedAndHighlight(e.property);
|
plugin.uniques.updateCheckedAndHighlight(e.property);
|
||||||
window.runHooks('pluginUniquesUpdateUniques', {guid: e.property});
|
window.runHooks('pluginUniquesUpdateUniques', {guid: e.property});
|
||||||
}
|
}
|
||||||
@ -323,21 +321,31 @@ window.plugin.uniques.syncInitialed = function(pluginName, fieldName) {
|
|||||||
if(fieldName === 'uniques') {
|
if(fieldName === 'uniques') {
|
||||||
plugin.uniques.enableSync = true;
|
plugin.uniques.enableSync = true;
|
||||||
if(Object.keys(plugin.uniques.updateQueue).length > 0) {
|
if(Object.keys(plugin.uniques.updateQueue).length > 0) {
|
||||||
plugin.uniques.delaySync();
|
plugin.uniques.syncQueue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.storeLocal = function(mapping) {
|
window.plugin.uniques.storeLocal = function(name) {
|
||||||
if(typeof(plugin.uniques[mapping.field]) !== 'undefined' && plugin.uniques[mapping.field] !== null) {
|
var key = window.plugin.uniques.FIELDS[name];
|
||||||
localStorage[mapping.key] = JSON.stringify(plugin.uniques[mapping.field]);
|
if(key === undefined) return;
|
||||||
|
|
||||||
|
var value = plugin.uniques[name];
|
||||||
|
|
||||||
|
if(typeof value !== 'undefined' && value !== null) {
|
||||||
|
localStorage[key] = JSON.stringify(plugin.uniques[name]);
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(mapping.key);
|
localStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.uniques.loadLocal = function(mapping) {
|
window.plugin.uniques.loadLocal = function(name) {
|
||||||
if (localStorage[mapping.key] !== undefined) { plugin.uniques[mapping.field] = JSON.parse(localStorage[mapping.key]); }
|
var key = window.plugin.uniques.FIELDS[name];
|
||||||
|
if(key === undefined) return;
|
||||||
|
|
||||||
|
if(localStorage[key] !== undefined) {
|
||||||
|
plugin.uniques[name] = JSON.parse(localStorage[key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************************************************************************/
|
/***************************************************************************************************************************************************************/
|
||||||
@ -400,11 +408,11 @@ var setup = function() {
|
|||||||
window.VALID_HOOKS.push('pluginUniquesRefreshAll');
|
window.VALID_HOOKS.push('pluginUniquesRefreshAll');
|
||||||
window.plugin.uniques.setupCSS();
|
window.plugin.uniques.setupCSS();
|
||||||
window.plugin.uniques.setupContent();
|
window.plugin.uniques.setupContent();
|
||||||
window.plugin.uniques.loadLocal(window.plugin.uniques.KEY);
|
window.plugin.uniques.loadLocal('uniques');
|
||||||
window.addHook('portalDetailsUpdated', window.plugin.uniques.onPortalDetailsUpdated);
|
window.addHook('portalDetailsUpdated', window.plugin.uniques.onPortalDetailsUpdated);
|
||||||
window.addHook('publicChatDataAvailable', window.plugin.uniques.onPublicChatDataAvailable);
|
window.addHook('publicChatDataAvailable', window.plugin.uniques.onPublicChatDataAvailable);
|
||||||
window.addHook('iitcLoaded', window.plugin.uniques.registerFieldForSyncing);
|
window.addHook('iitcLoaded', window.plugin.uniques.registerFieldForSyncing);
|
||||||
window.addPortalHighlighter('Uniques', window.plugin.uniques.highlighter);
|
window.addPortalHighlighter('Uniques', window.plugin.uniques.highlighter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//PLUGIN END //////////////////////////////////////////////////////////
|
//PLUGIN END //////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user