feat!: remove features related to the old thread page view

The old thread page view has been unusable for some time since the
introduction of nested replies in threads (since the old view doesn't
display them).

This CL removes all features related to that view:

- Block draft messages from being saved in Google servers.
- Activate the enableLoadingDraftMessages Community Console flag.
- Show the old thread page in the Community Console.

Fixed: twpowertools:124
Change-Id: I7fb815b7e1bf536a15a7bf76bcb2c1f3accdb648
diff --git a/src/contentScripts/communityConsole/main.js b/src/contentScripts/communityConsole/main.js
index 637e061..309e41b 100644
--- a/src/contentScripts/communityConsole/main.js
+++ b/src/contentScripts/communityConsole/main.js
@@ -58,9 +58,6 @@
   // Canned response tags (for the "import CR" popup for the workflows feature)
   'ec-canned-response-row .tags',
 
-  // Thread page main content
-  'ec-thread > .page > .material-content > div[role="list"]',
-
   // Thread page reply section (for the thread page toolbar)
   kRepliesSectionSelector,
 
@@ -141,12 +138,6 @@
       window.TWPTWorkflowsImport.addButtonIfEnabled(node);
     }
 
-    // Inject old thread page design warning if applicable
-    if (node.matches(
-            'ec-thread > .page > .material-content > div[role="list"]')) {
-      window.TWPTThreadPageDesignWarning.injectWarningIfApplicable(node);
-    }
-
     // Inject thread toolbar
     if (threadToolbar.shouldInject(node)) {
       threadToolbar.injectIfApplicable(node);
@@ -208,8 +199,7 @@
   flattenThreads = new FlattenThreads();
   reportDialogColorThemeFix = new ReportDialogColorThemeFix(options);
 
-  // threadPageDesignWarning and workflowsImport are
-  // initialized in start.js
+  // workflowsImport is initialized in start.js
 
   // Before starting the mutation Observer, check whether we missed any
   // mutations by manually checking whether some watched nodes already
diff --git a/src/contentScripts/communityConsole/start.js b/src/contentScripts/communityConsole/start.js
index 063f58a..cc54540 100644
--- a/src/contentScripts/communityConsole/start.js
+++ b/src/contentScripts/communityConsole/start.js
@@ -2,15 +2,11 @@
 import {getOptions} from '../../common/optionsUtils.js';
 
 import FlattenThreadsReplyActionHandler from './flattenThreads/replyActionHandler.js';
-import ThreadPageDesignWarning from './threadPageDesignWarning.js';
 import WorkflowsImport from './workflows/import.js';
 
-const SMEI_RCE_THREAD_INTEROP = 22;
-
 getOptions(null).then(options => {
   /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
-  if (options.loaddrafts || options.interopthreadpage ||
-      options.fixpekb269560789) {
+  if (options.fixpekb269560789) {
     var startup =
         JSON.parse(document.querySelector('html').getAttribute('data-startup'));
 
@@ -20,31 +16,12 @@
       }
     }
 
-    if (options.loaddrafts) {
-      startup[4][13] = true;
-    }
-
-    if (options.interopthreadpage) {
-      var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
-
-      switch (options.interopthreadpage_mode) {
-        case 'previous':
-          if (index > -1) startup[1][6].splice(index, 1);
-          break;
-
-        case 'next':
-          if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
-          break;
-      }
-    }
-
     document.querySelector('html').setAttribute(
         'data-startup', JSON.stringify(startup));
   }
 
   // Initialized here instead of in main.js so the first event is received if it
   // happens when the page loads.
-  window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
   window.TWPTWorkflowsImport = new WorkflowsImport();
 
   if (options.ccdarktheme) {
diff --git a/src/contentScripts/communityConsole/threadPageDesignWarning.js b/src/contentScripts/communityConsole/threadPageDesignWarning.js
deleted file mode 100644
index 155d916..0000000
--- a/src/contentScripts/communityConsole/threadPageDesignWarning.js
+++ /dev/null
@@ -1,162 +0,0 @@
-import {MDCTooltip} from '@material/tooltip';
-import {waitFor} from 'poll-until-promise';
-
-import {parseUrl} from '../../common/commonUtils.js';
-import {injectStylesheet} from '../../common/contentScriptsUtils.js';
-import {getDocURL} from '../../common/extUtils.js';
-import {getOptions} from '../../common/optionsUtils.js';
-
-import {createExtBadge} from './utils/common.js';
-
-const kSMEINestedReplies = 15;
-const kViewThreadResponse = 'TWPT_ViewThreadResponse';
-
-export default class ThreadPageDesignWarning {
-  constructor() {
-    this.lastThread = {
-      body: {},
-      id: -1,
-      timestamp: 0,
-    };
-    this.setUpHandler();
-
-    // We have to save whether the old UI was enabled at startup, since that's
-    // the moment when it takes effect. If the option changes while the tab is
-    // open, it won't take effect.
-    getOptions([
-      'interopthreadpage', 'interopthreadpage_mode'
-    ]).then(options => {
-      this.shouldShowWarning = options.interopthreadpage &&
-          options.interopthreadpage_mode == 'previous';
-
-      if (this.shouldShowWarning) {
-        injectStylesheet(
-            chrome.runtime.getURL('css/thread_page_design_warning.css'));
-      } else {
-        this.removeHandler();
-      }
-    });
-
-    this.isExperimentEnabled = this.isNestedRepliesExperimentEnabled();
-  }
-
-  isNestedRepliesExperimentEnabled() {
-    if (!document.documentElement.hasAttribute('data-startup')) return false;
-
-    let startup =
-        JSON.parse(document.documentElement.getAttribute('data-startup'));
-    return startup?.[1]?.[6]?.includes?.(kSMEINestedReplies);
-  }
-
-  eventHandler(e) {
-    if (e.detail.id < this.lastThread.id) return;
-
-    this.lastThread = {
-      body: e.detail.body,
-      id: e.detail.id,
-      timestamp: Date.now(),
-    };
-  }
-
-  setUpHandler() {
-    window.addEventListener(kViewThreadResponse, this.eventHandler.bind(this));
-  }
-
-  removeHandler() {
-    window.removeEventListener(
-        kViewThreadResponse, this.eventHandler.bind(this));
-  }
-
-  injectWarning(content) {
-    let div = document.createElement('div');
-    div.classList.add('TWPT-warning');
-
-    let icon = document.createElement('material-icon');
-    icon.classList.add('TWPT-warning--icon');
-
-    let iconContent = document.createElement('i');
-    iconContent.classList.add('material-icon-i', 'material-icons-extended');
-    iconContent.setAttribute('role', 'img');
-    iconContent.setAttribute('aria-hidden', 'true');
-    iconContent.textContent = 'warning';
-
-    icon.append(iconContent);
-
-    let text = document.createElement('div');
-    text.classList.add('TWPT-warning--text');
-    text.textContent =
-        chrome.i18n.getMessage('inject_threadpagedesign_warning');
-
-    let btn = document.createElement('a');
-    btn.classList.add('TWPT-warning--btn');
-    btn.href =
-        getDocURL('features.md#Thread-page-design-in-the-Community-Console');
-    btn.setAttribute('target', '_blank');
-    btn.setAttribute('rel', 'noopener noreferrer');
-
-    const [badge, badgeTooltip] = createExtBadge();
-
-    let btnText = document.createElement('div');
-    btnText.textContent = chrome.i18n.getMessage('btn_learnmore');
-
-    btn.append(badge, btnText);
-
-    div.append(icon, text, btn);
-    content.prepend(div);
-
-    new MDCTooltip(badgeTooltip);
-  }
-
-  injectWarningIfApplicable(content) {
-    return waitFor(
-               () => {
-                 if (this.shouldShowWarning === undefined)
-                   return Promise.reject(
-                       new Error('shouldShowWarning is not defined.'));
-
-                 return Promise.resolve({result: this.shouldShowWarning});
-               },
-               {
-                 interval: 500,
-                 timeout: 10 * 1000,
-               })
-        .then(preShouldShowWarning => {
-          if (!preShouldShowWarning.result) return;
-
-          // If the global SMEI experiment is enabled, all threads use nested
-          // replies, so we'll skip the per-thread check and always show the
-          // warning banner.
-          if (this.isExperimentEnabled) return Promise.resolve({result: true});
-
-          let currentThread = parseUrl(location.href);
-          if (currentThread === false)
-            throw new Error('current thread id cannot be parsed.');
-
-          return waitFor(() => {
-            let now = Date.now();
-            let lastThreadInfo = this.lastThread.body['1']?.['2']?.['1'];
-            if (now - this.lastThread.timestamp > 30 * 1000 ||
-                lastThreadInfo?.['1'] != currentThread.thread ||
-                lastThreadInfo?.['3'] != currentThread.forum)
-              throw new Error(
-                  'cannot obtain information about current thread.');
-
-            // If the messageOrGap field contains any items, the thread is using
-            // nested replies. Otherwise, it probably isn't using them.
-            return Promise.resolve(
-                {result: this.lastThread.body['1']?.['40']?.length > 0});
-          }, {
-            interval: 500,
-            timeout: 10 * 1000,
-          });
-        })
-        .then(shouldShowWarning => {
-          if (shouldShowWarning.result) this.injectWarning(content);
-        })
-        .catch(err => {
-          console.error(
-              '[threadPageDesignWarning] An error ocurred while trying to decide whether to show warning: ',
-              err);
-        });
-  }
-}