Settings: Fix notifications checkbox logic (#6211)

This commit is contained in:
Alexander Zinchuk 2025-09-19 14:35:07 +02:00
parent d3b4c57aab
commit ba80452ac1
19 changed files with 123 additions and 79 deletions

View File

@ -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),

View File

@ -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({

View File

@ -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,
},
}));
}

View File

@ -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,

View File

@ -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<OwnProps & StateProps> = ({
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<OwnProps & StateProps> = ({
</ListItem>
)}
{!isInSettings && (
<ListItem icon="unmute" narrow ripple onClick={handleNotificationChange}>
<ListItem icon={isMuted ? 'unmute' : 'mute'} narrow ripple onClick={handleToggleNotifications}>
<span>{oldLang('Notifications')}</span>
<Switcher
id="group-notifications"

View File

@ -4,7 +4,7 @@ import {
} from '../../lib/teact/teact';
import { getActions } from '../../global';
import { MAX_INT_32 } from '../../config';
import { MUTE_INDEFINITE_TIMESTAMP } from '../../config';
import useOldLang from '../../hooks/useOldLang';
@ -53,7 +53,7 @@ const MuteChatModal: FC<OwnProps> = ({
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);
}

View File

@ -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<OwnProps & StateProps> = ({
setShouldCloseRightColumn,
reportMessages,
openFrozenAccountModal,
updateChatMutedState,
} = getActions();
const { isMobile } = useAppLayout();
@ -292,6 +295,15 @@ const Chat: FC<OwnProps & StateProps> = ({
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<OwnProps & StateProps> = ({
user,
handleDelete,
handleMute,
handleUnmute,
handleChatFolderChange,
handleReport,
folderId,

View File

@ -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<OwnProps & StateProps> = ({
deleteTopic,
focusLastMessage,
setViewForumAsMessages,
updateTopicMutedState,
} = getActions();
const lang = useOldLang();
@ -129,6 +131,10 @@ const Topic: FC<OwnProps & StateProps> = ({
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<OwnProps & StateProps> = ({
canDelete,
handleDelete: handleOpenDeleteModal,
handleMute,
handleUnmute,
});
return (

View File

@ -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]);
}

View File

@ -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<OwnProps & StateProps> = ({
withOpenAppButton,
onClick,
}) => {
const { requestMainWebView } = getActions();
const { requestMainWebView, updateChatMutedState } = getActions();
const oldLang = useOldLang();
const [isMuteModalOpen, openMuteModal, closeMuteModal] = useFlag();
@ -70,6 +70,10 @@ const LeftSearchResultChat: FC<OwnProps & StateProps> = ({
openMuteModal();
}, [markRenderMuteModal, openMuteModal]);
const handleUnmute = useLastCallback(() => {
updateChatMutedState({ chatId, mutedUntil: UNMUTE_TIMESTAMP });
});
const contextActions = useChatContextActions({
chat,
user,
@ -77,6 +81,7 @@ const LeftSearchResultChat: FC<OwnProps & StateProps> = ({
isMuted,
canChangeFolder,
handleMute,
handleUnmute,
handleChatFolderChange,
}, true);

View File

@ -56,6 +56,10 @@ const SettingsNotifications: FC<OwnProps & StateProps> = ({
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<HTMLInputElement>,
peerType: ApiNotifyPeerType,
@ -169,14 +173,13 @@ const SettingsNotifications: FC<OwnProps & StateProps> = ({
<Checkbox
label={lang('NotificationsForPrivateChats')}
subLabel={lang(notifyDefaults?.users?.mutedUntil
? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={Boolean(notifyDefaults?.users?.mutedUntil)}
subLabel={lang(!areUsersMuted ? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={!areUsersMuted}
onChange={handlePrivateChatsNotificationsChange}
/>
<Checkbox
label={lang('MessagePreview')}
disabled={!notifyDefaults?.users?.mutedUntil}
disabled={areUsersMuted}
subLabel={lang(notifyDefaults?.users?.shouldShowPreviews
? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={Boolean(notifyDefaults?.users?.shouldShowPreviews)}
@ -189,14 +192,13 @@ const SettingsNotifications: FC<OwnProps & StateProps> = ({
<Checkbox
label={lang('NotificationsForGroups')}
subLabel={lang(notifyDefaults?.groups?.mutedUntil
? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={Boolean(notifyDefaults?.groups?.mutedUntil)}
subLabel={lang(!areGroupsMuted ? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={!areGroupsMuted}
onChange={handleGroupsNotificationsChange}
/>
<Checkbox
label={lang('MessagePreview')}
disabled={!notifyDefaults?.groups?.mutedUntil}
disabled={areGroupsMuted}
subLabel={lang(notifyDefaults?.groups?.shouldShowPreviews
? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={Boolean(notifyDefaults?.groups?.shouldShowPreviews)}
@ -209,14 +211,13 @@ const SettingsNotifications: FC<OwnProps & StateProps> = ({
<Checkbox
label={lang('NotificationsForChannels')}
subLabel={lang(notifyDefaults?.channels?.mutedUntil
? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={Boolean(notifyDefaults?.channels?.mutedUntil)}
subLabel={lang(!areChannelsMuted ? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={!areChannelsMuted}
onChange={handleChannelsNotificationsChange}
/>
<Checkbox
label={lang('MessagePreview')}
disabled={!notifyDefaults?.channels?.mutedUntil}
disabled={areChannelsMuted}
subLabel={lang(notifyDefaults?.channels?.shouldShowPreviews
? 'UserInfoNotificationsEnabled' : 'UserInfoNotificationsDisabled')}
checked={Boolean(notifyDefaults?.channels?.shouldShowPreviews)}
@ -244,6 +245,7 @@ export default memo(withGlobal<OwnProps>(
hasWebNotifications: global.settings.byKey.hasWebNotifications,
hasPushNotifications: global.settings.byKey.hasPushNotifications,
notificationSoundVolume: global.settings.byKey.notificationSoundVolume,
notifyDefaults: global.settings.notifyDefaults,
};
},
)(SettingsNotifications));

View File

@ -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<OwnProps & StateProps> = ({
if (isAccountFrozen) {
openFrozenAccountModal();
} else {
updateChatMutedState({ chatId, isMuted: false });
updateChatMutedState({ chatId, mutedUntil: UNMUTE_TIMESTAMP });
}
closeMenu();
});

View File

@ -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<OwnProps & StateProps> = ({
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<string | undefined>();
const [isNotificationsTouched, markNotificationsTouched, unmarkNotificationsTouched] = useFlag();
const lang = useOldLang();
useHistoryBack({
@ -93,7 +95,8 @@ const ManageUser: FC<OwnProps & StateProps> = ({
}, [isMuted]);
useEffect(() => {
setIsProfileFieldsTouched(false);
unmarkProfileFieldsTouched();
unmarkNotificationsTouched();
closeDeleteDialog();
}, [closeDeleteDialog, userId]);
@ -104,7 +107,7 @@ const ManageUser: FC<OwnProps & StateProps> = ({
useEffect(() => {
if (progress === ManagementProgress.Complete) {
setIsProfileFieldsTouched(false);
unmarkProfileFieldsTouched();
setError(undefined);
closeDeleteDialog();
}
@ -112,7 +115,7 @@ const ManageUser: FC<OwnProps & StateProps> = ({
const handleFirstNameChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
setFirstName(e.target.value);
setIsProfileFieldsTouched(true);
markProfileFieldsTouched();
if (error === ERROR_FIRST_NAME_MISSING) {
setError(undefined);
@ -121,12 +124,13 @@ const ManageUser: FC<OwnProps & StateProps> = ({
const handleLastNameChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
setLastName(e.target.value);
setIsProfileFieldsTouched(true);
markProfileFieldsTouched();
}, []);
const handleNotificationChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
setIsNotificationsEnabled(e.target.checked);
setIsProfileFieldsTouched(true);
markNotificationsTouched();
markProfileFieldsTouched();
}, []);
const handleProfileSave = useCallback(() => {
@ -140,11 +144,16 @@ const ManageUser: FC<OwnProps & StateProps> = ({
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<OwnProps & StateProps> = ({
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]);

View File

@ -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;

View File

@ -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,
});
});

View File

@ -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);

View File

@ -235,7 +235,7 @@ addActionHandler('openChatRefundModal', async (global, actions, payload): Promis
addActionHandler('updateContact', async (global, actions, payload): Promise<void> => {
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<void
return;
}
actions.updateChatMutedState({ chatId: userId, isMuted });
global = getGlobal();
global = updateManagementProgress(global, ManagementProgress.InProgress, tabId);
setGlobal(global);

View File

@ -1122,8 +1122,7 @@ export interface ActionPayloads {
};
updateChatMutedState: {
chatId: string;
isMuted?: boolean;
mutedUntil?: number;
mutedUntil: number;
};
updateChatSilentPosting: {
chatId: string;
@ -1823,7 +1822,6 @@ export interface ActionPayloads {
name?: string | undefined;
about?: string | undefined;
description?: string | undefined;
isMuted?: boolean;
} & WithTabId;
startBotFatherConversation: {
param: string;
@ -1853,7 +1851,6 @@ export interface ActionPayloads {
userId: string;
firstName: string;
lastName?: string;
isMuted?: boolean;
shouldSharePhoneNumber?: boolean;
} & WithTabId;
toggleNoPaidMessagesException: {
@ -2759,8 +2756,7 @@ export interface ActionPayloads {
updateTopicMutedState: {
chatId: string;
topicId: number;
isMuted?: boolean;
mutedUntil?: number;
mutedUntil: number;
};
setViewForumAsMessages: {
chatId: string;

View File

@ -27,6 +27,7 @@ const useChatContextActions = ({
topics,
handleDelete,
handleMute,
handleUnmute,
handleChatFolderChange,
handleReport,
}: {
@ -42,6 +43,7 @@ const useChatContextActions = ({
topics?: Record<number, ApiTopic>;
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,
]);
};