per-browser source id so we support having notecase opened in multiple tabs/windows

This commit is contained in:
azivner
2017-12-16 20:48:34 -05:00
parent 03d86209ca
commit 50ff5da947
17 changed files with 98 additions and 83 deletions

View File

@@ -1,5 +1,4 @@
const sql = require('./sql');
const source_id = require('./source_id');
const utils = require('./utils');
const messaging = require('./messaging');
const options = require('./options');
@@ -9,24 +8,10 @@ let startTime = utils.nowDate();
let sentSyncId = [];
async function sendPing() {
const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ? AND source_id != ?", [startTime, source_id.currentSourceId]);
const syncs = await sql.getResults("SELECT * FROM sync WHERE sync_date >= ?", [startTime]);
startTime = utils.nowDate();
const data = {};
const syncIds = [];
for (const sync of syncs) {
if (sentSyncId.includes(sync.id)) {
continue;
}
if (!data[sync.entity_name]) {
data[sync.entity_name] = [];
}
data[sync.entity_name].push(sync.entity_id);
syncIds.push(sync.id);
}
const syncData = syncs.filter(sync => !sentSyncId.includes(sync.id));
const lastSyncedPush = await options.getOption('last_synced_push');
@@ -34,12 +19,12 @@ async function sendPing() {
messaging.sendMessage({
type: 'sync',
data: data,
data: syncData,
changesToPushCount: sync_setup.isSyncSetup ? changesToPushCount : 0
});
for (const syncId of syncIds) {
sentSyncId.push(syncId);
for (const sync of syncData) {
sentSyncId.push(sync.id);
}
}