Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: unexpected merge conflicts on multiple devices

thecodrr50c95461b1fa
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js
index 8be8194de..5283eb741 100644
--- a/packages/core/api/sync/index.js
+++ b/packages/core/api/sync/index.js
@@ -82,7 +82,7 @@ export default class Sync {
await this._db.conflicts.check();
// send the data back to server
- lastSynced = await this._send(data, token);
+ lastSynced = await this._send(data, lastSynced, token);
// update our lastSynced time
if (lastSynced) {
@@ -91,11 +91,24 @@ export default class Sync {
}
async eventMerge(serverResponse) {
- let { lastSynced } = await this._performChecks();
+ let { lastSynced, token } = await this._performChecks();
+
+ const data = await this._collector.collect(lastSynced);
// merge the server response
await this._merger.merge(serverResponse, lastSynced);
+ // check for conflicts and throw
+ await this._db.conflicts.check();
+
+ // send the data back to server
+ lastSynced = await this._send(data, token);
+
+ // update our lastSynced time
+ if (lastSynced) {
+ await this._db.context.write("lastSynced", lastSynced);
+ }
+
EV.publish(EVENTS.appRefreshRequested);
// check for conflicts and throw
@@ -111,8 +124,8 @@ export default class Sync {
// }
}
- async _send(data, token) {
- if (areAllEmpty(data)) return;
+ async _send(data, lastSynced, token) {
+ if (lastSynced && areAllEmpty(data)) return;
let response = await http.post.json(
`${Constants.API_HOST}/sync`,