From b025fccf0f491034e4c9c4cdba6e29c9101a63bf Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 19 Mar 2022 21:19:08 +0100 Subject: [PATCH] [Refactoring] TeactN: `addReducer` => `addActionHandler`, `getDispatch` => `getActions` --- src/App.tsx | 4 +- src/bundles/main.ts | 4 +- src/components/auth/Auth.tsx | 4 +- src/components/auth/AuthCode.tsx | 4 +- src/components/auth/AuthPassword.tsx | 4 +- src/components/auth/AuthPhoneNumber.tsx | 4 +- src/components/auth/AuthQrCode.tsx | 4 +- src/components/auth/AuthRegister.tsx | 4 +- src/components/calls/ActiveCallHeader.tsx | 4 +- src/components/calls/CallFallbackConfirm.tsx | 4 +- src/components/calls/group/GroupCall.tsx | 4 +- .../calls/group/GroupCallParticipantList.tsx | 4 +- .../calls/group/GroupCallParticipantMenu.tsx | 4 +- .../calls/group/GroupCallTopPane.tsx | 4 +- .../calls/group/MicrophoneButton.tsx | 4 +- src/components/common/Audio.tsx | 6 +- src/components/common/ChatExtra.tsx | 4 +- src/components/common/ChatLink.tsx | 4 +- src/components/common/DeleteChatModal.tsx | 4 +- src/components/common/DeleteMessageModal.tsx | 4 +- src/components/common/Document.tsx | 4 +- src/components/common/GroupCallLink.tsx | 4 +- src/components/common/GroupChatInfo.tsx | 4 +- src/components/common/MessageLink.tsx | 4 +- src/components/common/PinMessageModal.tsx | 4 +- src/components/common/PrivateChatInfo.tsx | 4 +- src/components/common/ProfileInfo.tsx | 4 +- src/components/common/ReportMessageModal.tsx | 4 +- src/components/common/SafeLink.tsx | 4 +- src/components/common/SeenByModal.tsx | 4 +- src/components/common/StickerSetModal.tsx | 4 +- src/components/common/UiLoader.tsx | 4 +- src/components/common/UserLink.tsx | 4 +- .../common/helpers/renderTextWithEntities.tsx | 8 +- .../common/hooks/useAnimatedEmoji.ts | 4 +- src/components/left/ChatFolderModal.tsx | 4 +- src/components/left/LeftColumn.tsx | 4 +- src/components/left/main/Chat.tsx | 4 +- src/components/left/main/ChatFolders.tsx | 4 +- src/components/left/main/ChatList.tsx | 4 +- src/components/left/main/ContactList.tsx | 4 +- src/components/left/main/LeftMainHeader.tsx | 4 +- src/components/left/newChat/NewChatStep1.tsx | 4 +- src/components/left/newChat/NewChatStep2.tsx | 4 +- src/components/left/search/AudioResults.tsx | 4 +- src/components/left/search/ChatMessage.tsx | 4 +- .../left/search/ChatMessageResults.tsx | 4 +- src/components/left/search/ChatResults.tsx | 4 +- src/components/left/search/FileResults.tsx | 4 +- src/components/left/search/LeftSearch.tsx | 4 +- src/components/left/search/LinkResults.tsx | 4 +- src/components/left/search/MediaResults.tsx | 4 +- src/components/left/search/RecentContacts.tsx | 4 +- .../left/settings/BlockUserModal.tsx | 4 +- .../left/settings/SettingsDataStorage.tsx | 4 +- .../left/settings/SettingsEditProfile.tsx | 4 +- .../left/settings/SettingsGeneral.tsx | 4 +- .../settings/SettingsGeneralBackground.tsx | 4 +- .../SettingsGeneralBackgroundColor.tsx | 4 +- .../left/settings/SettingsHeader.tsx | 4 +- .../left/settings/SettingsLanguage.tsx | 4 +- src/components/left/settings/SettingsMain.tsx | 4 +- .../left/settings/SettingsNotifications.tsx | 4 +- .../left/settings/SettingsPrivacy.tsx | 4 +- .../SettingsPrivacyActiveSessions.tsx | 4 +- .../settings/SettingsPrivacyBlockedUsers.tsx | 4 +- .../settings/SettingsPrivacyVisibility.tsx | 4 +- ...SettingsPrivacyVisibilityExceptionList.tsx | 4 +- .../left/settings/SettingsQuickReaction.tsx | 4 +- .../settings/folders/SettingsFoldersEdit.tsx | 4 +- .../settings/folders/SettingsFoldersMain.tsx | 4 +- .../left/settings/twoFa/SettingsTwoFa.tsx | 4 +- src/components/main/Dialogs.tsx | 4 +- src/components/main/DownloadManager.tsx | 4 +- src/components/main/ForwardPicker.tsx | 4 +- src/components/main/HistoryCalendar.tsx | 4 +- src/components/main/Main.tsx | 4 +- src/components/main/Notifications.tsx | 4 +- src/components/main/SafeLinkModal.tsx | 4 +- src/components/mediaViewer/MediaViewer.tsx | 4 +- .../mediaViewer/MediaViewerActions.tsx | 4 +- src/components/mediaViewer/SenderInfo.tsx | 4 +- src/components/middle/AudioPlayer.tsx | 4 +- src/components/middle/ContactGreeting.tsx | 4 +- .../middle/DeleteSelectedMessageModal.tsx | 4 +- .../middle/EmojiInteractionAnimation.tsx | 4 +- src/components/middle/HeaderActions.tsx | 4 +- src/components/middle/HeaderMenuContainer.tsx | 4 +- src/components/middle/MessageList.tsx | 4 +- src/components/middle/MessageListContent.tsx | 4 +- .../middle/MessageSelectToolbar.tsx | 4 +- src/components/middle/MiddleColumn.tsx | 4 +- src/components/middle/MiddleHeader.tsx | 4 +- src/components/middle/MobileSearch.tsx | 4 +- src/components/middle/ReactorListModal.tsx | 4 +- src/components/middle/ScrollDownButton.tsx | 4 +- src/components/middle/UserReportPanel.tsx | 4 +- .../middle/composer/BotCommandMenu.tsx | 4 +- .../middle/composer/BotCommandTooltip.tsx | 4 +- .../middle/composer/BotKeyboardMenu.tsx | 4 +- src/components/middle/composer/Composer.tsx | 4 +- .../composer/ComposerEmbeddedMessage.tsx | 4 +- src/components/middle/composer/GifPicker.tsx | 4 +- .../middle/composer/InlineBotTooltip.tsx | 4 +- .../middle/composer/MessageInput.tsx | 4 +- src/components/middle/composer/SendAsMenu.tsx | 4 +- .../middle/composer/StickerPicker.tsx | 4 +- .../middle/composer/StickerTooltip.tsx | 4 +- .../middle/composer/WebPagePreview.tsx | 4 +- .../middle/composer/hooks/useDraft.ts | 4 +- .../middle/composer/hooks/useEditing.ts | 4 +- .../composer/hooks/useInlineBotTooltip.ts | 4 +- .../composer/hooks/useStickerTooltip.ts | 4 +- .../middle/hooks/useMessageObservers.ts | 4 +- src/components/middle/hooks/useScrollHooks.ts | 4 +- src/components/middle/message/Album.tsx | 4 +- .../middle/message/CommentButton.tsx | 4 +- src/components/middle/message/Contact.tsx | 4 +- .../middle/message/ContextMenuContainer.tsx | 4 +- src/components/middle/message/MentionLink.tsx | 4 +- src/components/middle/message/Message.tsx | 4 +- src/components/middle/message/Poll.tsx | 4 +- .../middle/message/ReactionAnimatedEmoji.tsx | 4 +- .../middle/message/ReactionButton.tsx | 4 +- src/components/middle/message/RoundVideo.tsx | 4 +- .../middle/message/SponsoredMessage.tsx | 4 +- src/components/middle/message/Video.tsx | 4 +- .../middle/message/hocs/withSelectControl.tsx | 4 +- .../middle/message/hooks/useInnerHandlers.ts | 4 +- .../middle/message/hooks/useOuterHandlers.ts | 4 +- src/components/payment/PaymentModal.tsx | 4 +- src/components/right/AddChatMembers.tsx | 4 +- src/components/right/DeleteMemberModal.tsx | 4 +- src/components/right/GifSearch.tsx | 4 +- src/components/right/PollAnswerResults.tsx | 4 +- src/components/right/Profile.tsx | 4 +- src/components/right/RightColumn.tsx | 4 +- src/components/right/RightHeader.tsx | 4 +- src/components/right/RightSearch.tsx | 4 +- src/components/right/StickerSearch.tsx | 4 +- src/components/right/StickerSetResult.tsx | 4 +- .../right/management/JoinRequest.tsx | 4 +- .../right/management/ManageChannel.tsx | 4 +- .../management/ManageChatPrivacyType.tsx | 4 +- .../management/ManageChatRemovedUsers.tsx | 4 +- .../right/management/ManageDiscussion.tsx | 4 +- .../right/management/ManageGroup.tsx | 4 +- .../management/ManageGroupAdminRights.tsx | 4 +- .../right/management/ManageGroupMembers.tsx | 4 +- .../management/ManageGroupPermissions.tsx | 4 +- .../management/ManageGroupUserPermissions.tsx | 4 +- .../right/management/ManageInvite.tsx | 4 +- .../right/management/ManageInviteInfo.tsx | 4 +- .../right/management/ManageInvites.tsx | 4 +- .../right/management/ManageJoinRequests.tsx | 4 +- .../right/management/ManageReactions.tsx | 4 +- .../right/management/ManageUser.tsx | 4 +- .../right/management/RemoveGroupUserModal.tsx | 4 +- .../right/statistics/Statistics.tsx | 4 +- src/global/cache.ts | 6 +- src/global/index.ts | 4 +- src/global/types.ts | 2 +- src/hooks/useAudioPlayer.ts | 4 +- src/hooks/useChatContextActions.ts | 4 +- src/hooks/useEnsureMessage.ts | 4 +- src/hooks/useHistoryBack.ts | 6 +- src/hooks/useSendMessageAction.ts | 4 +- src/index.tsx | 4 +- src/lib/teact/teactn.tsx | 48 ++++----- src/modules/actions/api/bots.ts | 20 ++-- src/modules/actions/api/calls.async.ts | 20 ++-- src/modules/actions/api/chats.ts | 100 +++++++++--------- src/modules/actions/api/globalSearch.ts | 8 +- src/modules/actions/api/initial.ts | 36 +++---- src/modules/actions/api/localSearch.ts | 10 +- src/modules/actions/api/management.ts | 32 +++--- src/modules/actions/api/messages.ts | 66 ++++++------ src/modules/actions/api/payments.ts | 20 ++-- src/modules/actions/api/reactions.ts | 28 ++--- src/modules/actions/api/settings.ts | 52 ++++----- src/modules/actions/api/statistics.ts | 6 +- src/modules/actions/api/symbols.ts | 40 +++---- src/modules/actions/api/sync.ts | 8 +- src/modules/actions/api/twoFaSettings.ts | 16 +-- src/modules/actions/api/users.ts | 28 ++--- src/modules/actions/apiUpdaters/calls.ts | 4 +- src/modules/actions/apiUpdaters/chats.ts | 4 +- src/modules/actions/apiUpdaters/initial.ts | 8 +- src/modules/actions/apiUpdaters/messages.ts | 4 +- src/modules/actions/apiUpdaters/misc.ts | 4 +- src/modules/actions/apiUpdaters/payments.ts | 4 +- src/modules/actions/apiUpdaters/settings.ts | 4 +- src/modules/actions/apiUpdaters/symbols.ts | 4 +- .../actions/apiUpdaters/twoFaSettings.ts | 4 +- src/modules/actions/apiUpdaters/users.ts | 4 +- src/modules/actions/ui/calls.ts | 22 ++-- src/modules/actions/ui/chats.ts | 14 +-- src/modules/actions/ui/globalSearch.ts | 12 +-- src/modules/actions/ui/initial.ts | 14 +-- src/modules/actions/ui/localSearch.ts | 10 +- src/modules/actions/ui/messages.ts | 80 +++++++------- src/modules/actions/ui/misc.ts | 38 +++---- src/modules/actions/ui/payments.ts | 8 +- src/modules/actions/ui/settings.ts | 6 +- src/modules/actions/ui/stickerSearch.ts | 6 +- src/modules/actions/ui/users.ts | 4 +- src/modules/index.ts | 4 +- src/util/audioPlayer.ts | 4 +- src/util/deeplink.ts | 4 +- src/util/folderManager.ts | 4 +- src/util/notifications.ts | 8 +- src/util/setupServiceWorker.ts | 6 +- 212 files changed, 752 insertions(+), 754 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index a8ebd651f..2c1a7cc99 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import React, { FC, useEffect } from './lib/teact/teact'; -import { getDispatch, withGlobal } from './modules'; +import { getActions, withGlobal } from './modules'; import { GlobalState } from './global/types'; @@ -19,7 +19,7 @@ import { hasStoredSession } from './util/sessions'; type StateProps = Pick; const App: FC = ({ authState }) => { - const { disconnect } = getDispatch(); + const { disconnect } = getActions(); const [isInactive, markInactive] = useFlag(false); diff --git a/src/bundles/main.ts b/src/bundles/main.ts index 4e84b68bc..2ff33f6eb 100644 --- a/src/bundles/main.ts +++ b/src/bundles/main.ts @@ -1,4 +1,4 @@ -import { getDispatch, getGlobal } from '../modules'; +import { getActions, getGlobal } from '../modules'; import { DEBUG } from '../config'; @@ -10,5 +10,5 @@ if (DEBUG) { } if (!getGlobal().connectionState) { - getDispatch().initApi(); + getActions().initApi(); } diff --git a/src/components/auth/Auth.tsx b/src/components/auth/Auth.tsx index 67e4aa787..921e4a826 100644 --- a/src/components/auth/Auth.tsx +++ b/src/components/auth/Auth.tsx @@ -1,5 +1,5 @@ import React, { FC, useEffect, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; @@ -25,7 +25,7 @@ const Auth: FC = ({ }) => { const { reset, initApi, returnToAuthPhoneNumber, goToAuthQrCode, - } = getDispatch(); + } = getActions(); useEffect(() => { reset(); diff --git a/src/components/auth/AuthCode.tsx b/src/components/auth/AuthCode.tsx index 797a17ed0..9a8f9e554 100644 --- a/src/components/auth/AuthCode.tsx +++ b/src/components/auth/AuthCode.tsx @@ -2,7 +2,7 @@ import { FormEvent } from 'react'; import React, { FC, useState, useEffect, useCallback, memo, useRef, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; import { IS_TOUCH_ENV } from '../../util/environment'; @@ -29,7 +29,7 @@ const AuthCode: FC = ({ setAuthCode, returnToAuthPhoneNumber, clearAuthError, - } = getDispatch(); + } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null diff --git a/src/components/auth/AuthPassword.tsx b/src/components/auth/AuthPassword.tsx index b487d3a3c..3c2f70796 100644 --- a/src/components/auth/AuthPassword.tsx +++ b/src/components/auth/AuthPassword.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; @@ -16,7 +16,7 @@ type StateProps = Pick; const AuthPassword: FC = ({ authIsLoading, authError, authHint, }) => { - const { setAuthPassword, clearAuthError } = getDispatch(); + const { setAuthPassword, clearAuthError } = getActions(); const lang = useLang(); const [showPassword, setShowPassword] = useState(false); diff --git a/src/components/auth/AuthPhoneNumber.tsx b/src/components/auth/AuthPhoneNumber.tsx index 82d71d87e..b80d20fba 100644 --- a/src/components/auth/AuthPhoneNumber.tsx +++ b/src/components/auth/AuthPhoneNumber.tsx @@ -5,7 +5,7 @@ import monkeyPath from '../../assets/monkey.svg'; import React, { FC, memo, useCallback, useEffect, useLayoutEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; import { LangCode } from '../../types'; @@ -62,7 +62,7 @@ const AuthPhoneNumber: FC = ({ clearAuthError, goToAuthQrCode, setSettingOption, - } = getDispatch(); + } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null diff --git a/src/components/auth/AuthQrCode.tsx b/src/components/auth/AuthQrCode.tsx index dceb86531..4f0b5c107 100644 --- a/src/components/auth/AuthQrCode.tsx +++ b/src/components/auth/AuthQrCode.tsx @@ -2,7 +2,7 @@ import QrCreator from 'qr-creator'; import React, { FC, useEffect, useRef, memo, useCallback, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; import { LangCode } from '../../types'; @@ -35,7 +35,7 @@ const AuthCode: FC = ({ const { returnToAuthPhoneNumber, setSettingOption, - } = getDispatch(); + } = getActions(); const suggestedLanguage = getSuggestedLanguage(); const lang = useLang(); diff --git a/src/components/auth/AuthRegister.tsx b/src/components/auth/AuthRegister.tsx index 067513951..88b54865c 100644 --- a/src/components/auth/AuthRegister.tsx +++ b/src/components/auth/AuthRegister.tsx @@ -1,6 +1,6 @@ import { ChangeEvent } from 'react'; import React, { FC, useState, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; @@ -16,7 +16,7 @@ type StateProps = Pick; const AuthRegister: FC = ({ authIsLoading, authError, }) => { - const { signUp, clearAuthError, uploadProfilePhoto } = getDispatch(); + const { signUp, clearAuthError, uploadProfilePhoto } = getActions(); const lang = useLang(); const [isButtonShown, setIsButtonShown] = useState(false); diff --git a/src/components/calls/ActiveCallHeader.tsx b/src/components/calls/ActiveCallHeader.tsx index 45853a37e..a011cf175 100644 --- a/src/components/calls/ActiveCallHeader.tsx +++ b/src/components/calls/ActiveCallHeader.tsx @@ -2,7 +2,7 @@ import { GroupCallParticipant } from '../../lib/secret-sauce'; import React, { FC, memo, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiGroupCall } from '../../api/types'; @@ -23,7 +23,7 @@ const ActiveCallHeader: FC = ({ meParticipant, isGroupCallPanelHidden, }) => { - const { toggleGroupCallPanel } = getDispatch(); + const { toggleGroupCallPanel } = getActions(); const lang = useLang(); diff --git a/src/components/calls/CallFallbackConfirm.tsx b/src/components/calls/CallFallbackConfirm.tsx index 9e3414bfb..42a010458 100644 --- a/src/components/calls/CallFallbackConfirm.tsx +++ b/src/components/calls/CallFallbackConfirm.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useState } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import ConfirmDialog from '../ui/ConfirmDialog'; import Checkbox from '../ui/Checkbox'; @@ -25,7 +25,7 @@ const CallFallbackConfirm: FC = ({ const { closeCallFallbackConfirm, inviteToCallFallback, - } = getDispatch(); + } = getActions(); const [shouldRemove, setShouldRemove] = useState(true); const renderingUserFullName = useCurrentOrPrev(userFullName, true); diff --git a/src/components/calls/group/GroupCall.tsx b/src/components/calls/group/GroupCall.tsx index 2caf9c170..d08a7865d 100644 --- a/src/components/calls/group/GroupCall.tsx +++ b/src/components/calls/group/GroupCall.tsx @@ -5,7 +5,7 @@ import { import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import '../../../modules/actions/calls'; import { IAnchorPosition } from '../../../types'; @@ -75,7 +75,7 @@ const GroupCall: FC = ({ toggleGroupCallPanel, connectToActiveGroupCall, playGroupCallSound, - } = getDispatch(); + } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null diff --git a/src/components/calls/group/GroupCallParticipantList.tsx b/src/components/calls/group/GroupCallParticipantList.tsx index 15d2081a2..d01d0c55a 100644 --- a/src/components/calls/group/GroupCallParticipantList.tsx +++ b/src/components/calls/group/GroupCallParticipantList.tsx @@ -1,6 +1,6 @@ import { GroupCallParticipant as TypeGroupCallParticipant } from '../../../lib/secret-sauce'; import React, { FC, memo, useMemo } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import useLang from '../../../hooks/useLang'; import { selectActiveGroupCall } from '../../../modules/selectors/calls'; @@ -27,7 +27,7 @@ const GroupCallParticipantList: FC = ({ const { createGroupCallInviteLink, loadMoreGroupCallParticipants, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/calls/group/GroupCallParticipantMenu.tsx b/src/components/calls/group/GroupCallParticipantMenu.tsx index 10f4cd2ec..3a3da0be1 100644 --- a/src/components/calls/group/GroupCallParticipantMenu.tsx +++ b/src/components/calls/group/GroupCallParticipantMenu.tsx @@ -2,7 +2,7 @@ import { GroupCallParticipant } from '../../../lib/secret-sauce'; import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { IAnchorPosition } from '../../../types'; @@ -56,7 +56,7 @@ const GroupCallParticipantMenu: FC = ({ toggleGroupCallPanel, openChat, requestToSpeak, - } = getDispatch(); + } = getActions(); const lang = useLang(); const [isDeleteUserModalOpen, openDeleteUserModal, closeDeleteUserModal] = useFlag(); diff --git a/src/components/calls/group/GroupCallTopPane.tsx b/src/components/calls/group/GroupCallTopPane.tsx index 1546b091b..f8d4ac2cc 100644 --- a/src/components/calls/group/GroupCallTopPane.tsx +++ b/src/components/calls/group/GroupCallTopPane.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiGroupCall, ApiUser } from '../../../api/types'; @@ -38,7 +38,7 @@ const GroupCallTopPane: FC = ({ const { joinGroupCall, subscribeToGroupCallUpdates, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/calls/group/MicrophoneButton.tsx b/src/components/calls/group/MicrophoneButton.tsx index ea8ec398b..592cc2788 100644 --- a/src/components/calls/group/MicrophoneButton.tsx +++ b/src/components/calls/group/MicrophoneButton.tsx @@ -2,7 +2,7 @@ import { GroupCallConnectionState } from '../../../lib/secret-sauce'; import React, { FC, memo, useEffect, useMemo, useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import buildClassName from '../../../util/buildClassName'; import { vibrateShort } from '../../../util/vibrate'; @@ -39,7 +39,7 @@ const MicrophoneButton: FC = ({ toggleGroupCallMute, requestToSpeak, playGroupCallSound, - } = getDispatch(); + } = getActions(); const lang = useLang(); const muteMouseDownState = useRef('up'); diff --git a/src/components/common/Audio.tsx b/src/components/common/Audio.tsx index 5996bdd39..da313de9e 100644 --- a/src/components/common/Audio.tsx +++ b/src/components/common/Audio.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import { ApiAudio, ApiMediaFormat, ApiMessage, ApiVoice, @@ -88,7 +88,7 @@ const Audio: FC = ({ const seekerRef = useRef(null); const lang = useLang(); const { isRtl } = lang; - const dispatch = getDispatch(); + const dispatch = getActions(); const [isActivated, setIsActivated] = useState(false); const shouldLoad = (isActivated || PRELOAD) && lastSyncTime; @@ -171,7 +171,7 @@ const Audio: FC = ({ onPlay(message.id, message.chatId); } - getDispatch().setAudioPlayerOrigin({ origin }); + getActions().setAudioPlayerOrigin({ origin }); setIsActivated(!isActivated); playPause(); }, [isUploading, isPlaying, isActivated, playPause, onCancelUpload, onPlay, message.id, message.chatId, origin]); diff --git a/src/components/common/ChatExtra.tsx b/src/components/common/ChatExtra.tsx index 72db60ec4..86b19f53e 100644 --- a/src/components/common/ChatExtra.tsx +++ b/src/components/common/ChatExtra.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; import { ApiChat, ApiCountryCode, ApiUser } from '../../api/types'; @@ -48,7 +48,7 @@ const ChatExtra: FC = ({ loadFullUser, showNotification, updateChatMutedState, - } = getDispatch(); + } = getActions(); const { id: userId, diff --git a/src/components/common/ChatLink.tsx b/src/components/common/ChatLink.tsx index e4af8a3ea..7354ffaca 100644 --- a/src/components/common/ChatLink.tsx +++ b/src/components/common/ChatLink.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import buildClassName from '../../util/buildClassName'; @@ -14,7 +14,7 @@ type OwnProps = { const ChatLink: FC = ({ className, chatId, children, }) => { - const { openChat } = getDispatch(); + const { openChat } = getActions(); const handleClick = useCallback(() => { if (chatId) { diff --git a/src/components/common/DeleteChatModal.tsx b/src/components/common/DeleteChatModal.tsx index 29d708ce6..b0cec612d 100644 --- a/src/components/common/DeleteChatModal.tsx +++ b/src/components/common/DeleteChatModal.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat } from '../../api/types'; @@ -63,7 +63,7 @@ const DeleteChatModal: FC = ({ deleteChannel, deleteChatUser, blockContact, - } = getDispatch(); + } = getActions(); const lang = useLang(); const chatTitle = getChatTitle(lang, chat); diff --git a/src/components/common/DeleteMessageModal.tsx b/src/components/common/DeleteMessageModal.tsx index e05b4fbee..97331ee7b 100644 --- a/src/components/common/DeleteMessageModal.tsx +++ b/src/components/common/DeleteMessageModal.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiMessage } from '../../api/types'; import { IAlbum } from '../../types'; @@ -52,7 +52,7 @@ const DeleteMessageModal: FC = ({ const { deleteMessages, deleteScheduledMessages, - } = getDispatch(); + } = getActions(); const handleDeleteMessageForAll = useCallback(() => { const messageIds = album?.messages diff --git a/src/components/common/Document.tsx b/src/components/common/Document.tsx index 6ec6d24db..d4c9f6fab 100644 --- a/src/components/common/Document.tsx +++ b/src/components/common/Document.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, memo, useRef, useEffect, useState, } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import { ApiMessage } from '../../api/types'; @@ -58,7 +58,7 @@ const Document: FC = ({ onDateClick, isDownloading, }) => { - const dispatch = getDispatch(); + const dispatch = getActions(); // eslint-disable-next-line no-null/no-null const ref = useRef(null); diff --git a/src/components/common/GroupCallLink.tsx b/src/components/common/GroupCallLink.tsx index f8304d3d0..9f9d2e670 100644 --- a/src/components/common/GroupCallLink.tsx +++ b/src/components/common/GroupCallLink.tsx @@ -5,7 +5,7 @@ import { ApiGroupCall } from '../../api/types'; import buildClassName from '../../util/buildClassName'; import Link from '../ui/Link'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; type OwnProps = { className?: string; @@ -16,7 +16,7 @@ type OwnProps = { const GroupCallLink: FC = ({ className, groupCall, children, }) => { - const { joinGroupCall } = getDispatch(); + const { joinGroupCall } = getActions(); const handleClick = useCallback(() => { if (groupCall) { diff --git a/src/components/common/GroupChatInfo.tsx b/src/components/common/GroupChatInfo.tsx index 5263b290a..fead0cdaf 100644 --- a/src/components/common/GroupChatInfo.tsx +++ b/src/components/common/GroupChatInfo.tsx @@ -2,7 +2,7 @@ import { MouseEvent as ReactMouseEvent } from 'react'; import React, { FC, useEffect, useCallback, memo, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat, ApiTypingStatus } from '../../api/types'; import { GlobalState } from '../../global/types'; @@ -63,7 +63,7 @@ const GroupChatInfo: FC = ({ const { loadFullChat, openMediaViewer, - } = getDispatch(); + } = getActions(); const isSuperGroup = chat && isChatSuperGroup(chat); const { id: chatId, isMin, isRestricted } = chat || {}; diff --git a/src/components/common/MessageLink.tsx b/src/components/common/MessageLink.tsx index 95d8a3942..949daeed7 100644 --- a/src/components/common/MessageLink.tsx +++ b/src/components/common/MessageLink.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import { ApiMessage } from '../../api/types'; @@ -16,7 +16,7 @@ type OwnProps = { const MessageLink: FC = ({ className, message, children, }) => { - const { focusMessage } = getDispatch(); + const { focusMessage } = getActions(); const handleMessageClick = useCallback((): void => { if (message) { diff --git a/src/components/common/PinMessageModal.tsx b/src/components/common/PinMessageModal.tsx index b1a992e42..6c294656b 100644 --- a/src/components/common/PinMessageModal.tsx +++ b/src/components/common/PinMessageModal.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { selectChat, selectIsChatWithSelf, selectUser } from '../../modules/selectors'; import { @@ -44,7 +44,7 @@ const PinMessageModal: FC = ({ contactName, onClose, }) => { - const { pinMessage } = getDispatch(); + const { pinMessage } = getActions(); const handlePinMessageForAll = useCallback(() => { pinMessage({ diff --git a/src/components/common/PrivateChatInfo.tsx b/src/components/common/PrivateChatInfo.tsx index ebb766d08..11cf57059 100644 --- a/src/components/common/PrivateChatInfo.tsx +++ b/src/components/common/PrivateChatInfo.tsx @@ -2,7 +2,7 @@ import { MouseEvent as ReactMouseEvent } from 'react'; import React, { FC, useEffect, useCallback, memo, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiUser, ApiTypingStatus, ApiUserStatus } from '../../api/types'; import { GlobalState } from '../../global/types'; @@ -64,7 +64,7 @@ const PrivateChatInfo: FC = ({ const { loadFullUser, openMediaViewer, - } = getDispatch(); + } = getActions(); const { id: userId } = user || {}; const fullName = getUserFullName(user); diff --git a/src/components/common/ProfileInfo.tsx b/src/components/common/ProfileInfo.tsx index 1cc91ca45..bf32ae154 100644 --- a/src/components/common/ProfileInfo.tsx +++ b/src/components/common/ProfileInfo.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useCallback, memo, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiUser, ApiChat, ApiUserStatus } from '../../api/types'; import { GlobalState } from '../../global/types'; @@ -53,7 +53,7 @@ const ProfileInfo: FC = ({ const { loadFullUser, openMediaViewer, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/common/ReportMessageModal.tsx b/src/components/common/ReportMessageModal.tsx index 63ef39dd0..5ea8a0a9c 100644 --- a/src/components/common/ReportMessageModal.tsx +++ b/src/components/common/ReportMessageModal.tsx @@ -3,7 +3,7 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useState, } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import { ApiReportReason } from '../../api/types'; @@ -28,7 +28,7 @@ const ReportMessageModal: FC = ({ const { reportMessages, exitMessageSelectMode, - } = getDispatch(); + } = getActions(); const [selectedReason, setSelectedReason] = useState('spam'); const [description, setDescription] = useState(''); diff --git a/src/components/common/SafeLink.tsx b/src/components/common/SafeLink.tsx index db89694a9..a1d32f305 100644 --- a/src/components/common/SafeLink.tsx +++ b/src/components/common/SafeLink.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import convertPunycode from '../../lib/punycode'; import { @@ -23,7 +23,7 @@ const SafeLink: FC = ({ children, isRtl, }) => { - const { toggleSafeLinkModal, openTelegramLink } = getDispatch(); + const { toggleSafeLinkModal, openTelegramLink } = getActions(); const content = children || text; const isNotSafe = url !== content; diff --git a/src/components/common/SeenByModal.tsx b/src/components/common/SeenByModal.tsx index 87acf22bb..dfb71453c 100644 --- a/src/components/common/SeenByModal.tsx +++ b/src/components/common/SeenByModal.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import useLang from '../../hooks/useLang'; import { selectChatMessage } from '../../modules/selectors'; @@ -27,7 +27,7 @@ const SeenByModal: FC = ({ const { openChat, closeSeenByModal, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/common/StickerSetModal.tsx b/src/components/common/StickerSetModal.tsx index 3ced4bbba..5d58a50d1 100644 --- a/src/components/common/StickerSetModal.tsx +++ b/src/components/common/StickerSetModal.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiSticker, ApiStickerSet } from '../../api/types'; @@ -47,7 +47,7 @@ const StickerSetModal: FC = ({ loadStickers, toggleStickerSet, sendMessage, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/common/UiLoader.tsx b/src/components/common/UiLoader.tsx index 56189e6f5..71e0a0205 100644 --- a/src/components/common/UiLoader.tsx +++ b/src/components/common/UiLoader.tsx @@ -1,5 +1,5 @@ import React, { FC, useEffect } from '../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../modules'; +import { getActions, getGlobal, withGlobal } from '../../modules'; import { ApiMediaFormat } from '../../api/types'; import { GlobalState } from '../../global/types'; @@ -85,7 +85,7 @@ const UiLoader: FC = ({ shouldSkipHistoryAnimations, leftColumnWidth, }) => { - const { setIsUiReady } = getDispatch(); + const { setIsUiReady } = getActions(); const [isReady, markReady] = useFlag(); const { diff --git a/src/components/common/UserLink.tsx b/src/components/common/UserLink.tsx index cfa8618bb..1ce2fe580 100644 --- a/src/components/common/UserLink.tsx +++ b/src/components/common/UserLink.tsx @@ -5,7 +5,7 @@ import { ApiChat, ApiUser } from '../../api/types'; import buildClassName from '../../util/buildClassName'; import Link from '../ui/Link'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; type OwnProps = { className?: string; @@ -16,7 +16,7 @@ type OwnProps = { const UserLink: FC = ({ className, sender, children, }) => { - const { openChat } = getDispatch(); + const { openChat } = getActions(); const handleClick = useCallback(() => { if (sender) { diff --git a/src/components/common/helpers/renderTextWithEntities.tsx b/src/components/common/helpers/renderTextWithEntities.tsx index 1690f18d4..d6ad0930c 100644 --- a/src/components/common/helpers/renderTextWithEntities.tsx +++ b/src/components/common/helpers/renderTextWithEntities.tsx @@ -1,6 +1,6 @@ import { MouseEvent } from 'react'; import React from '../../../lib/teact/teact'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { ApiFormattedText, ApiMessageEntity, ApiMessageEntityTypes } from '../../../api/types'; import renderText, { TextFilter } from './renderText'; @@ -454,10 +454,10 @@ function getLinkUrl(entityContent: string, entity: ApiMessageEntity) { } function handleBotCommandClick(e: MouseEvent) { - getDispatch().sendBotCommand({ command: e.currentTarget.innerText }); + getActions().sendBotCommand({ command: e.currentTarget.innerText }); } function handleHashtagClick(e: MouseEvent) { - getDispatch().setLocalTextSearchQuery({ query: e.currentTarget.innerText }); - getDispatch().searchTextMessagesLocal(); + getActions().setLocalTextSearchQuery({ query: e.currentTarget.innerText }); + getActions().searchTextMessagesLocal(); } diff --git a/src/components/common/hooks/useAnimatedEmoji.ts b/src/components/common/hooks/useAnimatedEmoji.ts index 33a0ddf61..33d0914a3 100644 --- a/src/components/common/hooks/useAnimatedEmoji.ts +++ b/src/components/common/hooks/useAnimatedEmoji.ts @@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState, } from '../../../lib/teact/teact'; import safePlay from '../../../util/safePlay'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import useMedia from '../../../hooks/useMedia'; import { ActiveEmojiInteraction } from '../../../global/types'; import useFlag from '../../../hooks/useFlag'; @@ -29,7 +29,7 @@ export default function useAnimatedEmoji( ) { const { interactWithAnimatedEmoji, sendEmojiInteraction, sendWatchingEmojiInteraction, - } = getDispatch(); + } = getActions(); const hasEffect = localEffect || emoji; const [isAnimationLoaded, markAnimationLoaded] = useFlag(); diff --git a/src/components/left/ChatFolderModal.tsx b/src/components/left/ChatFolderModal.tsx index c9a3ef280..f03d3d0cc 100644 --- a/src/components/left/ChatFolderModal.tsx +++ b/src/components/left/ChatFolderModal.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, memo, useMemo, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChatFolder } from '../../api/types'; @@ -31,7 +31,7 @@ const ChatFolderModal: FC = ({ onClose, onCloseAnimationEnd, }) => { - const { editChatFolders } = getDispatch(); + const { editChatFolders } = getActions(); const lang = useLang(); diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index b917e0a7e..9cecf6d77 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { LeftColumnContent, SettingsScreens } from '../../types'; @@ -57,7 +57,7 @@ const LeftColumn: FC = ({ clearTwoFaError, setLeftColumnWidth, resetLeftColumnWidth, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const resizeRef = useRef(null); diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index e91ebce65..fc98d552b 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useLayoutEffect, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import useLang, { LangFn } from '../../../hooks/useLang'; @@ -108,7 +108,7 @@ const Chat: FC = ({ const { openChat, focusLastMessage, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const ref = useRef(null); diff --git a/src/components/left/main/ChatFolders.tsx b/src/components/left/main/ChatFolders.tsx index 6a2cb2096..72f57c26d 100644 --- a/src/components/left/main/ChatFolders.tsx +++ b/src/components/left/main/ChatFolders.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChatFolder } from '../../../api/types'; import { SettingsScreens } from '../../../types'; @@ -51,7 +51,7 @@ const ChatFolders: FC = ({ loadChatFolders, setActiveChatFolder, openChat, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const transitionRef = useRef(null); diff --git a/src/components/left/main/ChatList.tsx b/src/components/left/main/ChatList.tsx index 873f89e9e..b3d3095f8 100644 --- a/src/components/left/main/ChatList.tsx +++ b/src/components/left/main/ChatList.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useMemo, useEffect, } from '../../../lib/teact/teact'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { SettingsScreens } from '../../../types'; import { FolderEditDispatch } from '../../../hooks/reducers/useFoldersReducer'; @@ -41,7 +41,7 @@ const ChatList: FC = ({ foldersDispatch, onScreenSelect, }) => { - const { openChat, openNextChat } = getDispatch(); + const { openChat, openNextChat } = getActions(); const resolvedFolderId = ( folderType === 'all' ? ALL_FOLDER_ID : folderType === 'archived' ? ARCHIVED_FOLDER_ID : folderId! diff --git a/src/components/left/main/ContactList.tsx b/src/components/left/main/ContactList.tsx index f12c808ad..cc547d84c 100644 --- a/src/components/left/main/ContactList.tsx +++ b/src/components/left/main/ContactList.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useCallback, useMemo, memo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiUser, ApiUserStatus } from '../../../api/types'; @@ -43,7 +43,7 @@ const ContactList: FC = ({ const { loadContactList, openChat, - } = getDispatch(); + } = getActions(); // Due to the parent Transition, this component never gets unmounted, // that's why we use throttled API call on every update. diff --git a/src/components/left/main/LeftMainHeader.tsx b/src/components/left/main/LeftMainHeader.tsx index 5434b7eba..1fed75f2e 100644 --- a/src/components/left/main/LeftMainHeader.tsx +++ b/src/components/left/main/LeftMainHeader.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ISettings, LeftColumnContent } from '../../../types'; import { ApiChat } from '../../../api/types'; @@ -95,7 +95,7 @@ const LeftMainHeader: FC = ({ setGlobalSearchDate, setSettingOption, setGlobalSearchChatId, - } = getDispatch(); + } = getActions(); const lang = useLang(); const hasMenu = content === LeftColumnContent.ChatList; diff --git a/src/components/left/newChat/NewChatStep1.tsx b/src/components/left/newChat/NewChatStep1.tsx index 8628ee121..079d70b0e 100644 --- a/src/components/left/newChat/NewChatStep1.tsx +++ b/src/components/left/newChat/NewChatStep1.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useEffect, useMemo, memo, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { ApiChat } from '../../../api/types'; @@ -52,7 +52,7 @@ const NewChatStep1: FC = ({ const { loadContactList, setGlobalSearchQuery, - } = getDispatch(); + } = getActions(); // Due to the parent Transition, this component never gets unmounted, // that's why we use throttled API call on every update. diff --git a/src/components/left/newChat/NewChatStep2.tsx b/src/components/left/newChat/NewChatStep2.tsx index d50c6a62d..64b7ad2ab 100644 --- a/src/components/left/newChat/NewChatStep2.tsx +++ b/src/components/left/newChat/NewChatStep2.tsx @@ -1,7 +1,7 @@ import React, { FC, useState, useCallback, useEffect, memo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ChatCreationProgress } from '../../../types'; @@ -42,7 +42,7 @@ const NewChatStep2: FC = ({ const { createGroupChat, createChannel, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/left/search/AudioResults.tsx b/src/components/left/search/AudioResults.tsx index 765c122ed..7806f7502 100644 --- a/src/components/left/search/AudioResults.tsx +++ b/src/components/left/search/AudioResults.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { AudioOrigin, LoadMoreDirection } from '../../../types'; @@ -43,7 +43,7 @@ const AudioResults: FC = ({ searchMessagesGlobal, focusMessage, openAudioPlayer, - } = getDispatch(); + } = getActions(); const lang = useLang(); const currentType = isVoice ? 'voice' : 'audio'; diff --git a/src/components/left/search/ChatMessage.tsx b/src/components/left/search/ChatMessage.tsx index f3134160f..5c84cefba 100644 --- a/src/components/left/search/ChatMessage.tsx +++ b/src/components/left/search/ChatMessage.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiUser, ApiMessage, ApiMessageOutgoingStatus, @@ -52,7 +52,7 @@ const ChatMessage: FC = ({ privateChatUser, lastSyncTime, }) => { - const { focusMessage } = getDispatch(); + const { focusMessage } = getActions(); const mediaThumbnail = getMessageMediaThumbDataUri(message); const mediaBlobUrl = useMedia(getMessageMediaHash(message, 'micro')); diff --git a/src/components/left/search/ChatMessageResults.tsx b/src/components/left/search/ChatMessageResults.tsx index a4252edf6..69f48784e 100644 --- a/src/components/left/search/ChatMessageResults.tsx +++ b/src/components/left/search/ChatMessageResults.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiMessage } from '../../../api/types'; import { LoadMoreDirection } from '../../../types'; @@ -45,7 +45,7 @@ const ChatMessageResults: FC = ({ lastSyncTime, onSearchDateSelect, }) => { - const { searchMessagesGlobal } = getDispatch(); + const { searchMessagesGlobal } = getActions(); const lang = useLang(); const handleLoadMore = useCallback(({ direction }: { direction: LoadMoreDirection }) => { diff --git a/src/components/left/search/ChatResults.tsx b/src/components/left/search/ChatResults.tsx index 969123e1c..1103c583c 100644 --- a/src/components/left/search/ChatResults.tsx +++ b/src/components/left/search/ChatResults.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { ApiChat, ApiMessage } from '../../../api/types'; import { LoadMoreDirection } from '../../../types'; @@ -61,7 +61,7 @@ const ChatResults: FC = ({ }) => { const { openChat, addRecentlyFoundChatId, searchMessagesGlobal, setGlobalSearchChatId, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/left/search/FileResults.tsx b/src/components/left/search/FileResults.tsx index 6835097a1..390c08649 100644 --- a/src/components/left/search/FileResults.tsx +++ b/src/components/left/search/FileResults.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiMessage } from '../../../api/types'; import { LoadMoreDirection } from '../../../types'; @@ -45,7 +45,7 @@ const FileResults: FC = ({ const { searchMessagesGlobal, focusMessage, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/left/search/LeftSearch.tsx b/src/components/left/search/LeftSearch.tsx index 2eed43d04..2096205b7 100644 --- a/src/components/left/search/LeftSearch.tsx +++ b/src/components/left/search/LeftSearch.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useState, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { GlobalSearchContent } from '../../../types'; @@ -60,7 +60,7 @@ const LeftSearch: FC = ({ const { setGlobalSearchContent, setGlobalSearchDate, - } = getDispatch(); + } = getActions(); const lang = useLang(); const [activeTab, setActiveTab] = useState(currentContent); diff --git a/src/components/left/search/LinkResults.tsx b/src/components/left/search/LinkResults.tsx index a586690d1..db72fae0a 100644 --- a/src/components/left/search/LinkResults.tsx +++ b/src/components/left/search/LinkResults.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { LoadMoreDirection } from '../../../types'; @@ -43,7 +43,7 @@ const LinkResults: FC = ({ const { searchMessagesGlobal, focusMessage, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/left/search/MediaResults.tsx b/src/components/left/search/MediaResults.tsx index 1553ca3ca..64b1e2606 100644 --- a/src/components/left/search/MediaResults.tsx +++ b/src/components/left/search/MediaResults.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { LoadMoreDirection, MediaViewerOrigin } from '../../../types'; @@ -41,7 +41,7 @@ const MediaResults: FC = ({ const { searchMessagesGlobal, openMediaViewer, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/left/search/RecentContacts.tsx b/src/components/left/search/RecentContacts.tsx index 5b2e12594..d98c8b527 100644 --- a/src/components/left/search/RecentContacts.tsx +++ b/src/components/left/search/RecentContacts.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useCallback, useRef, memo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiUser } from '../../../api/types'; @@ -39,7 +39,7 @@ const RecentContacts: FC = ({ const { loadTopUsers, loadContactList, openChat, addRecentlyFoundChatId, clearRecentlyFoundChats, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const topUsersRef = useRef(null); diff --git a/src/components/left/settings/BlockUserModal.tsx b/src/components/left/settings/BlockUserModal.tsx index a05be8442..56661e993 100644 --- a/src/components/left/settings/BlockUserModal.tsx +++ b/src/components/left/settings/BlockUserModal.tsx @@ -1,7 +1,7 @@ import React, { FC, useMemo, useState, memo, useRef, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiUser } from '../../../api/types'; @@ -37,7 +37,7 @@ const BlockUserModal: FC = ({ loadContactList, setUserSearchQuery, blockContact, - } = getDispatch(); + } = getActions(); const lang = useLang(); const [filter, setFilter] = useState(''); diff --git a/src/components/left/settings/SettingsDataStorage.tsx b/src/components/left/settings/SettingsDataStorage.tsx index 781131665..88dd4b413 100644 --- a/src/components/left/settings/SettingsDataStorage.tsx +++ b/src/components/left/settings/SettingsDataStorage.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens, ISettings } from '../../../types'; @@ -55,7 +55,7 @@ const SettingsDataStorage: FC = ({ canAutoPlayVideos, autoLoadFileMaxSizeMb, }) => { - const { setSettingOption } = getDispatch(); + const { setSettingOption } = getActions(); const lang = useLang(); diff --git a/src/components/left/settings/SettingsEditProfile.tsx b/src/components/left/settings/SettingsEditProfile.tsx index 0c43950bd..b5a341f3b 100644 --- a/src/components/left/settings/SettingsEditProfile.tsx +++ b/src/components/left/settings/SettingsEditProfile.tsx @@ -2,7 +2,7 @@ import { ChangeEvent } from 'react'; import React, { FC, useState, useCallback, memo, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiMediaFormat } from '../../../api/types'; import { ProfileEditProgress, SettingsScreens } from '../../../types'; @@ -60,7 +60,7 @@ const SettingsEditProfile: FC = ({ loadCurrentUser, updateProfile, checkUsername, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/left/settings/SettingsGeneral.tsx b/src/components/left/settings/SettingsGeneral.tsx index 31d4bee2e..cf369cff9 100644 --- a/src/components/left/settings/SettingsGeneral.tsx +++ b/src/components/left/settings/SettingsGeneral.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, memo, useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens, ISettings, TimeFormat } from '../../../types'; import { ApiSticker, ApiStickerSet } from '../../../api/types'; @@ -72,7 +72,7 @@ const SettingsGeneral: FC = ({ }) => { const { setSettingOption, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const stickerSettingsRef = useRef(null); diff --git a/src/components/left/settings/SettingsGeneralBackground.tsx b/src/components/left/settings/SettingsGeneralBackground.tsx index 894d3979c..1172aace4 100644 --- a/src/components/left/settings/SettingsGeneralBackground.tsx +++ b/src/components/left/settings/SettingsGeneralBackground.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useEffect, useCallback, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens, ThemeKey, UPLOADING_WALLPAPER_SLUG } from '../../../types'; import { ApiWallpaper } from '../../../api/types'; @@ -51,7 +51,7 @@ const SettingsGeneralBackground: FC = ({ loadWallpapers, uploadWallpaper, setThemeSettings, - } = getDispatch(); + } = getActions(); const themeRef = useRef(); themeRef.current = theme; diff --git a/src/components/left/settings/SettingsGeneralBackgroundColor.tsx b/src/components/left/settings/SettingsGeneralBackgroundColor.tsx index acb3d29bf..6b8afcae5 100644 --- a/src/components/left/settings/SettingsGeneralBackgroundColor.tsx +++ b/src/components/left/settings/SettingsGeneralBackgroundColor.tsx @@ -2,7 +2,7 @@ import { ChangeEvent, MutableRefObject, RefObject } from 'react'; import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens, ThemeKey } from '../../../types'; @@ -57,7 +57,7 @@ const SettingsGeneralBackground: FC = ({ theme, backgroundColor, }) => { - const { setThemeSettings } = getDispatch(); + const { setThemeSettings } = getActions(); const themeRef = useRef(); themeRef.current = theme; diff --git a/src/components/left/settings/SettingsHeader.tsx b/src/components/left/settings/SettingsHeader.tsx index 4817f7850..25872b678 100644 --- a/src/components/left/settings/SettingsHeader.tsx +++ b/src/components/left/settings/SettingsHeader.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { SettingsScreens } from '../../../types'; @@ -31,7 +31,7 @@ const SettingsHeader: FC = ({ const { signOut, deleteChatFolder, - } = getDispatch(); + } = getActions(); const [isSignOutDialogOpen, setIsSignOutDialogOpen] = useState(false); const [isDeleteFolderDialogOpen, setIsDeleteFolderDialogOpen] = useState(false); diff --git a/src/components/left/settings/SettingsLanguage.tsx b/src/components/left/settings/SettingsLanguage.tsx index dc321edaa..14d7a4e89 100644 --- a/src/components/left/settings/SettingsLanguage.tsx +++ b/src/components/left/settings/SettingsLanguage.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ISettings, LangCode, SettingsScreens } from '../../../types'; import { ApiLanguage } from '../../../api/types'; @@ -31,7 +31,7 @@ const SettingsLanguage: FC = ({ const { loadLanguages, setSettingOption, - } = getDispatch(); + } = getActions(); const [selectedLanguage, setSelectedLanguage] = useState(language); const [isLoading, markIsLoading, unmarkIsLoading] = useFlag(); diff --git a/src/components/left/settings/SettingsMain.tsx b/src/components/left/settings/SettingsMain.tsx index eb73fdc37..67a196c42 100644 --- a/src/components/left/settings/SettingsMain.tsx +++ b/src/components/left/settings/SettingsMain.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens } from '../../../types'; import { ApiUser } from '../../../api/types'; @@ -30,7 +30,7 @@ const SettingsMain: FC = ({ currentUser, lastSyncTime, }) => { - const { loadProfilePhotos } = getDispatch(); + const { loadProfilePhotos } = getActions(); const lang = useLang(); const profileId = currentUser?.id; diff --git a/src/components/left/settings/SettingsNotifications.tsx b/src/components/left/settings/SettingsNotifications.tsx index 0c9d9a40b..d0d366039 100644 --- a/src/components/left/settings/SettingsNotifications.tsx +++ b/src/components/left/settings/SettingsNotifications.tsx @@ -3,7 +3,7 @@ import useDebounce from '../../../hooks/useDebounce'; import React, { FC, memo, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens } from '../../../types'; @@ -53,7 +53,7 @@ const SettingsNotifications: FC = ({ updateContactSignUpNotification, updateNotificationSettings, updateWebNotificationSettings, - } = getDispatch(); + } = getActions(); useEffect(() => { loadNotificationSettings(); diff --git a/src/components/left/settings/SettingsPrivacy.tsx b/src/components/left/settings/SettingsPrivacy.tsx index e339b402a..13e8a2da0 100644 --- a/src/components/left/settings/SettingsPrivacy.tsx +++ b/src/components/left/settings/SettingsPrivacy.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { PrivacyVisibility, SettingsScreens } from '../../../types'; @@ -50,7 +50,7 @@ const SettingsPrivacy: FC = ({ loadAuthorizations, loadContentSettings, updateContentSettings, - } = getDispatch(); + } = getActions(); useEffect(() => { loadBlockedContacts(); diff --git a/src/components/left/settings/SettingsPrivacyActiveSessions.tsx b/src/components/left/settings/SettingsPrivacyActiveSessions.tsx index 8748b043d..cb8163c60 100644 --- a/src/components/left/settings/SettingsPrivacyActiveSessions.tsx +++ b/src/components/left/settings/SettingsPrivacyActiveSessions.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiSession } from '../../../api/types'; import { SettingsScreens } from '../../../types'; @@ -34,7 +34,7 @@ const SettingsPrivacyActiveSessions: FC = ({ loadAuthorizations, terminateAuthorization, terminateAllAuthorizations, - } = getDispatch(); + } = getActions(); const [isConfirmTerminateAllDialogOpen, openConfirmTerminateAllDialog, closeConfirmTerminateAllDialog] = useFlag(); useEffect(() => { diff --git a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx index b53d1cf6a..56b8075e5 100644 --- a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx +++ b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiCountryCode, ApiUser } from '../../../api/types'; import { SettingsScreens } from '../../../types'; @@ -45,7 +45,7 @@ const SettingsPrivacyBlockedUsers: FC = ({ blockedIds, phoneCodeList, }) => { - const { unblockContact } = getDispatch(); + const { unblockContact } = getActions(); const lang = useLang(); const [isBlockUserModalOpen, openBlockUserModal, closeBlockUserModal] = useFlag(); diff --git a/src/components/left/settings/SettingsPrivacyVisibility.tsx b/src/components/left/settings/SettingsPrivacyVisibility.tsx index 82afcfddd..59551ef50 100644 --- a/src/components/left/settings/SettingsPrivacyVisibility.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibility.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiUser } from '../../../api/types'; import { ApiPrivacySettings, SettingsScreens } from '../../../types'; @@ -38,7 +38,7 @@ const SettingsPrivacyVisibility: FC = ({ blockChatIds, chatsById, }) => { - const { setPrivacyVisibility } = getDispatch(); + const { setPrivacyVisibility } = getActions(); const lang = useLang(); diff --git a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx index ec32c5302..4dfba4dd6 100644 --- a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { GlobalState } from '../../../global/types'; import { ApiPrivacySettings, SettingsScreens } from '../../../types'; @@ -39,7 +39,7 @@ const SettingsPrivacyVisibilityExceptionList: FC = ({ currentUserId, settings, }) => { - const { setPrivacySettings } = getDispatch(); + const { setPrivacySettings } = getActions(); const lang = useLang(); diff --git a/src/components/left/settings/SettingsQuickReaction.tsx b/src/components/left/settings/SettingsQuickReaction.tsx index e20229658..032ac541a 100644 --- a/src/components/left/settings/SettingsQuickReaction.tsx +++ b/src/components/left/settings/SettingsQuickReaction.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { SettingsScreens } from '../../../types'; import { ApiAvailableReaction } from '../../../api/types'; @@ -27,7 +27,7 @@ const SettingsQuickReaction: FC = ({ availableReactions, selectedReaction, }) => { - const { setDefaultReaction } = getDispatch(); + const { setDefaultReaction } = getActions(); useHistoryBack(isActive, onReset, onScreenSelect, SettingsScreens.General); const options = availableReactions?.filter((l) => !l.isInactive).map((l) => { diff --git a/src/components/left/settings/folders/SettingsFoldersEdit.tsx b/src/components/left/settings/folders/SettingsFoldersEdit.tsx index bb1be6fd3..5013dbd42 100644 --- a/src/components/left/settings/folders/SettingsFoldersEdit.tsx +++ b/src/components/left/settings/folders/SettingsFoldersEdit.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../../modules'; +import { getActions, withGlobal } from '../../../../modules'; import { SettingsScreens } from '../../../../types'; @@ -66,7 +66,7 @@ const SettingsFoldersEdit: FC = ({ const { editChatFolder, addChatFolder, - } = getDispatch(); + } = getActions(); const [animationData, setAnimationData] = useState(); const [isAnimationLoaded, setIsAnimationLoaded] = useState(false); diff --git a/src/components/left/settings/folders/SettingsFoldersMain.tsx b/src/components/left/settings/folders/SettingsFoldersMain.tsx index 49604b290..5bf4b7dcf 100644 --- a/src/components/left/settings/folders/SettingsFoldersMain.tsx +++ b/src/components/left/settings/folders/SettingsFoldersMain.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useMemo, useCallback, useState, useEffect, } from '../../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../../modules'; +import { getActions, withGlobal } from '../../../../modules'; import { ApiChatFolder } from '../../../../api/types'; import { SettingsScreens } from '../../../../types'; @@ -51,7 +51,7 @@ const SettingsFoldersMain: FC = ({ loadRecommendedChatFolders, addChatFolder, showDialog, - } = getDispatch(); + } = getActions(); const [animationData, setAnimationData] = useState(); const [isAnimationLoaded, setIsAnimationLoaded] = useState(false); diff --git a/src/components/left/settings/twoFa/SettingsTwoFa.tsx b/src/components/left/settings/twoFa/SettingsTwoFa.tsx index 9066d9b01..b654f552c 100644 --- a/src/components/left/settings/twoFa/SettingsTwoFa.tsx +++ b/src/components/left/settings/twoFa/SettingsTwoFa.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, } from '../../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../../modules'; +import { getActions, withGlobal } from '../../../../modules'; import { GlobalState } from '../../../../global/types'; import { SettingsScreens } from '../../../../types'; @@ -48,7 +48,7 @@ const SettingsTwoFa: FC = ({ updateRecoveryEmail, provideTwoFaEmailCode, clearPassword, - } = getDispatch(); + } = getActions(); useEffect(() => { if (waitingEmailCodeLength) { diff --git a/src/components/main/Dialogs.tsx b/src/components/main/Dialogs.tsx index 132d3a6e6..148d91ce3 100644 --- a/src/components/main/Dialogs.tsx +++ b/src/components/main/Dialogs.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useEffect } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiContact, ApiError, ApiInviteInfo, ApiPhoto, @@ -27,7 +27,7 @@ const Dialogs: FC = ({ dialogs }) => { acceptInviteConfirmation, sendMessage, showNotification, - } = getDispatch(); + } = getActions(); const [isModalOpen, openModal, closeModal] = useFlag(); const lang = useLang(); diff --git a/src/components/main/DownloadManager.tsx b/src/components/main/DownloadManager.tsx index 90743f7eb..f8ebb848b 100644 --- a/src/components/main/DownloadManager.tsx +++ b/src/components/main/DownloadManager.tsx @@ -1,5 +1,5 @@ import { FC, memo, useEffect } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { Thread } from '../../global/types'; import { ApiMediaFormat, ApiMessage } from '../../api/types'; @@ -24,7 +24,7 @@ const DownloadManager: FC = ({ activeDownloads, messages, }) => { - const { cancelMessageMediaDownload } = getDispatch(); + const { cancelMessageMediaDownload } = getActions(); useEffect(() => { Object.entries(activeDownloads).forEach(([chatId, messageIds]) => { diff --git a/src/components/main/ForwardPicker.tsx b/src/components/main/ForwardPicker.tsx index 3f243401f..e175374d7 100644 --- a/src/components/main/ForwardPicker.tsx +++ b/src/components/main/ForwardPicker.tsx @@ -1,7 +1,7 @@ import React, { FC, useMemo, useState, memo, useRef, useCallback, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../modules'; +import { getActions, getGlobal, withGlobal } from '../../modules'; import { ApiChat, MAIN_THREAD_ID } from '../../api/types'; @@ -43,7 +43,7 @@ const ForwardPicker: FC = ({ const { setForwardChatId, exitForwardMode, - } = getDispatch(); + } = getActions(); const lang = useLang(); const [filter, setFilter] = useState(''); diff --git a/src/components/main/HistoryCalendar.tsx b/src/components/main/HistoryCalendar.tsx index 48676c83c..38bc088e3 100644 --- a/src/components/main/HistoryCalendar.tsx +++ b/src/components/main/HistoryCalendar.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import useLang from '../../hooks/useLang'; @@ -16,7 +16,7 @@ type StateProps = { const HistoryCalendar: FC = ({ isOpen, selectedAt, }) => { - const { searchMessagesByDate, closeHistoryCalendar } = getDispatch(); + const { searchMessagesByDate, closeHistoryCalendar } = getActions(); const handleJumpToDate = useCallback((date: Date) => { searchMessagesByDate({ timestamp: date.valueOf() / 1000 }); diff --git a/src/components/main/Main.tsx b/src/components/main/Main.tsx index 4cebdfe4d..17ba7925f 100644 --- a/src/components/main/Main.tsx +++ b/src/components/main/Main.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, memo, useCallback, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { LangCode } from '../../types'; import { ApiMessage, ApiUpdateAuthorizationStateType, ApiUpdateConnectionStateType } from '../../api/types'; @@ -122,7 +122,7 @@ const Main: FC = ({ openStickerSetShortName, checkVersionNotification, loadAppConfig, - } = getDispatch(); + } = getActions(); if (DEBUG && !DEBUG_isLogged) { DEBUG_isLogged = true; diff --git a/src/components/main/Notifications.tsx b/src/components/main/Notifications.tsx index b7d2650a9..9f22972de 100644 --- a/src/components/main/Notifications.tsx +++ b/src/components/main/Notifications.tsx @@ -1,5 +1,5 @@ import React, { FC, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiNotification } from '../../api/types'; @@ -13,7 +13,7 @@ type StateProps = { }; const Notifications: FC = ({ notifications }) => { - const { dismissNotification } = getDispatch(); + const { dismissNotification } = getActions(); if (!notifications.length) { return undefined; diff --git a/src/components/main/SafeLinkModal.tsx b/src/components/main/SafeLinkModal.tsx index 2f11621e7..07476650c 100644 --- a/src/components/main/SafeLinkModal.tsx +++ b/src/components/main/SafeLinkModal.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../lib/teact/teact'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; import { ensureProtocol } from '../../util/ensureProtocol'; import renderText from '../common/helpers/renderText'; @@ -13,7 +13,7 @@ export type OwnProps = { }; const SafeLinkModal: FC = ({ url }) => { - const { toggleSafeLinkModal } = getDispatch(); + const { toggleSafeLinkModal } = getActions(); const lang = useLang(); diff --git a/src/components/mediaViewer/MediaViewer.tsx b/src/components/mediaViewer/MediaViewer.tsx index f705fd606..43c701404 100644 --- a/src/components/mediaViewer/MediaViewer.tsx +++ b/src/components/mediaViewer/MediaViewer.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat, ApiDimensions, ApiMediaFormat, ApiMessage, ApiUser, @@ -101,7 +101,7 @@ const MediaViewer: FC = ({ openForwardMenu, focusMessage, toggleChatInfo, - } = getDispatch(); + } = getActions(); const isOpen = Boolean(avatarOwner || messageId); diff --git a/src/components/mediaViewer/MediaViewerActions.tsx b/src/components/mediaViewer/MediaViewerActions.tsx index 1b4a3ef9f..5f5809be7 100644 --- a/src/components/mediaViewer/MediaViewerActions.tsx +++ b/src/components/mediaViewer/MediaViewerActions.tsx @@ -4,7 +4,7 @@ import React, { useCallback, useMemo, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiMessage } from '../../api/types'; @@ -54,7 +54,7 @@ const MediaViewerActions: FC = ({ const { downloadMessageMedia, cancelMessageMediaDownload, - } = getDispatch(); + } = getActions(); const { loadProgress: downloadProgress } = useMediaWithLoadProgress( message && getMessageMediaHash(message, 'download'), diff --git a/src/components/mediaViewer/SenderInfo.tsx b/src/components/mediaViewer/SenderInfo.tsx index 07f12242d..0dd71f16e 100644 --- a/src/components/mediaViewer/SenderInfo.tsx +++ b/src/components/mediaViewer/SenderInfo.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat, ApiMessage, ApiUser } from '../../api/types'; @@ -43,7 +43,7 @@ const SenderInfo: FC = ({ closeMediaViewer, focusMessage, toggleChatInfo, - } = getDispatch(); + } = getActions(); const handleFocusMessage = useCallback(() => { closeMediaViewer(); diff --git a/src/components/middle/AudioPlayer.tsx b/src/components/middle/AudioPlayer.tsx index 08333cd01..8f3ce4418 100644 --- a/src/components/middle/AudioPlayer.tsx +++ b/src/components/middle/AudioPlayer.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useEffect, useMemo, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { AudioOrigin } from '../../types'; import { @@ -63,7 +63,7 @@ const AudioPlayer: FC = ({ setAudioPlayerMuted, focusMessage, closeAudioPlayer, - } = getDispatch(); + } = getActions(); const lang = useLang(); const { audio, voice, video } = getMessageContent(message); diff --git a/src/components/middle/ContactGreeting.tsx b/src/components/middle/ContactGreeting.tsx index 0c311fa67..ed0c5c572 100644 --- a/src/components/middle/ContactGreeting.tsx +++ b/src/components/middle/ContactGreeting.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiSticker, ApiUpdateConnectionStateType } from '../../api/types'; @@ -35,7 +35,7 @@ const ContactGreeting: FC = ({ loadGreetingStickers, sendMessage, markMessageListRead, - } = getDispatch(); + } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null diff --git a/src/components/middle/DeleteSelectedMessageModal.tsx b/src/components/middle/DeleteSelectedMessageModal.tsx index 05b33863f..d54524009 100644 --- a/src/components/middle/DeleteSelectedMessageModal.tsx +++ b/src/components/middle/DeleteSelectedMessageModal.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, memo, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { selectCanDeleteSelectedMessages, selectCurrentChat, selectUser } from '../../modules/selectors'; import { @@ -46,7 +46,7 @@ const DeleteSelectedMessageModal: FC = ({ deleteMessages, deleteScheduledMessages, exitMessageSelectMode, - } = getDispatch(); + } = getActions(); const prevIsOpen = usePrevious(isOpen); diff --git a/src/components/middle/EmojiInteractionAnimation.tsx b/src/components/middle/EmojiInteractionAnimation.tsx index be1209dc0..5db5fdbc9 100644 --- a/src/components/middle/EmojiInteractionAnimation.tsx +++ b/src/components/middle/EmojiInteractionAnimation.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useLayoutEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ActiveEmojiInteraction } from '../../global/types'; import { ApiMediaFormat } from '../../api/types'; @@ -38,7 +38,7 @@ const EmojiInteractionAnimation: FC = ({ localEffectAnimation, activeEmojiInteraction, }) => { - const { stopActiveEmojiInteraction } = getDispatch(); + const { stopActiveEmojiInteraction } = getActions(); const [isHiding, startHiding] = useFlag(false); const [isPlaying, startPlaying] = useFlag(false); diff --git a/src/components/middle/HeaderActions.tsx b/src/components/middle/HeaderActions.tsx index 52a0fc104..4b198f221 100644 --- a/src/components/middle/HeaderActions.tsx +++ b/src/components/middle/HeaderActions.tsx @@ -6,7 +6,7 @@ import React, { useState, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { MessageListType } from '../../global/types'; import { MAIN_THREAD_ID } from '../../api/types'; @@ -86,7 +86,7 @@ const HeaderActions: FC = ({ restartBot, openCallFallbackConfirm, requestNextManagementScreen, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const menuButtonRef = useRef(null); diff --git a/src/components/middle/HeaderMenuContainer.tsx b/src/components/middle/HeaderMenuContainer.tsx index 06818e6a1..ea17bc88c 100644 --- a/src/components/middle/HeaderMenuContainer.tsx +++ b/src/components/middle/HeaderMenuContainer.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat } from '../../api/types'; import { IAnchorPosition } from '../../types'; @@ -94,7 +94,7 @@ const HeaderMenuContainer: FC = ({ addContact, openCallFallbackConfirm, toggleStatistics, - } = getDispatch(); + } = getActions(); const [isMenuOpen, setIsMenuOpen] = useState(true); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 4c875d88b..1f36d71c9 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../modules'; +import { getActions, getGlobal, withGlobal } from '../../modules'; import { ApiMessage, ApiRestrictionReason, MAIN_THREAD_ID, @@ -140,7 +140,7 @@ const MessageList: FC = ({ }) => { const { loadViewportMessages, setScrollOffset, loadSponsoredMessages, loadMessageReactions, copyMessagesByIds, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/middle/MessageListContent.tsx b/src/components/middle/MessageListContent.tsx index 879e30582..c225d4821 100644 --- a/src/components/middle/MessageListContent.tsx +++ b/src/components/middle/MessageListContent.tsx @@ -19,7 +19,7 @@ import useMessageObservers from './hooks/useMessageObservers'; import Message from './message/Message'; import SponsoredMessage from './message/SponsoredMessage'; import ActionMessage from './ActionMessage'; -import { getDispatch } from '../../modules'; +import { getActions } from '../../modules'; interface OwnProps { chatId: string; @@ -74,7 +74,7 @@ const MessageListContent: FC = ({ onFabToggle, onNotchToggle, }) => { - const { openHistoryCalendar } = getDispatch(); + const { openHistoryCalendar } = getActions(); const { observeIntersectionForMedia, diff --git a/src/components/middle/MessageSelectToolbar.tsx b/src/components/middle/MessageSelectToolbar.tsx index 19dc64ca8..455323e41 100644 --- a/src/components/middle/MessageSelectToolbar.tsx +++ b/src/components/middle/MessageSelectToolbar.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { MessageListType } from '../../global/types'; @@ -60,7 +60,7 @@ const MessageSelectToolbar: FC = ({ openForwardMenuForSelectedMessages, downloadSelectedMessages, copySelectedMessages, - } = getDispatch(); + } = getActions(); const [isDeleteModalOpen, openDeleteModal, closeDeleteModal] = useFlag(); const [isReportModalOpen, openReportModal, closeReportModal] = useFlag(); diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 9bc9caa03..b2966cc11 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, useState, memo, useMemo, useCallback, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChatBannedRights, MAIN_THREAD_ID } from '../../api/types'; import { @@ -169,7 +169,7 @@ const MiddleColumn: FC = ({ joinChannel, sendBotCommand, restartBot, - } = getDispatch(); + } = getActions(); const { width: windowWidth } = useWindowSize(); diff --git a/src/components/middle/MiddleHeader.tsx b/src/components/middle/MiddleHeader.tsx index e39708121..5d25af836 100644 --- a/src/components/middle/MiddleHeader.tsx +++ b/src/components/middle/MiddleHeader.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import cycleRestrict from '../../util/cycleRestrict'; import { GlobalState, MessageListType } from '../../global/types'; @@ -124,7 +124,7 @@ const MiddleHeader: FC = ({ loadPinnedMessages, toggleLeftColumn, exitMessageSelectMode, - } = getDispatch(); + } = getActions(); const lang = useLang(); const isBackButtonActive = useRef(true); diff --git a/src/components/middle/MobileSearch.tsx b/src/components/middle/MobileSearch.tsx index 189bddc7c..c7d4fc634 100644 --- a/src/components/middle/MobileSearch.tsx +++ b/src/components/middle/MobileSearch.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, useLayoutEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat } from '../../api/types'; @@ -43,7 +43,7 @@ const MobileSearchFooter: FC = ({ focusMessage, closeLocalTextSearch, openHistoryCalendar, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); diff --git a/src/components/middle/ReactorListModal.tsx b/src/components/middle/ReactorListModal.tsx index b2052c786..7a0527509 100644 --- a/src/components/middle/ReactorListModal.tsx +++ b/src/components/middle/ReactorListModal.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, memo, useMemo, useEffect, useState, useRef, } from '../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../modules'; +import { getActions, getGlobal, withGlobal } from '../../modules'; import { ApiMessage } from '../../api/types'; import { LoadMoreDirection } from '../../types'; @@ -49,7 +49,7 @@ const ReactorListModal: FC = ({ loadReactors, closeReactorListModal, openChat, - } = getDispatch(); + } = getActions(); // No need for expensive global updates on users, so we avoid them const usersById = getGlobal().users.byId; diff --git a/src/components/middle/ScrollDownButton.tsx b/src/components/middle/ScrollDownButton.tsx index f5f9b99e1..480dd09ec 100644 --- a/src/components/middle/ScrollDownButton.tsx +++ b/src/components/middle/ScrollDownButton.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, memo, useRef, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { MessageListType } from '../../global/types'; import { MAIN_THREAD_ID } from '../../api/types'; @@ -36,7 +36,7 @@ const ScrollDownButton: FC = ({ unreadCount, withExtraShift, }) => { - const { focusNextReply } = getDispatch(); + const { focusNextReply } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null diff --git a/src/components/middle/UserReportPanel.tsx b/src/components/middle/UserReportPanel.tsx index 60569d365..0a4a8fd12 100644 --- a/src/components/middle/UserReportPanel.tsx +++ b/src/components/middle/UserReportPanel.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useState, } from '../../lib/teact/teact'; -import { withGlobal, getDispatch } from '../../modules'; +import { withGlobal, getActions } from '../../modules'; import { ApiUser } from '../../api/types'; @@ -31,7 +31,7 @@ const UserReportPanel: FC = ({ userId, user }) => { reportSpam, deleteChat, toggleChatArchived, - } = getDispatch(); + } = getActions(); const lang = useLang(); const [isBlockUserModalOpen, openBlockUserModal, closeBlockUserModal] = useFlag(); diff --git a/src/components/middle/composer/BotCommandMenu.tsx b/src/components/middle/composer/BotCommandMenu.tsx index 5eaa248b0..e0fd1f684 100644 --- a/src/components/middle/composer/BotCommandMenu.tsx +++ b/src/components/middle/composer/BotCommandMenu.tsx @@ -9,7 +9,7 @@ import Menu from '../../ui/Menu'; import BotCommand from './BotCommand'; import './BotCommandMenu.scss'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; export type OwnProps = { isOpen: boolean; @@ -20,7 +20,7 @@ export type OwnProps = { const BotCommandMenu: FC = ({ isOpen, botCommands, onClose, }) => { - const { sendBotCommand } = getDispatch(); + const { sendBotCommand } = getActions(); const [handleMouseEnter, handleMouseLeave] = useMouseInside(isOpen, onClose, undefined, IS_SINGLE_COLUMN_LAYOUT); diff --git a/src/components/middle/composer/BotCommandTooltip.tsx b/src/components/middle/composer/BotCommandTooltip.tsx index 5ded0952f..bfd6a61cf 100644 --- a/src/components/middle/composer/BotCommandTooltip.tsx +++ b/src/components/middle/composer/BotCommandTooltip.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useEffect, useRef, memo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiBotCommand, ApiUser } from '../../../api/types'; @@ -35,7 +35,7 @@ const BotCommandTooltip: FC = ({ onClick, onClose, }) => { - const { sendBotCommand } = getDispatch(); + const { sendBotCommand } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/middle/composer/BotKeyboardMenu.tsx b/src/components/middle/composer/BotKeyboardMenu.tsx index 90ad00be9..c12428244 100644 --- a/src/components/middle/composer/BotKeyboardMenu.tsx +++ b/src/components/middle/composer/BotKeyboardMenu.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiMessage } from '../../../api/types'; @@ -26,7 +26,7 @@ type StateProps = { const BotKeyboardMenu: FC = ({ isOpen, message, onClose, }) => { - const { clickInlineButton } = getDispatch(); + const { clickInlineButton } = getActions(); const [handleMouseEnter, handleMouseLeave] = useMouseInside(isOpen, onClose); const { isKeyboardSingleUse } = message || {}; diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index 8b5854546..968cb36e8 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { GlobalState, MessageListType } from '../../../global/types'; import { @@ -227,7 +227,7 @@ const Composer: FC = ({ sendInlineBotResult, loadSendAs, loadFullChat, - } = getDispatch(); + } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null diff --git a/src/components/middle/composer/ComposerEmbeddedMessage.tsx b/src/components/middle/composer/ComposerEmbeddedMessage.tsx index b45c5af76..1cbcce32a 100644 --- a/src/components/middle/composer/ComposerEmbeddedMessage.tsx +++ b/src/components/middle/composer/ComposerEmbeddedMessage.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiMessage, ApiUser } from '../../../api/types'; @@ -52,7 +52,7 @@ const ComposerEmbeddedMessage: FC = ({ setEditingId, focusMessage, exitForwardMode, - } = getDispatch(); + } = getActions(); const isShown = Boolean( ((replyingToId || editingId) && message) diff --git a/src/components/middle/composer/GifPicker.tsx b/src/components/middle/composer/GifPicker.tsx index ab6efffc6..328310a38 100644 --- a/src/components/middle/composer/GifPicker.tsx +++ b/src/components/middle/composer/GifPicker.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, memo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiVideo } from '../../../api/types'; @@ -36,7 +36,7 @@ const GifPicker: FC = ({ savedGifs, onGifSelect, }) => { - const { loadSavedGifs } = getDispatch(); + const { loadSavedGifs } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/middle/composer/InlineBotTooltip.tsx b/src/components/middle/composer/InlineBotTooltip.tsx index 17030e203..7e44ddf96 100644 --- a/src/components/middle/composer/InlineBotTooltip.tsx +++ b/src/components/middle/composer/InlineBotTooltip.tsx @@ -22,7 +22,7 @@ import ListItem from '../../ui/ListItem'; import InfiniteScroll from '../../ui/InfiniteScroll'; import './InlineBotTooltip.scss'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; const INTERSECTION_DEBOUNCE_MS = 200; const runThrottled = throttle((cb) => cb(), 500, true); @@ -51,7 +51,7 @@ const InlineBotTooltip: FC = ({ const { openChat, startBot, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx index 779d135e5..02fa1c3f5 100644 --- a/src/components/middle/composer/MessageInput.tsx +++ b/src/components/middle/composer/MessageInput.tsx @@ -2,7 +2,7 @@ import { ChangeEvent } from 'react'; import React, { FC, useEffect, useRef, memo, useState, useCallback, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { IAnchorPosition, ISettings } from '../../../types'; @@ -95,7 +95,7 @@ const MessageInput: FC = ({ const { editLastMessage, replyToNextMessage, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); diff --git a/src/components/middle/composer/SendAsMenu.tsx b/src/components/middle/composer/SendAsMenu.tsx index f424e6e76..33dab9110 100644 --- a/src/components/middle/composer/SendAsMenu.tsx +++ b/src/components/middle/composer/SendAsMenu.tsx @@ -10,7 +10,7 @@ import { getUserFullName, isUserId } from '../../../modules/helpers'; import useMouseInside from '../../../hooks/useMouseInside'; import useLang from '../../../hooks/useLang'; import buildClassName from '../../../util/buildClassName'; -import { getDispatch, getGlobal } from '../../../modules'; +import { getActions, getGlobal } from '../../../modules'; import ListItem from '../../ui/ListItem'; import Avatar from '../../common/Avatar'; @@ -33,7 +33,7 @@ const SendAsMenu: FC = ({ selectedSendAsId, sendAsIds, }) => { - const { saveDefaultSendAs } = getDispatch(); + const { saveDefaultSendAs } = getActions(); // No need for expensive global updates on users and chats, so we avoid them const usersById = getGlobal().users.byId; diff --git a/src/components/middle/composer/StickerPicker.tsx b/src/components/middle/composer/StickerPicker.tsx index c3294ce67..acba3de42 100644 --- a/src/components/middle/composer/StickerPicker.tsx +++ b/src/components/middle/composer/StickerPicker.tsx @@ -1,7 +1,7 @@ import React, { FC, useState, useEffect, memo, useRef, useMemo, useCallback, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiStickerSet, ApiSticker } from '../../../api/types'; import { StickerSetOrRecent } from '../../../types'; @@ -67,7 +67,7 @@ const StickerPicker: FC = ({ loadRecentStickers, addRecentSticker, unfaveSticker, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/middle/composer/StickerTooltip.tsx b/src/components/middle/composer/StickerTooltip.tsx index ab276a35f..bef4d1403 100644 --- a/src/components/middle/composer/StickerTooltip.tsx +++ b/src/components/middle/composer/StickerTooltip.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useEffect, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiSticker } from '../../../api/types'; @@ -38,7 +38,7 @@ const StickerTooltip: FC = ({ onStickerSelect, stickers, }) => { - const { clearStickersForEmoji } = getDispatch(); + const { clearStickersForEmoji } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/middle/composer/WebPagePreview.tsx b/src/components/middle/composer/WebPagePreview.tsx index 3203bc746..5a631bfa3 100644 --- a/src/components/middle/composer/WebPagePreview.tsx +++ b/src/components/middle/composer/WebPagePreview.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiMessage, ApiMessageEntityTypes, ApiWebPage } from '../../../api/types'; import { ISettings } from '../../../types'; @@ -47,7 +47,7 @@ const WebPagePreview: FC = ({ loadWebPagePreview, clearWebPagePreview, toggleMessageWebPage, - } = getDispatch(); + } = getActions(); const link = useDebouncedMemo(() => { const { text, entities } = parseMessageInput(messageText); diff --git a/src/components/middle/composer/hooks/useDraft.ts b/src/components/middle/composer/hooks/useDraft.ts index 76a046329..ba3f15f72 100644 --- a/src/components/middle/composer/hooks/useDraft.ts +++ b/src/components/middle/composer/hooks/useDraft.ts @@ -1,5 +1,5 @@ import { useCallback, useEffect, useMemo } from '../../../../lib/teact/teact'; -import { getDispatch } from '../../../../modules'; +import { getActions } from '../../../../modules'; import { ApiFormattedText, ApiMessage } from '../../../../api/types'; @@ -25,7 +25,7 @@ const useDraft = ( setHtml: (html: string) => void, editedMessage: ApiMessage | undefined, ) => { - const { saveDraft, clearDraft } = getDispatch(); + const { saveDraft, clearDraft } = getActions(); const updateDraft = useCallback((draftChatId: string, draftThreadId: number) => { const currentHtml = htmlRef.current; diff --git a/src/components/middle/composer/hooks/useEditing.ts b/src/components/middle/composer/hooks/useEditing.ts index 29476bf0b..705294fb8 100644 --- a/src/components/middle/composer/hooks/useEditing.ts +++ b/src/components/middle/composer/hooks/useEditing.ts @@ -1,5 +1,5 @@ import { useCallback } from '../../../../lib/teact/teact'; -import { getDispatch } from '../../../../modules'; +import { getActions } from '../../../../modules'; import { ApiMessage } from '../../../../api/types'; @@ -17,7 +17,7 @@ const useEditing = ( resetComposer: () => void, openDeleteModal: () => void, ) => { - const { editMessage } = getDispatch(); + const { editMessage } = getActions(); useOnChange(([prevEditedMessage]) => { if (!editedMessage) { diff --git a/src/components/middle/composer/hooks/useInlineBotTooltip.ts b/src/components/middle/composer/hooks/useInlineBotTooltip.ts index e7f02bba0..da8910ed1 100644 --- a/src/components/middle/composer/hooks/useInlineBotTooltip.ts +++ b/src/components/middle/composer/hooks/useInlineBotTooltip.ts @@ -1,5 +1,5 @@ import { useCallback, useEffect } from '../../../../lib/teact/teact'; -import { getDispatch } from '../../../../modules'; +import { getActions } from '../../../../modules'; import { InlineBotSettings } from '../../../../types'; import useFlag from '../../../../hooks/useFlag'; import usePrevious from '../../../../hooks/usePrevious'; @@ -23,7 +23,7 @@ export default function useInlineBotTooltip( html: string, inlineBots?: Record, ) { - const { queryInlineBot, resetInlineBot } = getDispatch(); + const { queryInlineBot, resetInlineBot } = getActions(); const [isOpen, markIsOpen, unmarkIsOpen] = useFlag(); const { diff --git a/src/components/middle/composer/hooks/useStickerTooltip.ts b/src/components/middle/composer/hooks/useStickerTooltip.ts index e82c807b9..465f78f7c 100644 --- a/src/components/middle/composer/hooks/useStickerTooltip.ts +++ b/src/components/middle/composer/hooks/useStickerTooltip.ts @@ -1,5 +1,5 @@ import { useEffect, useMemo } from '../../../../lib/teact/teact'; -import { getDispatch } from '../../../../modules'; +import { getActions } from '../../../../modules'; import { ApiSticker } from '../../../../api/types'; @@ -15,7 +15,7 @@ export default function useStickerTooltip( isDisabled = false, ) { const cleanHtml = useMemo(() => prepareForRegExp(html).trim(), [html]); - const { loadStickersForEmoji, clearStickersForEmoji } = getDispatch(); + const { loadStickersForEmoji, clearStickersForEmoji } = getActions(); const isSingleEmoji = ( (IS_EMOJI_SUPPORTED && parseEmojiOnlyString(cleanHtml) === 1) || (!IS_EMOJI_SUPPORTED && Boolean(html.match(/^]*?>$/g))) diff --git a/src/components/middle/hooks/useMessageObservers.ts b/src/components/middle/hooks/useMessageObservers.ts index 91afc56da..32387a2c0 100644 --- a/src/components/middle/hooks/useMessageObservers.ts +++ b/src/components/middle/hooks/useMessageObservers.ts @@ -1,5 +1,5 @@ import { RefObject } from 'react'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { MessageListType } from '../../../global/types'; @@ -16,7 +16,7 @@ export default function useMessageObservers( containerRef: RefObject, memoFirstUnreadIdRef: { current: number | undefined }, ) { - const { markMessageListRead, markMessagesRead } = getDispatch(); + const { markMessageListRead, markMessagesRead } = getActions(); const { observe: observeIntersectionForMedia, diff --git a/src/components/middle/hooks/useScrollHooks.ts b/src/components/middle/hooks/useScrollHooks.ts index f90b47e6b..633614f7d 100644 --- a/src/components/middle/hooks/useScrollHooks.ts +++ b/src/components/middle/hooks/useScrollHooks.ts @@ -1,5 +1,5 @@ import { RefObject } from 'react'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { useMemo, useRef } from '../../../lib/teact/teact'; import { LoadMoreDirection } from '../../../types'; @@ -27,7 +27,7 @@ export default function useScrollHooks( isScrollingRef: { current: boolean | undefined }, isScrollPatchNeededRef: { current: boolean | undefined }, ) { - const { loadViewportMessages } = getDispatch(); + const { loadViewportMessages } = getActions(); const [loadMoreBackwards, loadMoreForwards] = useMemo( () => (type === 'thread' ? [ diff --git a/src/components/middle/message/Album.tsx b/src/components/middle/message/Album.tsx index bc22ae9b1..1178be40b 100644 --- a/src/components/middle/message/Album.tsx +++ b/src/components/middle/message/Album.tsx @@ -6,7 +6,7 @@ import { IAlbum, ISettings } from '../../../types'; import { AlbumRectPart, IAlbumLayout } from './helpers/calculateAlbumLayout'; import { getMessageContent, getMessageHtmlId } from '../../../modules/helpers'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import withSelectControl from './hocs/withSelectControl'; import { ObserveFn } from '../../../hooks/useIntersectionObserver'; import { @@ -54,7 +54,7 @@ const Album: FC = ({ activeDownloadIds, theme, }) => { - const { cancelSendingMessage } = getDispatch(); + const { cancelSendingMessage } = getActions(); const mediaCount = album.messages.length; diff --git a/src/components/middle/message/CommentButton.tsx b/src/components/middle/message/CommentButton.tsx index f6daf42c3..e0a5625b7 100644 --- a/src/components/middle/message/CommentButton.tsx +++ b/src/components/middle/message/CommentButton.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal } from '../../../modules'; +import { getActions, getGlobal } from '../../../modules'; import { ApiChat, ApiThreadInfo, ApiUser, @@ -25,7 +25,7 @@ const CommentButton: FC = ({ threadInfo, disabled, }) => { - const { openChat } = getDispatch(); + const { openChat } = getActions(); const lang = useLang(); const { diff --git a/src/components/middle/message/Contact.tsx b/src/components/middle/message/Contact.tsx index 012543786..465fbb29c 100644 --- a/src/components/middle/message/Contact.tsx +++ b/src/components/middle/message/Contact.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiUser, ApiContact, ApiCountryCode } from '../../../api/types'; @@ -23,7 +23,7 @@ type StateProps = { const Contact: FC = ({ contact, user, phoneCodeList, }) => { - const { openChat } = getDispatch(); + const { openChat } = getActions(); const { firstName, diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index 3de360fc9..5f4158d9a 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { MessageListType } from '../../../global/types'; import { ApiAvailableReaction, ApiMessage } from '../../../api/types'; @@ -126,7 +126,7 @@ const ContextMenuContainer: FC = ({ loadFullChat, loadReactors, copyMessagesByIds, - } = getDispatch(); + } = getActions(); const { transitionClassNames } = useShowTransition(isOpen, onCloseAnimationEnd, undefined, false); const [isMenuOpen, setIsMenuOpen] = useState(true); diff --git a/src/components/middle/message/MentionLink.tsx b/src/components/middle/message/MentionLink.tsx index c3c501cf5..4afb024d2 100644 --- a/src/components/middle/message/MentionLink.tsx +++ b/src/components/middle/message/MentionLink.tsx @@ -1,5 +1,5 @@ import React, { FC } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiUser } from '../../../api/types'; @@ -23,7 +23,7 @@ const MentionLink: FC = ({ const { openChat, openChatByUsername, - } = getDispatch(); + } = getActions(); const handleClick = () => { if (userOrChat) { diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 2d1c237e2..1fc67b1b4 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -6,7 +6,7 @@ import React, { useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ActiveEmojiInteraction, ActiveReaction, MessageListType } from '../../../global/types'; import { @@ -283,7 +283,7 @@ const Message: FC = ({ toggleMessageSelection, clickInlineButton, disableContextMenuHint, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const ref = useRef(null); diff --git a/src/components/middle/message/Poll.tsx b/src/components/middle/message/Poll.tsx index ce0c19f30..259818874 100644 --- a/src/components/middle/message/Poll.tsx +++ b/src/components/middle/message/Poll.tsx @@ -7,7 +7,7 @@ import React, { useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiMessage, ApiPoll, ApiUser, ApiPollAnswer, @@ -51,7 +51,7 @@ const Poll: FC = ({ onSendVote, serverTimeOffset, }) => { - const { loadMessage, openPollResults } = getDispatch(); + const { loadMessage, openPollResults } = getActions(); const { id: messageId, chatId } = message; const { summary, results } = poll; diff --git a/src/components/middle/message/ReactionAnimatedEmoji.tsx b/src/components/middle/message/ReactionAnimatedEmoji.tsx index 81035351d..27359a843 100644 --- a/src/components/middle/message/ReactionAnimatedEmoji.tsx +++ b/src/components/middle/message/ReactionAnimatedEmoji.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { ActiveReaction } from '../../../global/types'; import { ApiAvailableReaction, ApiMediaFormat } from '../../../api/types'; @@ -30,7 +30,7 @@ const ReactionAnimatedEmoji: FC = ({ isInMeta, availableReactions, }) => { - const { stopActiveReaction } = getDispatch(); + const { stopActiveReaction } = getActions(); const availableReaction = availableReactions?.find((r) => r.reaction === reaction); const centerIconId = availableReaction?.centerIcon?.id; diff --git a/src/components/middle/message/ReactionButton.tsx b/src/components/middle/message/ReactionButton.tsx index 59bded625..a6fa02383 100644 --- a/src/components/middle/message/ReactionButton.tsx +++ b/src/components/middle/message/ReactionButton.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal } from '../../../modules'; +import { getActions, getGlobal } from '../../../modules'; import { ApiAvailableReaction, ApiMessage, ApiReactionCount, ApiUser, @@ -30,7 +30,7 @@ const ReactionButton: FC<{ activeReaction, availableReactions, }) => { - const { sendReaction } = getDispatch(); + const { sendReaction } = getActions(); const { recentReactions } = message.reactions!; diff --git a/src/components/middle/message/RoundVideo.tsx b/src/components/middle/message/RoundVideo.tsx index 54b9a4613..7482b0ac5 100644 --- a/src/components/middle/message/RoundVideo.tsx +++ b/src/components/middle/message/RoundVideo.tsx @@ -5,7 +5,7 @@ import React, { useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { ApiMediaFormat, ApiMessage } from '../../../api/types'; @@ -162,7 +162,7 @@ const RoundVideo: FC = ({ } if (isDownloading) { - getDispatch().cancelMessageMediaDownload({ message }); + getActions().cancelMessageMediaDownload({ message }); return; } diff --git a/src/components/middle/message/SponsoredMessage.tsx b/src/components/middle/message/SponsoredMessage.tsx index bc03214de..95c43d808 100644 --- a/src/components/middle/message/SponsoredMessage.tsx +++ b/src/components/middle/message/SponsoredMessage.tsx @@ -2,7 +2,7 @@ import { RefObject } from 'react'; import React, { FC, memo, useEffect, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiSponsoredMessage, ApiUser } from '../../../api/types'; @@ -43,7 +43,7 @@ const SponsoredMessage: FC = ({ openChatByInvite, startBot, focusMessage, - } = getDispatch(); + } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null const contentRef = useRef(null); diff --git a/src/components/middle/message/Video.tsx b/src/components/middle/message/Video.tsx index c43183863..2a9556bc6 100644 --- a/src/components/middle/message/Video.tsx +++ b/src/components/middle/message/Video.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useRef, useState, } from '../../../lib/teact/teact'; -import { getDispatch } from '../../../modules'; +import { getActions } from '../../../modules'; import { ApiMediaFormat, ApiMessage } from '../../../api/types'; import { IMediaDimensions } from './helpers/calculateAlbumLayout'; @@ -138,7 +138,7 @@ const Video: FC = ({ onCancelUpload(message); } } else if (isDownloading) { - getDispatch().cancelMessageMediaDownload({ message }); + getActions().cancelMessageMediaDownload({ message }); } else if (!fullMediaData) { setIsLoadAllowed((isAllowed) => !isAllowed); } else if (fullMediaData && !isPlayAllowed) { diff --git a/src/components/middle/message/hocs/withSelectControl.tsx b/src/components/middle/message/hocs/withSelectControl.tsx index 5b631ec2d..65d1cfb44 100644 --- a/src/components/middle/message/hocs/withSelectControl.tsx +++ b/src/components/middle/message/hocs/withSelectControl.tsx @@ -5,7 +5,7 @@ import React, { useMemo, memo, } from '../../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../../modules'; +import { getActions, withGlobal } from '../../../../modules'; import { OwnProps as PhotoProps } from '../Photo'; import { OwnProps as VideoProps } from '../Video'; @@ -33,7 +33,7 @@ export default function withSelectControl(WrappedComponent: FC) { message, dimensions, } = props; - const { toggleMessageSelection } = getDispatch(); + const { toggleMessageSelection } = getActions(); const handleMessageSelect = useCallback((e: ReactMouseEvent) => { e.stopPropagation(); diff --git a/src/components/middle/message/hooks/useInnerHandlers.ts b/src/components/middle/message/hooks/useInnerHandlers.ts index f1ee730c1..28a7440aa 100644 --- a/src/components/middle/message/hooks/useInnerHandlers.ts +++ b/src/components/middle/message/hooks/useInnerHandlers.ts @@ -1,5 +1,5 @@ import React, { useCallback } from '../../../../lib/teact/teact'; -import { getDispatch } from '../../../../modules'; +import { getActions } from '../../../../modules'; import { IAlbum, MediaViewerOrigin } from '../../../../types'; import { @@ -25,7 +25,7 @@ export default function useInnerHandlers( const { openChat, showNotification, focusMessage, openMediaViewer, openAudioPlayer, markMessagesRead, cancelSendingMessage, sendPollVote, openForwardMenu, focusMessageInComments, - } = getDispatch(); + } = getActions(); const { id: messageId, forwardInfo, replyToMessageId, replyToChatId, replyToTopMessageId, groupedId, diff --git a/src/components/middle/message/hooks/useOuterHandlers.ts b/src/components/middle/message/hooks/useOuterHandlers.ts index a50213234..50b556db1 100644 --- a/src/components/middle/message/hooks/useOuterHandlers.ts +++ b/src/components/middle/message/hooks/useOuterHandlers.ts @@ -1,6 +1,6 @@ import { RefObject } from 'react'; import React, { useEffect, useRef } from '../../../../lib/teact/teact'; -import { getDispatch } from '../../../../modules'; +import { getActions } from '../../../../modules'; import { IS_ANDROID, IS_TOUCH_ENV } from '../../../../util/environment'; import windowSize from '../../../../util/windowSize'; @@ -33,7 +33,7 @@ export default function useOuterHandlers( isOwn: boolean, shouldHandleMouseLeave: boolean, ) { - const { setReplyingToId, sendDefaultReaction } = getDispatch(); + const { setReplyingToId, sendDefaultReaction } = getActions(); const [isQuickReactionVisible, markQuickReactionVisible, unmarkQuickReactionVisible] = useFlag(); const [isSwiped, markSwiped, unmarkSwiped] = useFlag(); diff --git a/src/components/payment/PaymentModal.tsx b/src/components/payment/PaymentModal.tsx index 41b495e8b..56a52870b 100644 --- a/src/components/payment/PaymentModal.tsx +++ b/src/components/payment/PaymentModal.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { GlobalState } from '../../global/types'; import { PaymentStep, ShippingOption, Price } from '../../types'; @@ -86,7 +86,7 @@ const Invoice: FC = ({ setPaymentStep, sendCredentialsInfo, clearPaymentError, - } = getDispatch(); + } = getActions(); const [paymentState, paymentDispatch] = usePaymentReducer(); const [isLoading, setIsLoading] = useState(false); diff --git a/src/components/right/AddChatMembers.tsx b/src/components/right/AddChatMembers.tsx index 1b3574f1e..85d6ec38e 100644 --- a/src/components/right/AddChatMembers.tsx +++ b/src/components/right/AddChatMembers.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useMemo, memo, useState, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../modules'; +import { getActions, getGlobal, withGlobal } from '../../modules'; import { ApiChat, ApiChatMember, ApiUpdateConnectionStateType, @@ -60,7 +60,7 @@ const AddChatMembers: FC = ({ onClose, isActive, }) => { - const { setUserSearchQuery, loadContactList } = getDispatch(); + const { setUserSearchQuery, loadContactList } = getActions(); const lang = useLang(); const [selectedMemberIds, setSelectedMemberIds] = useState([]); diff --git a/src/components/right/DeleteMemberModal.tsx b/src/components/right/DeleteMemberModal.tsx index 8815c03c3..f71404a58 100644 --- a/src/components/right/DeleteMemberModal.tsx +++ b/src/components/right/DeleteMemberModal.tsx @@ -1,5 +1,5 @@ import React, { FC, useCallback, memo } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat } from '../../api/types'; @@ -29,7 +29,7 @@ const DeleteMemberModal: FC = ({ contactName, onClose, }) => { - const { deleteChatMember } = getDispatch(); + const { deleteChatMember } = getActions(); const lang = useLang(); diff --git a/src/components/right/GifSearch.tsx b/src/components/right/GifSearch.tsx index b14e8e6c5..904a6c749 100644 --- a/src/components/right/GifSearch.tsx +++ b/src/components/right/GifSearch.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useRef, useCallback, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat, ApiVideo } from '../../api/types'; @@ -51,7 +51,7 @@ const GifSearch: FC = ({ searchMoreGifs, sendMessage, setGifSearchQuery, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/right/PollAnswerResults.tsx b/src/components/right/PollAnswerResults.tsx index 5760a6b47..763c53ae9 100644 --- a/src/components/right/PollAnswerResults.tsx +++ b/src/components/right/PollAnswerResults.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useState, memo, useEffect, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiChat, @@ -48,7 +48,7 @@ const PollAnswerResults: FC = ({ loadPollOptionResults, openChat, closePollResults, - } = getDispatch(); + } = getActions(); const prevVotersCount = usePrevious(answerVote.votersCount); const [isLoading, setIsLoading] = useState(true); diff --git a/src/components/right/Profile.tsx b/src/components/right/Profile.tsx index 7ffd13ce9..7a75d8f87 100644 --- a/src/components/right/Profile.tsx +++ b/src/components/right/Profile.tsx @@ -1,7 +1,7 @@ import React, { FC, useCallback, useEffect, useMemo, useRef, useState, memo, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { MAIN_THREAD_ID, @@ -145,7 +145,7 @@ const Profile: FC = ({ focusMessage, loadProfilePhotos, setNewChatMembersDialogState, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/right/RightColumn.tsx b/src/components/right/RightColumn.tsx index 5feedcc99..bc7e6bf2b 100644 --- a/src/components/right/RightColumn.tsx +++ b/src/components/right/RightColumn.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ManagementScreens, NewChatMembersProgress, ProfileState, RightColumnContent, @@ -73,7 +73,7 @@ const RightColumn: FC = ({ toggleStatistics, setOpenedInviteInfo, requestNextManagementScreen, - } = getDispatch(); + } = getActions(); const { width: windowWidth } = useWindowSize(); const [profileState, setProfileState] = useState(ProfileState.Profile); diff --git a/src/components/right/RightHeader.tsx b/src/components/right/RightHeader.tsx index 9c2e41430..a4d38e50a 100644 --- a/src/components/right/RightHeader.tsx +++ b/src/components/right/RightHeader.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ManagementScreens, ProfileState } from '../../types'; import { ApiExportedInvite } from '../../api/types'; @@ -137,7 +137,7 @@ const RightHeader: FC = ({ toggleStatistics, setEditingExportedInvite, deleteExportedChatInvite, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const backButtonRef = useRef(null); diff --git a/src/components/right/RightSearch.tsx b/src/components/right/RightSearch.tsx index ac8bee0f9..286843b3c 100644 --- a/src/components/right/RightSearch.tsx +++ b/src/components/right/RightSearch.tsx @@ -1,7 +1,7 @@ import React, { FC, useMemo, memo, useRef, } from '../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../modules'; +import { getActions, getGlobal, withGlobal } from '../../modules'; import { ApiMessage, ApiUser, ApiChat } from '../../api/types'; @@ -60,7 +60,7 @@ const RightSearch: FC = ({ const { searchTextMessagesLocal, focusMessage, - } = getDispatch(); + } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/right/StickerSearch.tsx b/src/components/right/StickerSearch.tsx index 6c2e9f1a8..f9ee6114b 100644 --- a/src/components/right/StickerSearch.tsx +++ b/src/components/right/StickerSearch.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useEffect, useRef, useState, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { throttle } from '../../util/schedulers'; import { selectCurrentStickerSearch } from '../../modules/selectors'; @@ -36,7 +36,7 @@ const StickerSearch: FC = ({ featuredIds, resultIds, }) => { - const { loadFeaturedStickers } = getDispatch(); + const { loadFeaturedStickers } = getActions(); // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); diff --git a/src/components/right/StickerSetResult.tsx b/src/components/right/StickerSetResult.tsx index 3f0ea0e5e..599220675 100644 --- a/src/components/right/StickerSetResult.tsx +++ b/src/components/right/StickerSetResult.tsx @@ -1,7 +1,7 @@ import React, { FC, useEffect, memo, useMemo, useCallback, } from '../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../modules'; +import { getActions, withGlobal } from '../../modules'; import { ApiStickerSet } from '../../api/types'; import { ObserveFn } from '../../hooks/useIntersectionObserver'; @@ -35,7 +35,7 @@ const StickerSetResult: FC = ({ stickerSetId, observeIntersection, set, shouldPlay, isSomeModalOpen, onModalToggle, }) => { - const { loadStickers, toggleStickerSet } = getDispatch(); + const { loadStickers, toggleStickerSet } = getActions(); const lang = useLang(); const isAdded = set && Boolean(set.installedDate); diff --git a/src/components/right/management/JoinRequest.tsx b/src/components/right/management/JoinRequest.tsx index 6b67bb6c6..fabb16387 100644 --- a/src/components/right/management/JoinRequest.tsx +++ b/src/components/right/management/JoinRequest.tsx @@ -1,5 +1,5 @@ import React, { FC, memo, useCallback } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiUser } from '../../../api/types'; @@ -38,7 +38,7 @@ const JoinRequest: FC = ({ serverTimeOffset, chatId, }) => { - const { openChat, hideChatJoinRequest } = getDispatch(); + const { openChat, hideChatJoinRequest } = getActions(); const buildClassName = createClassNameBuilder('JoinRequest'); const lang = useLang(); diff --git a/src/components/right/management/ManageChannel.tsx b/src/components/right/management/ManageChannel.tsx index a3d777352..f427d6237 100644 --- a/src/components/right/management/ManageChannel.tsx +++ b/src/components/right/management/ManageChannel.tsx @@ -2,7 +2,7 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ManagementScreens, ManagementProgress } from '../../../types'; import { ApiChat, ApiExportedInvite, ApiMediaFormat } from '../../../api/types'; @@ -68,7 +68,7 @@ const ManageChannel: FC = ({ openChat, loadExportedChatInvites, loadChatJoinRequests, - } = getDispatch(); + } = getActions(); const currentTitle = chat ? (chat.title || '') : ''; const currentAbout = chat?.fullInfo ? (chat.fullInfo.about || '') : ''; diff --git a/src/components/right/management/ManageChatPrivacyType.tsx b/src/components/right/management/ManageChatPrivacyType.tsx index 9cda789c5..7dc686662 100644 --- a/src/components/right/management/ManageChatPrivacyType.tsx +++ b/src/components/right/management/ManageChatPrivacyType.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat } from '../../../api/types'; import { ManagementProgress } from '../../../types'; @@ -51,7 +51,7 @@ const ManageChatPrivacyType: FC = ({ updatePublicLink, updatePrivateLink, toggleIsProtected, - } = getDispatch(); + } = getActions(); const isPublic = Boolean(chat.username); const privateLink = chat.fullInfo?.inviteLink; diff --git a/src/components/right/management/ManageChatRemovedUsers.tsx b/src/components/right/management/ManageChatRemovedUsers.tsx index d9fade276..d82fbab07 100644 --- a/src/components/right/management/ManageChatRemovedUsers.tsx +++ b/src/components/right/management/ManageChatRemovedUsers.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiChatMember, ApiUser } from '../../../api/types'; @@ -37,7 +37,7 @@ const ManageChatRemovedUsers: FC = ({ onClose, isActive, }) => { - const { updateChatMemberBannedRights } = getDispatch(); + const { updateChatMemberBannedRights } = getActions(); const lang = useLang(); const [isRemoveUserModalOpen, openRemoveUserModal, closeRemoveUserModal] = useFlag(); diff --git a/src/components/right/management/ManageDiscussion.tsx b/src/components/right/management/ManageDiscussion.tsx index fa9c6d1a7..efe6753ce 100644 --- a/src/components/right/management/ManageDiscussion.tsx +++ b/src/components/right/management/ManageDiscussion.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat } from '../../../api/types'; import { ManagementScreens } from '../../../types'; @@ -52,7 +52,7 @@ const ManageDiscussion: FC = ({ loadGroupsForDiscussion, linkDiscussionGroup, unlinkDiscussionGroup, - } = getDispatch(); + } = getActions(); const [linkedGroupId, setLinkedGroupId] = useState(); const [animationData, setAnimationData] = useState(); diff --git a/src/components/right/management/ManageGroup.tsx b/src/components/right/management/ManageGroup.tsx index 613300c60..6ce62e40e 100644 --- a/src/components/right/management/ManageGroup.tsx +++ b/src/components/right/management/ManageGroup.tsx @@ -2,7 +2,7 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ManagementScreens, ManagementProgress } from '../../../types'; import { @@ -80,7 +80,7 @@ const ManageGroup: FC = ({ openChat, loadExportedChatInvites, loadChatJoinRequests, - } = getDispatch(); + } = getActions(); const [isDeleteDialogOpen, openDeleteDialog, closeDeleteDialog] = useFlag(); const currentTitle = chat.title; diff --git a/src/components/right/management/ManageGroupAdminRights.tsx b/src/components/right/management/ManageGroupAdminRights.tsx index 6c47e1df3..56d3c8b9a 100644 --- a/src/components/right/management/ManageGroupAdminRights.tsx +++ b/src/components/right/management/ManageGroupAdminRights.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { ApiChat, ApiChatAdminRights, ApiUser } from '../../../api/types'; import { ManagementScreens } from '../../../types'; @@ -54,7 +54,7 @@ const ManageGroupAdminRights: FC = ({ onClose, isActive, }) => { - const { updateChatAdmin } = getDispatch(); + const { updateChatAdmin } = getActions(); const [permissions, setPermissions] = useState({}); const [isTouched, setIsTouched] = useState(Boolean(isNewAdmin)); diff --git a/src/components/right/management/ManageGroupMembers.tsx b/src/components/right/management/ManageGroupMembers.tsx index 5db37a48a..9cdf8e415 100644 --- a/src/components/right/management/ManageGroupMembers.tsx +++ b/src/components/right/management/ManageGroupMembers.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useMemo, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { ApiChatMember, ApiUserStatus } from '../../../api/types'; import { ManagementScreens } from '../../../types'; @@ -62,7 +62,7 @@ const ManageGroupMembers: FC = ({ onScreenSelect, onChatMemberSelect, }) => { - const { openChat, setUserSearchQuery, loadContactList } = getDispatch(); + const { openChat, setUserSearchQuery, loadContactList } = getActions(); const lang = useLang(); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); diff --git a/src/components/right/management/ManageGroupPermissions.tsx b/src/components/right/management/ManageGroupPermissions.tsx index 03c93a80d..c92a82932 100644 --- a/src/components/right/management/ManageGroupPermissions.tsx +++ b/src/components/right/management/ManageGroupPermissions.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ManagementScreens } from '../../../types'; import { ApiChat, ApiChatBannedRights, ApiChatMember } from '../../../api/types'; @@ -62,7 +62,7 @@ const ManageGroupPermissions: FC = ({ onClose, isActive, }) => { - const { updateChatDefaultBannedRights } = getDispatch(); + const { updateChatDefaultBannedRights } = getActions(); const [permissions, setPermissions] = useState({}); const [havePermissionChanged, setHavePermissionChanged] = useState(false); diff --git a/src/components/right/management/ManageGroupUserPermissions.tsx b/src/components/right/management/ManageGroupUserPermissions.tsx index 8ad5ba912..9ff3277c7 100644 --- a/src/components/right/management/ManageGroupUserPermissions.tsx +++ b/src/components/right/management/ManageGroupUserPermissions.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiChatBannedRights } from '../../../api/types'; import { ManagementScreens } from '../../../types'; @@ -40,7 +40,7 @@ const ManageGroupUserPermissions: FC = ({ onClose, isActive, }) => { - const { updateChatMemberBannedRights } = getDispatch(); + const { updateChatMemberBannedRights } = getActions(); const [permissions, setPermissions] = useState({}); const [havePermissionChanged, setHavePermissionChanged] = useState(false); diff --git a/src/components/right/management/ManageInvite.tsx b/src/components/right/management/ManageInvite.tsx index 0988c1b30..6a57f9fb0 100644 --- a/src/components/right/management/ManageInvite.tsx +++ b/src/components/right/management/ManageInvite.tsx @@ -2,7 +2,7 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiExportedInvite } from '../../../api/types'; import { ManagementScreens } from '../../../types'; @@ -49,7 +49,7 @@ const ManageInvite: FC = ({ onClose, onScreenSelect, }) => { - const { editExportedChatInvite, exportChatInvite } = getDispatch(); + const { editExportedChatInvite, exportChatInvite } = getActions(); const lang = useLang(); const [isCalendarOpened, openCalendar, closeCalendar] = useFlag(); diff --git a/src/components/right/management/ManageInviteInfo.tsx b/src/components/right/management/ManageInviteInfo.tsx index 6d32fce6b..ad2a6abab 100644 --- a/src/components/right/management/ManageInviteInfo.tsx +++ b/src/components/right/management/ManageInviteInfo.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChatInviteImporter, ApiExportedInvite, ApiUser } from '../../../api/types'; @@ -48,7 +48,7 @@ const ManageInviteInfo: FC = ({ loadChatInviteImporters, loadChatInviteRequesters, openChat, - } = getDispatch(); + } = getActions(); const lang = useLang(); const { diff --git a/src/components/right/management/ManageInvites.tsx b/src/components/right/management/ManageInvites.tsx index f72dd81a5..a76285f19 100644 --- a/src/components/right/management/ManageInvites.tsx +++ b/src/components/right/management/ManageInvites.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat, ApiExportedInvite } from '../../../api/types'; import { ManagementScreens } from '../../../types'; @@ -71,7 +71,7 @@ const ManageInvites: FC = ({ deleteExportedChatInvite, deleteRevokedExportedChatInvites, setOpenedInviteInfo, - } = getDispatch(); + } = getActions(); const lang = useLang(); diff --git a/src/components/right/management/ManageJoinRequests.tsx b/src/components/right/management/ManageJoinRequests.tsx index de6111319..809ee297e 100644 --- a/src/components/right/management/ManageJoinRequests.tsx +++ b/src/components/right/management/ManageJoinRequests.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiChat } from '../../../api/types'; @@ -38,7 +38,7 @@ const ManageJoinRequests: FC = ({ isChannel, onClose, }) => { - const { hideAllChatJoinRequests, loadChatJoinRequests } = getDispatch(); + const { hideAllChatJoinRequests, loadChatJoinRequests } = getActions(); const [isAcceptAllDialogOpen, openAcceptAllDialog, closeAcceptAllDialog] = useFlag(); const [isRejectAllDialogOpen, openRejectAllDialog, closeRejectAllDialog] = useFlag(); diff --git a/src/components/right/management/ManageReactions.tsx b/src/components/right/management/ManageReactions.tsx index 7fef4793b..145757002 100644 --- a/src/components/right/management/ManageReactions.tsx +++ b/src/components/right/management/ManageReactions.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiAvailableReaction, ApiChat } from '../../../api/types'; @@ -33,7 +33,7 @@ const ManageReactions: FC = ({ isActive, onClose, }) => { - const { setChatEnabledReactions } = getDispatch(); + const { setChatEnabledReactions } = getActions(); const lang = useLang(); const [isTouched, setIsTouched] = useState(false); diff --git a/src/components/right/management/ManageUser.tsx b/src/components/right/management/ManageUser.tsx index feb237761..708fc205e 100644 --- a/src/components/right/management/ManageUser.tsx +++ b/src/components/right/management/ManageUser.tsx @@ -2,7 +2,7 @@ import { ChangeEvent } from 'react'; import React, { FC, memo, useCallback, useEffect, useState, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { ApiUser } from '../../../api/types'; import { ManagementProgress } from '../../../types'; @@ -51,7 +51,7 @@ const ManageUser: FC = ({ updateContact, deleteContact, closeManagement, - } = getDispatch(); + } = getActions(); const [isDeleteDialogOpen, openDeleteDialog, closeDeleteDialog] = useFlag(); const [isProfileFieldsTouched, setIsProfileFieldsTouched] = useState(false); diff --git a/src/components/right/management/RemoveGroupUserModal.tsx b/src/components/right/management/RemoveGroupUserModal.tsx index 392b6f679..6720487be 100644 --- a/src/components/right/management/RemoveGroupUserModal.tsx +++ b/src/components/right/management/RemoveGroupUserModal.tsx @@ -1,7 +1,7 @@ import React, { FC, useMemo, useState, memo, useRef, useCallback, } from '../../../lib/teact/teact'; -import { getDispatch, getGlobal, withGlobal } from '../../../modules'; +import { getActions, getGlobal, withGlobal } from '../../../modules'; import { ApiChat } from '../../../api/types'; @@ -29,7 +29,7 @@ const RemoveGroupUserModal: FC = ({ const { loadMoreMembers, deleteChatMember, - } = getDispatch(); + } = getActions(); const lang = useLang(); const [filter, setFilter] = useState(''); diff --git a/src/components/right/statistics/Statistics.tsx b/src/components/right/statistics/Statistics.tsx index 2cc1c4801..50fb2a8dd 100644 --- a/src/components/right/statistics/Statistics.tsx +++ b/src/components/right/statistics/Statistics.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useState, useEffect, useRef, } from '../../../lib/teact/teact'; -import { getDispatch, withGlobal } from '../../../modules'; +import { getActions, withGlobal } from '../../../modules'; import { callApi } from '../../../api/gramjs'; import { @@ -62,7 +62,7 @@ const Statistics: FC = ({ const [isReady, setIsReady] = useState(false); const loadedCharts = useRef([]); - const { loadStatistics, loadStatisticsAsyncGraph } = getDispatch(); + const { loadStatistics, loadStatisticsAsyncGraph } = getActions(); useEffect(() => { loadStatistics({ chatId }); diff --git a/src/global/cache.ts b/src/global/cache.ts index 5e7998578..7bead81b6 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -1,6 +1,6 @@ import { addCallback, removeCallback } from '../lib/teact/teactn'; -import { addReducer, getGlobal } from '../modules'; +import { addActionHandler, getGlobal } from '../modules'; import { GlobalState } from './types'; import { MAIN_THREAD_ID } from '../api/types'; @@ -45,7 +45,7 @@ export function initCache() { return; } - addReducer('saveSession', () => { + addActionHandler('saveSession', () => { if (isCaching) { return; } @@ -53,7 +53,7 @@ export function initCache() { setupCaching(); }); - addReducer('reset', () => { + addActionHandler('reset', () => { localStorage.removeItem(GLOBAL_STATE_CACHE_KEY); if (!isCaching) { diff --git a/src/global/index.ts b/src/global/index.ts index f96f16ce6..6a5241173 100644 --- a/src/global/index.ts +++ b/src/global/index.ts @@ -1,4 +1,4 @@ -import { addReducer } from '../modules'; +import { addActionHandler } from '../modules'; import { INITIAL_STATE } from './initial'; import { initCache, loadCache } from './cache'; @@ -6,7 +6,7 @@ import { cloneDeep } from '../util/iteratees'; initCache(); -addReducer('init', () => { +addActionHandler('init', () => { const initial = cloneDeep(INITIAL_STATE); return loadCache(initial) || initial; }); diff --git a/src/global/types.ts b/src/global/types.ts index 4c534affe..cd6d2565d 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -618,4 +618,4 @@ export type NonTypedActionNames = ( ); const typed = typify(); -export type GlobalActions = ReturnType; +export type GlobalActions = ReturnType; diff --git a/src/hooks/useAudioPlayer.ts b/src/hooks/useAudioPlayer.ts index 23cd9a0ee..71946e802 100644 --- a/src/hooks/useAudioPlayer.ts +++ b/src/hooks/useAudioPlayer.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect, useRef, useState, } from '../lib/teact/teact'; -import { getDispatch, getGlobal } from '../modules'; +import { getActions, getGlobal } from '../modules'; import { register, Track, TrackId } from '../util/audioPlayer'; import useEffectWithPrevDeps from './useEffectWithPrevDeps'; @@ -212,7 +212,7 @@ function makeMediaHandlers(controllerRef: React.RefObject { pause(); setCurrentTime(0); - getDispatch().closeAudioPlayer(); + getActions().closeAudioPlayer(); }, seekbackward: (event) => { const skipTime = event.seekOffset || DEFAULT_SKIP_TIME; diff --git a/src/hooks/useChatContextActions.ts b/src/hooks/useChatContextActions.ts index bfbe007a1..21fed407d 100644 --- a/src/hooks/useChatContextActions.ts +++ b/src/hooks/useChatContextActions.ts @@ -1,5 +1,5 @@ import { useMemo } from '../lib/teact/teact'; -import { getDispatch } from '../modules'; +import { getActions } from '../modules'; import { ApiChat, ApiUser } from '../api/types'; @@ -44,7 +44,7 @@ const useChatContextActions = ({ updateChatMutedState, toggleChatArchived, toggleChatUnread, - } = getDispatch(); + } = getActions(); const actionAddToFolder = canChangeFolder ? { title: lang('ChatList.Filter.AddToFolder'), diff --git a/src/hooks/useEnsureMessage.ts b/src/hooks/useEnsureMessage.ts index f9dc6158e..056c6ad6e 100644 --- a/src/hooks/useEnsureMessage.ts +++ b/src/hooks/useEnsureMessage.ts @@ -1,5 +1,5 @@ import { useEffect, useMemo } from '../lib/teact/teact'; -import { getDispatch } from '../modules'; +import { getActions } from '../modules'; import { ApiMessage } from '../api/types'; @@ -11,7 +11,7 @@ const useEnsureMessage = ( message?: ApiMessage, replyOriginForId?: number, ) => { - const { loadMessage } = getDispatch(); + const { loadMessage } = getActions(); const loadMessageThrottled = useMemo(() => { const throttled = throttle(loadMessage, 500, true); return () => { diff --git a/src/hooks/useHistoryBack.ts b/src/hooks/useHistoryBack.ts index 7cf5d7c43..ccb309e60 100644 --- a/src/hooks/useHistoryBack.ts +++ b/src/hooks/useHistoryBack.ts @@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef } from '../lib/teact/teact'; import { IS_IOS } from '../util/environment'; import usePrevious from './usePrevious'; -import { getDispatch } from '../modules'; +import { getActions } from '../modules'; import { areSortedArraysEqual } from '../util/iteratees'; type HistoryState = { @@ -213,7 +213,7 @@ export default function useHistoryBack( if (onBack) { if (historyState.isEdge) { - getDispatch() + getActions() .disableHistoryAnimations(); } onBack(!historyState.isEdge); @@ -222,7 +222,7 @@ export default function useHistoryBack( } else if (index === currIndex && isClosed.current && onForward && !hashes) { isForward.current = true; if (historyState.isEdge) { - getDispatch() + getActions() .disableHistoryAnimations(); } onForward(event.state.state); diff --git a/src/hooks/useSendMessageAction.ts b/src/hooks/useSendMessageAction.ts index 386836a11..3239f56ed 100644 --- a/src/hooks/useSendMessageAction.ts +++ b/src/hooks/useSendMessageAction.ts @@ -1,5 +1,5 @@ import { useMemo } from '../lib/teact/teact'; -import { getDispatch } from '../modules'; +import { getActions } from '../modules'; import { ApiSendMessageAction } from '../api/types'; @@ -9,7 +9,7 @@ import { throttle } from '../util/schedulers'; const useSendMessageAction = (chatId: string, threadId?: number) => { return useMemo(() => { return throttle((action: ApiSendMessageAction) => { - getDispatch().sendMessageAction({ chatId, threadId, action }); + getActions().sendMessageAction({ chatId, threadId, action }); }, SEND_MESSAGE_ACTION_INTERVAL); }, [chatId, threadId]); }; diff --git a/src/index.tsx b/src/index.tsx index 914f7ecf1..ce7db7d51 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,7 +4,7 @@ import './util/setupServiceWorker'; import React from './lib/teact/teact'; import TeactDOM from './lib/teact/teact-dom'; -import { getDispatch, getGlobal } from './modules'; +import { getActions, getGlobal } from './modules'; import './global'; import { DEBUG } from './config'; @@ -18,7 +18,7 @@ if (DEBUG) { console.log('>>> INIT'); } -getDispatch().init(); +getActions().init(); if (DEBUG) { // eslint-disable-next-line no-console diff --git a/src/lib/teact/teactn.tsx b/src/lib/teact/teactn.tsx index b6b1c373b..c868d6676 100644 --- a/src/lib/teact/teactn.tsx +++ b/src/lib/teact/teactn.tsx @@ -17,15 +17,15 @@ type GlobalState = AnyLiteral; type ActionNames = string; type ActionPayload = any; -export interface DispatchOptions { +interface ActionOptions { forceOnHeavyAnimation?: boolean; // Workaround for iOS gesture history navigation forceSyncOnIOs?: boolean; } -type Actions = Record void>; +type Actions = Record void>; -type Reducer = ( +type ActionHandler = ( global: GlobalState, actions: Actions, payload: any, @@ -35,7 +35,7 @@ type MapStateToProps = ((global: GlobalState, ownProps: Ow let currentGlobal = {} as GlobalState; -const reducers: Record = {}; +const actionHandlers: Record = {}; const callbacks: Function[] = [updateContainers]; const actions = {} as Actions; const containers = new Map cb(currentGlobal)); } -export function setGlobal(newGlobal?: GlobalState, options?: DispatchOptions) { +export function setGlobal(newGlobal?: GlobalState, options?: ActionOptions) { if (typeof newGlobal === 'object' && newGlobal !== currentGlobal) { currentGlobal = newGlobal; if (options?.forceSyncOnIOs) { @@ -74,19 +74,17 @@ export function getGlobal() { return currentGlobal; } -export function getDispatch() { +export function getActions() { return actions; } -function onDispatch(name: string, payload?: ActionPayload, options?: DispatchOptions) { - if (reducers[name]) { - reducers[name].forEach((reducer) => { - const newGlobal = reducer(currentGlobal, actions, payload); - if (newGlobal) { - setGlobal(newGlobal, options); - } - }); - } +function handleAction(name: string, payload?: ActionPayload, options?: ActionOptions) { + actionHandlers[name]?.forEach((handler) => { + const newGlobal = handler(currentGlobal, actions, payload); + if (newGlobal) { + setGlobal(newGlobal, options); + } + }); } function updateContainers() { @@ -150,16 +148,16 @@ function updateContainers() { } } -export function addReducer(name: ActionNames, reducer: Reducer) { - if (!reducers[name]) { - reducers[name] = []; +export function addActionHandler(name: ActionNames, handler: ActionHandler) { + if (!actionHandlers[name]) { + actionHandlers[name] = []; - actions[name] = (payload?: ActionPayload, options?: DispatchOptions) => { - onDispatch(name, payload, options); + actions[name] = (payload?: ActionPayload, options?: ActionOptions) => { + handleAction(name, payload, options); }; } - reducers[name].push(reducer); + actionHandlers[name].push(handler); } export function addCallback(cb: Function) { @@ -237,7 +235,7 @@ export function typify void; }; @@ -251,9 +249,9 @@ export function typify ProjectGlobalState, - setGlobal: setGlobal as (state: ProjectGlobalState, options?: DispatchOptions) => void, - getDispatch: getDispatch as () => ProjectActions, - addReducer: addReducer as ( + setGlobal: setGlobal as (state: ProjectGlobalState, options?: ActionOptions) => void, + getActions: getActions as () => ProjectActions, + addActionHandler: addActionHandler as ( name: ActionName, handler: ActionHandlers[ActionName], ) => void, diff --git a/src/modules/actions/api/bots.ts b/src/modules/actions/api/bots.ts index 63831c414..2be298f99 100644 --- a/src/modules/actions/api/bots.ts +++ b/src/modules/actions/api/bots.ts @@ -1,5 +1,5 @@ import { - addReducer, getDispatch, getGlobal, setGlobal, + addActionHandler, getActions, getGlobal, setGlobal, } from '../..'; import { ApiChat, ApiContact, ApiUser } from '../../../api/types'; @@ -22,7 +22,7 @@ import { getServerTime } from '../../../util/serverTime'; const TOP_PEERS_REQUEST_COOLDOWN = 60; // 1 min const runDebouncedForSearch = debounce((cb) => cb(), 500, false); -addReducer('clickInlineButton', (global, actions, payload) => { +addActionHandler('clickInlineButton', (global, actions, payload) => { const { button } = payload; switch (button.type) { @@ -82,7 +82,7 @@ addReducer('clickInlineButton', (global, actions, payload) => { } }); -addReducer('sendBotCommand', (global, actions, payload) => { +addActionHandler('sendBotCommand', (global, actions, payload) => { const { command, chatId } = payload; const { currentUserId } = global; const chat = chatId ? selectChat(global, chatId) : selectCurrentChat(global); @@ -101,7 +101,7 @@ addReducer('sendBotCommand', (global, actions, payload) => { ); }); -addReducer('restartBot', (global, actions, payload) => { +addActionHandler('restartBot', (global, actions, payload) => { const { chatId } = payload; const { currentUserId } = global; const chat = selectCurrentChat(global); @@ -121,7 +121,7 @@ addReducer('restartBot', (global, actions, payload) => { })(); }); -addReducer('loadTopInlineBots', (global) => { +addActionHandler('loadTopInlineBots', (global) => { const { lastRequestedAt } = global.topInlineBots; if (lastRequestedAt && getServerTime(global.serverTimeOffset) - lastRequestedAt < TOP_PEERS_REQUEST_COOLDOWN) { @@ -150,7 +150,7 @@ addReducer('loadTopInlineBots', (global) => { })(); }); -addReducer('queryInlineBot', ((global, actions, payload) => { +addActionHandler('queryInlineBot', ((global, actions, payload) => { const { chatId, username, query, offset, } = payload; @@ -201,7 +201,7 @@ addReducer('queryInlineBot', ((global, actions, payload) => { })(); })); -addReducer('sendInlineBotResult', (global, actions, payload) => { +addActionHandler('sendInlineBotResult', (global, actions, payload) => { const { id, queryId } = payload; const currentMessageList = selectCurrentMessageList(global); @@ -225,7 +225,7 @@ addReducer('sendInlineBotResult', (global, actions, payload) => { }); }); -addReducer('resetInlineBot', (global, actions, payload) => { +addActionHandler('resetInlineBot', (global, actions, payload) => { const { username } = payload; let inlineBotData = global.inlineBots.byUsername[username]; @@ -246,7 +246,7 @@ addReducer('resetInlineBot', (global, actions, payload) => { setGlobal(replaceInlineBotSettings(global, username, inlineBotData)); }); -addReducer('startBot', (global, actions, payload) => { +addActionHandler('startBot', (global, actions, payload) => { const { botId, param } = payload; const bot = selectUser(global, botId); @@ -346,7 +346,7 @@ async function answerCallbackButton(chat: ApiChat, messageId: number, data: stri return; } - const { showDialog, showNotification, toggleSafeLinkModal } = getDispatch(); + const { showDialog, showNotification, toggleSafeLinkModal } = getActions(); const { message, alert: isError, url } = result; if (isError) { diff --git a/src/modules/actions/api/calls.async.ts b/src/modules/actions/api/calls.async.ts index e12e1e62d..4e7c4bb72 100644 --- a/src/modules/actions/api/calls.async.ts +++ b/src/modules/actions/api/calls.async.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { joinGroupCall, startSharingScreen, @@ -35,7 +35,7 @@ import callFallbackAvatarPath from '../../../assets/call-fallback-avatar.png'; const FALLBACK_INVITE_EXPIRE_SECONDS = 1800; // 30 min -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { const { activeGroupCallId } = global.groupCalls; switch (update['@type']) { @@ -88,7 +88,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { return undefined; }); -addReducer('leaveGroupCall', (global, actions, payload) => { +addActionHandler('leaveGroupCall', (global, actions, payload) => { const { isFromLibrary, shouldDiscard, shouldRemove, rejoin, } = payload || {}; @@ -151,7 +151,7 @@ addReducer('leaveGroupCall', (global, actions, payload) => { })(); }); -addReducer('toggleGroupCallVideo', (global) => { +addActionHandler('toggleGroupCallVideo', (global) => { const groupCall = selectActiveGroupCall(global); const user = selectUser(global, global.currentUserId!); if (!user || !groupCall) { @@ -169,7 +169,7 @@ addReducer('toggleGroupCallVideo', (global) => { })(); }); -addReducer('requestToSpeak', (global, actions, payload) => { +addActionHandler('requestToSpeak', (global, actions, payload) => { const { value } = payload || { value: true }; const groupCall = selectActiveGroupCall(global); const user = selectUser(global, global.currentUserId!); @@ -184,7 +184,7 @@ addReducer('requestToSpeak', (global, actions, payload) => { }); }); -addReducer('setGroupCallParticipantVolume', (global, actions, payload) => { +addActionHandler('setGroupCallParticipantVolume', (global, actions, payload) => { const { participantId, volume } = payload!; const groupCall = selectActiveGroupCall(global); @@ -202,7 +202,7 @@ addReducer('setGroupCallParticipantVolume', (global, actions, payload) => { }); }); -addReducer('toggleGroupCallMute', (global, actions, payload) => { +addActionHandler('toggleGroupCallMute', (global, actions, payload) => { const { participantId, value } = payload || {}; const groupCall = selectActiveGroupCall(global); const user = selectUser(global, participantId || global.currentUserId!); @@ -227,7 +227,7 @@ addReducer('toggleGroupCallMute', (global, actions, payload) => { })(); }); -addReducer('toggleGroupCallPresentation', (global, actions, payload) => { +addActionHandler('toggleGroupCallPresentation', (global, actions, payload) => { const groupCall = selectActiveGroupCall(global); const user = selectUser(global, global.currentUserId!); if (!user || !groupCall) { @@ -261,7 +261,7 @@ addReducer('toggleGroupCallPresentation', (global, actions, payload) => { })(); }); -addReducer('connectToActiveGroupCall', (global, actions) => { +addActionHandler('connectToActiveGroupCall', (global, actions) => { const groupCall = selectActiveGroupCall(global); if (!groupCall) return; @@ -304,7 +304,7 @@ addReducer('connectToActiveGroupCall', (global, actions) => { })(); }); -addReducer('inviteToCallFallback', (global, actions, payload) => { +addActionHandler('inviteToCallFallback', (global, actions, payload) => { const { chatId } = selectCurrentMessageList(global) || {}; if (!chatId) { return; diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index a9a7f563d..0895bcb26 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -1,5 +1,5 @@ import { - addReducer, getDispatch, getGlobal, setGlobal, + addActionHandler, getActions, getGlobal, setGlobal, } from '../..'; import { @@ -48,7 +48,7 @@ const INFINITE_LOOP_MARKER = 100; const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true); const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true); -addReducer('preloadTopChatMessages', (global, actions) => { +addActionHandler('preloadTopChatMessages', (global, actions) => { (async () => { const preloadedChatIds = new Set(); @@ -69,7 +69,7 @@ addReducer('preloadTopChatMessages', (global, actions) => { })(); }); -addReducer('openChat', (global, actions, payload) => { +addActionHandler('openChat', (global, actions, payload) => { const { id, threadId } = payload!; const { currentUserId } = global; const chat = selectChat(global, id); @@ -107,7 +107,7 @@ addReducer('openChat', (global, actions, payload) => { } }); -addReducer('openLinkedChat', (global, actions, payload) => { +addActionHandler('openLinkedChat', (global, actions, payload) => { const { id } = payload!; const chat = selectChat(global, id); if (!chat) { @@ -123,7 +123,7 @@ addReducer('openLinkedChat', (global, actions, payload) => { })(); }); -addReducer('focusMessageInComments', (global, actions, payload) => { +addActionHandler('focusMessageInComments', (global, actions, payload) => { const { chatId, threadId, messageId } = payload!; const chat = selectChat(global, chatId); if (!chat) { @@ -140,7 +140,7 @@ addReducer('focusMessageInComments', (global, actions, payload) => { })(); }); -addReducer('openSupportChat', (global, actions) => { +addActionHandler('openSupportChat', (global, actions) => { const chat = selectSupportChat(global); if (chat) { actions.openChat({ id: chat.id, shouldReplaceHistory: true }); @@ -157,7 +157,7 @@ addReducer('openSupportChat', (global, actions) => { })(); }); -addReducer('openTipsChat', (global, actions, payload) => { +addActionHandler('openTipsChat', (global, actions, payload) => { const { langCode } = payload; const usernamePostfix = langCode === 'pt-br' @@ -167,7 +167,7 @@ addReducer('openTipsChat', (global, actions, payload) => { actions.openChatByUsername({ username: `${TIPS_USERNAME}${usernamePostfix}` }); }); -addReducer('loadAllChats', (global, actions, payload) => { +addActionHandler('loadAllChats', (global, actions, payload) => { const listType = payload.listType as 'active' | 'archived'; const { onReplace } = payload; let { shouldReplace } = payload; @@ -210,7 +210,7 @@ addReducer('loadAllChats', (global, actions, payload) => { })(); }); -addReducer('loadFullChat', (global, actions, payload) => { +addActionHandler('loadFullChat', (global, actions, payload) => { const { chatId, force } = payload!; const chat = selectChat(global, chatId); if (!chat) { @@ -224,11 +224,11 @@ addReducer('loadFullChat', (global, actions, payload) => { } }); -addReducer('loadTopChats', () => { +addActionHandler('loadTopChats', () => { runThrottledForLoadTopChats(() => loadChats('active')); }); -addReducer('requestChatUpdate', (global, actions, payload) => { +addActionHandler('requestChatUpdate', (global, actions, payload) => { const { serverTimeOffset } = global; const { chatId } = payload!; const chat = selectChat(global, chatId); @@ -245,7 +245,7 @@ addReducer('requestChatUpdate', (global, actions, payload) => { }); }); -addReducer('updateChatMutedState', (global, actions, payload) => { +addActionHandler('updateChatMutedState', (global, actions, payload) => { const { serverTimeOffset } = global; const { chatId, isMuted } = payload!; const chat = selectChat(global, chatId); @@ -257,7 +257,7 @@ addReducer('updateChatMutedState', (global, actions, payload) => { void callApi('updateChatMutedState', { chat, isMuted, serverTimeOffset }); }); -addReducer('createChannel', (global, actions, payload) => { +addActionHandler('createChannel', (global, actions, payload) => { const { title, about, photo, memberIds, } = payload!; @@ -269,7 +269,7 @@ addReducer('createChannel', (global, actions, payload) => { void createChannel(title, members, about, photo); }); -addReducer('joinChannel', (global, actions, payload) => { +addActionHandler('joinChannel', (global, actions, payload) => { const { chatId } = payload!; const chat = selectChat(global, chatId); if (!chat) { @@ -283,7 +283,7 @@ addReducer('joinChannel', (global, actions, payload) => { } }); -addReducer('deleteChatUser', (global, actions, payload) => { +addActionHandler('deleteChatUser', (global, actions, payload) => { const { chatId, userId }: { chatId: string; userId: string } = payload!; const chat = selectChat(global, chatId); const user = selectUser(global, userId); @@ -301,7 +301,7 @@ addReducer('deleteChatUser', (global, actions, payload) => { void callApi('deleteChatUser', { chat, user }); }); -addReducer('deleteChat', (global, actions, payload) => { +addActionHandler('deleteChat', (global, actions, payload) => { const { chatId }: { chatId: string } = payload!; const chat = selectChat(global, chatId); if (!chat) { @@ -318,7 +318,7 @@ addReducer('deleteChat', (global, actions, payload) => { void callApi('deleteChat', { chatId: chat.id }); }); -addReducer('leaveChannel', (global, actions, payload) => { +addActionHandler('leaveChannel', (global, actions, payload) => { const { chatId } = payload!; const chat = selectChat(global, chatId); if (!chat) { @@ -338,7 +338,7 @@ addReducer('leaveChannel', (global, actions, payload) => { } }); -addReducer('deleteChannel', (global, actions, payload) => { +addActionHandler('deleteChannel', (global, actions, payload) => { const { chatId } = payload!; const chat = selectChat(global, chatId); if (!chat) { @@ -358,7 +358,7 @@ addReducer('deleteChannel', (global, actions, payload) => { } }); -addReducer('createGroupChat', (global, actions, payload) => { +addActionHandler('createGroupChat', (global, actions, payload) => { const { title, memberIds, photo } = payload!; const members = (memberIds as string[]) .map((id) => selectUser(global, id)) @@ -367,7 +367,7 @@ addReducer('createGroupChat', (global, actions, payload) => { void createGroupChat(title, members, photo); }); -addReducer('toggleChatPinned', (global, actions, payload) => { +addActionHandler('toggleChatPinned', (global, actions, payload) => { const { id, folderId } = payload!; const chat = selectChat(global, id); if (!chat) { @@ -403,7 +403,7 @@ addReducer('toggleChatPinned', (global, actions, payload) => { } }); -addReducer('toggleChatArchived', (global, actions, payload) => { +addActionHandler('toggleChatArchived', (global, actions, payload) => { const { id } = payload!; const chat = selectChat(global, id); if (chat) { @@ -414,15 +414,15 @@ addReducer('toggleChatArchived', (global, actions, payload) => { } }); -addReducer('loadChatFolders', () => { +addActionHandler('loadChatFolders', () => { void loadChatFolders(); }); -addReducer('loadRecommendedChatFolders', () => { +addActionHandler('loadRecommendedChatFolders', () => { void loadRecommendedChatFolders(); }); -addReducer('editChatFolders', (global, actions, payload) => { +addActionHandler('editChatFolders', (global, actions, payload) => { const { chatId, idsToRemove, idsToAdd } = payload!; (idsToRemove as number[]).forEach(async (id) => { @@ -453,7 +453,7 @@ addReducer('editChatFolders', (global, actions, payload) => { }); }); -addReducer('editChatFolder', (global, actions, payload) => { +addActionHandler('editChatFolder', (global, actions, payload) => { const { id, folderUpdate } = payload!; const folder = selectChatFolder(global, id); @@ -470,7 +470,7 @@ addReducer('editChatFolder', (global, actions, payload) => { } }); -addReducer('addChatFolder', (global, actions, payload) => { +addActionHandler('addChatFolder', (global, actions, payload) => { const { folder } = payload!; const { orderedIds } = global.chatFolders; const maxId = orderedIds?.length ? Math.max.apply(Math.max, orderedIds) : ARCHIVED_FOLDER_ID; @@ -478,7 +478,7 @@ addReducer('addChatFolder', (global, actions, payload) => { void createChatFolder(folder, maxId); }); -addReducer('deleteChatFolder', (global, actions, payload) => { +addActionHandler('deleteChatFolder', (global, actions, payload) => { const { id } = payload!; const folder = selectChatFolder(global, id); @@ -487,7 +487,7 @@ addReducer('deleteChatFolder', (global, actions, payload) => { } }); -addReducer('toggleChatUnread', (global, actions, payload) => { +addActionHandler('toggleChatUnread', (global, actions, payload) => { const { id } = payload!; const { serverTimeOffset } = global; const chat = selectChat(global, id); @@ -503,7 +503,7 @@ addReducer('toggleChatUnread', (global, actions, payload) => { } }); -addReducer('openChatByInvite', (global, actions, payload) => { +addActionHandler('openChatByInvite', (global, actions, payload) => { const { hash } = payload!; (async () => { @@ -516,7 +516,7 @@ addReducer('openChatByInvite', (global, actions, payload) => { })(); }); -addReducer('openChatByPhoneNumber', (global, actions, payload) => { +addActionHandler('openChatByPhoneNumber', (global, actions, payload) => { const { phoneNumber } = payload!; (async () => { @@ -536,7 +536,7 @@ addReducer('openChatByPhoneNumber', (global, actions, payload) => { })(); }); -addReducer('openTelegramLink', (global, actions, payload) => { +addActionHandler('openTelegramLink', (global, actions, payload) => { const { url } = payload!; if (url.match(RE_TG_LINK)) { processDeepLink(url.match(RE_TG_LINK)[0]); @@ -604,7 +604,7 @@ addReducer('openTelegramLink', (global, actions, payload) => { } }); -addReducer('acceptInviteConfirmation', (global, actions, payload) => { +addActionHandler('acceptInviteConfirmation', (global, actions, payload) => { const { hash } = payload!; (async () => { const result = await callApi('importChatInvite', { hash }); @@ -616,7 +616,7 @@ addReducer('acceptInviteConfirmation', (global, actions, payload) => { })(); }); -addReducer('openChatByUsername', (global, actions, payload) => { +addActionHandler('openChatByUsername', (global, actions, payload) => { const { username, messageId, commentId, startParam, } = payload!; @@ -654,7 +654,7 @@ addReducer('openChatByUsername', (global, actions, payload) => { })(); }); -addReducer('togglePreHistoryHidden', (global, actions, payload) => { +addActionHandler('togglePreHistoryHidden', (global, actions, payload) => { const { chatId, isEnabled } = payload!; let chat = selectChat(global, chatId); @@ -677,7 +677,7 @@ addReducer('togglePreHistoryHidden', (global, actions, payload) => { })(); }); -addReducer('updateChatDefaultBannedRights', (global, actions, payload) => { +addActionHandler('updateChatDefaultBannedRights', (global, actions, payload) => { const { chatId, bannedRights } = payload!; const chat = selectChat(global, chatId); @@ -688,7 +688,7 @@ addReducer('updateChatDefaultBannedRights', (global, actions, payload) => { void callApi('updateChatDefaultBannedRights', { chat, bannedRights }); }); -addReducer('updateChatMemberBannedRights', (global, actions, payload) => { +addActionHandler('updateChatMemberBannedRights', (global, actions, payload) => { const { chatId, userId, bannedRights } = payload!; let chat = selectChat(global, chatId); const user = selectUser(global, userId); @@ -743,7 +743,7 @@ addReducer('updateChatMemberBannedRights', (global, actions, payload) => { })(); }); -addReducer('updateChatAdmin', (global, actions, payload) => { +addActionHandler('updateChatAdmin', (global, actions, payload) => { const { chatId, userId, adminRights, customTitle, } = payload!; @@ -798,7 +798,7 @@ addReducer('updateChatAdmin', (global, actions, payload) => { })(); }); -addReducer('updateChat', (global, actions, payload) => { +addActionHandler('updateChat', (global, actions, payload) => { const { chatId, title, about, photo, } = payload!; @@ -827,7 +827,7 @@ addReducer('updateChat', (global, actions, payload) => { })(); }); -addReducer('toggleSignatures', (global, actions, payload) => { +addActionHandler('toggleSignatures', (global, actions, payload) => { const { chatId, isEnabled } = payload!; const chat = selectChat(global, chatId); @@ -838,7 +838,7 @@ addReducer('toggleSignatures', (global, actions, payload) => { void callApi('toggleSignatures', { chat, isEnabled }); }); -addReducer('loadGroupsForDiscussion', () => { +addActionHandler('loadGroupsForDiscussion', () => { (async () => { const groups = await callApi('fetchGroupsForDiscussion'); if (!groups) { @@ -864,7 +864,7 @@ addReducer('loadGroupsForDiscussion', () => { })(); }); -addReducer('linkDiscussionGroup', (global, actions, payload) => { +addActionHandler('linkDiscussionGroup', (global, actions, payload) => { const { channelId, chatId } = payload!; const channel = selectChat(global, channelId); @@ -902,7 +902,7 @@ addReducer('linkDiscussionGroup', (global, actions, payload) => { })(); }); -addReducer('unlinkDiscussionGroup', (global, actions, payload) => { +addActionHandler('unlinkDiscussionGroup', (global, actions, payload) => { const { channelId } = payload!; const channel = selectChat(global, channelId); @@ -923,7 +923,7 @@ addReducer('unlinkDiscussionGroup', (global, actions, payload) => { })(); }); -addReducer('setActiveChatFolder', (global, actions, payload) => { +addActionHandler('setActiveChatFolder', (global, actions, payload) => { return { ...global, chatFolders: { @@ -933,7 +933,7 @@ addReducer('setActiveChatFolder', (global, actions, payload) => { }; }); -addReducer('loadMoreMembers', (global) => { +addActionHandler('loadMoreMembers', (global) => { (async () => { const { chatId } = selectCurrentMessageList(global) || {}; const chat = chatId ? selectChat(global, chatId) : undefined; @@ -959,7 +959,7 @@ addReducer('loadMoreMembers', (global) => { })(); }); -addReducer('addChatMembers', (global, actions, payload) => { +addActionHandler('addChatMembers', (global, actions, payload) => { const { chatId, memberIds } = payload; const chat = selectChat(global, chatId); const users = (memberIds as string[]).map((userId) => selectUser(global, userId)).filter(Boolean as any); @@ -976,7 +976,7 @@ addReducer('addChatMembers', (global, actions, payload) => { })(); }); -addReducer('deleteChatMember', (global, actions, payload) => { +addActionHandler('deleteChatMember', (global, actions, payload) => { const { chatId, userId } = payload; const chat = selectChat(global, chatId); const user = selectUser(global, userId); @@ -991,7 +991,7 @@ addReducer('deleteChatMember', (global, actions, payload) => { })(); }); -addReducer('toggleIsProtected', (global, actions, payload) => { +addActionHandler('toggleIsProtected', (global, actions, payload) => { const { chatId, isProtected } = payload; const chat = selectChat(global, chatId); @@ -1002,7 +1002,7 @@ addReducer('toggleIsProtected', (global, actions, payload) => { void callApi('toggleIsProtected', { chat, isProtected }); }); -addReducer('setChatEnabledReactions', (global, actions, payload) => { +addActionHandler('setChatEnabledReactions', (global, actions, payload) => { const { chatId, enabledReactions } = payload; const chat = selectChat(global, chatId); @@ -1155,7 +1155,7 @@ async function createChannel(title: string, users: ApiUser[], about?: string, ph }, }; setGlobal(global); - getDispatch().openChat({ id: channelId, shouldReplaceHistory: true }); + getActions().openChat({ id: channelId, shouldReplaceHistory: true }); if (channelId && accessHash && photo) { await callApi('editChatPhoto', { chatId: channelId, accessHash, photo }); @@ -1192,7 +1192,7 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) { }, }; setGlobal(global); - getDispatch() + getActions() .openChat({ id: chatId, shouldReplaceHistory: true, diff --git a/src/modules/actions/api/globalSearch.ts b/src/modules/actions/api/globalSearch.ts index c244a5c89..db603b8a9 100644 --- a/src/modules/actions/api/globalSearch.ts +++ b/src/modules/actions/api/globalSearch.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { callApi } from '../../../api/gramjs'; import { ApiChat, ApiGlobalMessageSearchType } from '../../../api/types'; @@ -19,7 +19,7 @@ import { timestampPlusDay } from '../../../util/dateFormat'; const searchThrottled = throttle((cb) => cb(), 500, false); -addReducer('setGlobalSearchQuery', (global, actions, payload) => { +addActionHandler('setGlobalSearchQuery', (global, actions, payload) => { const { chatId } = global.globalSearch; const { query } = payload!; @@ -30,7 +30,7 @@ addReducer('setGlobalSearchQuery', (global, actions, payload) => { } }); -addReducer('setGlobalSearchDate', (global, actions, payload) => { +addActionHandler('setGlobalSearchDate', (global, actions, payload) => { const { date } = payload!; const maxDate = date ? timestampPlusDay(date) : date; const newGlobal = updateGlobalSearch(global, { @@ -51,7 +51,7 @@ addReducer('setGlobalSearchDate', (global, actions, payload) => { searchMessagesGlobal('', 'text', undefined, chat, maxDate, date); }); -addReducer('searchMessagesGlobal', (global, actions, payload) => { +addActionHandler('searchMessagesGlobal', (global, actions, payload) => { const { query, resultsByType, chatId, date, } = global.globalSearch; diff --git a/src/modules/actions/api/initial.ts b/src/modules/actions/api/initial.ts index 0131f25ab..2800d956c 100644 --- a/src/modules/actions/api/initial.ts +++ b/src/modules/actions/api/initial.ts @@ -1,5 +1,5 @@ import { - addReducer, getDispatch, getGlobal, setGlobal, + addActionHandler, getActions, getGlobal, setGlobal, } from '../..'; import { initApi, callApi } from '../../../api/gramjs'; @@ -26,7 +26,7 @@ import { } from '../../../util/sessions'; import { forceWebsync } from '../../../util/websync'; -addReducer('initApi', (global: GlobalState, actions) => { +addActionHandler('initApi', (global: GlobalState, actions) => { (async () => { if (!IS_TEST) { await importLegacySession(); @@ -44,7 +44,7 @@ addReducer('initApi', (global: GlobalState, actions) => { })(); }); -addReducer('setAuthPhoneNumber', (global, actions, payload) => { +addActionHandler('setAuthPhoneNumber', (global, actions, payload) => { const { phoneNumber } = payload!; void callApi('provideAuthPhoneNumber', phoneNumber.replace(/[^\d]/g, '')); @@ -56,7 +56,7 @@ addReducer('setAuthPhoneNumber', (global, actions, payload) => { }; }); -addReducer('setAuthCode', (global, actions, payload) => { +addActionHandler('setAuthCode', (global, actions, payload) => { const { code } = payload!; void callApi('provideAuthCode', code); @@ -68,7 +68,7 @@ addReducer('setAuthCode', (global, actions, payload) => { }; }); -addReducer('setAuthPassword', (global, actions, payload) => { +addActionHandler('setAuthPassword', (global, actions, payload) => { const { password } = payload!; void callApi('provideAuthPassword', password); @@ -80,13 +80,13 @@ addReducer('setAuthPassword', (global, actions, payload) => { }; }); -addReducer('uploadProfilePhoto', (global, actions, payload) => { +addActionHandler('uploadProfilePhoto', (global, actions, payload) => { const { file } = payload!; void callApi('uploadProfilePhoto', file); }); -addReducer('signUp', (global, actions, payload) => { +addActionHandler('signUp', (global, actions, payload) => { const { firstName, lastName } = payload!; void callApi('provideAuthRegistration', { firstName, lastName }); @@ -98,7 +98,7 @@ addReducer('signUp', (global, actions, payload) => { }; }); -addReducer('returnToAuthPhoneNumber', (global) => { +addActionHandler('returnToAuthPhoneNumber', (global) => { void callApi('restartAuth'); return { @@ -107,7 +107,7 @@ addReducer('returnToAuthPhoneNumber', (global) => { }; }); -addReducer('goToAuthQrCode', (global) => { +addActionHandler('goToAuthQrCode', (global) => { void callApi('restartAuthWithQr'); return { @@ -117,7 +117,7 @@ addReducer('goToAuthQrCode', (global) => { }; }); -addReducer('saveSession', (global, actions, payload) => { +addActionHandler('saveSession', (global, actions, payload) => { const { sessionData } = payload; if (sessionData) { @@ -127,7 +127,7 @@ addReducer('saveSession', (global, actions, payload) => { } }); -addReducer('signOut', () => { +addActionHandler('signOut', () => { (async () => { try { await unsubscribe(); @@ -137,11 +137,11 @@ addReducer('signOut', () => { // Do nothing } - getDispatch().reset(); + getActions().reset(); })(); }); -addReducer('reset', () => { +addActionHandler('reset', () => { clearStoredSession(); void cacheApi.clear(MEDIA_CACHE_NAME); @@ -159,16 +159,16 @@ addReducer('reset', () => { updateAppBadge(0); - getDispatch().init(); + getActions().init(); }); -addReducer('disconnect', () => { +addActionHandler('disconnect', () => { (async () => { await callApi('disconnect'); })(); }); -addReducer('loadNearestCountry', (global) => { +addActionHandler('loadNearestCountry', (global) => { if (global.connectionState !== 'connectionStateReady') { return; } @@ -183,7 +183,7 @@ addReducer('loadNearestCountry', (global) => { })(); }); -addReducer('setDeviceToken', (global, actions, deviceToken) => { +addActionHandler('setDeviceToken', (global, actions, deviceToken) => { setGlobal({ ...global, push: { @@ -193,7 +193,7 @@ addReducer('setDeviceToken', (global, actions, deviceToken) => { }); }); -addReducer('deleteDeviceToken', (global) => { +addActionHandler('deleteDeviceToken', (global) => { const newGlobal = { ...global }; delete newGlobal.push; setGlobal(newGlobal); diff --git a/src/modules/actions/api/localSearch.ts b/src/modules/actions/api/localSearch.ts index 245bda4c5..24bca1e56 100644 --- a/src/modules/actions/api/localSearch.ts +++ b/src/modules/actions/api/localSearch.ts @@ -1,5 +1,5 @@ import { - addReducer, getDispatch, getGlobal, setGlobal, + addActionHandler, getActions, getGlobal, setGlobal, } from '../..'; import { ApiChat, MAIN_THREAD_ID } from '../../../api/types'; @@ -23,7 +23,7 @@ import { } from '../../reducers'; import { SharedMediaType } from '../../../types'; -addReducer('searchTextMessagesLocal', (global) => { +addActionHandler('searchTextMessagesLocal', (global) => { const { chatId, threadId } = selectCurrentMessageList(global) || {}; const chat = chatId ? selectChat(global, chatId) : undefined; const currentSearch = selectCurrentTextSearch(global); @@ -43,7 +43,7 @@ addReducer('searchTextMessagesLocal', (global) => { void searchTextMessages(chat, threadId, topMessageId, query, offsetId); }); -addReducer('searchMediaMessagesLocal', (global) => { +addActionHandler('searchMediaMessagesLocal', (global) => { const { chatId } = selectCurrentMessageList(global) || {}; if (!chatId) { return; @@ -67,7 +67,7 @@ addReducer('searchMediaMessagesLocal', (global) => { void searchSharedMedia(chat, type, offsetId); }); -addReducer('searchMessagesByDate', (global, actions, payload) => { +addActionHandler('searchMessagesByDate', (global, actions, payload) => { const { timestamp } = payload!; const { chatId } = selectCurrentMessageList(global) || {}; @@ -180,7 +180,7 @@ async function searchMessagesByDate(chat: ApiChat, timestamp: number) { return; } - getDispatch().focusMessage({ + getActions().focusMessage({ chatId: chat.id, messageId, }); diff --git a/src/modules/actions/api/management.ts b/src/modules/actions/api/management.ts index bafe3ca50..3e344b719 100644 --- a/src/modules/actions/api/management.ts +++ b/src/modules/actions/api/management.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ManagementProgress } from '../../../types'; import { callApi } from '../../../api/gramjs'; @@ -6,7 +6,7 @@ import { updateChat, updateManagement, updateManagementProgress } from '../../re import { selectChat, selectCurrentMessageList, selectUser } from '../../selectors'; import { isChatBasicGroup } from '../../helpers'; -addReducer('checkPublicLink', (global, actions, payload) => { +addActionHandler('checkPublicLink', (global, actions, payload) => { const { chatId } = selectCurrentMessageList(global) || {}; if (!chatId) { return; @@ -35,7 +35,7 @@ addReducer('checkPublicLink', (global, actions, payload) => { })(); }); -addReducer('updatePublicLink', (global, actions, payload) => { +addActionHandler('updatePublicLink', (global, actions, payload) => { const { chatId } = selectCurrentMessageList(global) || {}; let chat = chatId && selectChat(global, chatId); if (!chatId || !chat) { @@ -67,7 +67,7 @@ addReducer('updatePublicLink', (global, actions, payload) => { })(); }); -addReducer('updatePrivateLink', (global) => { +addActionHandler('updatePrivateLink', (global) => { const { chatId } = selectCurrentMessageList(global) || {}; const chat = chatId && selectChat(global, chatId); if (!chatId || !chat) { @@ -77,13 +77,13 @@ addReducer('updatePrivateLink', (global) => { callApi('updatePrivateLink', { chat }); }); -addReducer('setEditingExportedInvite', (global, actions, payload) => { +addActionHandler('setEditingExportedInvite', (global, actions, payload) => { const { chatId, invite } = payload; setGlobal(updateManagement(global, chatId, { editingInvite: invite })); }); -addReducer('setOpenedInviteInfo', (global, actions, payload) => { +addActionHandler('setOpenedInviteInfo', (global, actions, payload) => { const { chatId, invite } = payload; const update = invite ? { inviteInfo: { invite } } : { inviteInfo: undefined }; @@ -91,7 +91,7 @@ addReducer('setOpenedInviteInfo', (global, actions, payload) => { setGlobal(updateManagement(global, chatId, update)); }); -addReducer('loadExportedChatInvites', (global, actions, payload) => { +addActionHandler('loadExportedChatInvites', (global, actions, payload) => { const { chatId, adminId, isRevoked, limit, } = payload!; @@ -112,7 +112,7 @@ addReducer('loadExportedChatInvites', (global, actions, payload) => { })(); }); -addReducer('editExportedChatInvite', (global, actions, payload) => { +addActionHandler('editExportedChatInvite', (global, actions, payload) => { const { chatId, link, isRevoked, expireDate, usageLimit, isRequestNeeded, title, } = payload!; @@ -149,7 +149,7 @@ addReducer('editExportedChatInvite', (global, actions, payload) => { })(); }); -addReducer('exportChatInvite', (global, actions, payload) => { +addActionHandler('exportChatInvite', (global, actions, payload) => { const { chatId, expireDate, usageLimit, isRequestNeeded, title, } = payload!; @@ -175,7 +175,7 @@ addReducer('exportChatInvite', (global, actions, payload) => { })(); }); -addReducer('deleteExportedChatInvite', (global, actions, payload) => { +addActionHandler('deleteExportedChatInvite', (global, actions, payload) => { const { chatId, link, } = payload!; @@ -199,7 +199,7 @@ addReducer('deleteExportedChatInvite', (global, actions, payload) => { })(); }); -addReducer('deleteRevokedExportedChatInvites', (global, actions, payload) => { +addActionHandler('deleteRevokedExportedChatInvites', (global, actions, payload) => { const { chatId, adminId, } = payload!; @@ -222,7 +222,7 @@ addReducer('deleteRevokedExportedChatInvites', (global, actions, payload) => { })(); }); -addReducer('loadChatInviteImporters', (global, actions, payload) => { +addActionHandler('loadChatInviteImporters', (global, actions, payload) => { const { chatId, link, offsetDate, offsetUserId, limit, } = payload!; @@ -253,7 +253,7 @@ addReducer('loadChatInviteImporters', (global, actions, payload) => { })(); }); -addReducer('loadChatInviteRequesters', (global, actions, payload) => { +addActionHandler('loadChatInviteRequesters', (global, actions, payload) => { const { chatId, link, offsetDate, offsetUserId, limit, } = payload!; @@ -285,7 +285,7 @@ addReducer('loadChatInviteRequesters', (global, actions, payload) => { })(); }); -addReducer('loadChatJoinRequests', (global, actions, payload) => { +addActionHandler('loadChatJoinRequests', (global, actions, payload) => { const { chatId, offsetDate, offsetUserId, limit, } = payload!; @@ -309,7 +309,7 @@ addReducer('loadChatJoinRequests', (global, actions, payload) => { })(); }); -addReducer('hideChatJoinRequest', (global, actions, payload) => { +addActionHandler('hideChatJoinRequest', (global, actions, payload) => { const { chatId, userId, isApproved, } = payload!; @@ -334,7 +334,7 @@ addReducer('hideChatJoinRequest', (global, actions, payload) => { })(); }); -addReducer('hideAllChatJoinRequests', (global, actions, payload) => { +addActionHandler('hideAllChatJoinRequests', (global, actions, payload) => { const { chatId, isApproved, link, } = payload!; diff --git a/src/modules/actions/api/messages.ts b/src/modules/actions/api/messages.ts index af2aece7d..f71a848a1 100644 --- a/src/modules/actions/api/messages.ts +++ b/src/modules/actions/api/messages.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { GlobalActions } from '../../../global/types'; import { @@ -72,7 +72,7 @@ const uploadProgressCallbacks = new Map(); const runDebouncedForMarkRead = debounce((cb) => cb(), 500, false); -addReducer('loadViewportMessages', (global, actions, payload) => { +addActionHandler('loadViewportMessages', (global, actions, payload) => { const { direction = LoadMoreDirection.Around, isBudgetPreload = false, @@ -157,7 +157,7 @@ async function loadWithBudget( } } -addReducer('loadMessage', (global, actions, payload) => { +addActionHandler('loadMessage', (global, actions, payload) => { const { chatId, messageId, replyOriginForId, threadUpdate, } = payload!; @@ -183,7 +183,7 @@ addReducer('loadMessage', (global, actions, payload) => { })(); }); -addReducer('sendMessage', (global, actions, payload) => { +addActionHandler('sendMessage', (global, actions, payload) => { const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { return undefined; @@ -273,7 +273,7 @@ addReducer('sendMessage', (global, actions, payload) => { return undefined; }); -addReducer('editMessage', (global, actions, payload) => { +addActionHandler('editMessage', (global, actions, payload) => { const { serverTimeOffset } = global; const { text, entities } = payload!; @@ -296,7 +296,7 @@ addReducer('editMessage', (global, actions, payload) => { actions.setEditingId({ messageId: undefined }); }); -addReducer('cancelSendingMessage', (global, actions, payload) => { +addActionHandler('cancelSendingMessage', (global, actions, payload) => { const { chatId, messageId } = payload!; const message = selectChatMessage(global, chatId, messageId); const progressCallback = message && uploadProgressCallbacks.get(message.previousLocalId || message.id); @@ -311,7 +311,7 @@ addReducer('cancelSendingMessage', (global, actions, payload) => { }); }); -addReducer('saveDraft', (global, actions, payload) => { +addActionHandler('saveDraft', (global, actions, payload) => { const { chatId, threadId, draft } = payload!; if (!draft) { return undefined; @@ -335,7 +335,7 @@ addReducer('saveDraft', (global, actions, payload) => { return global; }); -addReducer('clearDraft', (global, actions, payload) => { +addActionHandler('clearDraft', (global, actions, payload) => { const { chatId, threadId, localOnly } = payload!; if (!selectDraft(global, chatId, threadId)) { return undefined; @@ -353,13 +353,13 @@ addReducer('clearDraft', (global, actions, payload) => { return global; }); -addReducer('toggleMessageWebPage', (global, actions, payload) => { +addActionHandler('toggleMessageWebPage', (global, actions, payload) => { const { chatId, threadId, noWebPage } = payload!; return replaceThreadParam(global, chatId, threadId, 'noWebPage', noWebPage); }); -addReducer('pinMessage', (global, actions, payload) => { +addActionHandler('pinMessage', (global, actions, payload) => { const chat = selectCurrentChat(global); if (!chat) { return; @@ -374,7 +374,7 @@ addReducer('pinMessage', (global, actions, payload) => { }); }); -addReducer('unpinAllMessages', (global, actions, payload) => { +addActionHandler('unpinAllMessages', (global, actions, payload) => { const chat = selectChat(global, payload.chatId); if (!chat) { return; @@ -390,7 +390,7 @@ async function unpinAllMessages(chat: ApiChat) { setGlobal(global); } -addReducer('deleteMessages', (global, actions, payload) => { +addActionHandler('deleteMessages', (global, actions, payload) => { const { messageIds, shouldDeleteForAll } = payload!; const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { @@ -407,7 +407,7 @@ addReducer('deleteMessages', (global, actions, payload) => { } }); -addReducer('deleteScheduledMessages', (global, actions, payload) => { +addActionHandler('deleteScheduledMessages', (global, actions, payload) => { const { messageIds } = payload!; const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { @@ -425,7 +425,7 @@ addReducer('deleteScheduledMessages', (global, actions, payload) => { } }); -addReducer('deleteHistory', (global, actions, payload) => { +addActionHandler('deleteHistory', (global, actions, payload) => { (async () => { const { chatId, shouldDeleteForAll } = payload!; const chat = selectChat(global, chatId); @@ -444,7 +444,7 @@ addReducer('deleteHistory', (global, actions, payload) => { })(); }); -addReducer('reportMessages', (global, actions, payload) => { +addActionHandler('reportMessages', (global, actions, payload) => { (async () => { const { messageIds, reason, description, @@ -469,7 +469,7 @@ addReducer('reportMessages', (global, actions, payload) => { })(); }); -addReducer('sendMessageAction', (global, actions, payload) => { +addActionHandler('sendMessageAction', (global, actions, payload) => { (async () => { const { action, chatId, threadId } = payload!; if (chatId === global.currentUserId) return; // Message actions are disabled in Saved Messages @@ -483,7 +483,7 @@ addReducer('sendMessageAction', (global, actions, payload) => { })(); }); -addReducer('markMessageListRead', (global, actions, payload) => { +addActionHandler('markMessageListRead', (global, actions, payload) => { const { serverTimeOffset } = global; const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { @@ -535,7 +535,7 @@ addReducer('markMessageListRead', (global, actions, payload) => { }); }); -addReducer('markMessagesRead', (global, actions, payload) => { +addActionHandler('markMessagesRead', (global, actions, payload) => { const chat = selectCurrentChat(global); if (!chat) { return; @@ -546,12 +546,12 @@ addReducer('markMessagesRead', (global, actions, payload) => { void callApi('markMessagesRead', { chat, messageIds }); }); -addReducer('loadWebPagePreview', (global, actions, payload) => { +addActionHandler('loadWebPagePreview', (global, actions, payload) => { const { text } = payload!; void loadWebPagePreview(text); }); -addReducer('clearWebPagePreview', (global) => { +addActionHandler('clearWebPagePreview', (global) => { if (!global.webPagePreview) { return undefined; } @@ -562,7 +562,7 @@ addReducer('clearWebPagePreview', (global) => { }; }); -addReducer('sendPollVote', (global, actions, payload) => { +addActionHandler('sendPollVote', (global, actions, payload) => { const { chatId, messageId, options } = payload!; const chat = selectChat(global, chatId); @@ -571,7 +571,7 @@ addReducer('sendPollVote', (global, actions, payload) => { } }); -addReducer('loadPollOptionResults', (global, actions, payload) => { +addActionHandler('loadPollOptionResults', (global, actions, payload) => { const { chat, messageId, option, offset, limit, shouldResetVoters, } = payload!; @@ -579,7 +579,7 @@ addReducer('loadPollOptionResults', (global, actions, payload) => { void loadPollOptionResults(chat, messageId, option, offset, limit, shouldResetVoters); }); -addReducer('forwardMessages', (global, action, payload) => { +addActionHandler('forwardMessages', (global, action, payload) => { const { fromChatId, messageIds, toChatId } = global.forwardMessages; const fromChat = fromChatId ? selectChat(global, fromChatId) : undefined; const toChat = toChatId ? selectChat(global, toChatId) : undefined; @@ -633,7 +633,7 @@ addReducer('forwardMessages', (global, action, payload) => { }); }); -addReducer('loadScheduledHistory', (global, actions, payload) => { +addActionHandler('loadScheduledHistory', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); if (!chat) { @@ -643,7 +643,7 @@ addReducer('loadScheduledHistory', (global, actions, payload) => { void loadScheduledHistory(chat); }); -addReducer('sendScheduledMessages', (global, actions, payload) => { +addActionHandler('sendScheduledMessages', (global, actions, payload) => { const { chatId, id, } = payload!; @@ -660,7 +660,7 @@ addReducer('sendScheduledMessages', (global, actions, payload) => { }); }); -addReducer('rescheduleMessage', (global, actions, payload) => { +addActionHandler('rescheduleMessage', (global, actions, payload) => { const { chatId, messageId, scheduledAt, } = payload!; @@ -678,7 +678,7 @@ addReducer('rescheduleMessage', (global, actions, payload) => { }); }); -addReducer('requestThreadInfoUpdate', (global, actions, payload) => { +addActionHandler('requestThreadInfoUpdate', (global, actions, payload) => { const { chatId, threadId } = payload; const chat = selectThreadOriginChat(global, chatId, threadId); if (!chat) { @@ -950,7 +950,7 @@ async function loadPollOptionResults( }); } -addReducer('loadPinnedMessages', (global, actions, payload) => { +addActionHandler('loadPinnedMessages', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); if (!chat) { @@ -960,7 +960,7 @@ addReducer('loadPinnedMessages', (global, actions, payload) => { void loadPinnedMessages(chat); }); -addReducer('loadSeenBy', (global, actions, payload) => { +addActionHandler('loadSeenBy', (global, actions, payload) => { const { chatId, messageId } = payload; const chat = selectChat(global, chatId); if (!chat) { @@ -979,7 +979,7 @@ addReducer('loadSeenBy', (global, actions, payload) => { })(); }); -addReducer('saveDefaultSendAs', (global, actions, payload) => { +addActionHandler('saveDefaultSendAs', (global, actions, payload) => { const { chatId, sendAsId } = payload; const chat = selectChat(global, chatId); const sendAsChat = selectChat(global, sendAsId) || selectUser(global, sendAsId); @@ -997,7 +997,7 @@ addReducer('saveDefaultSendAs', (global, actions, payload) => { }); }); -addReducer('loadSendAs', (global, actions, payload) => { +addActionHandler('loadSendAs', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); if (!chat) { @@ -1060,7 +1060,7 @@ async function loadScheduledHistory(chat: ApiChat) { setGlobal(global); } -addReducer('loadSponsoredMessages', (global, actions, payload) => { +addActionHandler('loadSponsoredMessages', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); if (!chat) { @@ -1081,7 +1081,7 @@ addReducer('loadSponsoredMessages', (global, actions, payload) => { })(); }); -addReducer('viewSponsoredMessage', (global, actions, payload) => { +addActionHandler('viewSponsoredMessage', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); const message = selectSponsoredMessage(global, chatId); diff --git a/src/modules/actions/api/payments.ts b/src/modules/actions/api/payments.ts index 8cd6c1408..7da4cffe4 100644 --- a/src/modules/actions/api/payments.ts +++ b/src/modules/actions/api/payments.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { PaymentStep } from '../../../types'; import { ApiChat } from '../../../api/types'; @@ -33,7 +33,7 @@ import { setSmartGlocalCardInfo, } from '../../reducers'; -addReducer('validateRequestedInfo', (global, actions, payload) => { +addActionHandler('validateRequestedInfo', (global, actions, payload) => { const { requestInfo, saveInfo } = payload; const chatId = selectPaymentChatId(global); const chat = chatId && selectChat(global, chatId); @@ -67,7 +67,7 @@ async function validateRequestedInfo(chat: ApiChat, messageId: number, requestIn setGlobal(global); } -addReducer('getPaymentForm', (global, actions, payload) => { +addActionHandler('getPaymentForm', (global, actions, payload) => { const { chat, messageId } = payload; if (!chat || !messageId) { return; @@ -93,7 +93,7 @@ async function getPaymentForm(chat: ApiChat, messageId: number) { setGlobal(global); } -addReducer('getReceipt', (global, actions, payload) => { +addActionHandler('getReceipt', (global, actions, payload) => { const { receiptMessageId, chatId, messageId } = payload; const chat = chatId && selectChat(global, chatId); if (!messageId || !receiptMessageId || !chat) { @@ -115,7 +115,7 @@ async function getReceipt(chat: ApiChat, messageId: number, receiptMessageId: nu setGlobal(global); } -addReducer('clearPaymentError', (global) => { +addActionHandler('clearPaymentError', (global) => { setGlobal({ ...global, payment: { @@ -125,7 +125,7 @@ addReducer('clearPaymentError', (global) => { }); }); -addReducer('clearReceipt', (global) => { +addActionHandler('clearReceipt', (global) => { setGlobal({ ...global, payment: { @@ -135,7 +135,7 @@ addReducer('clearReceipt', (global) => { }); }); -addReducer('sendCredentialsInfo', (global, actions, payload) => { +addActionHandler('sendCredentialsInfo', (global, actions, payload) => { const { nativeProvider } = global.payment; const { credentials } = payload; const { data } = credentials; @@ -155,7 +155,7 @@ addReducer('sendCredentialsInfo', (global, actions, payload) => { } }); -addReducer('sendPaymentForm', (global, actions, payload) => { +addActionHandler('sendPaymentForm', (global, actions, payload) => { const { shippingOptionId, saveCredentials } = payload; const chatId = selectPaymentChatId(global); const chat = chatId && selectChat(global, chatId); @@ -303,10 +303,10 @@ async function sendPaymentForm( } } -addReducer('setPaymentStep', (global, actions, payload = {}) => { +addActionHandler('setPaymentStep', (global, actions, payload = {}) => { return setPaymentStep(global, payload.step || PaymentStep.ShippingInfo); }); -addReducer('setInvoiceMessageInfo', (global, actions, payload) => { +addActionHandler('setInvoiceMessageInfo', (global, actions, payload) => { return setInvoiceMessageInfo(global, payload); }); diff --git a/src/modules/actions/api/reactions.ts b/src/modules/actions/api/reactions.ts index 9d8cbebc8..59c20dcdd 100644 --- a/src/modules/actions/api/reactions.ts +++ b/src/modules/actions/api/reactions.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { callApi } from '../../../api/gramjs'; import * as mediaLoader from '../../../util/mediaLoader'; import { ApiAppConfig, ApiMediaFormat } from '../../../api/types'; @@ -19,7 +19,7 @@ const INTERACTION_RANDOM_OFFSET = 40; let interactionLocalId = 0; -addReducer('loadAvailableReactions', () => { +addActionHandler('loadAvailableReactions', () => { (async () => { const result = await callApi('getAvailableReactions'); @@ -44,7 +44,7 @@ addReducer('loadAvailableReactions', () => { })(); }); -addReducer('interactWithAnimatedEmoji', (global, actions, payload) => { +addActionHandler('interactWithAnimatedEmoji', (global, actions, payload) => { const { emoji, x, y, localEffect, startSize, isReversed, } = payload!; @@ -65,7 +65,7 @@ addReducer('interactWithAnimatedEmoji', (global, actions, payload) => { }; }); -addReducer('sendEmojiInteraction', (global, actions, payload) => { +addActionHandler('sendEmojiInteraction', (global, actions, payload) => { const { messageId, chatId, emoji, interactions, localEffect, } = payload!; @@ -84,7 +84,7 @@ addReducer('sendEmojiInteraction', (global, actions, payload) => { }); }); -addReducer('sendDefaultReaction', (global, actions, payload) => { +addActionHandler('sendDefaultReaction', (global, actions, payload) => { const { chatId, messageId, x, y, } = payload; @@ -102,7 +102,7 @@ addReducer('sendDefaultReaction', (global, actions, payload) => { }); }); -addReducer('sendReaction', (global, actions, payload) => { +addActionHandler('sendReaction', (global, actions, payload) => { const { chatId, }: { chatId: string } = payload; @@ -152,14 +152,14 @@ addReducer('sendReaction', (global, actions, payload) => { return addMessageReaction(global, chatId, messageId, reaction); }); -addReducer('openChat', (global) => { +addActionHandler('openChat', (global) => { return { ...global, activeReactions: {}, }; }); -addReducer('startActiveReaction', (global, actions, payload) => { +addActionHandler('startActiveReaction', (global, actions, payload) => { const { messageId, reaction } = payload; const { animationLevel } = global.settings.byKey; @@ -183,7 +183,7 @@ addReducer('startActiveReaction', (global, actions, payload) => { }; }); -addReducer('stopActiveReaction', (global, actions, payload) => { +addActionHandler('stopActiveReaction', (global, actions, payload) => { const { messageId, reaction } = payload; if (global.activeReactions[messageId]?.reaction !== reaction) { @@ -196,7 +196,7 @@ addReducer('stopActiveReaction', (global, actions, payload) => { }; }); -addReducer('setDefaultReaction', (global, actions, payload) => { +addActionHandler('setDefaultReaction', (global, actions, payload) => { const { reaction } = payload; (async () => { @@ -217,7 +217,7 @@ addReducer('setDefaultReaction', (global, actions, payload) => { })(); }); -addReducer('stopActiveEmojiInteraction', (global, actions, payload) => { +addActionHandler('stopActiveEmojiInteraction', (global, actions, payload) => { const { id } = payload; return { @@ -226,7 +226,7 @@ addReducer('stopActiveEmojiInteraction', (global, actions, payload) => { }; }); -addReducer('loadReactors', (global, actions, payload) => { +addActionHandler('loadReactors', (global, actions, payload) => { const { chatId, messageId, reaction } = payload; const chat = selectChat(global, chatId); const message = selectChatMessage(global, chatId, messageId); @@ -268,7 +268,7 @@ addReducer('loadReactors', (global, actions, payload) => { })(); }); -addReducer('loadMessageReactions', (global, actions, payload) => { +addActionHandler('loadMessageReactions', (global, actions, payload) => { const { ids, chatId } = payload; const chat = selectChat(global, chatId); @@ -280,7 +280,7 @@ addReducer('loadMessageReactions', (global, actions, payload) => { callApi('fetchMessageReactions', { ids, chat }); }); -addReducer('sendWatchingEmojiInteraction', (global, actions, payload) => { +addActionHandler('sendWatchingEmojiInteraction', (global, actions, payload) => { const { chatId, emoticon, x, y, startSize, isReversed, id, } = payload; diff --git a/src/modules/actions/api/settings.ts b/src/modules/actions/api/settings.ts index 4b70a5f04..7b4ae08fc 100644 --- a/src/modules/actions/api/settings.ts +++ b/src/modules/actions/api/settings.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { GlobalState } from '../../../global/types'; import { @@ -18,7 +18,7 @@ import { } from '../../reducers'; import { isUserId } from '../../helpers'; -addReducer('updateProfile', (global, actions, payload) => { +addActionHandler('updateProfile', (global, actions, payload) => { const { photo, firstName, lastName, bio: about, username, } = payload!; @@ -79,7 +79,7 @@ addReducer('updateProfile', (global, actions, payload) => { })(); }); -addReducer('checkUsername', (global, actions, payload) => { +addActionHandler('checkUsername', (global, actions, payload) => { const { username } = payload!; (async () => { @@ -109,7 +109,7 @@ addReducer('checkUsername', (global, actions, payload) => { })(); }); -addReducer('loadWallpapers', () => { +addActionHandler('loadWallpapers', () => { (async () => { const result = await callApi('fetchWallpapers'); if (!result) { @@ -127,7 +127,7 @@ addReducer('loadWallpapers', () => { })(); }); -addReducer('uploadWallpaper', (global, actions, payload) => { +addActionHandler('uploadWallpaper', (global, actions, payload) => { const file = payload; const previewBlobUrl = URL.createObjectURL(file); @@ -189,7 +189,7 @@ addReducer('uploadWallpaper', (global, actions, payload) => { })(); }); -addReducer('loadBlockedContacts', () => { +addActionHandler('loadBlockedContacts', () => { (async () => { const result = await callApi('fetchBlockedContacts'); @@ -219,7 +219,7 @@ addReducer('loadBlockedContacts', () => { })(); }); -addReducer('blockContact', (global, actions, payload) => { +addActionHandler('blockContact', (global, actions, payload) => { const { contactId, accessHash } = payload!; (async () => { @@ -234,7 +234,7 @@ addReducer('blockContact', (global, actions, payload) => { })(); }); -addReducer('unblockContact', (global, actions, payload) => { +addActionHandler('unblockContact', (global, actions, payload) => { const { contactId } = payload!; let accessHash: string | undefined; const isPrivate = isUserId(contactId); @@ -260,7 +260,7 @@ addReducer('unblockContact', (global, actions, payload) => { })(); }); -addReducer('loadAuthorizations', () => { +addActionHandler('loadAuthorizations', () => { (async () => { const result = await callApi('fetchAuthorizations'); if (!result) { @@ -274,7 +274,7 @@ addReducer('loadAuthorizations', () => { })(); }); -addReducer('terminateAuthorization', (global, actions, payload) => { +addActionHandler('terminateAuthorization', (global, actions, payload) => { const { hash } = payload!; (async () => { @@ -292,7 +292,7 @@ addReducer('terminateAuthorization', (global, actions, payload) => { })(); }); -addReducer('terminateAllAuthorizations', () => { +addActionHandler('terminateAllAuthorizations', () => { (async () => { const result = await callApi('terminateAllAuthorizations'); if (!result) { @@ -308,7 +308,7 @@ addReducer('terminateAllAuthorizations', () => { })(); }); -addReducer('loadNotificationExceptions', (global) => { +addActionHandler('loadNotificationExceptions', (global) => { const { serverTimeOffset } = global; (async () => { @@ -321,7 +321,7 @@ addReducer('loadNotificationExceptions', (global) => { })(); }); -addReducer('loadNotificationSettings', (global) => { +addActionHandler('loadNotificationSettings', (global) => { const { serverTimeOffset } = global; (async () => { const result = await callApi('fetchNotificationSettings', { @@ -335,7 +335,7 @@ addReducer('loadNotificationSettings', (global) => { })(); }); -addReducer('updateNotificationSettings', (global, actions, payload) => { +addActionHandler('updateNotificationSettings', (global, actions, payload) => { const { peerType, isSilent, shouldShowPreviews } = payload!; (async () => { @@ -349,7 +349,7 @@ addReducer('updateNotificationSettings', (global, actions, payload) => { })(); }); -addReducer('updateWebNotificationSettings', (global, actions, payload) => { +addActionHandler('updateWebNotificationSettings', (global, actions, payload) => { (async () => { setGlobal(replaceSettings(getGlobal(), payload)); const newGlobal = getGlobal(); @@ -362,7 +362,7 @@ addReducer('updateWebNotificationSettings', (global, actions, payload) => { })(); }); -addReducer('updateContactSignUpNotification', (global, actions, payload) => { +addActionHandler('updateContactSignUpNotification', (global, actions, payload) => { const { isSilent } = payload!; (async () => { @@ -375,7 +375,7 @@ addReducer('updateContactSignUpNotification', (global, actions, payload) => { })(); }); -addReducer('loadLanguages', () => { +addActionHandler('loadLanguages', () => { (async () => { const result = await callApi('fetchLanguages'); if (!result) { @@ -386,7 +386,7 @@ addReducer('loadLanguages', () => { })(); }); -addReducer('loadPrivacySettings', () => { +addActionHandler('loadPrivacySettings', () => { (async () => { const [ phoneNumberSettings, lastSeenSettings, profilePhotoSettings, forwardsSettings, chatInviteSettings, @@ -416,7 +416,7 @@ addReducer('loadPrivacySettings', () => { })(); }); -addReducer('setPrivacyVisibility', (global, actions, payload) => { +addActionHandler('setPrivacyVisibility', (global, actions, payload) => { const { privacyKey, visibility } = payload!; const { @@ -446,7 +446,7 @@ addReducer('setPrivacyVisibility', (global, actions, payload) => { })(); }); -addReducer('setPrivacySettings', (global, actions, payload) => { +addActionHandler('setPrivacySettings', (global, actions, payload) => { const { privacyKey, isAllowList, contactsIds } = payload!; const { privacy: { [privacyKey as ApiPrivacyKey]: settings }, @@ -543,11 +543,11 @@ function buildInputPrivacyRules(global: GlobalState, { return rules; } -addReducer('updateIsOnline', (global, actions, payload) => { +addActionHandler('updateIsOnline', (global, actions, payload) => { callApi('updateIsOnline', payload); }); -addReducer('loadContentSettings', () => { +addActionHandler('loadContentSettings', () => { (async () => { const result = await callApi('fetchContentSettings'); if (!result) return; @@ -556,7 +556,7 @@ addReducer('loadContentSettings', () => { })(); }); -addReducer('updateContentSettings', (global, actions, payload) => { +addActionHandler('updateContentSettings', (global, actions, payload) => { (async () => { setGlobal(replaceSettings(getGlobal(), { isSensitiveEnabled: payload })); @@ -567,7 +567,7 @@ addReducer('updateContentSettings', (global, actions, payload) => { })(); }); -addReducer('loadCountryList', (global, actions, payload = {}) => { +addActionHandler('loadCountryList', (global, actions, payload = {}) => { let { langCode } = payload; if (!langCode) langCode = global.settings.byKey.language; @@ -582,7 +582,7 @@ addReducer('loadCountryList', (global, actions, payload = {}) => { })(); }); -addReducer('ensureTimeFormat', (global, actions) => { +addActionHandler('ensureTimeFormat', (global, actions) => { if (global.authNearestCountry) { const timeFormat = COUNTRIES_WITH_12H_TIME_FORMAT.has(global.authNearestCountry.toUpperCase()) ? '12h' : '24h'; actions.setSettingOption({ timeFormat }); @@ -603,7 +603,7 @@ addReducer('ensureTimeFormat', (global, actions) => { })(); }); -addReducer('loadAppConfig', () => { +addActionHandler('loadAppConfig', () => { (async () => { const appConfig = await callApi('fetchAppConfig'); diff --git a/src/modules/actions/api/statistics.ts b/src/modules/actions/api/statistics.ts index fdc617a29..9c47e6d79 100644 --- a/src/modules/actions/api/statistics.ts +++ b/src/modules/actions/api/statistics.ts @@ -1,10 +1,10 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { callApi } from '../../../api/gramjs'; import { updateStatistics, updateStatisticsGraph } from '../../reducers'; import { selectChatMessages, selectChat } from '../../selectors'; -addReducer('loadStatistics', (global, actions, payload) => { +addActionHandler('loadStatistics', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); if (!chat?.fullInfo) { @@ -33,7 +33,7 @@ addReducer('loadStatistics', (global, actions, payload) => { })(); }); -addReducer('loadStatisticsAsyncGraph', (global, actions, payload) => { +addActionHandler('loadStatisticsAsyncGraph', (global, actions, payload) => { const { chatId, token, name, isPercentage, } = payload; diff --git a/src/modules/actions/api/symbols.ts b/src/modules/actions/api/symbols.ts index e70437e36..cc412435e 100644 --- a/src/modules/actions/api/symbols.ts +++ b/src/modules/actions/api/symbols.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ApiSticker } from '../../../api/types'; import { LangCode } from '../../../types'; @@ -20,12 +20,12 @@ const ADDED_SETS_THROTTLE_CHUNK = 10; const searchThrottled = throttle((cb) => cb(), 500, false); -addReducer('loadStickerSets', (global) => { +addActionHandler('loadStickerSets', (global) => { const { hash } = global.stickers.added || {}; void loadStickerSets(hash); }); -addReducer('loadAddedStickers', (global, actions) => { +addActionHandler('loadAddedStickers', (global, actions) => { const { setIds: addedSetIds } = global.stickers.added; const cached = global.stickers.setsById; if (!addedSetIds || !addedSetIds.length) { @@ -47,17 +47,17 @@ addReducer('loadAddedStickers', (global, actions) => { })(); }); -addReducer('loadRecentStickers', (global) => { +addActionHandler('loadRecentStickers', (global) => { const { hash } = global.stickers.recent || {}; void loadRecentStickers(hash); }); -addReducer('loadFavoriteStickers', (global) => { +addActionHandler('loadFavoriteStickers', (global) => { const { hash } = global.stickers.favorite || {}; void loadFavoriteStickers(hash); }); -addReducer('loadGreetingStickers', (global) => { +addActionHandler('loadGreetingStickers', (global) => { const { hash } = global.stickers.greeting || {}; (async () => { @@ -82,12 +82,12 @@ addReducer('loadGreetingStickers', (global) => { })(); }); -addReducer('loadFeaturedStickers', (global) => { +addActionHandler('loadFeaturedStickers', (global) => { const { hash } = global.stickers.featured || {}; void loadFeaturedStickers(hash); }); -addReducer('loadStickers', (global, actions, payload) => { +addActionHandler('loadStickers', (global, actions, payload) => { const { stickerSetId, stickerSetShortName } = payload!; let { stickerSetAccessHash } = payload!; @@ -103,17 +103,17 @@ addReducer('loadStickers', (global, actions, payload) => { void loadStickers(stickerSetId, stickerSetAccessHash, stickerSetShortName); }); -addReducer('loadAnimatedEmojis', () => { +addActionHandler('loadAnimatedEmojis', () => { void loadAnimatedEmojis(); void loadAnimatedEmojiEffects(); }); -addReducer('loadSavedGifs', (global) => { +addActionHandler('loadSavedGifs', (global) => { const { hash } = global.gifs.saved; void loadSavedGifs(hash); }); -addReducer('faveSticker', (global, actions, payload) => { +addActionHandler('faveSticker', (global, actions, payload) => { const { sticker } = payload!; if (sticker) { @@ -121,7 +121,7 @@ addReducer('faveSticker', (global, actions, payload) => { } }); -addReducer('unfaveSticker', (global, actions, payload) => { +addActionHandler('unfaveSticker', (global, actions, payload) => { const { sticker } = payload!; if (sticker) { @@ -129,7 +129,7 @@ addReducer('unfaveSticker', (global, actions, payload) => { } }); -addReducer('toggleStickerSet', (global, actions, payload) => { +addActionHandler('toggleStickerSet', (global, actions, payload) => { const { stickerSetId } = payload!; const stickerSet = selectStickerSet(global, stickerSetId); if (!stickerSet) { @@ -141,7 +141,7 @@ addReducer('toggleStickerSet', (global, actions, payload) => { void callApi(!installedDate ? 'installStickerSet' : 'uninstallStickerSet', { stickerSetId, accessHash }); }); -addReducer('loadEmojiKeywords', (global, actions, payload: { language: LangCode }) => { +addActionHandler('loadEmojiKeywords', (global, actions, payload: { language: LangCode }) => { const { language } = payload; let currentEmojiKeywords = global.emojiKeywords[language]; @@ -330,7 +330,7 @@ function unfaveSticker(sticker: ApiSticker) { void callApi('faveSticker', { sticker, unfave: true }); } -addReducer('setStickerSearchQuery', (global, actions, payload) => { +addActionHandler('setStickerSearchQuery', (global, actions, payload) => { const { query } = payload!; if (query) { @@ -340,7 +340,7 @@ addReducer('setStickerSearchQuery', (global, actions, payload) => { } }); -addReducer('setGifSearchQuery', (global, actions, payload) => { +addActionHandler('setGifSearchQuery', (global, actions, payload) => { const { query } = payload!; if (typeof query === 'string') { @@ -350,7 +350,7 @@ addReducer('setGifSearchQuery', (global, actions, payload) => { } }); -addReducer('searchMoreGifs', (global) => { +addActionHandler('searchMoreGifs', (global) => { const { query, offset } = global.gifs.search; if (typeof query === 'string') { @@ -360,7 +360,7 @@ addReducer('searchMoreGifs', (global) => { } }); -addReducer('loadStickersForEmoji', (global, actions, payload) => { +addActionHandler('loadStickersForEmoji', (global, actions, payload) => { const { emoji } = payload!; const { hash } = global.stickers.forEmoji; @@ -369,7 +369,7 @@ addReducer('loadStickersForEmoji', (global, actions, payload) => { }); }); -addReducer('clearStickersForEmoji', (global) => { +addActionHandler('clearStickersForEmoji', (global) => { return { ...global, stickers: { @@ -379,7 +379,7 @@ addReducer('clearStickersForEmoji', (global) => { }; }); -addReducer('openStickerSetShortName', (global, actions, payload) => { +addActionHandler('openStickerSetShortName', (global, actions, payload) => { const { stickerSetShortName } = payload!; return { ...global, diff --git a/src/modules/actions/api/sync.ts b/src/modules/actions/api/sync.ts index 69d4c231b..a1e8c010e 100644 --- a/src/modules/actions/api/sync.ts +++ b/src/modules/actions/api/sync.ts @@ -1,5 +1,5 @@ import { - addReducer, getGlobal, setGlobal, getDispatch, + addActionHandler, getGlobal, setGlobal, getActions, } from '../..'; import { @@ -32,7 +32,7 @@ const RELEASE_STATUS_TIMEOUT = 15000; // 10 sec; let releaseStatusTimeout: number | undefined; -addReducer('sync', () => { +addActionHandler('sync', () => { if (DEBUG) { // eslint-disable-next-line no-console console.log('>>> START SYNC'); @@ -50,7 +50,7 @@ addReducer('sync', () => { releaseStatusTimeout = undefined; }, RELEASE_STATUS_TIMEOUT); - const { loadAllChats, preloadTopChatMessages } = getDispatch(); + const { loadAllChats, preloadTopChatMessages } = getActions(); loadAllChats({ listType: 'active', @@ -190,7 +190,7 @@ async function loadAndReplaceMessages() { const { chatId: audioChatId, messageId: audioMessageId } = global.audioPlayer; if (audioChatId && audioMessageId && !selectChatMessage(global, audioChatId, audioMessageId)) { - getDispatch().closeAudioPlayer(); + getActions().closeAudioPlayer(); } } diff --git a/src/modules/actions/api/twoFaSettings.ts b/src/modules/actions/api/twoFaSettings.ts index 24b1a9e35..382eb3be9 100644 --- a/src/modules/actions/api/twoFaSettings.ts +++ b/src/modules/actions/api/twoFaSettings.ts @@ -1,9 +1,9 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { callApi } from '../../../api/gramjs'; import { replaceSettings, updateTwoFaSettings } from '../../reducers'; -addReducer('loadPasswordInfo', () => { +addActionHandler('loadPasswordInfo', () => { (async () => { const result = await callApi('getPasswordInfo'); if (!result) { @@ -17,7 +17,7 @@ addReducer('loadPasswordInfo', () => { })(); }); -addReducer('checkPassword', (global, actions, payload) => { +addActionHandler('checkPassword', (global, actions, payload) => { const { currentPassword, onSuccess } = payload; setGlobal(updateTwoFaSettings(global, { isLoading: true, error: undefined })); @@ -33,7 +33,7 @@ addReducer('checkPassword', (global, actions, payload) => { })(); }); -addReducer('clearPassword', (global, actions, payload) => { +addActionHandler('clearPassword', (global, actions, payload) => { const { currentPassword, onSuccess } = payload; setGlobal(updateTwoFaSettings(global, { isLoading: true, error: undefined })); @@ -49,7 +49,7 @@ addReducer('clearPassword', (global, actions, payload) => { })(); }); -addReducer('updatePassword', (global, actions, payload) => { +addActionHandler('updatePassword', (global, actions, payload) => { const { currentPassword, password, hint, email, onSuccess, } = payload; @@ -67,7 +67,7 @@ addReducer('updatePassword', (global, actions, payload) => { })(); }); -addReducer('updateRecoveryEmail', (global, actions, payload) => { +addActionHandler('updateRecoveryEmail', (global, actions, payload) => { const { currentPassword, email, onSuccess, } = payload; @@ -85,12 +85,12 @@ addReducer('updateRecoveryEmail', (global, actions, payload) => { })(); }); -addReducer('provideTwoFaEmailCode', (global, actions, payload) => { +addActionHandler('provideTwoFaEmailCode', (global, actions, payload) => { const { code } = payload; void callApi('provideRecoveryEmailCode', code); }); -addReducer('clearTwoFaError', (global) => { +addActionHandler('clearTwoFaError', (global) => { return updateTwoFaSettings(global, { error: undefined }); }); diff --git a/src/modules/actions/api/users.ts b/src/modules/actions/api/users.ts index fa75b0506..425f271aa 100644 --- a/src/modules/actions/api/users.ts +++ b/src/modules/actions/api/users.ts @@ -1,5 +1,5 @@ import { - addReducer, getDispatch, getGlobal, setGlobal, + addActionHandler, getActions, getGlobal, setGlobal, } from '../..'; import { ApiUser } from '../../../api/types'; @@ -20,7 +20,7 @@ const runDebouncedForFetchFullUser = debounce((cb) => cb(), 500, false, true); const TOP_PEERS_REQUEST_COOLDOWN = 60; // 1 min const runThrottledForSearch = throttle((cb) => cb(), 500, false); -addReducer('loadFullUser', (global, actions, payload) => { +addActionHandler('loadFullUser', (global, actions, payload) => { const { userId } = payload!; const user = selectUser(global, userId); if (!user) { @@ -32,7 +32,7 @@ addReducer('loadFullUser', (global, actions, payload) => { runDebouncedForFetchFullUser(() => callApi('fetchFullUser', { id, accessHash })); }); -addReducer('loadUser', (global, actions, payload) => { +addActionHandler('loadUser', (global, actions, payload) => { const { userId } = payload!; const user = selectUser(global, userId); if (!user) { @@ -59,7 +59,7 @@ addReducer('loadUser', (global, actions, payload) => { })(); }); -addReducer('loadTopUsers', (global) => { +addActionHandler('loadTopUsers', (global) => { const { topPeers: { lastRequestedAt } } = global; if (!lastRequestedAt || getServerTime(global.serverTimeOffset) - lastRequestedAt > TOP_PEERS_REQUEST_COOLDOWN) { @@ -67,15 +67,15 @@ addReducer('loadTopUsers', (global) => { } }); -addReducer('loadContactList', () => { +addActionHandler('loadContactList', () => { void loadContactList(); }); -addReducer('loadCurrentUser', () => { +addActionHandler('loadCurrentUser', () => { void callApi('fetchCurrentUser'); }); -addReducer('loadCommonChats', (global) => { +addActionHandler('loadCommonChats', (global) => { const { chatId } = selectCurrentMessageList(global) || {}; const user = chatId ? selectUser(global, chatId) : undefined; if (!user || isUserBot(user) || user.commonChats?.isFullyLoaded) { @@ -106,7 +106,7 @@ addReducer('loadCommonChats', (global) => { })(); }); -addReducer('updateContact', (global, actions, payload) => { +addActionHandler('updateContact', (global, actions, payload) => { const { userId, isMuted, firstName, lastName, } = payload!; @@ -114,7 +114,7 @@ addReducer('updateContact', (global, actions, payload) => { void updateContact(userId, isMuted, firstName, lastName); }); -addReducer('deleteContact', (global, actions, payload) => { +addActionHandler('deleteContact', (global, actions, payload) => { const { userId } = payload!; void deleteContact(userId); @@ -178,7 +178,7 @@ async function updateContact( return; } - getDispatch().updateChatMutedState({ chatId: userId, isMuted }); + getActions().updateChatMutedState({ chatId: userId, isMuted }); setGlobal(updateManagementProgress(getGlobal(), ManagementProgress.InProgress)); @@ -223,7 +223,7 @@ async function deleteContact(userId: string) { await callApi('deleteContact', { id, accessHash }); } -addReducer('loadProfilePhotos', (global, actions, payload) => { +addActionHandler('loadProfilePhotos', (global, actions, payload) => { const { profileId } = payload!; const isPrivate = isUserId(profileId); const user = isPrivate ? selectUser(global, profileId) : undefined; @@ -251,7 +251,7 @@ addReducer('loadProfilePhotos', (global, actions, payload) => { })(); }); -addReducer('setUserSearchQuery', (global, actions, payload) => { +addActionHandler('setUserSearchQuery', (global, actions, payload) => { const { query } = payload!; if (!query) return; @@ -261,7 +261,7 @@ addReducer('setUserSearchQuery', (global, actions, payload) => { }); }); -addReducer('addContact', (global, actions, payload) => { +addActionHandler('addContact', (global, actions, payload) => { const { userId } = payload!; const user = selectUser(global, userId); if (!user) { @@ -271,7 +271,7 @@ addReducer('addContact', (global, actions, payload) => { void callApi('addContact', pick(user, ['id', 'accessHash', 'firstName', 'lastName', 'phoneNumber'])); }); -addReducer('reportSpam', (global, actions, payload) => { +addActionHandler('reportSpam', (global, actions, payload) => { const { userId } = payload!; const user = selectUser(global, userId); if (!user) { diff --git a/src/modules/actions/apiUpdaters/calls.ts b/src/modules/actions/apiUpdaters/calls.ts index be405e4c3..4d09a4e5b 100644 --- a/src/modules/actions/apiUpdaters/calls.ts +++ b/src/modules/actions/apiUpdaters/calls.ts @@ -1,10 +1,10 @@ -import { addReducer, getGlobal } from '../..'; +import { addActionHandler, getGlobal } from '../..'; import { removeGroupCall, updateGroupCall, updateGroupCallParticipant } from '../../reducers/calls'; import { omit } from '../../../util/iteratees'; import { selectChat } from '../../selectors'; import { updateChat } from '../../reducers'; -addReducer('apiUpdate', (global, actions, update) => { +addActionHandler('apiUpdate', (global, actions, update) => { switch (update['@type']) { case 'updateGroupCall': { if (update.call.connectionState === 'discarded') { diff --git a/src/modules/actions/apiUpdaters/chats.ts b/src/modules/actions/apiUpdaters/chats.ts index d2c992848..082769e98 100644 --- a/src/modules/actions/apiUpdaters/chats.ts +++ b/src/modules/actions/apiUpdaters/chats.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ApiUpdate, MAIN_THREAD_ID } from '../../../api/types'; @@ -25,7 +25,7 @@ const TYPING_STATUS_CLEAR_DELAY = 6000; // 6 seconds // Enough to animate and mark as read in Message List const CURRENT_CHAT_UNREAD_DELAY = 1500; -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'updateChat': { if (!update.noTopChatsRequest && !selectIsChatListed(global, update.id)) { diff --git a/src/modules/actions/apiUpdaters/initial.ts b/src/modules/actions/apiUpdaters/initial.ts index 391b76114..00c78f159 100644 --- a/src/modules/actions/apiUpdaters/initial.ts +++ b/src/modules/actions/apiUpdaters/initial.ts @@ -1,5 +1,5 @@ import { - addReducer, getDispatch, getGlobal, setGlobal, + addActionHandler, getActions, getGlobal, setGlobal, } from '../..'; import { GlobalState } from '../../../global/types'; @@ -20,7 +20,7 @@ import { selectNotifySettings } from '../../selectors'; import { forceWebsync } from '../../../util/websync'; import { getShippingError } from '../../../util/getReadableErrorText'; -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { if (DEBUG) { if (update['@type'] !== 'updateUserStatus' && update['@type'] !== 'updateServerTimeOffset') { // eslint-disable-next-line no-console @@ -162,7 +162,7 @@ function onUpdateConnectionState(update: ApiUpdateConnectionState) { }); if (connectionState === 'connectionStateBroken') { - getDispatch().signOut(); + getActions().signOut(); } } @@ -175,7 +175,7 @@ function onUpdateSession(update: ApiUpdateSession) { return; } - getDispatch().saveSession({ sessionData }); + getActions().saveSession({ sessionData }); } function onUpdateServerTimeOffset(update: ApiUpdateServerTimeOffset) { diff --git a/src/modules/actions/apiUpdaters/messages.ts b/src/modules/actions/apiUpdaters/messages.ts index c7982a026..67bcd8804 100644 --- a/src/modules/actions/apiUpdaters/messages.ts +++ b/src/modules/actions/apiUpdaters/messages.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ApiUpdate, ApiMessage, ApiPollResult, ApiThreadInfo, MAIN_THREAD_ID, @@ -51,7 +51,7 @@ import { const ANIMATION_DELAY = 350; -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'newMessage': { const { diff --git a/src/modules/actions/apiUpdaters/misc.ts b/src/modules/actions/apiUpdaters/misc.ts index b3821ea96..55a3fe3d1 100644 --- a/src/modules/actions/apiUpdaters/misc.ts +++ b/src/modules/actions/apiUpdaters/misc.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ApiUpdate } from '../../../api/types'; import { ApiPrivacyKey, PaymentStep } from '../../../types'; @@ -7,7 +7,7 @@ import { addBlockedContact, removeBlockedContact, setConfirmPaymentUrl, setPaymentStep, } from '../../reducers'; -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'updatePeerBlocked': if (update.isBlocked) { diff --git a/src/modules/actions/apiUpdaters/payments.ts b/src/modules/actions/apiUpdaters/payments.ts index ff1308cf0..30b040a86 100644 --- a/src/modules/actions/apiUpdaters/payments.ts +++ b/src/modules/actions/apiUpdaters/payments.ts @@ -1,10 +1,10 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { ApiUpdate } from '../../../api/types'; import { clearPayment } from '../../reducers'; -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'updatePaymentStateCompleted': { return clearPayment(global); diff --git a/src/modules/actions/apiUpdaters/settings.ts b/src/modules/actions/apiUpdaters/settings.ts index 18c7800de..994c39cc9 100644 --- a/src/modules/actions/apiUpdaters/settings.ts +++ b/src/modules/actions/apiUpdaters/settings.ts @@ -1,10 +1,10 @@ -import { addReducer, setGlobal } from '../..'; +import { addActionHandler, setGlobal } from '../..'; import { ApiUpdate } from '../../../api/types'; import { GlobalState } from '../../../global/types'; import { addNotifyException, updateChat, updateNotifySettings } from '../../reducers'; -addReducer('apiUpdate', (global, actions, update: ApiUpdate): GlobalState | undefined => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate): GlobalState | undefined => { switch (update['@type']) { case 'updateNotifySettings': { return updateNotifySettings(global, update.peerType, update.isSilent, update.shouldShowPreviews); diff --git a/src/modules/actions/apiUpdaters/symbols.ts b/src/modules/actions/apiUpdaters/symbols.ts index f09ff5c03..047801f65 100644 --- a/src/modules/actions/apiUpdaters/symbols.ts +++ b/src/modules/actions/apiUpdaters/symbols.ts @@ -1,10 +1,10 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { ApiUpdate } from '../../../api/types'; import { updateStickerSet } from '../../reducers'; -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'updateStickerSet': { return updateStickerSet(global, update.id, update.stickerSet); diff --git a/src/modules/actions/apiUpdaters/twoFaSettings.ts b/src/modules/actions/apiUpdaters/twoFaSettings.ts index d62174bcf..e5e11650b 100644 --- a/src/modules/actions/apiUpdaters/twoFaSettings.ts +++ b/src/modules/actions/apiUpdaters/twoFaSettings.ts @@ -1,9 +1,9 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { ApiUpdate } from '../../../api/types'; import { GlobalState } from '../../../global/types'; -addReducer('apiUpdate', (global, actions, update: ApiUpdate): GlobalState | undefined => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate): GlobalState | undefined => { switch (update['@type']) { case 'updateTwoFaStateWaitCode': { return { diff --git a/src/modules/actions/apiUpdaters/users.ts b/src/modules/actions/apiUpdaters/users.ts index e56b690e3..b1366821c 100644 --- a/src/modules/actions/apiUpdaters/users.ts +++ b/src/modules/actions/apiUpdaters/users.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ApiUpdate, ApiUserStatus } from '../../../api/types'; @@ -27,7 +27,7 @@ function flushStatusUpdates() { pendingStatusUpdates = {}; } -addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { +addActionHandler('apiUpdate', (global, actions, update: ApiUpdate) => { switch (update['@type']) { case 'deleteContact': { return deleteContact(global, update.id); diff --git a/src/modules/actions/ui/calls.ts b/src/modules/actions/ui/calls.ts index b6cc5302c..c3b3cb7e4 100644 --- a/src/modules/actions/ui/calls.ts +++ b/src/modules/actions/ui/calls.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { selectActiveGroupCall, selectChatGroupCall, selectGroupCall } from '../../selectors/calls'; import { callApi } from '../../../api/gramjs'; import { selectChat } from '../../selectors'; @@ -92,7 +92,7 @@ async function fetchGroupCallParticipants(groupCall: Partial, next setGlobal(global); } -addReducer('toggleGroupCallPanel', (global) => { +addActionHandler('toggleGroupCallPanel', (global) => { return { ...global, groupCalls: { @@ -102,7 +102,7 @@ addReducer('toggleGroupCallPanel', (global) => { }; }); -addReducer('subscribeToGroupCallUpdates', (global, actions, payload) => { +addActionHandler('subscribeToGroupCallUpdates', (global, actions, payload) => { const { subscribed, id } = payload!; const groupCall = selectGroupCall(global, id); @@ -121,7 +121,7 @@ addReducer('subscribeToGroupCallUpdates', (global, actions, payload) => { })(); }); -addReducer('createGroupCall', (global, actions, payload) => { +addActionHandler('createGroupCall', (global, actions, payload) => { const { chatId } = payload; const chat = selectChat(global, chatId); @@ -146,7 +146,7 @@ addReducer('createGroupCall', (global, actions, payload) => { })(); }); -addReducer('createGroupCallInviteLink', (global, actions) => { +addActionHandler('createGroupCallInviteLink', (global, actions) => { const groupCall = selectActiveGroupCall(global); if (!groupCall || !groupCall.chatId) { @@ -180,7 +180,7 @@ addReducer('createGroupCallInviteLink', (global, actions) => { })(); }); -addReducer('joinVoiceChatByLink', (global, actions, payload) => { +addActionHandler('joinVoiceChatByLink', (global, actions, payload) => { const { username, inviteHash } = payload!; (async () => { @@ -199,7 +199,7 @@ addReducer('joinVoiceChatByLink', (global, actions, payload) => { })(); }); -addReducer('joinGroupCall', (global, actions, payload) => { +addActionHandler('joinGroupCall', (global, actions, payload) => { if (!ARE_CALLS_SUPPORTED) return; const { @@ -263,7 +263,7 @@ addReducer('joinGroupCall', (global, actions, payload) => { })(); }); -addReducer('playGroupCallSound', (global, actions, payload) => { +addActionHandler('playGroupCallSound', (global, actions, payload) => { const { sound } = payload!; if (!sounds[sound]) { @@ -282,7 +282,7 @@ addReducer('playGroupCallSound', (global, actions, payload) => { } }); -addReducer('loadMoreGroupCallParticipants', (global) => { +addActionHandler('loadMoreGroupCallParticipants', (global) => { const groupCall = selectActiveGroupCall(global); if (!groupCall) { return; @@ -324,7 +324,7 @@ export function removeGroupCallAudioElement() { audioElement = undefined; } -addReducer('openCallFallbackConfirm', (global) => { +addActionHandler('openCallFallbackConfirm', (global) => { return { ...global, groupCalls: { @@ -334,7 +334,7 @@ addReducer('openCallFallbackConfirm', (global) => { }; }); -addReducer('closeCallFallbackConfirm', (global) => { +addActionHandler('closeCallFallbackConfirm', (global) => { return { ...global, groupCalls: { diff --git a/src/modules/actions/ui/chats.ts b/src/modules/actions/ui/chats.ts index 8d6c6c12f..cced0991b 100644 --- a/src/modules/actions/ui/chats.ts +++ b/src/modules/actions/ui/chats.ts @@ -1,4 +1,4 @@ -import { addReducer, setGlobal } from '../..'; +import { addActionHandler, setGlobal } from '../..'; import { exitMessageSelectMode, replaceThreadParam, updateCurrentMessageList, @@ -6,7 +6,7 @@ import { import { selectCurrentMessageList } from '../../selectors'; import { closeLocalTextSearch } from './localSearch'; -addReducer('openChat', (global, actions, payload) => { +addActionHandler('openChat', (global, actions, payload) => { const { id, threadId = -1, type = 'thread', shouldReplaceHistory = false, } = payload!; @@ -40,11 +40,11 @@ addReducer('openChat', (global, actions, payload) => { return updateCurrentMessageList(global, id, threadId, type, shouldReplaceHistory); }); -addReducer('openPreviousChat', (global) => { +addActionHandler('openPreviousChat', (global) => { return updateCurrentMessageList(global, undefined); }); -addReducer('openChatWithInfo', (global, actions, payload) => { +addActionHandler('openChatWithInfo', (global, actions, payload) => { setGlobal({ ...global, isChatInfoShown: true, @@ -53,21 +53,21 @@ addReducer('openChatWithInfo', (global, actions, payload) => { actions.openChat(payload); }); -addReducer('resetChatCreation', (global) => { +addActionHandler('resetChatCreation', (global) => { return { ...global, chatCreation: undefined, }; }); -addReducer('setNewChatMembersDialogState', (global, actions, payload) => { +addActionHandler('setNewChatMembersDialogState', (global, actions, payload) => { return { ...global, newChatMembersProgress: payload, }; }); -addReducer('openNextChat', (global, actions, payload) => { +addActionHandler('openNextChat', (global, actions, payload) => { const { targetIndexDelta, orderedIds } = payload; const { chatId } = selectCurrentMessageList(global) || {}; diff --git a/src/modules/actions/ui/globalSearch.ts b/src/modules/actions/ui/globalSearch.ts index e7e8cadfc..787ccebc9 100644 --- a/src/modules/actions/ui/globalSearch.ts +++ b/src/modules/actions/ui/globalSearch.ts @@ -1,10 +1,10 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { updateGlobalSearch, updateGlobalSearchContent } from '../../reducers'; const MAX_RECENTLY_FOUND_IDS = 10; -addReducer('setGlobalSearchQuery', (global, actions, payload) => { +addActionHandler('setGlobalSearchQuery', (global, actions, payload) => { const { query } = payload!; const { chatId } = global.globalSearch; @@ -17,7 +17,7 @@ addReducer('setGlobalSearchQuery', (global, actions, payload) => { }); }); -addReducer('addRecentlyFoundChatId', (global, actions, payload) => { +addActionHandler('addRecentlyFoundChatId', (global, actions, payload) => { const { id } = payload!; const { recentlyFoundChatIds } = global.globalSearch; @@ -34,17 +34,17 @@ addReducer('addRecentlyFoundChatId', (global, actions, payload) => { return updateGlobalSearch(global, { recentlyFoundChatIds: newRecentIds }); }); -addReducer('clearRecentlyFoundChats', (global) => { +addActionHandler('clearRecentlyFoundChats', (global) => { return updateGlobalSearch(global, { recentlyFoundChatIds: undefined }); }); -addReducer('setGlobalSearchContent', (global, actions, payload) => { +addActionHandler('setGlobalSearchContent', (global, actions, payload) => { const { content } = payload!; return updateGlobalSearchContent(global, content); }); -addReducer('setGlobalSearchChatId', (global, actions, payload) => { +addActionHandler('setGlobalSearchChatId', (global, actions, payload) => { const { id } = payload!; return updateGlobalSearch(global, { chatId: id, query: undefined, resultsByType: undefined }); diff --git a/src/modules/actions/ui/initial.ts b/src/modules/actions/ui/initial.ts index a400670a4..39352ec85 100644 --- a/src/modules/actions/ui/initial.ts +++ b/src/modules/actions/ui/initial.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ANIMATION_LEVEL_MAX } from '../../../config'; import { @@ -14,7 +14,7 @@ const HISTORY_ANIMATION_DURATION = 450; subscribeToSystemThemeChange(); -addReducer('init', (global) => { +addActionHandler('init', (global) => { const { animationLevel, messageTextSize, language } = global.settings.byKey; const theme = selectTheme(global); @@ -47,7 +47,7 @@ addReducer('init', (global) => { } }); -addReducer('setIsUiReady', (global, actions, payload) => { +addActionHandler('setIsUiReady', (global, actions, payload) => { const { uiReadyState } = payload!; if (uiReadyState === 2) { @@ -60,7 +60,7 @@ addReducer('setIsUiReady', (global, actions, payload) => { }; }); -addReducer('setAuthPhoneNumber', (global, actions, payload) => { +addActionHandler('setAuthPhoneNumber', (global, actions, payload) => { const { phoneNumber } = payload!; return { @@ -69,21 +69,21 @@ addReducer('setAuthPhoneNumber', (global, actions, payload) => { }; }); -addReducer('setAuthRememberMe', (global, actions, payload) => { +addActionHandler('setAuthRememberMe', (global, actions, payload) => { return { ...global, authRememberMe: Boolean(payload), }; }); -addReducer('clearAuthError', (global) => { +addActionHandler('clearAuthError', (global) => { return { ...global, authError: undefined, }; }); -addReducer('disableHistoryAnimations', () => { +addActionHandler('disableHistoryAnimations', () => { setTimeout(() => { setGlobal({ ...getGlobal(), diff --git a/src/modules/actions/ui/localSearch.ts b/src/modules/actions/ui/localSearch.ts index b2b3a25f2..6cc31db1c 100644 --- a/src/modules/actions/ui/localSearch.ts +++ b/src/modules/actions/ui/localSearch.ts @@ -1,4 +1,4 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { updateLocalTextSearch, @@ -10,7 +10,7 @@ import { selectCurrentMessageList } from '../../selectors'; import { buildChatThreadKey } from '../../helpers'; import { GlobalState } from '../../../global/types'; -addReducer('openLocalTextSearch', (global) => { +addActionHandler('openLocalTextSearch', (global) => { const { chatId, threadId } = selectCurrentMessageList(global) || {}; if (!chatId || !threadId) { return undefined; @@ -19,9 +19,9 @@ addReducer('openLocalTextSearch', (global) => { return updateLocalTextSearch(global, chatId, threadId, true); }); -addReducer('closeLocalTextSearch', closeLocalTextSearch); +addActionHandler('closeLocalTextSearch', closeLocalTextSearch); -addReducer('setLocalTextSearchQuery', (global, actions, payload) => { +addActionHandler('setLocalTextSearchQuery', (global, actions, payload) => { const { chatId, threadId } = selectCurrentMessageList(global) || {}; if (!chatId || !threadId) { return undefined; @@ -40,7 +40,7 @@ addReducer('setLocalTextSearchQuery', (global, actions, payload) => { return global; }); -addReducer('setLocalMediaSearchType', (global, actions, payload) => { +addActionHandler('setLocalMediaSearchType', (global, actions, payload) => { const { chatId } = selectCurrentMessageList(global) || {}; if (!chatId) { return undefined; diff --git a/src/modules/actions/ui/messages.ts b/src/modules/actions/ui/messages.ts index c827533d0..a7e1e0f72 100644 --- a/src/modules/actions/ui/messages.ts +++ b/src/modules/actions/ui/messages.ts @@ -1,4 +1,4 @@ -import { addReducer, getGlobal, setGlobal } from '../..'; +import { addActionHandler, getGlobal, setGlobal } from '../..'; import { ApiMessage, MAIN_THREAD_ID } from '../../../api/types'; import { FocusDirection } from '../../../types'; @@ -51,13 +51,13 @@ const SERVICE_NOTIFICATIONS_MAX_AMOUNT = 1e3; let blurTimeout: number | undefined; -addReducer('setScrollOffset', (global, actions, payload) => { +addActionHandler('setScrollOffset', (global, actions, payload) => { const { chatId, threadId, scrollOffset } = payload!; return replaceThreadParam(global, chatId, threadId, 'scrollOffset', scrollOffset); }); -addReducer('setReplyingToId', (global, actions, payload) => { +addActionHandler('setReplyingToId', (global, actions, payload) => { const { messageId } = payload!; const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { @@ -68,7 +68,7 @@ addReducer('setReplyingToId', (global, actions, payload) => { return replaceThreadParam(global, chatId, threadId, 'replyingToId', messageId); }); -addReducer('setEditingId', (global, actions, payload) => { +addActionHandler('setEditingId', (global, actions, payload) => { const { messageId } = payload!; const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { @@ -81,7 +81,7 @@ addReducer('setEditingId', (global, actions, payload) => { return replaceThreadParam(global, chatId, threadId, paramName, messageId); }); -addReducer('editLastMessage', (global) => { +addActionHandler('editLastMessage', (global) => { const { chatId, threadId } = selectCurrentMessageList(global) || {}; if (!chatId || !threadId) { return undefined; @@ -104,7 +104,7 @@ addReducer('editLastMessage', (global) => { return replaceThreadParam(global, chatId, threadId, 'editingId', lastOwnEditableMessageId); }); -addReducer('replyToNextMessage', (global, actions, payload) => { +addActionHandler('replyToNextMessage', (global, actions, payload) => { const { targetIndexDelta } = payload; const { chatId, threadId } = selectCurrentMessageList(global) || {}; if (!chatId || !threadId) { @@ -146,7 +146,7 @@ addReducer('replyToNextMessage', (global, actions, payload) => { }); }); -addReducer('openMediaViewer', (global, actions, payload) => { +addActionHandler('openMediaViewer', (global, actions, payload) => { const { chatId, threadId, messageId, avatarOwnerId, profilePhotoIndex, origin, } = payload!; @@ -165,14 +165,14 @@ addReducer('openMediaViewer', (global, actions, payload) => { }; }); -addReducer('closeMediaViewer', (global) => { +addActionHandler('closeMediaViewer', (global) => { return { ...global, mediaViewer: {}, }; }); -addReducer('openAudioPlayer', (global, actions, payload) => { +addActionHandler('openAudioPlayer', (global, actions, payload) => { const { chatId, threadId, messageId, origin, volume, playbackRate, isMuted, } = payload!; @@ -191,7 +191,7 @@ addReducer('openAudioPlayer', (global, actions, payload) => { }; }); -addReducer('setAudioPlayerVolume', (global, actions, payload) => { +addActionHandler('setAudioPlayerVolume', (global, actions, payload) => { const { volume, } = payload!; @@ -205,7 +205,7 @@ addReducer('setAudioPlayerVolume', (global, actions, payload) => { }; }); -addReducer('setAudioPlayerPlaybackRate', (global, actions, payload) => { +addActionHandler('setAudioPlayerPlaybackRate', (global, actions, payload) => { const { playbackRate, } = payload!; @@ -219,7 +219,7 @@ addReducer('setAudioPlayerPlaybackRate', (global, actions, payload) => { }; }); -addReducer('setAudioPlayerMuted', (global, actions, payload) => { +addActionHandler('setAudioPlayerMuted', (global, actions, payload) => { const { isMuted, } = payload!; @@ -233,7 +233,7 @@ addReducer('setAudioPlayerMuted', (global, actions, payload) => { }; }); -addReducer('setAudioPlayerOrigin', (global, actions, payload) => { +addActionHandler('setAudioPlayerOrigin', (global, actions, payload) => { const { origin, } = payload!; @@ -247,7 +247,7 @@ addReducer('setAudioPlayerOrigin', (global, actions, payload) => { }; }); -addReducer('closeAudioPlayer', (global) => { +addActionHandler('closeAudioPlayer', (global) => { return { ...global, audioPlayer: { @@ -258,7 +258,7 @@ addReducer('closeAudioPlayer', (global) => { }; }); -addReducer('openPollResults', (global, actions, payload) => { +addActionHandler('openPollResults', (global, actions, payload) => { const { chatId, messageId } = payload!; const shouldOpenInstantly = selectIsRightColumnShown(global); @@ -288,14 +288,14 @@ addReducer('openPollResults', (global, actions, payload) => { } }); -addReducer('closePollResults', (global) => { +addActionHandler('closePollResults', (global) => { setGlobal({ ...global, pollResults: {}, }); }); -addReducer('focusLastMessage', (global, actions) => { +addActionHandler('focusLastMessage', (global, actions) => { const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { return; @@ -323,7 +323,7 @@ addReducer('focusLastMessage', (global, actions) => { }); }); -addReducer('focusNextReply', (global, actions) => { +addActionHandler('focusNextReply', (global, actions) => { const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { return undefined; @@ -352,7 +352,7 @@ addReducer('focusNextReply', (global, actions) => { return undefined; }); -addReducer('focusMessage', (global, actions, payload) => { +addActionHandler('focusMessage', (global, actions, payload) => { const { chatId, threadId = MAIN_THREAD_ID, messageListType = 'thread', noHighlight, groupedId, groupedChatId, replyMessageId, isResizingContainer, @@ -422,7 +422,7 @@ addReducer('focusMessage', (global, actions, payload) => { return undefined; }); -addReducer('openForwardMenu', (global, actions, payload) => { +addActionHandler('openForwardMenu', (global, actions, payload) => { const { fromChatId, messageIds, groupedId } = payload!; let groupedMessageIds; if (groupedId) { @@ -438,14 +438,14 @@ addReducer('openForwardMenu', (global, actions, payload) => { }; }); -addReducer('exitForwardMode', (global) => { +addActionHandler('exitForwardMode', (global) => { setGlobal({ ...global, forwardMessages: {}, }); }); -addReducer('setForwardChatId', (global, actions, payload) => { +addActionHandler('setForwardChatId', (global, actions, payload) => { const { id } = payload!; setGlobal({ @@ -462,7 +462,7 @@ addReducer('setForwardChatId', (global, actions, payload) => { actions.exitMessageSelectMode(); }); -addReducer('openForwardMenuForSelectedMessages', (global, actions) => { +addActionHandler('openForwardMenuForSelectedMessages', (global, actions) => { if (!global.selectedMessages) { return; } @@ -472,7 +472,7 @@ addReducer('openForwardMenuForSelectedMessages', (global, actions) => { actions.openForwardMenu({ fromChatId, messageIds }); }); -addReducer('cancelMessageMediaDownload', (global, actions, payload) => { +addActionHandler('cancelMessageMediaDownload', (global, actions, payload) => { const { message } = payload!; const byChatId = global.activeDownloads.byChatId[message.chatId]; @@ -489,7 +489,7 @@ addReducer('cancelMessageMediaDownload', (global, actions, payload) => { }); }); -addReducer('downloadMessageMedia', (global, actions, payload) => { +addActionHandler('downloadMessageMedia', (global, actions, payload) => { const { message } = payload!; if (!message) return; @@ -504,7 +504,7 @@ addReducer('downloadMessageMedia', (global, actions, payload) => { }); }); -addReducer('downloadSelectedMessages', (global, actions) => { +addActionHandler('downloadSelectedMessages', (global, actions) => { if (!global.selectedMessages) { return; } @@ -519,7 +519,7 @@ addReducer('downloadSelectedMessages', (global, actions) => { messages.forEach((message) => actions.downloadMessageMedia({ message })); }); -addReducer('enterMessageSelectMode', (global, actions, payload) => { +addActionHandler('enterMessageSelectMode', (global, actions, payload) => { const { messageId } = payload || {}; const openChat = selectCurrentChat(global); if (!openChat) { @@ -529,7 +529,7 @@ addReducer('enterMessageSelectMode', (global, actions, payload) => { return enterMessageSelectMode(global, openChat.id, messageId); }); -addReducer('toggleMessageSelection', (global, actions, payload) => { +addActionHandler('toggleMessageSelection', (global, actions, payload) => { const { messageId, groupedId, @@ -558,7 +558,7 @@ addReducer('toggleMessageSelection', (global, actions, payload) => { } }); -addReducer('disableContextMenuHint', (global) => { +addActionHandler('disableContextMenuHint', (global) => { if (!global.shouldShowContextMenuHint) { return undefined; } @@ -569,23 +569,23 @@ addReducer('disableContextMenuHint', (global) => { }; }); -addReducer('exitMessageSelectMode', exitMessageSelectMode); +addActionHandler('exitMessageSelectMode', exitMessageSelectMode); -addReducer('openPollModal', (global) => { +addActionHandler('openPollModal', (global) => { return { ...global, isPollModalOpen: true, }; }); -addReducer('closePollModal', (global) => { +addActionHandler('closePollModal', (global) => { return { ...global, isPollModalOpen: false, }; }); -addReducer('checkVersionNotification', (global, actions) => { +addActionHandler('checkVersionNotification', (global, actions) => { const currentVersion = APP_VERSION.split('.').slice(0, 2).join('.'); const { serviceNotifications } = global; @@ -608,7 +608,7 @@ addReducer('checkVersionNotification', (global, actions) => { }); }); -addReducer('createServiceNotification', (global, actions, payload) => { +addActionHandler('createServiceNotification', (global, actions, payload) => { const { message, version } = payload; const { serviceNotifications } = global; const serviceChat = selectChat(global, SERVICE_NOTIFICATIONS_USER_ID)!; @@ -646,7 +646,7 @@ addReducer('createServiceNotification', (global, actions, payload) => { }); }); -addReducer('openReactorListModal', (global, actions, payload) => { +addActionHandler('openReactorListModal', (global, actions, payload) => { const { chatId, messageId } = payload!; return { @@ -655,14 +655,14 @@ addReducer('openReactorListModal', (global, actions, payload) => { }; }); -addReducer('closeReactorListModal', (global) => { +addActionHandler('closeReactorListModal', (global) => { return { ...global, reactorModal: undefined, }; }); -addReducer('openSeenByModal', (global, actions, payload) => { +addActionHandler('openSeenByModal', (global, actions, payload) => { const { chatId, messageId } = payload!; return { @@ -671,14 +671,14 @@ addReducer('openSeenByModal', (global, actions, payload) => { }; }); -addReducer('closeSeenByModal', (global) => { +addActionHandler('closeSeenByModal', (global) => { return { ...global, seenByModal: undefined, }; }); -addReducer('copySelectedMessages', (global) => { +addActionHandler('copySelectedMessages', (global) => { if (!global.selectedMessages) { return; } @@ -687,7 +687,7 @@ addReducer('copySelectedMessages', (global) => { copyTextForMessages(global, chatId, messageIds); }); -addReducer('copyMessagesByIds', (global, actions, payload: { messageIds?: number[] }) => { +addActionHandler('copyMessagesByIds', (global, actions, payload: { messageIds?: number[] }) => { const { messageIds } = payload; const chat = selectCurrentChat(global); if (!messageIds || messageIds.length === 0 || !chat) { diff --git a/src/modules/actions/ui/misc.ts b/src/modules/actions/ui/misc.ts index 7d1b7f5d9..c636c4ae3 100644 --- a/src/modules/actions/ui/misc.ts +++ b/src/modules/actions/ui/misc.ts @@ -1,4 +1,4 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { GlobalState } from '../../../global/types'; import { ApiError } from '../../../api/types'; @@ -10,14 +10,14 @@ import generateIdFor from '../../../util/generateIdFor'; const MAX_STORED_EMOJIS = 18; // Represents two rows of recent emojis -addReducer('toggleChatInfo', (global, action, payload) => { +addActionHandler('toggleChatInfo', (global, action, payload) => { return { ...global, isChatInfoShown: payload !== undefined ? payload : !global.isChatInfoShown, }; }); -addReducer('setLeftColumnWidth', (global, actions, payload) => { +addActionHandler('setLeftColumnWidth', (global, actions, payload) => { const leftColumnWidth = payload; return { @@ -26,14 +26,14 @@ addReducer('setLeftColumnWidth', (global, actions, payload) => { }; }); -addReducer('resetLeftColumnWidth', (global) => { +addActionHandler('resetLeftColumnWidth', (global) => { return { ...global, leftColumnWidth: undefined, }; }); -addReducer('toggleManagement', (global): GlobalState | undefined => { +addActionHandler('toggleManagement', (global): GlobalState | undefined => { const { chatId } = selectCurrentMessageList(global) || {}; if (!chatId) { @@ -54,7 +54,7 @@ addReducer('toggleManagement', (global): GlobalState | undefined => { }; }); -addReducer('requestNextManagementScreen', (global, actions, payload): GlobalState | undefined => { +addActionHandler('requestNextManagementScreen', (global, actions, payload): GlobalState | undefined => { const { screen } = payload || {}; const { chatId } = selectCurrentMessageList(global) || {}; @@ -77,7 +77,7 @@ addReducer('requestNextManagementScreen', (global, actions, payload): GlobalStat }; }); -addReducer('closeManagement', (global): GlobalState | undefined => { +addActionHandler('closeManagement', (global): GlobalState | undefined => { const { chatId } = selectCurrentMessageList(global) || {}; if (!chatId) { @@ -98,7 +98,7 @@ addReducer('closeManagement', (global): GlobalState | undefined => { }; }); -addReducer('openChat', (global) => { +addActionHandler('openChat', (global) => { if (!IS_SINGLE_COLUMN_LAYOUT && !IS_TABLET_COLUMN_LAYOUT) { return undefined; } @@ -109,21 +109,21 @@ addReducer('openChat', (global) => { }; }); -addReducer('toggleStatistics', (global) => { +addActionHandler('toggleStatistics', (global) => { return { ...global, isStatisticsShown: !global.isStatisticsShown, }; }); -addReducer('toggleLeftColumn', (global) => { +addActionHandler('toggleLeftColumn', (global) => { return { ...global, isLeftColumnShown: !global.isLeftColumnShown, }; }); -addReducer('addRecentEmoji', (global, action, payload) => { +addActionHandler('addRecentEmoji', (global, action, payload) => { const { emoji } = payload!; const { recentEmojis } = global; if (!recentEmojis) { @@ -145,7 +145,7 @@ addReducer('addRecentEmoji', (global, action, payload) => { }; }); -addReducer('addRecentSticker', (global, action, payload) => { +addActionHandler('addRecentSticker', (global, action, payload) => { const { sticker } = payload!; const { recent } = global.stickers; if (!recent) { @@ -176,7 +176,7 @@ addReducer('addRecentSticker', (global, action, payload) => { }; }); -addReducer('showNotification', (global, actions, payload) => { +addActionHandler('showNotification', (global, actions, payload) => { const notification = payload!; notification.localId = generateIdFor({}); @@ -194,7 +194,7 @@ addReducer('showNotification', (global, actions, payload) => { }; }); -addReducer('dismissNotification', (global, actions, payload) => { +addActionHandler('dismissNotification', (global, actions, payload) => { const newNotifications = global.notifications.filter(({ localId }) => localId !== payload.localId); return { @@ -203,7 +203,7 @@ addReducer('dismissNotification', (global, actions, payload) => { }; }); -addReducer('showDialog', (global, actions, payload) => { +addActionHandler('showDialog', (global, actions, payload) => { const { data } = payload!; // Filter out errors that we don't want to show to the user @@ -227,7 +227,7 @@ addReducer('showDialog', (global, actions, payload) => { }; }); -addReducer('dismissDialog', (global) => { +addActionHandler('dismissDialog', (global) => { const newDialogs = [...global.dialogs]; newDialogs.pop(); @@ -238,7 +238,7 @@ addReducer('dismissDialog', (global) => { }; }); -addReducer('toggleSafeLinkModal', (global, actions, payload) => { +addActionHandler('toggleSafeLinkModal', (global, actions, payload) => { const { url: safeLinkModalUrl } = payload; return { @@ -247,7 +247,7 @@ addReducer('toggleSafeLinkModal', (global, actions, payload) => { }; }); -addReducer('openHistoryCalendar', (global, actions, payload) => { +addActionHandler('openHistoryCalendar', (global, actions, payload) => { const { selectedAt } = payload; return { @@ -256,7 +256,7 @@ addReducer('openHistoryCalendar', (global, actions, payload) => { }; }); -addReducer('closeHistoryCalendar', (global) => { +addActionHandler('closeHistoryCalendar', (global) => { return { ...global, historyCalendarSelectedAt: undefined, diff --git a/src/modules/actions/ui/payments.ts b/src/modules/actions/ui/payments.ts index 26d2dbcb0..425705f9f 100644 --- a/src/modules/actions/ui/payments.ts +++ b/src/modules/actions/ui/payments.ts @@ -1,8 +1,8 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { clearPayment, closeInvoice } from '../../reducers'; -addReducer('openPaymentModal', (global, actions, payload) => { +addActionHandler('openPaymentModal', (global, actions, payload) => { const { chatId, messageId } = payload; return { ...global, @@ -15,12 +15,12 @@ addReducer('openPaymentModal', (global, actions, payload) => { }; }); -addReducer('closePaymentModal', (global) => { +addActionHandler('closePaymentModal', (global) => { const newGlobal = clearPayment(global); return closeInvoice(newGlobal); }); -addReducer('addPaymentError', (global, actions, payload) => { +addActionHandler('addPaymentError', (global, actions, payload) => { const { error } = payload!; return { diff --git a/src/modules/actions/ui/settings.ts b/src/modules/actions/ui/settings.ts index 2be4c0e3b..79e14a5d0 100644 --- a/src/modules/actions/ui/settings.ts +++ b/src/modules/actions/ui/settings.ts @@ -1,12 +1,12 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { ISettings, IThemeSettings, ThemeKey } from '../../../types'; import { replaceSettings, replaceThemeSettings } from '../../reducers'; -addReducer('setSettingOption', (global, actions, payload?: Partial) => { +addActionHandler('setSettingOption', (global, actions, payload?: Partial) => { return replaceSettings(global, payload); }); -addReducer('setThemeSettings', (global, actions, payload: { theme: ThemeKey } & Partial) => { +addActionHandler('setThemeSettings', (global, actions, payload: { theme: ThemeKey } & Partial) => { const { theme, ...settings } = payload; return replaceThemeSettings(global, theme, settings); diff --git a/src/modules/actions/ui/stickerSearch.ts b/src/modules/actions/ui/stickerSearch.ts index 1227ded45..8b0a231b7 100644 --- a/src/modules/actions/ui/stickerSearch.ts +++ b/src/modules/actions/ui/stickerSearch.ts @@ -1,6 +1,6 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; -addReducer('setStickerSearchQuery', (global, actions, payload) => { +addActionHandler('setStickerSearchQuery', (global, actions, payload) => { const { query } = payload!; return { @@ -15,7 +15,7 @@ addReducer('setStickerSearchQuery', (global, actions, payload) => { }; }); -addReducer('setGifSearchQuery', (global, actions, payload) => { +addActionHandler('setGifSearchQuery', (global, actions, payload) => { const { query } = payload!; return { diff --git a/src/modules/actions/ui/users.ts b/src/modules/actions/ui/users.ts index bb469f0b0..1bf5945e8 100644 --- a/src/modules/actions/ui/users.ts +++ b/src/modules/actions/ui/users.ts @@ -1,8 +1,8 @@ -import { addReducer } from '../..'; +import { addActionHandler } from '../..'; import { updateUserSearch } from '../../reducers'; -addReducer('setUserSearchQuery', (global, actions, payload) => { +addActionHandler('setUserSearchQuery', (global, actions, payload) => { const { query } = payload!; return updateUserSearch(global, { diff --git a/src/modules/index.ts b/src/modules/index.ts index d472b0207..ebbde7ebb 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -5,6 +5,6 @@ const typed = typify(); export const getGlobal = typed.getGlobal; export const setGlobal = typed.setGlobal; -export const getDispatch = typed.getDispatch; -export const addReducer = typed.addReducer; +export const getActions = typed.getActions; +export const addActionHandler = typed.addActionHandler; export const withGlobal = typed.withGlobal; diff --git a/src/util/audioPlayer.ts b/src/util/audioPlayer.ts index 805ff35c8..3f5c3f6ed 100644 --- a/src/util/audioPlayer.ts +++ b/src/util/audioPlayer.ts @@ -1,4 +1,4 @@ -import { getDispatch, getGlobal } from '../modules'; +import { getActions, getGlobal } from '../modules'; import { AudioOrigin, GlobalSearchContent } from '../types'; import { ApiMessage } from '../api/types'; @@ -99,7 +99,7 @@ function playNext(trackId: TrackId, isReverseOrder?: boolean) { if (!tracks.has(nextTrackId)) { // A bit hacky way to continue playlist when switching chat - getDispatch().openAudioPlayer(parseMessageKey(splitTrackId(nextTrackId).messageKey)); + getActions().openAudioPlayer(parseMessageKey(splitTrackId(nextTrackId).messageKey)); return; } diff --git a/src/util/deeplink.ts b/src/util/deeplink.ts index 42544182f..a5e062b0b 100644 --- a/src/util/deeplink.ts +++ b/src/util/deeplink.ts @@ -1,4 +1,4 @@ -import { getDispatch } from '../modules'; +import { getActions } from '../modules'; import { IS_SAFARI } from './environment'; type DeepLinkMethod = 'resolve' | 'login' | 'passport' | 'settings' | 'join' | 'addstickers' | 'setlanguage' | @@ -18,7 +18,7 @@ export const processDeepLink = (url: string) => { openStickerSetShortName, focusMessage, joinVoiceChatByLink, - } = getDispatch(); + } = getActions(); // Safari thinks the path in tg://path links is hostname for some reason const method = (IS_SAFARI ? hostname : pathname).replace(/^\/\//, '') as DeepLinkMethod; diff --git a/src/util/folderManager.ts b/src/util/folderManager.ts index 2a8301bb3..28a3d43d5 100644 --- a/src/util/folderManager.ts +++ b/src/util/folderManager.ts @@ -1,5 +1,5 @@ import { addCallback } from '../lib/teact/teactn'; -import { addReducer, getGlobal } from '../modules'; +import { addActionHandler, getGlobal } from '../modules'; import { GlobalState } from '../global/types'; import { NotifyException, NotifySettings } from '../types'; @@ -101,7 +101,7 @@ export function init() { inited = true; addCallback(updateFolderManagerThrottled); - addReducer('reset', reset); + addActionHandler('reset', reset); updateFolderManager(getGlobal()); } diff --git a/src/util/notifications.ts b/src/util/notifications.ts index e24fdc941..45d7571a9 100644 --- a/src/util/notifications.ts +++ b/src/util/notifications.ts @@ -4,7 +4,7 @@ import { } from '../api/types'; import { renderActionMessageText } from '../components/common/helpers/renderActionMessageText'; import { DEBUG, IS_TEST } from '../config'; -import { getDispatch, getGlobal, setGlobal } from '../modules'; +import { getActions, getGlobal, setGlobal } from '../modules'; import { getChatAvatarHash, getChatTitle, @@ -143,7 +143,7 @@ async function requestPermission() { async function unsubscribeFromPush(subscription: PushSubscription | null) { const global = getGlobal(); - const dispatch = getDispatch(); + const dispatch = getActions(); if (subscription) { try { const deviceToken = getDeviceToken(subscription); @@ -217,7 +217,7 @@ export async function subscribe() { console.log('[PUSH] Received push subscription: ', deviceToken); } await callApi('registerDevice', deviceToken); - getDispatch() + getActions() .setDeviceToken(deviceToken); } catch (error: any) { if (Notification.permission === 'denied' as NotificationPermission) { @@ -376,7 +376,7 @@ export async function notifyAboutMessage({ }); } } else { - const dispatch = getDispatch(); + const dispatch = getActions(); const options: NotificationOptions = { body, icon, diff --git a/src/util/setupServiceWorker.ts b/src/util/setupServiceWorker.ts index 4142aa81f..ca8f99745 100644 --- a/src/util/setupServiceWorker.ts +++ b/src/util/setupServiceWorker.ts @@ -1,5 +1,5 @@ import { DEBUG, DEBUG_MORE } from '../config'; -import { getDispatch } from '../modules'; +import { getActions } from '../modules'; import { IS_ANDROID, IS_IOS, IS_SERVICE_WORKER_SUPPORTED } from './environment'; import { notifyClientReady, playNotifySoundDebounced } from './notifications'; @@ -15,7 +15,7 @@ function handleWorkerMessage(e: MessageEvent) { console.log('[SW] Message from worker', action); } if (!action.type) return; - const dispatch = getDispatch(); + const dispatch = getActions(); const payload = action.payload; switch (action.type) { case 'focusMessage': @@ -78,7 +78,7 @@ if (IS_SERVICE_WORKER_SUPPORTED) { } if (!IS_IOS && !IS_ANDROID) { - getDispatch().showDialog({ data: { message: 'SERVICE_WORKER_DISABLED', hasErrorKey: true } }); + getActions().showDialog({ data: { message: 'SERVICE_WORKER_DISABLED', hasErrorKey: true } }); } } } catch (err) {