Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33341364
D13238.1768922738.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D13238.1768922738.diff
View Options
diff --git a/lib/actions/activity-actions.js b/lib/actions/activity-actions.js
--- a/lib/actions/activity-actions.js
+++ b/lib/actions/activity-actions.js
@@ -1,17 +1,27 @@
// @flow
+import invariant from 'invariant';
+import * as React from 'react';
+
import {
extractKeyserverIDFromID,
extractKeyserverIDFromIDOptional,
} from '../keyserver-conn/keyserver-call-utils.js';
import { useKeyserverCall } from '../keyserver-conn/keyserver-call.js';
import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js';
+import type { OutboundDMOperationSpecification } from '../shared/dm-ops/dm-op-utils.js';
+import { dmOperationSpecificationTypes } from '../shared/dm-ops/dm-op-utils.js';
+import { useProcessAndSendDMOperation } from '../shared/dm-ops/process-dm-ops.js';
import type {
ActivityUpdate,
ActivityUpdateSuccessPayload,
SetThreadUnreadStatusPayload,
SetThreadUnreadStatusRequest,
} from '../types/activity-types.js';
+import type { DMChangeThreadReadStatusOperation } from '../types/dm-ops.js';
+import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types';
+import { threadTypeIsThick } from '../types/thread-types-enum.js';
+import { useSelector } from '../utils/redux-utils.js';
export type UpdateActivityInput = {
+activityUpdates: $ReadOnlyArray<ActivityUpdate>,
@@ -98,10 +108,49 @@
};
};
-function useSetThreadUnreadStatus(): (
+function useSetThreadUnreadStatus(
+ threadInfo: ThreadInfo,
+): (
request: SetThreadUnreadStatusRequest,
) => Promise<SetThreadUnreadStatusPayload> {
- return useKeyserverCall(setThreadUnreadStatus);
+ const viewerID = useSelector(
+ state => state.currentUserInfo && state.currentUserInfo.id,
+ );
+ const processAndSendDMOperation = useProcessAndSendDMOperation();
+ const keyserverCall = useKeyserverCall(setThreadUnreadStatus);
+
+ return React.useCallback(
+ async (input: SetThreadUnreadStatusRequest) => {
+ if (!threadTypeIsThick(threadInfo.type)) {
+ return await keyserverCall(input);
+ }
+
+ invariant(viewerID, 'viewerID must be set');
+ const op: DMChangeThreadReadStatusOperation = {
+ type: 'change_thread_read_status',
+ time: Date.now(),
+ threadID: threadInfo.id,
+ creatorID: viewerID,
+ unread: !threadInfo.currentUser.unread,
+ };
+
+ const opSpecification: OutboundDMOperationSpecification = {
+ type: dmOperationSpecificationTypes.OUTBOUND,
+ op,
+ recipients: {
+ type: 'self_devices',
+ },
+ };
+
+ await processAndSendDMOperation(opSpecification);
+ return {
+ resetToUnread: false,
+ threadID: threadInfo.id,
+ };
+ },
+
+ [keyserverCall, threadInfo, viewerID, processAndSendDMOperation],
+ );
}
export {
diff --git a/lib/hooks/toggle-unread-status.js b/lib/hooks/toggle-unread-status.js
--- a/lib/hooks/toggle-unread-status.js
+++ b/lib/hooks/toggle-unread-status.js
@@ -22,7 +22,9 @@
const { currentUser } = threadInfo;
const boundSetThreadUnreadStatus: (
request: SetThreadUnreadStatusRequest,
- ) => Promise<SetThreadUnreadStatusPayload> = useSetThreadUnreadStatus();
+ ) => Promise<SetThreadUnreadStatusPayload> =
+ useSetThreadUnreadStatus(threadInfo);
+
const toggleUnreadStatus = React.useCallback(() => {
const request = {
threadID: threadInfo.id,
@@ -40,7 +42,7 @@
);
afterAction();
}, [
- threadInfo.id,
+ threadInfo,
currentUser.unread,
mostRecentNonLocalMessage,
dispatchActionPromise,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 20, 3:25 PM (6 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5961345
Default Alt Text
D13238.1768922738.diff (3 KB)
Attached To
Mode
D13238: Implement maunally marking DM thread as read/unread
Attached
Detach File
Event Timeline
Log In to Comment