Revert "feat!: remove features related to the old thread page view"
This reverts commit 879d44aef99524c84719d91c628e772fba9335cb.
Reason for revert: It turns out the old reply editor can still be used
in the new thread page view by pressing the "R" key, and this can/will
make the CC communicate with the draft endpoints to save/retrieve
information.
Apart from this, some PEs were using the "old thread page" option as
well, even if it doesn't load all replies.
Finally, this revert also contains some changes to the modifications to
the data startup object so they work correctly (since now we have to use
StartupDataStorage, otherwise changes might not be saved).
Bug: twpowertools:124
Change-Id: Ie8153b9c8ef150b2417cb19b73bde0a5593876e2
diff --git a/src/features/Features.ts b/src/features/Features.ts
index 67c93aa..afcba59 100644
--- a/src/features/Features.ts
+++ b/src/features/Features.ts
@@ -5,6 +5,8 @@
import ExtraInfoFeature from './extraInfo/extraInfo.feature';
import WorkflowsFeature from './workflows/workflows.feature';
import CCDarkThemeFeature from './ccDarkTheme/ccDarkTheme.feature';
+import LoadDraftsFeature from './loadDrafts/loadDrafts.feature';
+import InteropThreadPageFeature from './interopThreadPage/interopThreadPage.feature';
export type ConcreteFeatureClass = { new (): Feature };
@@ -14,6 +16,8 @@
CCDarkThemeFeature,
ExtraInfoFeature,
InfiniteScrollFeature,
+ InteropThreadPageFeature,
+ LoadDraftsFeature,
WorkflowsFeature,
];
private initializedFeatures: Feature[];
diff --git a/src/features/interopThreadPage/interopThreadPage.feature.ts b/src/features/interopThreadPage/interopThreadPage.feature.ts
new file mode 100644
index 0000000..0d84075
--- /dev/null
+++ b/src/features/interopThreadPage/interopThreadPage.feature.ts
@@ -0,0 +1,16 @@
+import Feature from '../../common/architecture/features/Feature';
+import { ConcreteScript } from '../../common/architecture/scripts/Script';
+import { OptionCodename } from '../../common/options/optionsPrototype';
+import SetThreadPageInDataStartupScript from './scripts/setThreadPageInDataStartupScript.script';
+
+export default class InteropThreadPageFeature extends Feature {
+ public readonly scripts: ConcreteScript[] = [
+ SetThreadPageInDataStartupScript,
+ ];
+
+ readonly codename = 'interopThreadPage';
+ readonly relatedOptions: OptionCodename[] = [
+ 'interopthreadpage',
+ 'interopthreadpage_mode',
+ ];
+}
diff --git a/src/features/interopThreadPage/scripts/setThreadPageInDataStartupScript.script.ts b/src/features/interopThreadPage/scripts/setThreadPageInDataStartupScript.script.ts
new file mode 100644
index 0000000..32c17eb
--- /dev/null
+++ b/src/features/interopThreadPage/scripts/setThreadPageInDataStartupScript.script.ts
@@ -0,0 +1,53 @@
+import DependenciesProviderSingleton, {
+ OptionsProviderDependency,
+ StartupDataStorageDependency,
+} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
+import Script, {
+ ScriptEnvironment,
+ ScriptPage,
+ ScriptRunPhase,
+} from '../../../common/architecture/scripts/Script';
+
+const SMEI_RCE_THREAD_INTEROP = 22;
+
+export default class SetThreadPageInDataStartupScript extends Script {
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+ runPhase = ScriptRunPhase.Start;
+
+ async execute() {
+ const dependenciesProvider = DependenciesProviderSingleton.getInstance();
+ const optionsProvider = dependenciesProvider.getDependency(
+ OptionsProviderDependency,
+ );
+ if (await optionsProvider.isEnabled('interopthreadpage')) {
+ const startupDataStorage = dependenciesProvider.getDependency(
+ StartupDataStorageDependency,
+ );
+ const mode = await optionsProvider.getOptionValue(
+ 'interopthreadpage_mode',
+ );
+ startupDataStorage.enqueueModification((startupDataModel) => {
+ const index = startupDataModel.data[1][6].indexOf(
+ SMEI_RCE_THREAD_INTEROP,
+ );
+
+ switch (mode) {
+ case 'previous':
+ if (index > -1) {
+ startupDataModel.data[1][6].splice(index, 1);
+ }
+ break;
+
+ case 'next':
+ if (index == -1) {
+ startupDataModel.data[1][6].push(SMEI_RCE_THREAD_INTEROP);
+ }
+ break;
+ }
+ });
+ // NOTE: Workaround because otherwise the modifications would be applied too late.
+ startupDataStorage.applyModifications();
+ }
+ }
+}
diff --git a/src/features/loadDrafts/loadDrafts.feature.ts b/src/features/loadDrafts/loadDrafts.feature.ts
new file mode 100644
index 0000000..23f6873
--- /dev/null
+++ b/src/features/loadDrafts/loadDrafts.feature.ts
@@ -0,0 +1,13 @@
+import Feature from '../../common/architecture/features/Feature';
+import { ConcreteScript } from '../../common/architecture/scripts/Script';
+import { OptionCodename } from '../../common/options/optionsPrototype';
+import EnableLoadDraftsFlagInDataStartupScript from './scripts/setThreadPageInDataStartupScript.script';
+
+export default class LoadDraftsFeature extends Feature {
+ public readonly scripts: ConcreteScript[] = [
+ EnableLoadDraftsFlagInDataStartupScript,
+ ];
+
+ readonly codename = 'loadDrafts';
+ readonly relatedOptions: OptionCodename[] = ['loaddrafts'];
+}
diff --git a/src/features/loadDrafts/scripts/setThreadPageInDataStartupScript.script.ts b/src/features/loadDrafts/scripts/setThreadPageInDataStartupScript.script.ts
new file mode 100644
index 0000000..6319fb7
--- /dev/null
+++ b/src/features/loadDrafts/scripts/setThreadPageInDataStartupScript.script.ts
@@ -0,0 +1,32 @@
+import DependenciesProviderSingleton, {
+ OptionsProviderDependency,
+ StartupDataStorageDependency,
+} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
+import Script, {
+ ScriptEnvironment,
+ ScriptPage,
+ ScriptRunPhase,
+} from '../../../common/architecture/scripts/Script';
+
+export default class EnableLoadDraftsFlagInDataStartupScript extends Script {
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+ runPhase = ScriptRunPhase.Start;
+
+ async execute() {
+ const dependenciesProvider = DependenciesProviderSingleton.getInstance();
+ const optionsProvider = dependenciesProvider.getDependency(
+ OptionsProviderDependency,
+ );
+ if (await optionsProvider.isEnabled('loaddrafts')) {
+ const startupDataStorage = dependenciesProvider.getDependency(
+ StartupDataStorageDependency,
+ );
+ startupDataStorage.enqueueModification((startupDataModel) => {
+ startupDataModel.data[4][13] = true;
+ });
+ // NOTE: Workaround because otherwise the modifications would be applied too late.
+ startupDataStorage.applyModifications();
+ }
+ }
+}