Remove draft comment from local storage upon discard
Previously, when a user discarded a draft comment, the draft was still
stored in local storage. If they tried to reply to a comment on the same
line, the previous message appeared when it shouldn't have. This change
removes drafts from local storage when they are discarded.
Bug: Issue 4361
Change-Id: Id234676972a21a879e68e754968abf7008098cf6
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
index 8905854..72138ff 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
@@ -125,12 +125,7 @@
this.comment.message = this._messageText;
this.disabled = true;
- this.$.storage.eraseDraftComment({
- changeNum: this.changeNum,
- patchNum: this.patchNum,
- path: this.comment.path,
- line: this.comment.line,
- });
+ this._eraseDraftComment();
this._xhrPromise = this._saveDraft(this.comment).then(function(response) {
this.disabled = false;
@@ -155,6 +150,15 @@
}.bind(this));
},
+ _eraseDraftComment: function() {
+ this.$.storage.eraseDraftComment({
+ changeNum: this.changeNum,
+ patchNum: this.patchNum,
+ path: this.comment.path,
+ line: this.comment.line,
+ });
+ },
+
_commentChanged: function(comment) {
this.editing = !!comment.__editing;
if (this.editing) { // It's a new draft/reply, notify.
@@ -338,6 +342,8 @@
}
this.editing = false;
this.disabled = true;
+ this._eraseDraftComment();
+
if (!this.comment.id) {
this.disabled = false;
this._fireDiscard();