diff --git a/lib/shared/dm-ops/leave-thread-spec.js b/lib/shared/dm-ops/leave-thread-spec.js --- a/lib/shared/dm-ops/leave-thread-spec.js +++ b/lib/shared/dm-ops/leave-thread-spec.js @@ -9,8 +9,12 @@ } from './dm-op-spec.js'; import type { DMLeaveThreadOperation } from '../../types/dm-ops.js'; import { messageTypes } from '../../types/message-types-enum.js'; +import type { ThickRawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from '../../types/thread-types-enum.js'; +import type { RawThreadInfos } from '../../types/thread-types.js'; import { updateTypes } from '../../types/update-types-enum.js'; +import type { ClientUpdateInfo } from '../../types/update-types.js'; +import { values } from '../../utils/objects.js'; import { rawMessageInfoFromMessageData } from '../message-utils.js'; import { userIsMember } from '../thread-utils.js'; @@ -24,6 +28,29 @@ }; } +function createLeaveThreadSubthreadsUpdates( + dmOperation: DMLeaveThreadOperation, + threadInfo: ThickRawThreadInfo, + viewerID: string, + threadInfos: RawThreadInfos, +): $ReadOnlyArray { + const updates = []; + for (const thread of values(threadInfos)) { + if (thread.parentThreadID !== threadInfo.id) { + continue; + } + + updates.push({ + type: updateTypes.DELETE_THREAD, + id: uuid.v4(), + time: dmOperation.time, + threadID: thread.id, + }); + } + + return updates; +} + const leaveThreadSpec: DMOperationSpec = Object.freeze({ notificationsCreationData: async (dmOperation: DMLeaveThreadOperation) => { const messageData = createMessageDataFromDMOperation(dmOperation); @@ -60,6 +87,12 @@ time, threadID, }, + ...createLeaveThreadSubthreadsUpdates( + dmOperation, + threadInfo, + viewerID, + utilities.threadInfos, + ), ], }; }