diff --git a/lib/shared/dm-ops/change-thread-subscription.js b/lib/shared/dm-ops/change-thread-subscription.js --- a/lib/shared/dm-ops/change-thread-subscription.js +++ b/lib/shared/dm-ops/change-thread-subscription.js @@ -35,11 +35,17 @@ member => member.id !== creatorID, ); const membersUpdate = [...otherMemberInfos, updatedCreatorMemberInfo]; + const currentUserUpdate = { + ...threadInfo.currentUser, + subscription, + }; const threadInfoUpdate = { ...threadInfo, members: membersUpdate, + currentUser: currentUserUpdate, }; + const updateInfos: Array = [ { type: updateTypes.UPDATE_THREAD, 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 @@ -1,7 +1,11 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; +import type { OutboundDMOperationSpecification } from './dm-ops/dm-op-utils.js'; +import { dmOperationSpecificationTypes } from './dm-ops/dm-op-utils.js'; +import { useProcessAndSendDMOperation } from './dm-ops/process-dm-ops.js'; import { threadIsSidebar } from './thread-utils.js'; import { updateSubscriptionActionTypes, @@ -10,7 +14,12 @@ import { useCanPromoteSidebar } from '../hooks/promote-sidebar.react.js'; import { createLoadingStatusSelector } from '../selectors/loading-selectors.js'; import { threadInfoSelector } from '../selectors/thread-selectors.js'; +import type { DMChangeThreadSubscriptionOperation } from '../types/dm-ops.js'; import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; +import { + thickThreadTypes, + threadTypeIsThick, +} from '../types/thread-types-enum.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -123,6 +132,49 @@ threadInfo.id, ]); + const viewerID = useSelector( + state => state.currentUserInfo && state.currentUserInfo.id, + ); + + const processAndSendDMOperation = useProcessAndSendDMOperation(); + + const updateDMSubscriptionPromise = React.useCallback(async () => { + invariant(viewerID, 'viewerID must be set'); + + const op: DMChangeThreadSubscriptionOperation = { + type: 'change_thread_subscription', + time: Date.now(), + threadID: threadInfo.id, + creatorID: viewerID, + subscription: { + home: notificationSettings !== 'muted', + pushNotifs: notificationSettings === 'home', + }, + }; + + const opSpecification: OutboundDMOperationSpecification = { + type: dmOperationSpecificationTypes.OUTBOUND, + op, + recipients: { + type: 'all_thread_members', + threadID: + threadInfo.type === thickThreadTypes.THICK_SIDEBAR && + threadInfo.parentThreadID + ? threadInfo.parentThreadID + : threadInfo.id, + }, + }; + + await processAndSendDMOperation(opSpecification); + onSuccessCallback(); + }, [ + onSuccessCallback, + viewerID, + threadInfo, + notificationSettings, + processAndSendDMOperation, + ]); + const updateSubscriptionLoadingStatus = useSelector( updateSubscriptionLoadingStatusSelector, ); @@ -135,11 +187,22 @@ return; } + if (threadTypeIsThick(threadInfo.type)) { + void updateDMSubscriptionPromise(); + return; + } + void dispatchActionPromise( updateSubscriptionActionTypes, updateSubscriptionPromise(), ); - }, [saveButtonDisabled, dispatchActionPromise, updateSubscriptionPromise]); + }, [ + saveButtonDisabled, + dispatchActionPromise, + updateSubscriptionPromise, + updateDMSubscriptionPromise, + threadInfo, + ]); const isSidebar = threadIsSidebar(threadInfo);