mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-23 07:36:12 +08:00
fix(SyncbackCategoryTask): Make category operations optimistic again
Summary: We don't see any weird double object behavior when delete deltas are working properly, so might as well be optimistic since it makes for a better user experience. This diff also notifies the user if a category operation fails because of a mail provider restriction. Fixes T7475 Test Plan: tested locally Reviewers: juan, evan Reviewed By: evan Maniphest Tasks: T7475 Differential Revision: https://phab.nylas.com/D3648
This commit is contained in:
parent
99e3f732d9
commit
348ead5c11
1 changed files with 34 additions and 6 deletions
|
@ -18,9 +18,28 @@ export default class SyncbackCategoryTask extends Task {
|
||||||
return `${verb} ${this.category.displayType()}...`;
|
return `${verb} ${this.category.displayType()}...`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_revertLocal() {
|
||||||
|
return DatabaseStore.inTransaction((t) => {
|
||||||
|
if (this.isUpdate) {
|
||||||
|
this.category.displayName = this._initialDisplayName;
|
||||||
|
return t.persistModel(this.category)
|
||||||
|
}
|
||||||
|
return t.unpersistModel(this.category)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
performLocal() {
|
performLocal() {
|
||||||
// This operation is non-optimistic! Don't do anything.
|
if (!this.category) {
|
||||||
return Promise.resolve();
|
return Promise.reject(new Error("Attempt to call SyncbackCategoryTask.performLocal without this.category."));
|
||||||
|
}
|
||||||
|
this.isUpdate = !!this.category.serverId; // True if updating an existing category
|
||||||
|
return DatabaseStore.inTransaction((t) => {
|
||||||
|
if (this.isUpdate && this.displayName) {
|
||||||
|
this._initialDisplayName = this.category.displayName;
|
||||||
|
this.category.displayName = this.displayName;
|
||||||
|
}
|
||||||
|
return t.persistModel(this.category);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
performRemote() {
|
performRemote() {
|
||||||
|
@ -58,12 +77,21 @@ export default class SyncbackCategoryTask extends Task {
|
||||||
return DatabaseStore.inTransaction(t => t.persistModel(this.category))
|
return DatabaseStore.inTransaction(t => t.persistModel(this.category))
|
||||||
})
|
})
|
||||||
.thenReturn(Task.Status.Success)
|
.thenReturn(Task.Status.Success)
|
||||||
.catch(APIError, (err) => {
|
.catch(APIError, async (err) => {
|
||||||
if (!NylasAPI.PermanentErrorCodes.includes(err.statusCode)) {
|
if (!NylasAPI.PermanentErrorCodes.includes(err.statusCode)) {
|
||||||
return Promise.resolve(Task.Status.Retry);
|
return Task.Status.Retry;
|
||||||
}
|
}
|
||||||
this._isReverting = true;
|
await this._revertLocal()
|
||||||
return this.performLocal().thenReturn(Task.Status.Failed);
|
try {
|
||||||
|
if (/command argument error/gi.test(err.message)) {
|
||||||
|
const action = this.isUpdate ? 'update' : 'create';
|
||||||
|
const type = this.category.displayType();
|
||||||
|
NylasEnv.showErrorDialog(`Could not ${action} ${type}. Your mail provider has placed restrictions on this ${type}.`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// If notifying the user fails, just move on and mark the task as failed.
|
||||||
|
}
|
||||||
|
return Task.Status.Failed;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue