From ba80452ac191dc31d58810cc86d77dd666371299 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 19 Sep 2025 14:35:07 +0200 Subject: [PATCH] Settings: Fix notifications checkbox logic (#6211) --- src/api/gramjs/methods/chats.ts | 16 +++++----- src/api/gramjs/methods/settings.ts | 5 +-- src/api/gramjs/scheduleUnmute.ts | 12 +++---- src/api/gramjs/updates/mtpUpdateHandler.ts | 8 +++-- src/components/common/profile/ChatExtra.tsx | 13 +++++--- src/components/left/MuteChatModal.tsx | 4 +-- src/components/left/main/Chat.tsx | 13 ++++++++ src/components/left/main/Topic.tsx | 7 +++++ .../left/main/hooks/useTopicContextActions.ts | 7 +++-- .../left/search/LeftSearchResultChat.tsx | 9 ++++-- .../left/settings/SettingsNotifications.tsx | 26 +++++++++------- src/components/middle/HeaderMenuContainer.tsx | 3 +- .../right/management/ManageUser.tsx | 31 ++++++++++++------- src/config.ts | 3 ++ src/global/actions/api/chats.ts | 11 ++----- src/global/actions/api/settings.ts | 15 ++++++--- src/global/actions/api/users.ts | 4 +-- src/global/types/actions.ts | 8 ++--- src/hooks/useChatContextActions.ts | 7 +++-- 19 files changed, 123 insertions(+), 79 deletions(-) diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index 6da6ded2a..05a4fab8e 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -27,7 +27,6 @@ import { ARCHIVED_FOLDER_ID, DEBUG, GENERAL_TOPIC_ID, - MAX_INT_32, MEMBERS_LOAD_SLICE, SERVICE_NOTIFICATIONS_USER_ID, TOPICS_SLICE, @@ -201,7 +200,9 @@ export async function fetchChats({ if (Object.values(omitUndefined(notifySettings)).length) { notifyExceptionById[chat.id] = notifySettings; - scheduleMutedChatUpdate(chat.id, notifySettings.mutedUntil, sendApiUpdate); + if (notifySettings.mutedUntil) { + scheduleMutedChatUpdate(chat.id, notifySettings.mutedUntil, sendApiUpdate); + } } if (withPinned && dialog.pinned) { @@ -512,7 +513,9 @@ export async function requestChatUpdate({ const notifySettings = buildApiPeerNotifySettings(dialog.notifySettings); - scheduleMutedChatUpdate(chatUpdate.id, notifySettings.mutedUntil, sendApiUpdate); + if (notifySettings.mutedUntil) { + scheduleMutedChatUpdate(chatUpdate.id, notifySettings.mutedUntil, sendApiUpdate); + } } export function saveDraft({ @@ -798,13 +801,10 @@ export function updateChatNotifySettings({ } export function updateTopicMutedState({ - chat, topicId, isMuted, mutedUntil = 0, + chat, topicId, mutedUntil, }: { - chat: ApiChat; topicId: number; isMuted?: boolean; mutedUntil?: number; + chat: ApiChat; topicId: number; mutedUntil: number; }) { - if (isMuted && !mutedUntil) { - mutedUntil = MAX_INT_32; - } invokeRequest(new GramJs.account.UpdateNotifySettings({ peer: new GramJs.InputNotifyForumTopic({ peer: buildInputPeer(chat.id, chat.accessHash), diff --git a/src/api/gramjs/methods/settings.ts b/src/api/gramjs/methods/settings.ts index ea4c16aca..bd7c8d631 100644 --- a/src/api/gramjs/methods/settings.ts +++ b/src/api/gramjs/methods/settings.ts @@ -19,7 +19,8 @@ import type { import { ACCEPTABLE_USERNAME_ERRORS, LANG_PACK, - MAX_INT_32, + MUTE_INDEFINITE_TIMESTAMP, + UNMUTE_TIMESTAMP, } from '../../../config'; import { buildCollectionByKey } from '../../../util/iteratees'; import { BLOCKED_LIST_LIMIT } from '../../../limits'; @@ -394,7 +395,7 @@ export function updateNotificationSettings(peerType: ApiNotifyPeerType, { const settings = { showPreviews: shouldShowPreviews, - muteUntil: isMuted ? MAX_INT_32 : 0, + muteUntil: isMuted ? MUTE_INDEFINITE_TIMESTAMP : UNMUTE_TIMESTAMP, }; return invokeRequest(new GramJs.account.UpdateNotifySettings({ diff --git a/src/api/gramjs/scheduleUnmute.ts b/src/api/gramjs/scheduleUnmute.ts index 98fa12d2f..9b233891a 100644 --- a/src/api/gramjs/scheduleUnmute.ts +++ b/src/api/gramjs/scheduleUnmute.ts @@ -1,6 +1,6 @@ import type { OnApiUpdate } from '../types'; -import { MAX_INT_32 } from '../../config'; +import { MUTE_INDEFINITE_TIMESTAMP } from '../../config'; import { getServerTime } from '../../util/serverTime'; type UnmuteQueueItem = { chatId: string; topicId?: number; mutedUntil: number }; @@ -12,7 +12,7 @@ const scheduleUnmute = (item: UnmuteQueueItem, onUpdate: NoneToVoidFunction) => clearTimeout(unmuteTimers.get(id)); unmuteTimers.delete(id); } - if (item.mutedUntil === MAX_INT_32 || item.mutedUntil <= getServerTime()) return; + if (item.mutedUntil === MUTE_INDEFINITE_TIMESTAMP || item.mutedUntil <= getServerTime()) return; unmuteQueue.push(item); unmuteQueue.sort((a, b) => b.mutedUntil - a.mutedUntil); const next = unmuteQueue.pop(); @@ -27,7 +27,7 @@ const scheduleUnmute = (item: UnmuteQueueItem, onUpdate: NoneToVoidFunction) => unmuteTimers.set(id, timer); }; -export function scheduleMutedChatUpdate(chatId: string, mutedUntil = 0, onUpdate: OnApiUpdate) { +export function scheduleMutedChatUpdate(chatId: string, mutedUntil: number, onUpdate: OnApiUpdate) { scheduleUnmute({ chatId, mutedUntil, @@ -35,12 +35,12 @@ export function scheduleMutedChatUpdate(chatId: string, mutedUntil = 0, onUpdate '@type': 'updateChatNotifySettings', chatId, settings: { - mutedUntil: 0, + mutedUntil: undefined, }, })); } -export function scheduleMutedTopicUpdate(chatId: string, topicId: number, mutedUntil = 0, onUpdate: OnApiUpdate) { +export function scheduleMutedTopicUpdate(chatId: string, topicId: number, mutedUntil: number, onUpdate: OnApiUpdate) { scheduleUnmute({ chatId, topicId, @@ -50,7 +50,7 @@ export function scheduleMutedTopicUpdate(chatId: string, topicId: number, mutedU chatId, topicId, settings: { - mutedUntil: 0, + mutedUntil: undefined, }, })); } diff --git a/src/api/gramjs/updates/mtpUpdateHandler.ts b/src/api/gramjs/updates/mtpUpdateHandler.ts index 03048b304..61666135d 100644 --- a/src/api/gramjs/updates/mtpUpdateHandler.ts +++ b/src/api/gramjs/updates/mtpUpdateHandler.ts @@ -803,7 +803,9 @@ export function updater(update: Update) { if (notifyPeer instanceof GramJs.NotifyPeer) { const peerId = getApiChatIdFromMtpPeer(notifyPeer.peer); - scheduleMutedChatUpdate(peerId, settings.mutedUntil, sendApiUpdate); + if (settings.mutedUntil) { + scheduleMutedChatUpdate(peerId, settings.mutedUntil, sendApiUpdate); + } sendApiUpdate({ '@type': 'updateChatNotifySettings', chatId: peerId, @@ -814,7 +816,9 @@ export function updater(update: Update) { if (notifyPeer instanceof GramJs.NotifyForumTopic) { const peerId = getApiChatIdFromMtpPeer(notifyPeer.peer); - scheduleMutedTopicUpdate(peerId, notifyPeer.topMsgId, settings.mutedUntil, sendApiUpdate); + if (settings.mutedUntil) { + scheduleMutedTopicUpdate(peerId, notifyPeer.topMsgId, settings.mutedUntil, sendApiUpdate); + } sendApiUpdate({ '@type': 'updateTopicNotifySettings', chatId: peerId, diff --git a/src/components/common/profile/ChatExtra.tsx b/src/components/common/profile/ChatExtra.tsx index 2e4970d28..56ea29679 100644 --- a/src/components/common/profile/ChatExtra.tsx +++ b/src/components/common/profile/ChatExtra.tsx @@ -15,7 +15,9 @@ import type { import type { BotAppPermissions } from '../../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; -import { FRAGMENT_PHONE_CODE, FRAGMENT_PHONE_LENGTH } from '../../../config'; +import { + FRAGMENT_PHONE_CODE, FRAGMENT_PHONE_LENGTH, MUTE_INDEFINITE_TIMESTAMP, UNMUTE_TIMESTAMP, +} from '../../../config'; import { buildStaticMapHash, getChatLink, @@ -202,15 +204,16 @@ const ChatExtra: FC = ({ openMapModal({ geoPoint: geo, zoom }); }); - const handleNotificationChange = useLastCallback(() => { + const handleToggleNotifications = useLastCallback(() => { + const mutedUntil = isMuted ? UNMUTE_TIMESTAMP : MUTE_INDEFINITE_TIMESTAMP; if (isTopicInfo) { updateTopicMutedState({ chatId: chatId!, topicId: topicId!, - isMuted: !isMuted, + mutedUntil, }); } else { - updateChatMutedState({ chatId: chatId!, isMuted: !isMuted }); + updateChatMutedState({ chatId: chatId!, mutedUntil }); } }); @@ -415,7 +418,7 @@ const ChatExtra: FC = ({ )} {!isInSettings && ( - + {oldLang('Notifications')} = ({ const handleSubmit = useCallback(() => { let mutedUntil: number; if (muteUntilOption === MuteDuration.Forever) { - mutedUntil = MAX_INT_32; + mutedUntil = MUTE_INDEFINITE_TIMESTAMP; } else { mutedUntil = Math.floor(Date.now() / 1000) + Number(muteUntilOption); } diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index 14285ada8..397982460 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -20,6 +20,7 @@ import type { ChatAnimationTypes } from './hooks'; import { MAIN_THREAD_ID } from '../../../api/types'; import { StoryViewerOrigin } from '../../../types'; +import { UNMUTE_TIMESTAMP } from '../../../config'; import { groupStatefulContent, isUserOnline, @@ -81,6 +82,7 @@ import ChatCallStatus from './ChatCallStatus'; import ChatTags from './ChatTags'; import './Chat.scss'; + type OwnProps = { chatId: string; folderId?: number; @@ -185,6 +187,7 @@ const Chat: FC = ({ setShouldCloseRightColumn, reportMessages, openFrozenAccountModal, + updateChatMutedState, } = getActions(); const { isMobile } = useAppLayout(); @@ -292,6 +295,15 @@ const Chat: FC = ({ openMuteModal(); }); + const handleUnmute = useLastCallback(() => { + if (isAccountFrozen) { + openFrozenAccountModal(); + return; + } + + updateChatMutedState({ chatId, mutedUntil: UNMUTE_TIMESTAMP }); + }); + const handleChatFolderChange = useLastCallback(() => { markRenderChatFolderModal(); openChatFolderModal(); @@ -312,6 +324,7 @@ const Chat: FC = ({ user, handleDelete, handleMute, + handleUnmute, handleChatFolderChange, handleReport, folderId, diff --git a/src/components/left/main/Topic.tsx b/src/components/left/main/Topic.tsx index 140f51862..08d0ee425 100644 --- a/src/components/left/main/Topic.tsx +++ b/src/components/left/main/Topic.tsx @@ -9,6 +9,7 @@ import type { import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; import type { ChatAnimationTypes } from './hooks'; +import { UNMUTE_TIMESTAMP } from '../../../config'; import { groupStatefulContent } from '../../../global/helpers'; import { getIsChatMuted } from '../../../global/helpers/notifications'; import { @@ -101,6 +102,7 @@ const Topic: FC = ({ deleteTopic, focusLastMessage, setViewForumAsMessages, + updateTopicMutedState, } = getActions(); const lang = useOldLang(); @@ -129,6 +131,10 @@ const Topic: FC = ({ openMuteModal(); }); + const handleUnmute = useLastCallback(() => { + updateTopicMutedState({ chatId, topicId: topic.id, mutedUntil: UNMUTE_TIMESTAMP }); + }); + const { renderSubtitle, ref } = useChatListEntry({ chat, chatId, @@ -164,6 +170,7 @@ const Topic: FC = ({ canDelete, handleDelete: handleOpenDeleteModal, handleMute, + handleUnmute, }); return ( diff --git a/src/components/left/main/hooks/useTopicContextActions.ts b/src/components/left/main/hooks/useTopicContextActions.ts index f35859ac7..0e080a16d 100644 --- a/src/components/left/main/hooks/useTopicContextActions.ts +++ b/src/components/left/main/hooks/useTopicContextActions.ts @@ -18,6 +18,7 @@ export default function useTopicContextActions({ canDelete, handleDelete, handleMute, + handleUnmute, }: { topic: ApiTopic; chat: ApiChat; @@ -26,6 +27,7 @@ export default function useTopicContextActions({ canDelete?: boolean; handleDelete?: NoneToVoidFunction; handleMute?: NoneToVoidFunction; + handleUnmute?: NoneToVoidFunction; }) { const lang = useOldLang(); @@ -40,7 +42,6 @@ export default function useTopicContextActions({ editTopic, toggleTopicPinned, markTopicRead, - updateTopicMutedState, openChatInNewTab, } = getActions(); @@ -81,7 +82,7 @@ export default function useTopicContextActions({ ? { title: lang('ChatList.Unmute'), icon: 'unmute', - handler: () => updateTopicMutedState({ chatId, topicId, isMuted: false }), + handler: handleUnmute, } : { title: `${lang('ChatList.Mute')}...`, @@ -116,5 +117,5 @@ export default function useTopicContextActions({ actionCloseTopic, actionDelete, ]) as MenuItemContextAction[]; - }, [topic, chat, isChatMuted, wasOpened, lang, canDelete, handleDelete, handleMute]); + }, [topic, chat, isChatMuted, wasOpened, lang, canDelete, handleDelete, handleMute, handleUnmute]); } diff --git a/src/components/left/search/LeftSearchResultChat.tsx b/src/components/left/search/LeftSearchResultChat.tsx index a9a9ef8d6..0f83166f6 100644 --- a/src/components/left/search/LeftSearchResultChat.tsx +++ b/src/components/left/search/LeftSearchResultChat.tsx @@ -1,11 +1,11 @@ import type { FC } from '../../../lib/teact/teact'; -import type React from '../../../lib/teact/teact'; import { memo, useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiChat, ApiUser } from '../../../api/types'; import { StoryViewerOrigin } from '../../../types'; +import { UNMUTE_TIMESTAMP } from '../../../config'; import { getIsChatMuted } from '../../../global/helpers/notifications'; import { selectChat, selectIsChatPinned, selectNotifyDefaults, selectNotifyException, selectUser, @@ -52,7 +52,7 @@ const LeftSearchResultChat: FC = ({ withOpenAppButton, onClick, }) => { - const { requestMainWebView } = getActions(); + const { requestMainWebView, updateChatMutedState } = getActions(); const oldLang = useOldLang(); const [isMuteModalOpen, openMuteModal, closeMuteModal] = useFlag(); @@ -70,6 +70,10 @@ const LeftSearchResultChat: FC = ({ openMuteModal(); }, [markRenderMuteModal, openMuteModal]); + const handleUnmute = useLastCallback(() => { + updateChatMutedState({ chatId, mutedUntil: UNMUTE_TIMESTAMP }); + }); + const contextActions = useChatContextActions({ chat, user, @@ -77,6 +81,7 @@ const LeftSearchResultChat: FC = ({ isMuted, canChangeFolder, handleMute, + handleUnmute, handleChatFolderChange, }, true); diff --git a/src/components/left/settings/SettingsNotifications.tsx b/src/components/left/settings/SettingsNotifications.tsx index 7d76fc555..f0c65d1b5 100644 --- a/src/components/left/settings/SettingsNotifications.tsx +++ b/src/components/left/settings/SettingsNotifications.tsx @@ -56,6 +56,10 @@ const SettingsNotifications: FC = ({ const areNotificationsSupported = checkIfNotificationsSupported(); const areOfflineNotificationsSupported = areNotificationsSupported && !checkIfOfflinePushFailed(); + const areChannelsMuted = Boolean(notifyDefaults?.channels?.mutedUntil); + const areGroupsMuted = Boolean(notifyDefaults?.groups?.mutedUntil); + const areUsersMuted = Boolean(notifyDefaults?.users?.mutedUntil); + const handleSettingsChange = useCallback(( e: ChangeEvent, peerType: ApiNotifyPeerType, @@ -169,14 +173,13 @@ const SettingsNotifications: FC = ({ = ({ = ({ ( hasWebNotifications: global.settings.byKey.hasWebNotifications, hasPushNotifications: global.settings.byKey.hasPushNotifications, notificationSoundVolume: global.settings.byKey.notificationSoundVolume, + notifyDefaults: global.settings.notifyDefaults, }; }, )(SettingsNotifications)); diff --git a/src/components/middle/HeaderMenuContainer.tsx b/src/components/middle/HeaderMenuContainer.tsx index 550ba96ed..529b5aefc 100644 --- a/src/components/middle/HeaderMenuContainer.tsx +++ b/src/components/middle/HeaderMenuContainer.tsx @@ -11,6 +11,7 @@ import type { IAnchorPosition, ThreadId } from '../../types'; import type { IconName } from '../../types/icons'; import { MAIN_THREAD_ID } from '../../api/types'; +import { UNMUTE_TIMESTAMP } from '../../config'; import { getCanAddContact, getCanDeleteChat, @@ -303,7 +304,7 @@ const HeaderMenuContainer: FC = ({ if (isAccountFrozen) { openFrozenAccountModal(); } else { - updateChatMutedState({ chatId, isMuted: false }); + updateChatMutedState({ chatId, mutedUntil: UNMUTE_TIMESTAMP }); } closeMenu(); }); diff --git a/src/components/right/management/ManageUser.tsx b/src/components/right/management/ManageUser.tsx index 7898296c9..c44c7a665 100644 --- a/src/components/right/management/ManageUser.tsx +++ b/src/components/right/management/ManageUser.tsx @@ -8,7 +8,7 @@ import { getActions, withGlobal } from '../../../global'; import type { ApiPhoto, ApiUser } from '../../../api/types'; import { ManagementProgress } from '../../../types'; -import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; +import { MUTE_INDEFINITE_TIMESTAMP, SERVICE_NOTIFICATIONS_USER_ID, UNMUTE_TIMESTAMP } from '../../../config'; import { isUserBot } from '../../../global/helpers'; import { getIsChatMuted } from '../../../global/helpers/notifications'; import { @@ -68,12 +68,14 @@ const ManageUser: FC = ({ deleteContact, closeManagement, uploadContactProfilePhoto, + updateChatMutedState, } = getActions(); const [isDeleteDialogOpen, openDeleteDialog, closeDeleteDialog] = useFlag(); const [isResetPersonalPhotoDialogOpen, openResetPersonalPhotoDialog, closeResetPersonalPhotoDialog] = useFlag(); - const [isProfileFieldsTouched, setIsProfileFieldsTouched] = useState(false); + const [isProfileFieldsTouched, markProfileFieldsTouched, unmarkProfileFieldsTouched] = useFlag(); const [error, setError] = useState(); + const [isNotificationsTouched, markNotificationsTouched, unmarkNotificationsTouched] = useFlag(); const lang = useOldLang(); useHistoryBack({ @@ -93,7 +95,8 @@ const ManageUser: FC = ({ }, [isMuted]); useEffect(() => { - setIsProfileFieldsTouched(false); + unmarkProfileFieldsTouched(); + unmarkNotificationsTouched(); closeDeleteDialog(); }, [closeDeleteDialog, userId]); @@ -104,7 +107,7 @@ const ManageUser: FC = ({ useEffect(() => { if (progress === ManagementProgress.Complete) { - setIsProfileFieldsTouched(false); + unmarkProfileFieldsTouched(); setError(undefined); closeDeleteDialog(); } @@ -112,7 +115,7 @@ const ManageUser: FC = ({ const handleFirstNameChange = useCallback((e: ChangeEvent) => { setFirstName(e.target.value); - setIsProfileFieldsTouched(true); + markProfileFieldsTouched(); if (error === ERROR_FIRST_NAME_MISSING) { setError(undefined); @@ -121,12 +124,13 @@ const ManageUser: FC = ({ const handleLastNameChange = useCallback((e: ChangeEvent) => { setLastName(e.target.value); - setIsProfileFieldsTouched(true); + markProfileFieldsTouched(); }, []); const handleNotificationChange = useCallback((e: ChangeEvent) => { setIsNotificationsEnabled(e.target.checked); - setIsProfileFieldsTouched(true); + markNotificationsTouched(); + markProfileFieldsTouched(); }, []); const handleProfileSave = useCallback(() => { @@ -140,11 +144,16 @@ const ManageUser: FC = ({ updateContact({ userId, - isMuted: !isNotificationsEnabled, firstName: trimmedFirstName, lastName: trimmedLastName, }); - }, [firstName, lastName, updateContact, userId, isNotificationsEnabled]); + + if (isNotificationsTouched) { + updateChatMutedState({ + chatId: userId, mutedUntil: isNotificationsEnabled ? UNMUTE_TIMESTAMP : MUTE_INDEFINITE_TIMESTAMP, + }); + } + }, [firstName, isNotificationsEnabled, isNotificationsTouched, lastName, userId]); const handleDeleteContact = useCallback(() => { deleteContact({ userId }); @@ -167,12 +176,12 @@ const ManageUser: FC = ({ const handleResetPersonalAvatar = useCallback(() => { closeResetPersonalPhotoDialog(); - setIsProfileFieldsTouched(true); + markProfileFieldsTouched(); uploadContactProfilePhoto({ userId }); }, [closeResetPersonalPhotoDialog, uploadContactProfilePhoto, userId]); const handleSelectAvatar = useCallback((file: File) => { - setIsProfileFieldsTouched(true); + markProfileFieldsTouched(); uploadContactProfilePhoto({ userId, file, isSuggest: isSuggestRef.current }); }, [uploadContactProfilePhoto, userId]); diff --git a/src/config.ts b/src/config.ts index 2575595b2..425bab6f8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -180,6 +180,9 @@ export const MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT = 450; // px export const MAX_INT_32 = 2 ** 31 - 1; export const TMP_CHAT_ID = '0'; +export const MUTE_INDEFINITE_TIMESTAMP = MAX_INT_32; +export const UNMUTE_TIMESTAMP = 0; + export const ANIMATION_END_DELAY = 100; export const ANIMATION_WAVE_MIN_INTERVAL = 200; export const MESSAGE_APPEARANCE_DELAY = 10; diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index c57af60c7..ab54a6991 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -24,7 +24,6 @@ import { CHAT_LIST_LOAD_SLICE, DEBUG, GLOBAL_SUGGESTED_CHANNELS_ID, - MAX_INT_32, RE_TG_LINK, SAVED_FOLDER_ID, SERVICE_NOTIFICATIONS_USER_ID, @@ -689,8 +688,7 @@ addActionHandler('requestSavedDialogUpdate', async (global, actions, payload): P }); addActionHandler('updateChatMutedState', (global, actions, payload): ActionReturnType => { - const { chatId, isMuted } = payload; - let { mutedUntil } = payload; + const { chatId, mutedUntil } = payload; if (selectIsCurrentUserFrozen(global)) { actions.openFrozenAccountModal({ tabId: getCurrentTabId() }); @@ -701,9 +699,6 @@ addActionHandler('updateChatMutedState', (global, actions, payload): ActionRetur if (!chat) { return; } - if (isMuted && !mutedUntil) { - mutedUntil = MAX_INT_32; - } void callApi('updateChatNotifySettings', { chat, settings: { mutedUntil } }); }); @@ -721,7 +716,7 @@ addActionHandler('updateChatSilentPosting', (global, actions, payload): ActionRe addActionHandler('updateTopicMutedState', (global, actions, payload): ActionReturnType => { const { - chatId, topicId, isMuted, mutedUntil, + chatId, topicId, mutedUntil, } = payload; const chat = selectChat(global, chatId); if (!chat) { @@ -729,7 +724,7 @@ addActionHandler('updateTopicMutedState', (global, actions, payload): ActionRetu } void callApi('updateTopicMutedState', { - chat, topicId, isMuted, mutedUntil, + chat, topicId, mutedUntil, }); }); diff --git a/src/global/actions/api/settings.ts b/src/global/actions/api/settings.ts index 2cf839a72..9532d7130 100644 --- a/src/global/actions/api/settings.ts +++ b/src/global/actions/api/settings.ts @@ -5,7 +5,12 @@ import { UPLOADING_WALLPAPER_SLUG, } from '../../../types'; -import { APP_CONFIG_REFETCH_INTERVAL, COUNTRIES_WITH_12H_TIME_FORMAT, MAX_INT_32 } from '../../../config'; +import { + APP_CONFIG_REFETCH_INTERVAL, + COUNTRIES_WITH_12H_TIME_FORMAT, + MUTE_INDEFINITE_TIMESTAMP, + UNMUTE_TIMESTAMP, +} from '../../../config'; import { getCurrentTabId } from '../../../util/establishMultitabRole'; import { buildCollectionByKey } from '../../../util/iteratees'; import { requestPermission, subscribe, unsubscribe } from '../../../util/notifications'; @@ -16,9 +21,9 @@ import { callApi } from '../../../api/gramjs'; import { buildApiInputPrivacyRules } from '../../helpers'; import { addActionHandler, getGlobal, setGlobal } from '../../index'; import { - addBlockedUser, addNotifyException, addNotifyExceptions, deletePeerPhoto, + addBlockedUser, addNotifyExceptions, deletePeerPhoto, removeBlockedUser, replaceSettings, updateChat, - updateSharedSettings, updateUser, updateUserFullInfo, + updateNotifyDefaults, updateSharedSettings, updateUser, updateUserFullInfo, } from '../../reducers'; import { updateTabState } from '../../reducers/tabs'; import { @@ -338,8 +343,8 @@ addActionHandler('updateNotificationSettings', async (global, actions, payload): } global = getGlobal(); - global = addNotifyException(global, peerType, { - mutedUntil: isMuted ? MAX_INT_32 : undefined, + global = updateNotifyDefaults(global, peerType, { + mutedUntil: isMuted ? MUTE_INDEFINITE_TIMESTAMP : UNMUTE_TIMESTAMP, shouldShowPreviews, }); setGlobal(global); diff --git a/src/global/actions/api/users.ts b/src/global/actions/api/users.ts index 334dfdf8b..23ad78241 100644 --- a/src/global/actions/api/users.ts +++ b/src/global/actions/api/users.ts @@ -235,7 +235,7 @@ addActionHandler('openChatRefundModal', async (global, actions, payload): Promis addActionHandler('updateContact', async (global, actions, payload): Promise => { const { - userId, isMuted = false, firstName, lastName, shouldSharePhoneNumber, + userId, firstName, lastName, shouldSharePhoneNumber, tabId = getCurrentTabId(), } = payload; @@ -244,8 +244,6 @@ addActionHandler('updateContact', async (global, actions, payload): Promise; handleDelete?: NoneToVoidFunction; handleMute?: NoneToVoidFunction; + handleUnmute?: NoneToVoidFunction; handleChatFolderChange: NoneToVoidFunction; handleReport?: NoneToVoidFunction; }, isInSearch = false) => { @@ -80,7 +82,6 @@ const useChatContextActions = ({ const { toggleChatPinned, toggleSavedDialogPinned, - updateChatMutedState, toggleChatArchived, markChatMessagesRead, markChatUnread, @@ -140,7 +141,7 @@ const useChatContextActions = ({ ? { title: lang('ChatsUnmute'), icon: 'unmute', - handler: () => updateChatMutedState({ chatId: chat.id, isMuted: false }), + handler: handleUnmute, } : { title: `${lang('ChatsMute')}...`, @@ -188,7 +189,7 @@ const useChatContextActions = ({ }, [ chat, user, canChangeFolder, lang, handleChatFolderChange, isPinned, isInSearch, isMuted, currentUserId, handleDelete, handleMute, handleReport, folderId, isSelf, isServiceNotifications, isSavedDialog, deleteTitle, - isPreview, topics, + isPreview, topics, handleUnmute, ]); };