2025-03-17 20:37:14 +05:30
|
|
|
/*
|
|
|
|
|
* Copyright 2025 New Vector Ltd.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
* Please see LICENSE files in the repository root for full details.
|
|
|
|
|
*/
|
2025-04-24 16:03:39 +01:00
|
|
|
import { useCallback } from "react";
|
2025-03-17 20:37:14 +05:30
|
|
|
|
|
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
|
|
|
|
import { SettingLevel } from "../../../settings/SettingLevel";
|
2025-04-24 16:03:39 +01:00
|
|
|
import { useSettingValue } from "../../../hooks/useSettings";
|
2025-03-17 20:37:14 +05:30
|
|
|
|
|
|
|
|
interface MessagePreviewToggleState {
|
|
|
|
|
shouldShowMessagePreview: boolean;
|
|
|
|
|
toggleMessagePreview: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This hook:
|
|
|
|
|
* - Provides a state that tracks whether message previews are turned on or off.
|
|
|
|
|
* - Provides a function to toggle message previews.
|
|
|
|
|
*/
|
|
|
|
|
export function useMessagePreviewToggle(): MessagePreviewToggleState {
|
2025-04-24 16:03:39 +01:00
|
|
|
const shouldShowMessagePreview = useSettingValue("RoomList.showMessagePreview");
|
2025-03-17 20:37:14 +05:30
|
|
|
|
|
|
|
|
const toggleMessagePreview = useCallback((): void => {
|
2025-04-24 16:03:39 +01:00
|
|
|
const toggled = !shouldShowMessagePreview;
|
|
|
|
|
SettingsStore.setValue("RoomList.showMessagePreview", null, SettingLevel.DEVICE, toggled);
|
|
|
|
|
}, [shouldShowMessagePreview]);
|
2025-03-17 20:37:14 +05:30
|
|
|
|
|
|
|
|
return { toggleMessagePreview, shouldShowMessagePreview };
|
|
|
|
|
}
|