| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {DiffId} from './types'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import {atom} from 'jotai'; |
| b69ab31 | | | 11 | import serverAPI from './ClientToServerAPI'; |
| b69ab31 | | | 12 | import {codeReviewProvider} from './codeReview/CodeReviewInfo'; |
| b69ab31 | | | 13 | |
| b69ab31 | | | 14 | /** |
| b69ab31 | | | 15 | * In some cases, we need to explicitly disable message syncing after a failure. |
| b69ab31 | | | 16 | * This setting overrides the default value from the code review provider. |
| b69ab31 | | | 17 | * It's not intended to be set by users nor is it persisted across restarts. |
| b69ab31 | | | 18 | * When this is set, a warning will also be shown to the user. |
| b69ab31 | | | 19 | */ |
| b69ab31 | | | 20 | export const messageSyncingOverrideState = atom<boolean | null>(null); |
| b69ab31 | | | 21 | |
| b69ab31 | | | 22 | /** Whether message syncing is enabled for the current repo. */ |
| b69ab31 | | | 23 | export const messageSyncingEnabledState = atom(get => { |
| b69ab31 | | | 24 | const override = get(messageSyncingOverrideState); |
| b69ab31 | | | 25 | if (override != null) { |
| b69ab31 | | | 26 | return override; |
| b69ab31 | | | 27 | } |
| b69ab31 | | | 28 | const provider = get(codeReviewProvider); |
| b69ab31 | | | 29 | return provider?.enableMessageSyncing ?? false; |
| b69ab31 | | | 30 | }); |
| b69ab31 | | | 31 | |
| b69ab31 | | | 32 | export async function updateRemoteMessage( |
| b69ab31 | | | 33 | diffId: DiffId, |
| b69ab31 | | | 34 | title: string, |
| b69ab31 | | | 35 | description: string, |
| b69ab31 | | | 36 | ): Promise<void> { |
| b69ab31 | | | 37 | serverAPI.postMessage({type: 'updateRemoteDiffMessage', diffId, title, description}); |
| b69ab31 | | | 38 | const response = await serverAPI.nextMessageMatching( |
| b69ab31 | | | 39 | 'updatedRemoteDiffMessage', |
| b69ab31 | | | 40 | msg => msg.diffId === diffId, |
| b69ab31 | | | 41 | ); |
| b69ab31 | | | 42 | if (response.error != null) { |
| b69ab31 | | | 43 | throw new Error(response.error); |
| b69ab31 | | | 44 | } |
| b69ab31 | | | 45 | } |