addons/isl/src/messageSyncing.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {DiffId} from './types';
b69ab319
b69ab3110import {atom} from 'jotai';
b69ab3111import serverAPI from './ClientToServerAPI';
b69ab3112import {codeReviewProvider} from './codeReview/CodeReviewInfo';
b69ab3113
b69ab3114/**
b69ab3115 * In some cases, we need to explicitly disable message syncing after a failure.
b69ab3116 * This setting overrides the default value from the code review provider.
b69ab3117 * It's not intended to be set by users nor is it persisted across restarts.
b69ab3118 * When this is set, a warning will also be shown to the user.
b69ab3119 */
b69ab3120export const messageSyncingOverrideState = atom<boolean | null>(null);
b69ab3121
b69ab3122/** Whether message syncing is enabled for the current repo. */
b69ab3123export const messageSyncingEnabledState = atom(get => {
b69ab3124 const override = get(messageSyncingOverrideState);
b69ab3125 if (override != null) {
b69ab3126 return override;
b69ab3127 }
b69ab3128 const provider = get(codeReviewProvider);
b69ab3129 return provider?.enableMessageSyncing ?? false;
b69ab3130});
b69ab3131
b69ab3132export async function updateRemoteMessage(
b69ab3133 diffId: DiffId,
b69ab3134 title: string,
b69ab3135 description: string,
b69ab3136): Promise<void> {
b69ab3137 serverAPI.postMessage({type: 'updateRemoteDiffMessage', diffId, title, description});
b69ab3138 const response = await serverAPI.nextMessageMatching(
b69ab3139 'updatedRemoteDiffMessage',
b69ab3140 msg => msg.diffId === diffId,
b69ab3141 );
b69ab3142 if (response.error != null) {
b69ab3143 throw new Error(response.error);
b69ab3144 }
b69ab3145}