Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3350156
D13289.id44100.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13289.id44100.diff
View Options
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -78,10 +78,7 @@
SubscriptionUpdateRequest,
SubscriptionUpdateResult,
} from '../types/subscription-types.js';
-import {
- thickThreadTypes,
- threadTypeIsThick,
-} from '../types/thread-types-enum.js';
+import { thickThreadTypes } from '../types/thread-types-enum.js';
import type { RawThreadInfos } from '../types/thread-types.js';
import {
userActionsP2PMessageTypes,
@@ -1209,9 +1206,20 @@
};
};
-function useUpdateSubscription(
- threadInfo: ThreadInfo,
-): (input: SubscriptionUpdateRequest) => Promise<SubscriptionUpdateResult> {
+type UseUpdateSubscriptionInput = $ReadOnly<
+ | {
+ +thick: false,
+ ...SubscriptionUpdateRequest,
+ }
+ | {
+ +thick: true,
+ +threadInfo: ThreadInfo,
+ ...SubscriptionUpdateRequest,
+ },
+>;
+function useUpdateSubscription(): (
+ input: UseUpdateSubscriptionInput,
+) => Promise<SubscriptionUpdateResult> {
const processAndSendDMOperation = useProcessAndSendDMOperation();
const viewerID = useSelector(
state => state.currentUserInfo && state.currentUserInfo.id,
@@ -1219,16 +1227,20 @@
const keyserverCall = useKeyserverCall(updateSubscription);
return React.useCallback(
- async (input: SubscriptionUpdateRequest) => {
- if (!threadTypeIsThick(threadInfo.type)) {
- return await keyserverCall(input);
+ async (input: UseUpdateSubscriptionInput) => {
+ if (!input.thick) {
+ const { thick, ...rest } = input;
+ return await keyserverCall({ ...rest });
}
invariant(viewerID, 'viewerID must be set');
+
+ const { threadInfo, updatedFields } = input;
const subscription = {
...threadInfo.currentUser.subscription,
- ...input.updatedFields,
+ ...updatedFields,
};
+
const op: DMChangeThreadSubscriptionOperation = {
type: 'change_thread_subscription',
time: Date.now(),
@@ -1253,7 +1265,7 @@
await processAndSendDMOperation(opSpecification);
return { threadID: threadInfo.id, subscription };
},
- [keyserverCall, processAndSendDMOperation, viewerID, threadInfo],
+ [keyserverCall, processAndSendDMOperation, viewerID],
);
}
diff --git a/lib/shared/thread-settings-notifications-utils.js b/lib/shared/thread-settings-notifications-utils.js
--- a/lib/shared/thread-settings-notifications-utils.js
+++ b/lib/shared/thread-settings-notifications-utils.js
@@ -11,6 +11,7 @@
import { createLoadingStatusSelector } from '../selectors/loading-selectors.js';
import { threadInfoSelector } from '../selectors/thread-selectors.js';
import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
+import { threadTypeIsThick } from '../types/thread-types-enum.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector } from '../utils/redux-utils.js';
@@ -102,16 +103,28 @@
const dispatchActionPromise = useDispatchActionPromise();
- const callUpdateSubscription = useUpdateSubscription(threadInfo);
+ const callUpdateSubscription = useUpdateSubscription();
const updateSubscriptionPromise = React.useCallback(async () => {
- const res = await callUpdateSubscription({
+ const updateSubscriptionRequest = {
threadID: threadInfo.id,
updatedFields: {
home: notificationSettings !== 'muted',
pushNotifs: notificationSettings === 'home',
},
- });
+ };
+ const updateSubscriptionInput = threadTypeIsThick(threadInfo.type)
+ ? {
+ thick: true,
+ threadInfo,
+ ...updateSubscriptionRequest,
+ }
+ : {
+ thick: false,
+ ...updateSubscriptionRequest,
+ };
+
+ const res = await callUpdateSubscription(updateSubscriptionInput);
onSuccessCallback();
@@ -120,7 +133,7 @@
callUpdateSubscription,
notificationSettings,
onSuccessCallback,
- threadInfo.id,
+ threadInfo,
]);
const updateSubscriptionLoadingStatus = useSelector(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 9:02 PM (20 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2571487
Default Alt Text
D13289.id44100.diff (4 KB)
Attached To
Mode
D13289: Update input type of useUpdateSubscription
Attached
Detach File
Event Timeline
Log In to Comment