Workflows: add mark as read/unread actions
Fixed: twpowertools:147
Change-Id: I6bb2363256cfd2a0ff3aafb4df71f24561576b27
diff --git a/src/contentScripts/communityConsole/workflows/actionRunners/readState.js b/src/contentScripts/communityConsole/workflows/actionRunners/readState.js
new file mode 100644
index 0000000..73d9a4f
--- /dev/null
+++ b/src/contentScripts/communityConsole/workflows/actionRunners/readState.js
@@ -0,0 +1,21 @@
+import {CCApi} from '../../../../common/api.js';
+import {getAuthUser} from '../../../../common/communityConsoleUtils.js';
+
+export default class ReadStateRunner {
+ execute(readState, thread) {
+ // Although this should in theory be the last message ID, it seems like
+ // setting 0 marks the entire thread as read anyways.
+ const lastMessageId = readState ? '0' : '-1';
+
+ return CCApi(
+ 'SetUserReadStateBulk', {
+ // bulkItem:
+ 1: [{
+ 1: thread.forumId,
+ 2: thread.threadId,
+ 3: lastMessageId,
+ }],
+ },
+ /* authenticated = */ true, getAuthUser());
+ }
+}