Rename `__draft` to `state`

Release-Notes: skip
Change-Id: Iff498a5750f97b23bcba3932427b7fe6df6bd752
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts
index 4a6b6cb..747a982 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts
@@ -154,7 +154,7 @@
           updated: '2018-02-13 22:48:48.018000000' as Timestamp,
           message: 'draft',
           unresolved: false,
-          __draft: DraftState.SAVED,
+          state: DraftState.SAVED,
           patch_set: 2 as RevisionPatchSetNum,
         },
       ],
@@ -257,7 +257,7 @@
           updated: '2018-02-15 22:48:48.018000000' as Timestamp,
           message: 'resolved draft',
           unresolved: false,
-          __draft: DraftState.SAVED,
+          state: DraftState.SAVED,
           patch_set: 2 as RevisionPatchSetNum,
         },
       ],
diff --git a/polygerrit-ui/app/elements/change/gr-message/gr-message_test.ts b/polygerrit-ui/app/elements/change/gr-message/gr-message_test.ts
index 032a7a7..0028380 100644
--- a/polygerrit-ui/app/elements/change/gr-message/gr-message_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-message/gr-message_test.ts
@@ -776,7 +776,7 @@
               message: 'n',
               unresolved: false,
               path: '/PATCHSET_LEVEL',
-              __draft: DraftState.SAVED,
+              state: DraftState.SAVED,
             },
           ],
           patchNum: 1 as RevisionPatchSetNum,
diff --git a/polygerrit-ui/app/elements/change/gr-thread-list/gr-thread-list_test.ts b/polygerrit-ui/app/elements/change/gr-thread-list/gr-thread-list_test.ts
index b113c20..4158f31 100644
--- a/polygerrit-ui/app/elements/change/gr-thread-list/gr-thread-list_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-thread-list/gr-thread-list_test.ts
@@ -76,7 +76,7 @@
             updated: '2015-12-01 15:16:15.000000000' as Timestamp,
             message: 'draft',
             unresolved: true,
-            __draft: DraftState.SAVED,
+            state: DraftState.SAVED,
             patch_set: '2' as RevisionPatchSetNum,
           },
         ],
@@ -163,7 +163,7 @@
             updated: '2015-12-05 15:16:15.000000000' as Timestamp,
             message: 'resolved draft',
             unresolved: false,
-            __draft: DraftState.SAVED,
+            state: DraftState.SAVED,
             patch_set: '2' as RevisionPatchSetNum,
           },
         ],
diff --git a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts
index 6d52902..8d1f24c 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread_test.ts
@@ -60,7 +60,7 @@
   message: 'stop it',
   updated: '2021-11-03 10:11:12.000000000' as Timestamp,
   in_reply_to: 'the-reply' as UrlEncodedCommentId,
-  __draft: DraftState.SAVED,
+  state: DraftState.SAVED,
 };
 
 const commentWithContext = {
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index 46288f4..ade21a2 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -678,7 +678,7 @@
               .dateStr=${this.comment!.updated}
             ></gr-date-formatter>
           `,
-          () => (this.comment as DraftInfo).__draft
+          () => (this.comment as DraftInfo).state
         )}
       </span>
     `;
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
index fed61d2..8299516 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment_test.ts
@@ -273,7 +273,7 @@
 
     test('renders draft', async () => {
       element.initiallyCollapsed = false;
-      (element.comment as DraftInfo).__draft = DraftState.SAVED;
+      (element.comment as DraftInfo).state = DraftState.SAVED;
       await element.updateComplete;
       assert.shadowDom.equal(
         element,
@@ -353,7 +353,7 @@
 
     test('renders draft in editing mode', async () => {
       element.initiallyCollapsed = false;
-      (element.comment as DraftInfo).__draft = DraftState.SAVED;
+      (element.comment as DraftInfo).state = DraftState.SAVED;
       element.editing = true;
       await element.updateComplete;
       assert.shadowDom.equal(
@@ -467,7 +467,7 @@
       },
       line: 5,
       path: 'test',
-      __draft: DraftState.SAVED,
+      state: DraftState.SAVED,
       message: 'hello world',
     };
     element.editing = true;
@@ -492,7 +492,7 @@
       },
       line: 5,
       path: 'test',
-      __draft: DraftState.SAVED,
+      state: DraftState.SAVED,
       message: 'hello world',
     };
     element.editing = true;
@@ -542,7 +542,7 @@
       element.changeNum = 42 as NumericChangeId;
       element.comment = {
         ...createComment(),
-        __draft: DraftState.SAVED,
+        state: DraftState.SAVED,
         path: '/path/to/file',
         line: 5,
       };
@@ -565,7 +565,7 @@
       await element.updateComplete;
       assert.isTrue(element.isSaveDisabled());
 
-      element.comment = {...element.comment, __draft: DraftState.SAVING};
+      element.comment = {...element.comment, state: DraftState.SAVING};
       await element.updateComplete;
       assert.isTrue(element.isSaveDisabled());
     });
@@ -627,7 +627,7 @@
         Promise.resolve({
           ...createUnsaved(),
           message: 'something, not important',
-          __draft: DraftState.ERROR,
+          state: DraftState.ERROR,
         })
       );
 
@@ -670,7 +670,7 @@
       const saveStub = sinon.stub(commentsModel, 'saveDraft');
       element.comment = {
         ...createComment(),
-        __draft: DraftState.SAVED,
+        state: DraftState.SAVED,
         unresolved: false,
       };
       await element.updateComplete;
@@ -797,14 +797,14 @@
 
       autoSavePromise.resolve({
         ...element.comment,
-        __draft: DraftState.SAVED,
+        state: DraftState.SAVED,
         message: 'auto save text',
         id: 'exp123' as UrlEncodedCommentId,
         updated: '2018-02-13 22:48:48.018000000' as Timestamp,
       });
       savePromise.resolve({
         ...element.comment,
-        __draft: DraftState.SAVED,
+        state: DraftState.SAVED,
         message: 'actual save text',
         id: 'exp123' as UrlEncodedCommentId,
         updated: '2018-02-13 22:48:49.018000000' as Timestamp,
@@ -829,7 +829,7 @@
         },
         line: 5,
         path: 'test',
-        __draft: DraftState.SAVED,
+        state: DraftState.SAVED,
         message: 'hello world',
       };
       element = await fixture(
diff --git a/polygerrit-ui/app/models/comments/comments-model.ts b/polygerrit-ui/app/models/comments/comments-model.ts
index f8e8be5..e74647b 100644
--- a/polygerrit-ui/app/models/comments/comments-model.ts
+++ b/polygerrit-ui/app/models/comments/comments-model.ts
@@ -60,7 +60,7 @@
   comments?: {[path: string]: CommentInfo[]};
   /** undefined means 'still loading' */
   robotComments?: {[path: string]: RobotCommentInfo[]};
-  // All drafts are DraftInfo objects and have `__draft` state set.
+  // All drafts are DraftInfo objects and have `state` state set.
   /** undefined means 'still loading' */
   drafts?: {[path: string]: DraftInfo[]};
   // Ported comments only affect `CommentThread` properties, not individual
@@ -580,7 +580,7 @@
       ...found,
       id: undefined,
       updated: undefined,
-      __draft: DraftState.UNSAVED,
+      state: DraftState.UNSAVED,
       client_id: uuid() as UrlEncodedCommentId,
     };
     await this.saveDraft(newDraft);
@@ -609,10 +609,10 @@
     assertIsDefined(this.changeNum, 'change number');
     assertIsDefined(draft.patch_set, 'patchset number of comment draft');
     assert(!!draft.message?.trim(), 'cannot save empty draft');
-    assert(draft.__draft !== DraftState.SAVING, 'saving already in progress');
+    assert(draft.state !== DraftState.SAVING, 'saving already in progress');
 
     // optimistic update
-    const draftSaving: DraftInfo = {...draft, __draft: DraftState.SAVING};
+    const draftSaving: DraftInfo = {...draft, state: DraftState.SAVING};
     this.modifyState(s => setDraft(s, draftSaving));
 
     // Saving the change number as to make sure that the response is still
@@ -637,7 +637,7 @@
       )) as unknown as CommentInfo;
     } catch (error) {
       if (showToast) this.handleFailedDraftRequest();
-      const draftError: DraftInfo = {...draft, __draft: DraftState.ERROR};
+      const draftError: DraftInfo = {...draft, state: DraftState.ERROR};
       this.modifyState(s => setDraft(s, draftError));
       return draftError;
     }
@@ -646,7 +646,7 @@
       ...draft,
       id: savedComment.id,
       updated: savedComment.updated,
-      __draft: DraftState.SAVED,
+      state: DraftState.SAVED,
     };
     timer.end({id: draftSaved.id});
     if (showToast) this.showEndRequest();
@@ -659,13 +659,13 @@
     const draft = this.lookupDraft(draftId);
     assertIsDefined(draft, `draft not found by id ${draftId}`);
     assertIsDefined(draft.patch_set, 'patchset number of comment draft');
-    assert(draft.__draft !== DraftState.SAVING, 'saving already in progress');
+    assert(draft.state !== DraftState.SAVING, 'saving already in progress');
 
     // optimistic update
     this.modifyState(s => deleteDraft(s, draft));
 
     // For "unsaved" drafts there is nothing to discard on the server side.
-    if (draft.__draft !== DraftState.UNSAVED) {
+    if (draft.state !== DraftState.UNSAVED) {
       assertIsDefined(draft.id, 'missing id');
       if (!draft.message?.trim()) throw new Error('empty draft');
       // Saving the change number as to make sure that the response is still
diff --git a/polygerrit-ui/app/test/test-data-generators.ts b/polygerrit-ui/app/test/test-data-generators.ts
index d5d58f2..a0a1ebd 100644
--- a/polygerrit-ui/app/test/test-data-generators.ts
+++ b/polygerrit-ui/app/test/test-data-generators.ts
@@ -843,7 +843,7 @@
 export function createDraft(extra: Partial<CommentInfo> = {}): DraftInfo {
   return {
     ...createComment(),
-    __draft: DraftState.SAVED,
+    state: DraftState.SAVED,
     ...extra,
   };
 }
@@ -851,7 +851,7 @@
 export function createUnsaved(extra: Partial<CommentInfo> = {}): DraftInfo {
   return {
     ...createComment(),
-    __draft: DraftState.UNSAVED,
+    state: DraftState.UNSAVED,
     client_id: uuid() as UrlEncodedCommentId,
     id: undefined,
     updated: undefined,
diff --git a/polygerrit-ui/app/types/common.ts b/polygerrit-ui/app/types/common.ts
index ecab4d4..4688b1f 100644
--- a/polygerrit-ui/app/types/common.ts
+++ b/polygerrit-ui/app/types/common.ts
@@ -727,8 +727,8 @@
 export type DraftInfo = Omit<CommentInfo, 'id' | 'updated'> & {
   // Must be set for all drafts.
   // Drafts received from the backend will be modified immediately with
-  // `__draft: SAVED` before allowing them to get into the model.
-  __draft: DraftState;
+  // `state: SAVED` before allowing them to get into the model.
+  state: DraftState;
   // Must be set for UNSAVED drafts. Can be set for other drafts.
   // Use the id() utility function for uniquely identifying drafts.
   client_id?: UrlEncodedCommentId;
@@ -762,33 +762,33 @@
 ): x is DraftInfo {
   return (
     !!x &&
-    (x as DraftInfo).__draft !== undefined &&
-    (x as DraftInfo).__draft !== DraftState.UNSAVED
+    (x as DraftInfo).state !== undefined &&
+    (x as DraftInfo).state !== DraftState.UNSAVED
   );
 }
 
 export function isUnsaved<T extends Comment>(
   x: T | DraftInfo | undefined
 ): x is DraftInfo {
-  return !!x && (x as DraftInfo).__draft === DraftState.UNSAVED;
+  return !!x && (x as DraftInfo).state === DraftState.UNSAVED;
 }
 
 export function isSaved<T extends Comment>(
   x: T | DraftInfo | undefined
 ): x is DraftInfo {
-  return !!x && (x as DraftInfo).__draft === DraftState.SAVED;
+  return !!x && (x as DraftInfo).state === DraftState.SAVED;
 }
 
 export function isSaving<T extends Comment>(
   x: T | DraftInfo | undefined
 ): x is DraftInfo {
-  return !!x && (x as DraftInfo).__draft === DraftState.SAVING;
+  return !!x && (x as DraftInfo).state === DraftState.SAVING;
 }
 
 export function isError<T extends Comment>(
   x: T | DraftInfo | undefined
 ): x is DraftInfo {
-  return !!x && (x as DraftInfo).__draft === DraftState.ERROR;
+  return !!x && (x as DraftInfo).state === DraftState.ERROR;
 }
 
 // TODO: Find a better name for this. Maybe this can become just `isDraft()`.
diff --git a/polygerrit-ui/app/utils/comment-util.ts b/polygerrit-ui/app/utils/comment-util.ts
index 2570708..cee7e2c 100644
--- a/polygerrit-ui/app/utils/comment-util.ts
+++ b/polygerrit-ui/app/utils/comment-util.ts
@@ -101,7 +101,7 @@
   return {
     message,
     unresolved,
-    __draft: DraftState.UNSAVED,
+    state: DraftState.UNSAVED,
     client_id: uuid() as UrlEncodedCommentId,
   };
 }
@@ -419,7 +419,7 @@
 }
 
 /**
- * Add __draft:SAVED to all drafts returned from server so that they can be told
+ * Add state:SAVED to all drafts returned from server so that they can be told
  * apart from published comments easily.
  */
 export function addDraftProp(
@@ -428,7 +428,7 @@
   const updated: {[path: string]: DraftInfo[]} = {};
   for (const filePath of Object.keys(draftsByPath)) {
     updated[filePath] = (draftsByPath[filePath] ?? []).map(draft => {
-      return {...draft, __draft: DraftState.SAVED};
+      return {...draft, state: DraftState.SAVED};
     });
   }
   return updated;
diff --git a/polygerrit-ui/app/utils/comment-util_test.ts b/polygerrit-ui/app/utils/comment-util_test.ts
index 8a37a95..49d387e 100644
--- a/polygerrit-ui/app/utils/comment-util_test.ts
+++ b/polygerrit-ui/app/utils/comment-util_test.ts
@@ -134,7 +134,7 @@
       {
         id: 'new_draft' as UrlEncodedCommentId,
         message: 'i do not like either of you',
-        __draft: DraftState.SAVED,
+        state: DraftState.SAVED,
         updated: '2015-12-20 15:01:20.396000000' as Timestamp,
       } as DraftInfo,
       {
@@ -180,7 +180,7 @@
         {
           id: 'new_draft' as UrlEncodedCommentId,
           message: 'i do not like either of you' as UrlEncodedCommentId,
-          __draft: DraftState.SAVED,
+          state: DraftState.SAVED,
           updated: '2015-12-20 15:01:20.396000000' as Timestamp,
           patch_set: 1 as RevisionPatchSetNum,
           path: 'some/path',