From 6563d37e8a84c2b912f89d1ab8e46cffad900bea Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Sun, 29 Dec 2024 11:58:32 +0100 Subject: [PATCH] Global: Split types into separate files (#5341) --- src/api/gramjs/apiBuilders/appConfig.ts | 3 +- src/api/gramjs/apiBuilders/common.ts | 4 +- src/api/gramjs/apiBuilders/messages.ts | 2 +- src/api/gramjs/apiBuilders/misc.ts | 17 +- src/api/gramjs/apiBuilders/payments.ts | 2 +- src/api/gramjs/gramjsBuilders/index.ts | 3 +- src/api/gramjs/methods/chats.ts | 2 +- src/api/gramjs/methods/messages.ts | 3 +- src/api/gramjs/methods/settings.ts | 3 +- src/api/gramjs/methods/stories.ts | 2 +- src/api/types/chats.ts | 10 +- src/api/types/messages.ts | 3 +- src/api/types/misc.ts | 34 +- src/api/types/payments.ts | 12 +- src/api/types/settings.ts | 30 + src/api/types/stories.ts | 2 +- src/api/types/updates.ts | 7 +- src/components/common/Composer.tsx | 10 +- .../common/CustomEmojiSetsModal.tsx | 3 +- src/components/common/StickerSetModal.tsx | 2 +- .../common/embedded/EmbeddedMessage.tsx | 2 +- .../common/hooks/useAnimatedEmoji.ts | 2 +- src/components/left/main/Chat.tsx | 2 +- src/components/left/main/ForumPanel.tsx | 2 +- src/components/left/main/Topic.tsx | 3 +- .../left/main/hooks/useChatListEntry.tsx | 3 +- .../left/settings/PremiumStatusItem.tsx | 2 +- .../left/settings/SettingsPrivacy.tsx | 2 +- .../left/settings/SettingsPrivacyLastSeen.tsx | 2 +- .../settings/SettingsPrivacyVisibility.tsx | 3 +- ...SettingsPrivacyVisibilityExceptionList.tsx | 3 +- .../left/settings/helpers/privacy.ts | 2 +- src/components/main/Dialogs.tsx | 2 +- src/components/main/GameModal.tsx | 4 +- src/components/main/Main.tsx | 4 +- .../main/premium/PremiumFeatureModal.tsx | 9 +- .../main/premium/PremiumMainModal.tsx | 4 +- .../common/PremiumLimitReachedModal.tsx | 2 +- .../main/visualEffects/ConfettiContainer.tsx | 3 +- .../mediaViewer/MediaViewerActions.tsx | 3 +- src/components/middle/ActionMessage.tsx | 3 +- src/components/middle/ContactGreeting.tsx | 2 +- .../middle/EmojiInteractionAnimation.tsx | 2 +- .../middle/FloatingActionButtons.tsx | 2 +- src/components/middle/HeaderActions.tsx | 3 +- src/components/middle/MessageList.tsx | 3 +- src/components/middle/MessageListContent.tsx | 3 +- .../middle/MessageListHistoryHandler.tsx | 2 +- .../middle/MessageSelectToolbar.tsx | 2 +- src/components/middle/MiddleColumn.tsx | 5 +- src/components/middle/MiddleHeader.tsx | 4 +- src/components/middle/MiddleHeaderPanes.tsx | 3 +- src/components/middle/NoMessages.tsx | 2 +- .../middle/composer/AttachmentModal.tsx | 4 +- .../composer/ComposerEmbeddedMessage.tsx | 3 +- .../middle/composer/WebPagePreview.tsx | 4 +- .../middle/composer/hooks/useDraft.ts | 3 +- .../middle/composer/hooks/useEditing.ts | 5 +- .../middle/hooks/useMessageObservers.ts | 2 +- src/components/middle/hooks/useScrollHooks.ts | 2 +- .../middle/message/AnimatedCustomEmoji.tsx | 2 +- .../middle/message/AnimatedEmoji.tsx | 2 +- .../middle/message/ContextMenuContainer.tsx | 9 +- src/components/middle/message/Message.tsx | 10 +- .../middle/message/ReadTimeMenuItem.tsx | 2 +- .../message/hooks/useMessageTranslation.ts | 2 +- src/components/middle/panes/BotAdPane.tsx | 2 +- .../middle/panes/HeaderPinnedMessage.tsx | 3 +- src/components/modals/gift/GiftModal.tsx | 3 +- .../modals/gift/StarGiftCategoryList.tsx | 2 +- .../modals/webApp/MinimizedWebAppModal.tsx | 2 +- src/components/modals/webApp/WebAppModal.tsx | 4 +- .../modals/webApp/WebAppModalTabContent.tsx | 6 +- .../modals/webApp/hooks/useWebAppFrame.ts | 3 +- src/components/right/GifSearch.tsx | 2 +- src/components/story/Story.tsx | 2 +- src/components/story/StorySettings.tsx | 5 +- src/components/story/helpers/dimensions.ts | 2 +- .../story/helpers/ghostAnimation.ts | 2 +- src/config.ts | 5 +- src/global/actions/api/bots.ts | 9 +- src/global/actions/api/chats.ts | 4 +- src/global/actions/api/messages.ts | 5 +- src/global/actions/api/settings.ts | 5 +- src/global/actions/api/stars.ts | 4 +- src/global/actions/api/sync.ts | 4 +- src/global/actions/apiUpdaters/messages.ts | 4 +- src/global/actions/ui/calls.ts | 3 +- src/global/actions/ui/messages.ts | 3 +- src/global/cache.ts | 4 +- src/global/helpers/bots.ts | 4 +- src/global/helpers/messageMedia.ts | 2 +- src/global/helpers/misc.ts | 2 +- src/global/reducers/bots.ts | 3 +- src/global/reducers/chats.ts | 3 +- src/global/reducers/messages.ts | 12 +- src/global/reducers/payments.ts | 9 +- src/global/reducers/topics.ts | 3 +- src/global/reducers/translations.ts | 3 +- src/global/selectors/chats.ts | 3 +- src/global/selectors/limits.ts | 3 +- src/global/selectors/messages.ts | 10 +- src/global/selectors/topics.ts | 4 +- src/global/{types.ts => types/actions.ts} | 1333 +---------------- src/global/types/globalState.ts | 449 ++++++ src/global/types/index.ts | 3 + src/global/types/tabState.ts | 711 +++++++++ src/hooks/useHistoryBack.ts | 2 +- src/lib/teact/teactn.tsx | 28 +- src/types/index.ts | 166 +- src/types/webapp.ts | 27 + src/util/routing.ts | 3 +- src/util/windowSize.ts | 2 +- 113 files changed, 1665 insertions(+), 1507 deletions(-) rename src/global/{types.ts => types/actions.ts} (66%) create mode 100644 src/global/types/globalState.ts create mode 100644 src/global/types/index.ts create mode 100644 src/global/types/tabState.ts diff --git a/src/api/gramjs/apiBuilders/appConfig.ts b/src/api/gramjs/apiBuilders/appConfig.ts index 4e123c8fd..61c89b9b3 100644 --- a/src/api/gramjs/apiBuilders/appConfig.ts +++ b/src/api/gramjs/apiBuilders/appConfig.ts @@ -2,8 +2,7 @@ import BigInt from 'big-integer'; import { Api as GramJs } from '../../../lib/gramjs'; -import type { ApiLimitType, ApiPremiumSection } from '../../../global/types'; -import type { ApiAppConfig } from '../../types'; +import type { ApiAppConfig, ApiLimitType, ApiPremiumSection } from '../../types'; import { DEFAULT_LIMITS, diff --git a/src/api/gramjs/apiBuilders/common.ts b/src/api/gramjs/apiBuilders/common.ts index 581e34c75..e6168e0f8 100644 --- a/src/api/gramjs/apiBuilders/common.ts +++ b/src/api/gramjs/apiBuilders/common.ts @@ -1,16 +1,18 @@ import { Api as GramJs } from '../../../lib/gramjs'; import { strippedPhotoToJpg } from '../../../lib/gramjs/Utils'; -import type { ApiPrivacySettings, BotsPrivacyType, PrivacyVisibility } from '../../../types'; import type { ApiFormattedText, ApiMessageEntity, ApiMessageEntityDefault, ApiPhoto, ApiPhotoSize, + ApiPrivacySettings, ApiThumbnail, ApiUsername, ApiVideoSize, + BotsPrivacyType, + PrivacyVisibility, } from '../../types'; import { ApiMessageEntityTypes, diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index b8d532147..21e5e61ee 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -1,11 +1,11 @@ import { Api as GramJs } from '../../../lib/gramjs'; -import type { ApiDraft } from '../../../global/types'; import type { ApiAction, ApiAttachment, ApiChat, ApiContact, + ApiDraft, ApiFactCheck, ApiFormattedText, ApiGroupCall, diff --git a/src/api/gramjs/apiBuilders/misc.ts b/src/api/gramjs/apiBuilders/misc.ts index 4e721f521..f727e8647 100644 --- a/src/api/gramjs/apiBuilders/misc.ts +++ b/src/api/gramjs/apiBuilders/misc.ts @@ -1,12 +1,19 @@ import { Api as GramJs } from '../../../lib/gramjs'; -import type { ApiPrivacyKey } from '../../../types'; import type { ApiChatLink, - ApiCollectionInfo, - ApiConfig, ApiCountry, ApiLanguage, ApiOldLangString, + ApiCollectibleInfo, + ApiConfig, + ApiCountry, + ApiLanguage, + ApiOldLangString, ApiPeerColors, - ApiSession, ApiTimezone, ApiUrlAuthResult, ApiWallpaper, ApiWebSession, + ApiPrivacyKey, + ApiSession, + ApiTimezone, + ApiUrlAuthResult, + ApiWallpaper, + ApiWebSession, LangPackStringValue, } from '../../types'; @@ -332,7 +339,7 @@ export function buildApiChatLink(data: GramJs.account.ResolvedBusinessChatLinks) }; } -export function buildApiCollectibleInfo(info: GramJs.fragment.TypeCollectibleInfo): ApiCollectionInfo { +export function buildApiCollectibleInfo(info: GramJs.fragment.TypeCollectibleInfo): ApiCollectibleInfo { const { amount, currency, diff --git a/src/api/gramjs/apiBuilders/payments.ts b/src/api/gramjs/apiBuilders/payments.ts index ad9770459..9b1edcb2c 100644 --- a/src/api/gramjs/apiBuilders/payments.ts +++ b/src/api/gramjs/apiBuilders/payments.ts @@ -1,7 +1,6 @@ import bigInt from 'big-integer'; import { Api as GramJs } from '../../../lib/gramjs'; -import type { ApiPremiumSection } from '../../../global/types'; import type { ApiBoost, ApiBoostsStatus, @@ -15,6 +14,7 @@ import type { ApiPaymentSavedInfo, ApiPremiumGiftCodeOption, ApiPremiumPromo, + ApiPremiumSection, ApiPremiumSubscriptionOption, ApiPrepaidGiveaway, ApiPrepaidStarsGiveaway, diff --git a/src/api/gramjs/gramjsBuilders/index.ts b/src/api/gramjs/gramjsBuilders/index.ts index 06fe3776d..92104689c 100644 --- a/src/api/gramjs/gramjsBuilders/index.ts +++ b/src/api/gramjs/gramjsBuilders/index.ts @@ -2,7 +2,6 @@ import BigInt from 'big-integer'; import { Api as GramJs } from '../../../lib/gramjs'; import { generateRandomBytes, readBigIntFromBuffer } from '../../../lib/gramjs/Helpers'; -import type { ApiInputPrivacyRules, ApiPrivacyKey } from '../../../types'; import type { ApiBotApp, ApiChatAdminRights, @@ -11,6 +10,7 @@ import type { ApiChatReactions, ApiFormattedText, ApiGroupCall, + ApiInputPrivacyRules, ApiInputReplyInfo, ApiInputStorePaymentPurpose, ApiMessageEntity, @@ -19,6 +19,7 @@ import type { ApiPhoto, ApiPoll, ApiPremiumGiftCodeOption, + ApiPrivacyKey, ApiReactionWithPaid, ApiReportReason, ApiRequestInputInvoice, diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index a3c1beca2..5c4c7474c 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -1,7 +1,6 @@ import BigInt from 'big-integer'; import { Api as GramJs } from '../../../lib/gramjs'; -import type { ApiDraft } from '../../../global/types'; import type { ApiChat, ApiChatAdminRights, @@ -9,6 +8,7 @@ import type { ApiChatFolder, ApiChatFullInfo, ApiChatReactions, + ApiDraft, ApiGroupCall, ApiMessage, ApiMissingInvitedUser, diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index a41d223ea..07501629f 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -1,8 +1,7 @@ import BigInt from 'big-integer'; import { Api as GramJs } from '../../../lib/gramjs'; -import type { WebPageMediaSize } from '../../../global/types'; -import type { ThreadId } from '../../../types'; +import type { ThreadId, WebPageMediaSize } from '../../../types'; import type { ApiAttachment, ApiChat, diff --git a/src/api/gramjs/methods/settings.ts b/src/api/gramjs/methods/settings.ts index 8cae5a1e3..cc9cb3a29 100644 --- a/src/api/gramjs/methods/settings.ts +++ b/src/api/gramjs/methods/settings.ts @@ -2,14 +2,15 @@ import BigInt from 'big-integer'; import { Api as GramJs } from '../../../lib/gramjs'; import type { LANG_PACKS } from '../../../config'; -import type { ApiInputPrivacyRules, ApiPrivacyKey } from '../../../types'; import type { ApiAppConfig, ApiConfig, ApiError, + ApiInputPrivacyRules, ApiLanguage, ApiNotifyException, ApiPhoto, + ApiPrivacyKey, ApiUser, } from '../../types'; diff --git a/src/api/gramjs/methods/stories.ts b/src/api/gramjs/methods/stories.ts index d4bf066f6..4f9275638 100644 --- a/src/api/gramjs/methods/stories.ts +++ b/src/api/gramjs/methods/stories.ts @@ -1,8 +1,8 @@ import { Api as GramJs } from '../../../lib/gramjs'; -import type { ApiInputPrivacyRules } from '../../../types'; import type { ApiError, + ApiInputPrivacyRules, ApiPeer, ApiPeerStories, ApiReaction, diff --git a/src/api/types/chats.ts b/src/api/types/chats.ts index d63b2c297..db24d5620 100644 --- a/src/api/types/chats.ts +++ b/src/api/types/chats.ts @@ -1,6 +1,6 @@ import type { ApiBotCommand } from './bots'; import type { - ApiChatReactions, ApiFormattedText, ApiPhoto, ApiStickerSet, + ApiChatReactions, ApiFormattedText, ApiInputMessageReplyInfo, ApiPhoto, ApiStickerSet, } from './messages'; import type { ApiChatInviteImporter } from './misc'; import type { @@ -296,3 +296,11 @@ export interface ApiChatLink { chatId: string; text: ApiFormattedText; } + +export type ApiDraft = { + text?: ApiFormattedText; + replyInfo?: ApiInputMessageReplyInfo; + date?: number; + effectId?: string; + isLocal?: boolean; +}; diff --git a/src/api/types/messages.ts b/src/api/types/messages.ts index cfc431392..0157a5122 100644 --- a/src/api/types/messages.ts +++ b/src/api/types/messages.ts @@ -1,5 +1,4 @@ -import type { WebPageMediaSize } from '../../global/types'; -import type { ThreadId } from '../../types'; +import type { ThreadId, WebPageMediaSize } from '../../types'; import type { ApiWebDocument } from './bots'; import type { ApiGroupCall, PhoneCallAction } from './calls'; import type { ApiChat, ApiPeerColor } from './chats'; diff --git a/src/api/types/misc.ts b/src/api/types/misc.ts index a8a49b5fb..5deb1fe12 100644 --- a/src/api/types/misc.ts +++ b/src/api/types/misc.ts @@ -1,9 +1,10 @@ import type { TeactNode } from '../../lib/teact/teact'; -import type { ApiLimitType, ApiPremiumSection, CallbackAction } from '../../global/types'; +import type { CallbackAction } from '../../global/types'; import type { IconName } from '../../types/icons'; import type { LangFnParameters } from '../../util/localization'; import type { ApiDocument, ApiPhoto, ApiReaction } from './messages'; +import type { ApiPremiumSection, ApiStarsSubscriptionPricing } from './payments'; import type { ApiUser } from './users'; export interface ApiInitialArgs { @@ -176,11 +177,6 @@ export type ApiChatInviteInfo = { subscriptionPricing?: ApiStarsSubscriptionPricing; }; -export type ApiStarsSubscriptionPricing = { - period: number; - amount: number; -}; - export type ApiChatInviteImporter = { userId: string; date: number; @@ -304,7 +300,7 @@ type ApiUrlAuthResultDefault = { export type ApiUrlAuthResult = ApiUrlAuthResultRequest | ApiUrlAuthResultAccepted | ApiUrlAuthResultDefault; -export interface ApiCollectionInfo { +export interface ApiCollectibleInfo { amount: number; currency: string; cryptoAmount: number; @@ -321,3 +317,27 @@ export interface ApiPeerPhotos { nextOffset?: number; isLoading?: boolean; } + +export type ApiLimitType = + | 'uploadMaxFileparts' + | 'stickersFaved' + | 'savedGifs' + | 'dialogFiltersChats' + | 'dialogFilters' + | 'dialogFolderPinned' + | 'captionLength' + | 'channels' + | 'channelsPublic' + | 'aboutLength' + | 'chatlistInvites' + | 'chatlistJoined' + | 'recommendedChannels' + | 'savedDialogsPinned'; + +export type ApiLimitTypeWithModal = Exclude; + +export type ApiLimitTypeForPromo = Exclude; diff --git a/src/api/types/payments.ts b/src/api/types/payments.ts index c854b6979..a62fa18f3 100644 --- a/src/api/types/payments.ts +++ b/src/api/types/payments.ts @@ -1,4 +1,4 @@ -import type { ApiPremiumSection } from '../../global/types'; +import type { PREMIUM_FEATURE_SECTIONS } from '../../config'; import type { ApiWebDocument } from './bots'; import type { ApiChat } from './chats'; import type { @@ -9,7 +9,6 @@ import type { ApiPaymentCredentials, BoughtPaidMedia, } from './messages'; -import type { ApiStarsSubscriptionPricing } from './misc'; import type { StatisticsOverviewPercentage } from './statistics'; import type { ApiUser } from './users'; @@ -116,6 +115,8 @@ export interface ApiReceiptRegular { export type ApiReceipt = ApiReceiptRegular | ApiReceiptStars; +export type ApiPremiumSection = typeof PREMIUM_FEATURE_SECTIONS[number]; + export interface ApiPremiumPromo { videoSections: ApiPremiumSection[]; videos: ApiDocument[]; @@ -387,6 +388,11 @@ export interface ApiStarsSubscription { invoiceSlug?: string; } +export type ApiStarsSubscriptionPricing = { + period: number; + amount: number; +}; + export interface ApiStarTopupOption { isExtended?: true; stars: number; @@ -409,3 +415,5 @@ export interface ApiStarGiveawayOption { amount: number; winners: ApiStarsGiveawayWinnerOption[]; } + +export type ApiPaymentStatus = 'paid' | 'failed' | 'pending' | 'cancelled'; diff --git a/src/api/types/settings.ts b/src/api/types/settings.ts index 0d182961b..12a54ff24 100644 --- a/src/api/types/settings.ts +++ b/src/api/types/settings.ts @@ -1,3 +1,33 @@ +import type { ApiChat } from './chats'; +import type { ApiUser } from './users'; + +export type ApiPrivacyKey = 'phoneNumber' | 'addByPhone' | 'lastSeen' | 'profilePhoto' | 'voiceMessages' | +'forwards' | 'chatInvite' | 'phoneCall' | 'phoneP2P' | 'bio' | 'birthday' | 'gifts'; +export type PrivacyVisibility = 'everybody' | 'contacts' | 'closeFriends' | 'nonContacts' | 'nobody'; +export type BotsPrivacyType = 'allow' | 'disallow' | 'none'; + +export interface ApiPrivacySettings { + visibility: PrivacyVisibility; + isUnspecified?: boolean; + allowUserIds: string[]; + allowChatIds: string[]; + blockUserIds: string[]; + blockChatIds: string[]; + shouldAllowPremium?: true; + botsPrivacy: BotsPrivacyType; +} + +export interface ApiInputPrivacyRules { + visibility: PrivacyVisibility; + isUnspecified?: boolean; + allowedUsers?: ApiUser[]; + allowedChats?: ApiChat[]; + blockedUsers?: ApiUser[]; + blockedChats?: ApiChat[]; + shouldAllowPremium?: true; + botsPrivacy: BotsPrivacyType; +} + export interface ApiLanguage { isOfficial?: true; isRtl?: true; diff --git a/src/api/types/stories.ts b/src/api/types/stories.ts index 0fdd0a853..dc6aadf33 100644 --- a/src/api/types/stories.ts +++ b/src/api/types/stories.ts @@ -1,4 +1,3 @@ -import type { ApiPrivacySettings } from '../../types'; import type { ApiGeoPoint, ApiMessage, @@ -8,6 +7,7 @@ import type { ApiStoryForwardInfo, MediaContent, } from './messages'; +import type { ApiPrivacySettings } from './settings'; export interface ApiStory { '@type'?: 'story'; diff --git a/src/api/types/updates.ts b/src/api/types/updates.ts index 638539e64..d223f0a27 100644 --- a/src/api/types/updates.ts +++ b/src/api/types/updates.ts @@ -1,4 +1,4 @@ -import type { ApiDraft, TabState } from '../../global/types'; +import type { TabState } from '../../global/types'; import type { GroupCallConnectionData, GroupCallConnectionState, @@ -6,7 +6,7 @@ import type { VideoRotation, VideoState, } from '../../lib/secret-sauce'; -import type { ApiPrivacyKey, PrivacyVisibility, ThreadId } from '../../types'; +import type { ThreadId } from '../../types'; import type { ApiBotMenuButton } from './bots'; import type { ApiGroupCall, ApiPhoneCall, @@ -16,6 +16,7 @@ import type { ApiChatFolder, ApiChatFullInfo, ApiChatMember, + ApiDraft, ApiTypingStatus, } from './chats'; import type { @@ -35,7 +36,7 @@ import type { ApiEmojiInteraction, ApiError, ApiNotifyException, ApiSessionData, } from './misc'; import type { ApiStarsAmount } from './payments'; -import type { LangPackStringValue } from './settings'; +import type { ApiPrivacyKey, LangPackStringValue, PrivacyVisibility } from './settings'; import type { ApiStealthMode, ApiStory, ApiStorySkipped } from './stories'; import type { ApiEmojiStatus, ApiUser, ApiUserFullInfo, ApiUserStatus, diff --git a/src/components/common/Composer.tsx b/src/components/common/Composer.tsx index 054a0a6eb..2f2a0258e 100644 --- a/src/components/common/Composer.tsx +++ b/src/components/common/Composer.tsx @@ -15,6 +15,7 @@ import type { ApiBotMenuButton, ApiChat, ApiChatFullInfo, + ApiDraft, ApiFormattedText, ApiMessage, ApiMessageEntity, @@ -29,10 +30,15 @@ import type { ApiWebPage, } from '../../api/types'; import type { - ApiDraft, GlobalState, MessageList, MessageListType, TabState, + GlobalState, TabState, } from '../../global/types'; import type { - IAnchorPosition, InlineBotSettings, ISettings, ThreadId, + IAnchorPosition, + InlineBotSettings, + ISettings, + MessageList, + MessageListType, + ThreadId, } from '../../types'; import { MAIN_THREAD_ID } from '../../api/types'; diff --git a/src/components/common/CustomEmojiSetsModal.tsx b/src/components/common/CustomEmojiSetsModal.tsx index 4274ad598..0776d9fe9 100644 --- a/src/components/common/CustomEmojiSetsModal.tsx +++ b/src/components/common/CustomEmojiSetsModal.tsx @@ -4,8 +4,7 @@ import React, { useMemo, useRef, } from '../../lib/teact/teact'; -import { getGlobal } from '../../lib/teact/teactn'; -import { getActions, withGlobal } from '../../global'; +import { getActions, getGlobal, withGlobal } from '../../global'; import type { ApiSticker } from '../../api/types'; diff --git a/src/components/common/StickerSetModal.tsx b/src/components/common/StickerSetModal.tsx index 6f38b7f1b..7da2e4632 100644 --- a/src/components/common/StickerSetModal.tsx +++ b/src/components/common/StickerSetModal.tsx @@ -5,7 +5,7 @@ import React, { import { getActions, withGlobal } from '../../global'; import type { ApiSticker, ApiStickerSet } from '../../api/types'; -import type { MessageList } from '../../global/types'; +import type { MessageList } from '../../types'; import { EMOJI_SIZE_MODAL, STICKER_SIZE_MODAL, TME_LINK_PREFIX } from '../../config'; import { getAllowedAttachmentOptions, getCanPostInChat } from '../../global/helpers'; diff --git a/src/components/common/embedded/EmbeddedMessage.tsx b/src/components/common/embedded/EmbeddedMessage.tsx index a1b79af66..9256e66b5 100644 --- a/src/components/common/embedded/EmbeddedMessage.tsx +++ b/src/components/common/embedded/EmbeddedMessage.tsx @@ -5,8 +5,8 @@ import type { ApiChat, ApiMessage, ApiPeer, ApiReplyInfo, MediaContainer, } from '../../../api/types'; -import type { ChatTranslatedMessages } from '../../../global/types'; import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; +import type { ChatTranslatedMessages } from '../../../types'; import type { IconName } from '../../../types/icons'; import { CONTENT_NOT_SUPPORTED } from '../../../config'; diff --git a/src/components/common/hooks/useAnimatedEmoji.ts b/src/components/common/hooks/useAnimatedEmoji.ts index 8b446b688..63dddd746 100644 --- a/src/components/common/hooks/useAnimatedEmoji.ts +++ b/src/components/common/hooks/useAnimatedEmoji.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from '../../../lib/teact/teact'; import { getActions } from '../../../global'; -import type { ActiveEmojiInteraction } from '../../../global/types'; +import type { ActiveEmojiInteraction } from '../../../types'; import buildStyle from '../../../util/buildStyle'; import safePlay from '../../../util/safePlay'; diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index 87902ba91..b21a191d5 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -4,6 +4,7 @@ import { getActions, withGlobal } from '../../../global'; import type { ApiChat, + ApiDraft, ApiMessage, ApiMessageOutgoingStatus, ApiPeer, @@ -13,7 +14,6 @@ import type { ApiUser, ApiUserStatus, } from '../../../api/types'; -import type { ApiDraft } from '../../../global/types'; import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; import type { ChatAnimationTypes } from './hooks'; import { MAIN_THREAD_ID } from '../../../api/types'; diff --git a/src/components/left/main/ForumPanel.tsx b/src/components/left/main/ForumPanel.tsx index d26ef4e38..6a3c47f3d 100644 --- a/src/components/left/main/ForumPanel.tsx +++ b/src/components/left/main/ForumPanel.tsx @@ -6,7 +6,7 @@ import React, { import { getActions, withGlobal } from '../../../global'; import type { ApiChat } from '../../../api/types'; -import type { TopicsInfo } from '../../../global/types'; +import type { TopicsInfo } from '../../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; import { diff --git a/src/components/left/main/Topic.tsx b/src/components/left/main/Topic.tsx index 47468e08d..c467a0a29 100644 --- a/src/components/left/main/Topic.tsx +++ b/src/components/left/main/Topic.tsx @@ -3,10 +3,9 @@ import React, { memo } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { - ApiChat, ApiMessage, ApiMessageOutgoingStatus, + ApiChat, ApiDraft, ApiMessage, ApiMessageOutgoingStatus, ApiPeer, ApiTopic, ApiTypeStory, ApiTypingStatus, } from '../../../api/types'; -import type { ApiDraft } from '../../../global/types'; import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; import type { ChatAnimationTypes } from './hooks'; diff --git a/src/components/left/main/hooks/useChatListEntry.tsx b/src/components/left/main/hooks/useChatListEntry.tsx index 7cd185db9..a6e43c97e 100644 --- a/src/components/left/main/hooks/useChatListEntry.tsx +++ b/src/components/left/main/hooks/useChatListEntry.tsx @@ -4,10 +4,9 @@ import React, { import { getGlobal } from '../../../../global'; import type { - ApiChat, ApiMessage, ApiPeer, ApiTopic, ApiTypingStatus, ApiUser, + ApiChat, ApiDraft, ApiMessage, ApiPeer, ApiTopic, ApiTypingStatus, ApiUser, StatefulMediaContent, } from '../../../../api/types'; -import type { ApiDraft } from '../../../../global/types'; import type { ObserveFn } from '../../../../hooks/useIntersectionObserver'; import { ANIMATION_END_DELAY, CHAT_HEIGHT_PX } from '../../../../config'; diff --git a/src/components/left/settings/PremiumStatusItem.tsx b/src/components/left/settings/PremiumStatusItem.tsx index 22a953bc4..6a63beb3c 100644 --- a/src/components/left/settings/PremiumStatusItem.tsx +++ b/src/components/left/settings/PremiumStatusItem.tsx @@ -1,7 +1,7 @@ import React, { memo } from '../../../lib/teact/teact'; import { getActions } from '../../../global'; -import type { ApiPremiumSection } from '../../../global/types'; +import type { ApiPremiumSection } from '../../../api/types'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; diff --git a/src/components/left/settings/SettingsPrivacy.tsx b/src/components/left/settings/SettingsPrivacy.tsx index 938665d12..b0dd8e292 100644 --- a/src/components/left/settings/SettingsPrivacy.tsx +++ b/src/components/left/settings/SettingsPrivacy.tsx @@ -2,8 +2,8 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback, useEffect } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; +import type { ApiPrivacySettings } from '../../../api/types'; import type { GlobalState } from '../../../global/types'; -import type { ApiPrivacySettings } from '../../../types'; import { SettingsScreens } from '../../../types'; import { selectCanSetPasscode, selectIsCurrentUserPremium } from '../../../global/selectors'; diff --git a/src/components/left/settings/SettingsPrivacyLastSeen.tsx b/src/components/left/settings/SettingsPrivacyLastSeen.tsx index 0149e7b4e..7e979e1a3 100644 --- a/src/components/left/settings/SettingsPrivacyLastSeen.tsx +++ b/src/components/left/settings/SettingsPrivacyLastSeen.tsx @@ -1,7 +1,7 @@ import React, { memo } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; -import type { PrivacyVisibility } from '../../../types'; +import type { PrivacyVisibility } from '../../../api/types'; import { selectIsCurrentUserPremium, selectShouldHideReadMarks } from '../../../global/selectors'; import renderText from '../../common/helpers/renderText'; diff --git a/src/components/left/settings/SettingsPrivacyVisibility.tsx b/src/components/left/settings/SettingsPrivacyVisibility.tsx index b3946e1c9..e4bda6f00 100644 --- a/src/components/left/settings/SettingsPrivacyVisibility.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibility.tsx @@ -2,8 +2,7 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback, useMemo } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; -import type { ApiPhoto } from '../../../api/types'; -import type { ApiPrivacySettings, BotsPrivacyType } from '../../../types'; +import type { ApiPhoto, ApiPrivacySettings, BotsPrivacyType } from '../../../api/types'; import { SettingsScreens } from '../../../types'; import { selectIsCurrentUserPremium, selectUserFullInfo } from '../../../global/selectors'; diff --git a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx index 9a4c04d08..37cc0913f 100644 --- a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx @@ -4,8 +4,9 @@ import React, { } from '../../../lib/teact/teact'; import { getActions, getGlobal, withGlobal } from '../../../global'; +import type { ApiPrivacySettings } from '../../../api/types'; import type { GlobalState } from '../../../global/types'; -import type { ApiPrivacySettings, CustomPeerType, UniqueCustomPeer } from '../../../types'; +import type { CustomPeerType, UniqueCustomPeer } from '../../../types'; import { SettingsScreens } from '../../../types'; import { ALL_FOLDER_ID, ARCHIVED_FOLDER_ID, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; diff --git a/src/components/left/settings/helpers/privacy.ts b/src/components/left/settings/helpers/privacy.ts index a9b123bf3..3cca7a76d 100644 --- a/src/components/left/settings/helpers/privacy.ts +++ b/src/components/left/settings/helpers/privacy.ts @@ -1,4 +1,4 @@ -import type { ApiPrivacyKey } from '../../../../types'; +import type { ApiPrivacyKey } from '../../../../api/types'; import { SettingsScreens } from '../../../../types'; export function getPrivacyKey(screen: SettingsScreens): ApiPrivacyKey | undefined { diff --git a/src/components/main/Dialogs.tsx b/src/components/main/Dialogs.tsx index 2c29f442e..4656f2892 100644 --- a/src/components/main/Dialogs.tsx +++ b/src/components/main/Dialogs.tsx @@ -5,7 +5,7 @@ import { getActions, withGlobal } from '../../global'; import type { ApiContact, ApiError, } from '../../api/types'; -import type { MessageList } from '../../global/types'; +import type { MessageList } from '../../types'; import { selectCurrentMessageList, selectTabState } from '../../global/selectors'; import getReadableErrorText from '../../util/getReadableErrorText'; diff --git a/src/components/main/GameModal.tsx b/src/components/main/GameModal.tsx index 0edfc78a8..4be33bf9e 100644 --- a/src/components/main/GameModal.tsx +++ b/src/components/main/GameModal.tsx @@ -1,7 +1,6 @@ import type { FC } from '../../lib/teact/teact'; import React, { memo, useCallback, useEffect } from '../../lib/teact/teact'; -import { getActions } from '../../lib/teact/teactn'; -import { withGlobal } from '../../global'; +import { getActions, withGlobal } from '../../global'; import type { TabState } from '../../global/types'; @@ -41,6 +40,7 @@ const GameModal: FC = ({ openedGame, gameTitle, canPost } }, isOpen && canPost ? PLAY_GAME_ACTION_INTERVAL : undefined); const handleMessage = useCallback((event: MessageEvent) => { + if (!chatId || !messageId) return; try { const data = JSON.parse(event.data) as GameEvents; if (data.eventType === 'share_score') { diff --git a/src/components/main/Main.tsx b/src/components/main/Main.tsx index 95f10808e..b212045e6 100644 --- a/src/components/main/Main.tsx +++ b/src/components/main/Main.tsx @@ -8,8 +8,8 @@ import React, { import { addExtraClass } from '../../lib/teact/teact-dom'; import { getActions, getGlobal, withGlobal } from '../../global'; -import type { ApiChatFolder, ApiUser } from '../../api/types'; -import type { ApiLimitTypeWithModal, TabState } from '../../global/types'; +import type { ApiChatFolder, ApiLimitTypeWithModal, ApiUser } from '../../api/types'; +import type { TabState } from '../../global/types'; import { ElectronEvent } from '../../types/electron'; import { BASE_EMOJI_KEYWORD_LANG, DEBUG, INACTIVE_MARKER } from '../../config'; diff --git a/src/components/main/premium/PremiumFeatureModal.tsx b/src/components/main/premium/PremiumFeatureModal.tsx index 78cdccaf0..7bedbc47d 100644 --- a/src/components/main/premium/PremiumFeatureModal.tsx +++ b/src/components/main/premium/PremiumFeatureModal.tsx @@ -4,8 +4,13 @@ import React, { } from '../../../lib/teact/teact'; import { toggleExtraClass } from '../../../lib/teact/teact-dom'; -import type { ApiPremiumPromo, ApiPremiumSubscriptionOption } from '../../../api/types'; -import type { ApiLimitTypeForPromo, ApiPremiumSection, GlobalState } from '../../../global/types'; +import type { + ApiLimitTypeForPromo, + ApiPremiumPromo, + ApiPremiumSection, + ApiPremiumSubscriptionOption, +} from '../../../api/types'; +import type { GlobalState } from '../../../global/types'; import { PREMIUM_BOTTOM_VIDEOS, PREMIUM_FEATURE_SECTIONS, PREMIUM_LIMITS_ORDER } from '../../../config'; import { requestMutation } from '../../../lib/fasterdom/fasterdom'; diff --git a/src/components/main/premium/PremiumMainModal.tsx b/src/components/main/premium/PremiumMainModal.tsx index 39d76ce37..b39b05bff 100644 --- a/src/components/main/premium/PremiumMainModal.tsx +++ b/src/components/main/premium/PremiumMainModal.tsx @@ -5,9 +5,9 @@ import React, { import { getActions, withGlobal } from '../../../global'; import type { - ApiPremiumPromo, ApiPremiumSubscriptionOption, ApiSticker, ApiStickerSet, ApiUser, + ApiPremiumPromo, ApiPremiumSection, ApiPremiumSubscriptionOption, ApiSticker, ApiStickerSet, ApiUser, } from '../../../api/types'; -import type { ApiPremiumSection, GlobalState } from '../../../global/types'; +import type { GlobalState } from '../../../global/types'; import { PREMIUM_FEATURE_SECTIONS, TME_LINK_PREFIX } from '../../../config'; import { getUserFullName } from '../../../global/helpers'; diff --git a/src/components/main/premium/common/PremiumLimitReachedModal.tsx b/src/components/main/premium/common/PremiumLimitReachedModal.tsx index 6ef1e4aa0..a2c0981db 100644 --- a/src/components/main/premium/common/PremiumLimitReachedModal.tsx +++ b/src/components/main/premium/common/PremiumLimitReachedModal.tsx @@ -2,7 +2,7 @@ import type { FC } from '../../../../lib/teact/teact'; import React, { memo, useCallback, useEffect } from '../../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../../global'; -import type { ApiLimitTypeWithModal } from '../../../../global/types'; +import type { ApiLimitTypeWithModal } from '../../../../api/types'; import type { OldLangFn } from '../../../../hooks/useOldLang'; import type { IconName } from '../../../../types/icons'; diff --git a/src/components/main/visualEffects/ConfettiContainer.tsx b/src/components/main/visualEffects/ConfettiContainer.tsx index 6dd45791e..6bcf67da8 100644 --- a/src/components/main/visualEffects/ConfettiContainer.tsx +++ b/src/components/main/visualEffects/ConfettiContainer.tsx @@ -1,7 +1,8 @@ import React, { memo, useRef } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; -import type { ConfettiStyle, TabState } from '../../../global/types'; +import type { TabState } from '../../../global/types'; +import type { ConfettiStyle } from '../../../types'; import { requestMeasure } from '../../../lib/fasterdom/fasterdom'; import { selectTabState } from '../../../global/selectors'; diff --git a/src/components/mediaViewer/MediaViewerActions.tsx b/src/components/mediaViewer/MediaViewerActions.tsx index 54ffce9b8..1169f693a 100644 --- a/src/components/mediaViewer/MediaViewerActions.tsx +++ b/src/components/mediaViewer/MediaViewerActions.tsx @@ -2,8 +2,7 @@ import type { FC } from '../../lib/teact/teact'; import React, { memo, useMemo } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { ActiveDownloads, MessageListType } from '../../global/types'; -import type { MediaViewerOrigin } from '../../types'; +import type { ActiveDownloads, MediaViewerOrigin, MessageListType } from '../../types'; import type { MenuItemProps } from '../ui/MenuItem'; import type { MediaViewerItem } from './helpers/getViewableMedia'; diff --git a/src/components/middle/ActionMessage.tsx b/src/components/middle/ActionMessage.tsx index 4d51800b2..350888f9b 100644 --- a/src/components/middle/ActionMessage.tsx +++ b/src/components/middle/ActionMessage.tsx @@ -7,9 +7,8 @@ import { getActions, getGlobal, withGlobal } from '../../global'; import type { ApiChat, ApiMessage, ApiSticker, ApiTopic, ApiUser, } from '../../api/types'; -import type { MessageListType } from '../../global/types'; import type { ObserveFn } from '../../hooks/useIntersectionObserver'; -import type { FocusDirection, ThreadId } from '../../types'; +import type { FocusDirection, MessageListType, ThreadId } from '../../types'; import type { OnIntersectPinnedMessage } from './hooks/usePinnedMessage'; import { getChatTitle, getMessageHtmlId, isJoinedChannelMessage } from '../../global/helpers'; diff --git a/src/components/middle/ContactGreeting.tsx b/src/components/middle/ContactGreeting.tsx index 55cc601ed..7c6fc40ca 100644 --- a/src/components/middle/ContactGreeting.tsx +++ b/src/components/middle/ContactGreeting.tsx @@ -7,7 +7,7 @@ import { getActions, withGlobal } from '../../global'; import type { ApiBusinessIntro, ApiSticker, ApiUpdateConnectionStateType, ApiUser, } from '../../api/types'; -import type { MessageList } from '../../global/types'; +import type { MessageList } from '../../types'; import { getUserFullName } from '../../global/helpers'; import { diff --git a/src/components/middle/EmojiInteractionAnimation.tsx b/src/components/middle/EmojiInteractionAnimation.tsx index 10bdbe187..0c92e41ac 100644 --- a/src/components/middle/EmojiInteractionAnimation.tsx +++ b/src/components/middle/EmojiInteractionAnimation.tsx @@ -5,7 +5,7 @@ import React, { } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { ActiveEmojiInteraction } from '../../global/types'; +import type { ActiveEmojiInteraction } from '../../types'; import { selectAnimatedEmojiEffect, diff --git a/src/components/middle/FloatingActionButtons.tsx b/src/components/middle/FloatingActionButtons.tsx index 2a269a645..def72edec 100644 --- a/src/components/middle/FloatingActionButtons.tsx +++ b/src/components/middle/FloatingActionButtons.tsx @@ -2,7 +2,7 @@ import type { FC } from '../../lib/teact/teact'; import React, { memo, useEffect, useRef } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { MessageListType } from '../../global/types'; +import type { MessageListType } from '../../types'; import { MAIN_THREAD_ID } from '../../api/types'; import { selectChat, selectCurrentMessageList, selectCurrentMiddleSearch } from '../../global/selectors'; diff --git a/src/components/middle/HeaderActions.tsx b/src/components/middle/HeaderActions.tsx index e50ded80f..08d4e6c2f 100644 --- a/src/components/middle/HeaderActions.tsx +++ b/src/components/middle/HeaderActions.tsx @@ -4,8 +4,7 @@ import React, { } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { MessageListType } from '../../global/types'; -import type { IAnchorPosition, ThreadId } from '../../types'; +import type { IAnchorPosition, MessageListType, ThreadId } from '../../types'; import { MAIN_THREAD_ID } from '../../api/types'; import { ManagementScreens } from '../../types'; diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index d457cdcee..d0e7825b1 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -8,10 +8,9 @@ import { getActions, getGlobal, withGlobal } from '../../global'; import type { ApiChatFullInfo, ApiMessage, ApiRestrictionReason, ApiTopic, } from '../../api/types'; -import type { MessageListType } from '../../global/types'; import type { OnIntersectPinnedMessage } from './hooks/usePinnedMessage'; import { MAIN_THREAD_ID } from '../../api/types'; -import { LoadMoreDirection, type ThreadId } from '../../types'; +import { LoadMoreDirection, type MessageListType, type ThreadId } from '../../types'; import { ANIMATION_END_DELAY, diff --git a/src/components/middle/MessageListContent.tsx b/src/components/middle/MessageListContent.tsx index d08fee19f..184ec3b3a 100644 --- a/src/components/middle/MessageListContent.tsx +++ b/src/components/middle/MessageListContent.tsx @@ -3,8 +3,7 @@ import type { FC } from '../../lib/teact/teact'; import React, { getIsHeavyAnimating, memo } from '../../lib/teact/teact'; import { getActions } from '../../global'; -import type { MessageListType } from '../../global/types'; -import type { ThreadId } from '../../types'; +import type { MessageListType, ThreadId } from '../../types'; import type { Signal } from '../../util/signals'; import type { MessageDateGroup } from './helpers/groupMessages'; import type { OnIntersectPinnedMessage } from './hooks/usePinnedMessage'; diff --git a/src/components/middle/MessageListHistoryHandler.tsx b/src/components/middle/MessageListHistoryHandler.tsx index 0a70af7de..2f74eee12 100644 --- a/src/components/middle/MessageListHistoryHandler.tsx +++ b/src/components/middle/MessageListHistoryHandler.tsx @@ -2,7 +2,7 @@ import type { FC } from '../../lib/teact/teact'; import React, { memo } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { MessageList as GlobalMessageList } from '../../global/types'; +import type { MessageList as GlobalMessageList } from '../../types'; import { selectTabState } from '../../global/selectors'; import { createLocationHash } from '../../util/routing'; diff --git a/src/components/middle/MessageSelectToolbar.tsx b/src/components/middle/MessageSelectToolbar.tsx index 1db1dca6f..fd6a0539f 100644 --- a/src/components/middle/MessageSelectToolbar.tsx +++ b/src/components/middle/MessageSelectToolbar.tsx @@ -3,7 +3,7 @@ import React, { memo, useEffect } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { ApiChat } from '../../api/types'; -import type { MessageListType } from '../../global/types'; +import type { MessageListType } from '../../types'; import type { IconName } from '../../types/icons'; import { diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 0b1686c54..4bc64bddf 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -10,8 +10,9 @@ import type { import type { ActiveEmojiInteraction, MessageListType, -} from '../../global/types'; -import type { ThemeKey, ThreadId } from '../../types'; + ThemeKey, + ThreadId, +} from '../../types'; import { MAIN_THREAD_ID } from '../../api/types'; import { diff --git a/src/components/middle/MiddleHeader.tsx b/src/components/middle/MiddleHeader.tsx index 1b160e8af..af4d3ca56 100644 --- a/src/components/middle/MiddleHeader.tsx +++ b/src/components/middle/MiddleHeader.tsx @@ -7,10 +7,10 @@ import { getActions, withGlobal } from '../../global'; import type { ApiChat, ApiMessage, ApiSticker, ApiTypingStatus, } from '../../api/types'; -import type { GlobalState, MessageListType } from '../../global/types'; +import type { GlobalState } from '../../global/types'; import type { Signal } from '../../util/signals'; import { MAIN_THREAD_ID } from '../../api/types'; -import { StoryViewerOrigin, type ThreadId } from '../../types'; +import { type MessageListType, StoryViewerOrigin, type ThreadId } from '../../types'; import { EDITABLE_INPUT_CSS_SELECTOR, diff --git a/src/components/middle/MiddleHeaderPanes.tsx b/src/components/middle/MiddleHeaderPanes.tsx index bdd7d2b0c..6e198baaa 100644 --- a/src/components/middle/MiddleHeaderPanes.tsx +++ b/src/components/middle/MiddleHeaderPanes.tsx @@ -4,8 +4,7 @@ import React, { import { setExtraStyles } from '../../lib/teact/teact-dom'; import { withGlobal } from '../../global'; -import type { MessageListType } from '../../global/types'; -import type { ThreadId } from '../../types'; +import type { MessageListType, ThreadId } from '../../types'; import type { Signal } from '../../util/signals'; import { type ApiChat, MAIN_THREAD_ID } from '../../api/types'; diff --git a/src/components/middle/NoMessages.tsx b/src/components/middle/NoMessages.tsx index 55ca2d936..70fd8c273 100644 --- a/src/components/middle/NoMessages.tsx +++ b/src/components/middle/NoMessages.tsx @@ -2,8 +2,8 @@ import type { FC } from '../../lib/teact/teact'; import React, { memo } from '../../lib/teact/teact'; import type { ApiTopic } from '../../api/types'; -import type { MessageListType } from '../../global/types'; import type { OldLangFn } from '../../hooks/useOldLang'; +import type { MessageListType } from '../../types'; import { REM } from '../common/helpers/mediaDimensions'; import renderText from '../common/helpers/renderText'; diff --git a/src/components/middle/composer/AttachmentModal.tsx b/src/components/middle/composer/AttachmentModal.tsx index dfe4e27b0..c27a4315b 100644 --- a/src/components/middle/composer/AttachmentModal.tsx +++ b/src/components/middle/composer/AttachmentModal.tsx @@ -7,8 +7,8 @@ import { getActions, withGlobal } from '../../../global'; import type { ApiAttachment, ApiChatMember, ApiMessage, ApiSticker, } from '../../../api/types'; -import type { GlobalState, MessageListType } from '../../../global/types'; -import type { ThreadId } from '../../../types'; +import type { GlobalState } from '../../../global/types'; +import type { MessageListType, ThreadId } from '../../../types'; import type { Signal } from '../../../util/signals'; import { diff --git a/src/components/middle/composer/ComposerEmbeddedMessage.tsx b/src/components/middle/composer/ComposerEmbeddedMessage.tsx index 96b137ffe..9c2b38977 100644 --- a/src/components/middle/composer/ComposerEmbeddedMessage.tsx +++ b/src/components/middle/composer/ComposerEmbeddedMessage.tsx @@ -7,8 +7,7 @@ import { getActions, withGlobal } from '../../../global'; import type { ApiChat, ApiInputMessageReplyInfo, ApiMessage, ApiPeer, } from '../../../api/types'; -import type { MessageListType } from '../../../global/types'; -import type { ThreadId } from '../../../types/index'; +import type { MessageListType, ThreadId } from '../../../types/index'; import { isChatChannel, stripCustomEmoji } from '../../../global/helpers'; import { diff --git a/src/components/middle/composer/WebPagePreview.tsx b/src/components/middle/composer/WebPagePreview.tsx index 72ca5fe62..77ddfd3f1 100644 --- a/src/components/middle/composer/WebPagePreview.tsx +++ b/src/components/middle/composer/WebPagePreview.tsx @@ -5,8 +5,8 @@ import { getActions, withGlobal } from '../../../global'; import type { ApiFormattedText, ApiMessage, ApiMessageEntityTextUrl, ApiWebPage, } from '../../../api/types'; -import type { GlobalState, WebPageMediaSize } from '../../../global/types'; -import type { ISettings, ThreadId } from '../../../types'; +import type { GlobalState } from '../../../global/types'; +import type { ISettings, ThreadId, WebPageMediaSize } from '../../../types'; import type { Signal } from '../../../util/signals'; import { ApiMessageEntityTypes } from '../../../api/types'; diff --git a/src/components/middle/composer/hooks/useDraft.ts b/src/components/middle/composer/hooks/useDraft.ts index 395c23ce6..4b34518a7 100644 --- a/src/components/middle/composer/hooks/useDraft.ts +++ b/src/components/middle/composer/hooks/useDraft.ts @@ -1,8 +1,7 @@ import { useEffect, useLayoutEffect, useRef } from '../../../../lib/teact/teact'; import { getActions } from '../../../../global'; -import type { ApiMessage } from '../../../../api/types'; -import type { ApiDraft } from '../../../../global/types'; +import type { ApiDraft, ApiMessage } from '../../../../api/types'; import type { ThreadId } from '../../../../types'; import type { Signal } from '../../../../util/signals'; import { ApiMessageEntityTypes } from '../../../../api/types'; diff --git a/src/components/middle/composer/hooks/useEditing.ts b/src/components/middle/composer/hooks/useEditing.ts index 967666879..11a8d08ac 100644 --- a/src/components/middle/composer/hooks/useEditing.ts +++ b/src/components/middle/composer/hooks/useEditing.ts @@ -1,9 +1,8 @@ import { useEffect, useState } from '../../../../lib/teact/teact'; import { getActions } from '../../../../global'; -import type { ApiFormattedText, ApiMessage } from '../../../../api/types'; -import type { ApiDraft, MessageListType } from '../../../../global/types'; -import type { ThreadId } from '../../../../types'; +import type { ApiDraft, ApiFormattedText, ApiMessage } from '../../../../api/types'; +import type { MessageListType, ThreadId } from '../../../../types'; import type { Signal } from '../../../../util/signals'; import { ApiMessageEntityTypes } from '../../../../api/types'; diff --git a/src/components/middle/hooks/useMessageObservers.ts b/src/components/middle/hooks/useMessageObservers.ts index 7c68df00d..815fe5358 100644 --- a/src/components/middle/hooks/useMessageObservers.ts +++ b/src/components/middle/hooks/useMessageObservers.ts @@ -1,7 +1,7 @@ import type { RefObject } from 'react'; import { getActions } from '../../../global'; -import type { MessageListType } from '../../../global/types'; +import type { MessageListType } from '../../../types'; import type { OnIntersectPinnedMessage } from './usePinnedMessage'; import { IS_ANDROID } from '../../../util/windowEnvironment'; diff --git a/src/components/middle/hooks/useScrollHooks.ts b/src/components/middle/hooks/useScrollHooks.ts index 2c468e00c..5e411c62e 100644 --- a/src/components/middle/hooks/useScrollHooks.ts +++ b/src/components/middle/hooks/useScrollHooks.ts @@ -2,7 +2,7 @@ import type { RefObject } from 'react'; import { useEffect, useMemo, useRef } from '../../../lib/teact/teact'; import { getActions } from '../../../global'; -import type { MessageListType } from '../../../global/types'; +import type { MessageListType } from '../../../types'; import type { Signal } from '../../../util/signals'; import { LoadMoreDirection } from '../../../types'; diff --git a/src/components/middle/message/AnimatedCustomEmoji.tsx b/src/components/middle/message/AnimatedCustomEmoji.tsx index 0c5adca49..06c9b25c2 100644 --- a/src/components/middle/message/AnimatedCustomEmoji.tsx +++ b/src/components/middle/message/AnimatedCustomEmoji.tsx @@ -3,8 +3,8 @@ import React, { memo } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; import type { ApiSticker } from '../../../api/types'; -import type { ActiveEmojiInteraction } from '../../../global/types'; import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; +import type { ActiveEmojiInteraction } from '../../../types'; import { selectAnimatedEmojiEffect, diff --git a/src/components/middle/message/AnimatedEmoji.tsx b/src/components/middle/message/AnimatedEmoji.tsx index 767837a0a..6616b5237 100644 --- a/src/components/middle/message/AnimatedEmoji.tsx +++ b/src/components/middle/message/AnimatedEmoji.tsx @@ -3,8 +3,8 @@ import React, { memo } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; import type { ApiSticker } from '../../../api/types'; -import type { ActiveEmojiInteraction } from '../../../global/types'; import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; +import type { ActiveEmojiInteraction } from '../../../types'; import { selectAnimatedEmoji, diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index a03b4302c..2d1135f56 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -16,8 +16,13 @@ import type { ApiThreadInfo, ApiTypeStory, } from '../../../api/types'; -import type { ActiveDownloads, MessageListType } from '../../../global/types'; -import type { IAlbum, IAnchorPosition, ThreadId } from '../../../types'; +import type { + ActiveDownloads, + IAlbum, + IAnchorPosition, + MessageListType, + ThreadId, +} from '../../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; import { PREVIEW_AVATAR_COUNT, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index a70170a1e..975c09fd7 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -28,10 +28,16 @@ import type { ApiTypeStory, ApiUser, } from '../../../api/types'; -import type { ActiveEmojiInteraction, ChatTranslatedMessages, MessageListType } from '../../../global/types'; import type { ObserveFn } from '../../../hooks/useIntersectionObserver'; import type { - FocusDirection, IAlbum, ISettings, ScrollTargetPosition, ThreadId, + ActiveEmojiInteraction, + ChatTranslatedMessages, + FocusDirection, + IAlbum, + ISettings, + MessageListType, + ScrollTargetPosition, + ThreadId, } from '../../../types'; import type { Signal } from '../../../util/signals'; import type { OnIntersectPinnedMessage } from '../hooks/usePinnedMessage'; diff --git a/src/components/middle/message/ReadTimeMenuItem.tsx b/src/components/middle/message/ReadTimeMenuItem.tsx index 30a6b43d3..6dc90f32a 100644 --- a/src/components/middle/message/ReadTimeMenuItem.tsx +++ b/src/components/middle/message/ReadTimeMenuItem.tsx @@ -1,5 +1,5 @@ import React, { memo } from '../../../lib/teact/teact'; -import { getActions } from '../../../lib/teact/teactn'; +import { getActions } from '../../../global'; import type { ApiMessage } from '../../../api/types'; diff --git a/src/components/middle/message/hooks/useMessageTranslation.ts b/src/components/middle/message/hooks/useMessageTranslation.ts index 4a1a01f6a..e4ebf2849 100644 --- a/src/components/middle/message/hooks/useMessageTranslation.ts +++ b/src/components/middle/message/hooks/useMessageTranslation.ts @@ -1,7 +1,7 @@ import { useEffect } from '../../../../lib/teact/teact'; import { getActions } from '../../../../global'; -import type { ChatTranslatedMessages } from '../../../../global/types'; +import type { ChatTranslatedMessages } from '../../../../types'; import { throttle } from '../../../../util/schedulers'; diff --git a/src/components/middle/panes/BotAdPane.tsx b/src/components/middle/panes/BotAdPane.tsx index af54b87ad..3cf88ea07 100644 --- a/src/components/middle/panes/BotAdPane.tsx +++ b/src/components/middle/panes/BotAdPane.tsx @@ -2,7 +2,7 @@ import React, { memo, useEffect } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiSponsoredMessage } from '../../../api/types'; -import type { MessageListType } from '../../../global/types'; +import type { MessageListType } from '../../../types'; import { selectBot, selectSponsoredMessage } from '../../../global/selectors'; import buildClassName from '../../../util/buildClassName'; diff --git a/src/components/middle/panes/HeaderPinnedMessage.tsx b/src/components/middle/panes/HeaderPinnedMessage.tsx index 648b53102..3341b66e5 100644 --- a/src/components/middle/panes/HeaderPinnedMessage.tsx +++ b/src/components/middle/panes/HeaderPinnedMessage.tsx @@ -2,8 +2,7 @@ import React, { memo, useEffect } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiChat, ApiMessage, ApiPeer } from '../../../api/types'; -import type { MessageListType } from '../../../global/types'; -import type { ThreadId } from '../../../types'; +import type { MessageListType, ThreadId } from '../../../types'; import type { Signal } from '../../../util/signals'; import { MAIN_THREAD_ID } from '../../../api/types'; diff --git a/src/components/modals/gift/GiftModal.tsx b/src/components/modals/gift/GiftModal.tsx index a218e3b36..929334711 100644 --- a/src/components/modals/gift/GiftModal.tsx +++ b/src/components/modals/gift/GiftModal.tsx @@ -10,7 +10,8 @@ import type { ApiStarsAmount, ApiUser, } from '../../../api/types'; -import type { StarGiftCategory, TabState } from '../../../global/types'; +import type { TabState } from '../../../global/types'; +import type { StarGiftCategory } from '../../../types'; import { getUserFullName } from '../../../global/helpers'; import { selectUser } from '../../../global/selectors'; diff --git a/src/components/modals/gift/StarGiftCategoryList.tsx b/src/components/modals/gift/StarGiftCategoryList.tsx index 4c9616649..a26d7af57 100644 --- a/src/components/modals/gift/StarGiftCategoryList.tsx +++ b/src/components/modals/gift/StarGiftCategoryList.tsx @@ -3,7 +3,7 @@ import React, { } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; -import type { StarGiftCategory } from '../../../global/types'; +import type { StarGiftCategory } from '../../../types'; import buildClassName from '../../../util/buildClassName'; diff --git a/src/components/modals/webApp/MinimizedWebAppModal.tsx b/src/components/modals/webApp/MinimizedWebAppModal.tsx index 2e1df861e..f87d83faa 100644 --- a/src/components/modals/webApp/MinimizedWebAppModal.tsx +++ b/src/components/modals/webApp/MinimizedWebAppModal.tsx @@ -5,7 +5,7 @@ import React, { import { getActions, getGlobal, withGlobal } from '../../../global'; import type { ApiUser } from '../../../api/types'; -import type { WebApp } from '../../../global/types'; +import type { WebApp } from '../../../types/webapp'; import { selectActiveWebApp, selectTabState, selectUser } from '../../../global/selectors'; import buildClassName from '../../../util/buildClassName'; diff --git a/src/components/modals/webApp/WebAppModal.tsx b/src/components/modals/webApp/WebAppModal.tsx index 7ba45b684..976762d86 100644 --- a/src/components/modals/webApp/WebAppModal.tsx +++ b/src/components/modals/webApp/WebAppModal.tsx @@ -8,9 +8,9 @@ import React, { import { getActions, getGlobal, withGlobal } from '../../../global'; import type { ApiAttachBot, ApiChat, ApiUser } from '../../../api/types'; -import type { TabState, WebApp } from '../../../global/types'; +import type { TabState } from '../../../global/types'; import type { ThemeKey } from '../../../types'; -import type { WebAppOutboundEvent } from '../../../types/webapp'; +import type { WebApp, WebAppOutboundEvent } from '../../../types/webapp'; import { RESIZE_HANDLE_CLASS_NAME } from '../../../config'; import { getWebAppKey } from '../../../global/helpers/bots'; diff --git a/src/components/modals/webApp/WebAppModalTabContent.tsx b/src/components/modals/webApp/WebAppModalTabContent.tsx index 1f231d33a..c3886f16e 100644 --- a/src/components/modals/webApp/WebAppModalTabContent.tsx +++ b/src/components/modals/webApp/WebAppModalTabContent.tsx @@ -9,9 +9,11 @@ import { getActions, withGlobal } from '../../../global'; import type { ApiAttachBot, ApiBotAppSettings, ApiChat, ApiUser, } from '../../../api/types'; -import type { TabState, WebApp, WebAppModalStateType } from '../../../global/types'; +import type { TabState } from '../../../global/types'; import type { ThemeKey } from '../../../types'; -import type { PopupOptions, WebAppInboundEvent, WebAppOutboundEvent } from '../../../types/webapp'; +import type { + PopupOptions, WebApp, WebAppInboundEvent, WebAppModalStateType, WebAppOutboundEvent, +} from '../../../types/webapp'; import { TME_LINK_PREFIX } from '../../../config'; import { convertToApiChatType } from '../../../global/helpers'; diff --git a/src/components/modals/webApp/hooks/useWebAppFrame.ts b/src/components/modals/webApp/hooks/useWebAppFrame.ts index bdb2f8128..c17fe2d43 100644 --- a/src/components/modals/webApp/hooks/useWebAppFrame.ts +++ b/src/components/modals/webApp/hooks/useWebAppFrame.ts @@ -2,8 +2,7 @@ import { useCallback, useEffect, useRef } from '../../../../lib/teact/teact'; import { getActions } from '../../../../global'; -import type { WebApp } from '../../../../global/types'; -import type { WebAppInboundEvent, WebAppOutboundEvent } from '../../../../types/webapp'; +import type { WebApp, WebAppInboundEvent, WebAppOutboundEvent } from '../../../../types/webapp'; import { getWebAppKey } from '../../../../global/helpers'; import { extractCurrentThemeParams } from '../../../../util/themeStyle'; diff --git a/src/components/right/GifSearch.tsx b/src/components/right/GifSearch.tsx index 2320749d6..ac15f77ad 100644 --- a/src/components/right/GifSearch.tsx +++ b/src/components/right/GifSearch.tsx @@ -3,7 +3,7 @@ import React, { memo, useCallback, useRef } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import type { ApiChat, ApiChatFullInfo, ApiVideo } from '../../api/types'; -import type { MessageList } from '../../global/types'; +import type { MessageList } from '../../types'; import { getAllowedAttachmentOptions, getCanPostInChat } from '../../global/helpers'; import { diff --git a/src/components/story/Story.tsx b/src/components/story/Story.tsx index 0571a47a3..7cc627dcf 100644 --- a/src/components/story/Story.tsx +++ b/src/components/story/Story.tsx @@ -9,7 +9,7 @@ import type { ApiMediaAreaChannelPost, ApiPeer, ApiStealthMode, ApiStory, ApiTypeStory, } from '../../api/types'; -import type { IDimensions } from '../../global/types'; +import type { IDimensions } from '../../types'; import type { Signal } from '../../util/signals'; import { MAIN_THREAD_ID } from '../../api/types'; diff --git a/src/components/story/StorySettings.tsx b/src/components/story/StorySettings.tsx index dfcc52a3a..5cd754987 100644 --- a/src/components/story/StorySettings.tsx +++ b/src/components/story/StorySettings.tsx @@ -3,8 +3,9 @@ import React, { } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { ApiStory, ApiUser } from '../../api/types'; -import type { ApiPrivacySettings, PrivacyVisibility } from '../../types'; +import type { + ApiPrivacySettings, ApiStory, ApiUser, PrivacyVisibility, +} from '../../api/types'; import type { IconName } from '../../types/icons'; import { getSenderTitle, getUserFullName } from '../../global/helpers'; diff --git a/src/components/story/helpers/dimensions.ts b/src/components/story/helpers/dimensions.ts index ec7ab7808..47d3463c1 100644 --- a/src/components/story/helpers/dimensions.ts +++ b/src/components/story/helpers/dimensions.ts @@ -1,4 +1,4 @@ -import type { IDimensions } from '../../../global/types'; +import type { IDimensions } from '../../../types'; import { roundToNearestEven } from '../../../util/math'; diff --git a/src/components/story/helpers/ghostAnimation.ts b/src/components/story/helpers/ghostAnimation.ts index 53d2dd4c5..6b454d36b 100644 --- a/src/components/story/helpers/ghostAnimation.ts +++ b/src/components/story/helpers/ghostAnimation.ts @@ -1,4 +1,4 @@ -import type { IDimensions } from '../../../global/types'; +import type { IDimensions } from '../../../types'; import { StoryViewerOrigin } from '../../../types'; import { ANIMATION_END_DELAY } from '../../../config'; diff --git a/src/config.ts b/src/config.ts index bcadeec26..089d9b52e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ -import type { ApiReactionEmoji } from './api/types'; -import type { ApiLimitType, ApiLimitTypeForPromo, ApiPremiumSection } from './global/types'; +import type { + ApiLimitType, ApiLimitTypeForPromo, ApiPremiumSection, ApiReactionEmoji, +} from './api/types'; export const APP_CODE_NAME = 'A'; export const APP_NAME = process.env.APP_NAME || `Telegram Web ${APP_CODE_NAME}`; diff --git a/src/global/actions/api/bots.ts b/src/global/actions/api/bots.ts index e439904b4..d9aec5e84 100644 --- a/src/global/actions/api/bots.ts +++ b/src/global/actions/api/bots.ts @@ -1,10 +1,15 @@ import type { InlineBotSettings } from '../../../types'; +import type { WebApp } from '../../../types/webapp'; import type { RequiredGlobalActions } from '../../index'; import type { - ActionReturnType, GlobalState, TabArgs, WebApp, + ActionReturnType, GlobalState, TabArgs, } from '../../types'; import { - type ApiChat, type ApiContact, type ApiInputMessageReplyInfo, type ApiPeer, type ApiUrlAuthResult, + type ApiChat, + type ApiContact, + type ApiInputMessageReplyInfo, + type ApiPeer, + type ApiUrlAuthResult, MAIN_THREAD_ID, } from '../../../api/types'; import { ManagementProgress } from '../../../types'; diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 1ffbbe6c2..7448d1137 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -4,12 +4,12 @@ import type { } from '../../../api/types'; import type { RequiredGlobalActions } from '../../index'; import type { - ActionReturnType, - ChatListType, GlobalState, TabArgs, + ActionReturnType, GlobalState, TabArgs, } from '../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; import { ChatCreationProgress, + type ChatListType, ManagementProgress, NewChatMembersProgress, SettingsScreens, diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index 9d6bb0536..6397bccf9 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -1,6 +1,7 @@ import type { ApiAttachment, ApiChat, + ApiDraft, ApiError, ApiInputMessageReplyInfo, ApiInputReplyInfo, @@ -19,10 +20,10 @@ import type { import type { MessageKey } from '../../../util/keys/messageKey'; import type { RequiredGlobalActions } from '../../index'; import type { - ActionReturnType, ApiDraft, GlobalState, TabArgs, WebPageMediaSize, + ActionReturnType, GlobalState, TabArgs, } from '../../types'; import { MAIN_THREAD_ID, MESSAGE_DELETED } from '../../../api/types'; -import { LoadMoreDirection, type ThreadId } from '../../../types'; +import { LoadMoreDirection, type ThreadId, type WebPageMediaSize } from '../../../types'; import { GIF_MIME_TYPE, diff --git a/src/global/actions/api/settings.ts b/src/global/actions/api/settings.ts index 8648b1dd4..0c96e7b3e 100644 --- a/src/global/actions/api/settings.ts +++ b/src/global/actions/api/settings.ts @@ -1,7 +1,4 @@ -import type { ApiUsername } from '../../../api/types'; -import type { - ApiPrivacySettings, -} from '../../../types'; +import type { ApiPrivacySettings, ApiUsername } from '../../../api/types'; import type { ActionReturnType } from '../../types'; import { ProfileEditProgress, diff --git a/src/global/actions/api/stars.ts b/src/global/actions/api/stars.ts index b8f4c3341..a868a4034 100644 --- a/src/global/actions/api/stars.ts +++ b/src/global/actions/api/stars.ts @@ -1,6 +1,4 @@ -import type { - StarGiftCategory, -} from '../../types'; +import type { StarGiftCategory } from '../../../types'; import { getCurrentTabId } from '../../../util/establishMultitabRole'; import { buildCollectionByKey } from '../../../util/iteratees'; diff --git a/src/global/actions/api/sync.ts b/src/global/actions/api/sync.ts index 4edc70a30..f1613601a 100644 --- a/src/global/actions/api/sync.ts +++ b/src/global/actions/api/sync.ts @@ -1,8 +1,8 @@ import { addCallback } from '../../../lib/teact/teactn'; -import type { ThreadId } from '../../../types'; +import type { Thread, ThreadId } from '../../../types'; import type { RequiredGlobalActions } from '../../index'; -import type { ActionReturnType, GlobalState, Thread } from '../../types'; +import type { ActionReturnType, GlobalState } from '../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; import { DEBUG, MESSAGE_LIST_SLICE, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; diff --git a/src/global/actions/apiUpdaters/messages.ts b/src/global/actions/apiUpdaters/messages.ts index bf2df6e20..bc8162730 100644 --- a/src/global/actions/apiUpdaters/messages.ts +++ b/src/global/actions/apiUpdaters/messages.ts @@ -2,10 +2,10 @@ import type { ApiChat, ApiMediaExtendedPreview, ApiMessage, ApiReactions, MediaContent, } from '../../../api/types'; -import type { ThreadId } from '../../../types'; +import type { ActiveEmojiInteraction, ThreadId } from '../../../types'; import type { RequiredGlobalActions } from '../../index'; import type { - ActionReturnType, ActiveEmojiInteraction, GlobalState, RequiredGlobalState, + ActionReturnType, GlobalState, RequiredGlobalState, } from '../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; diff --git a/src/global/actions/ui/calls.ts b/src/global/actions/ui/calls.ts index 1067bdea4..aca27b4e8 100644 --- a/src/global/actions/ui/calls.ts +++ b/src/global/actions/ui/calls.ts @@ -1,7 +1,8 @@ import type { ApiGroupCall } from '../../../api/types'; +import type { CallSound } from '../../../types'; import type { RequiredGlobalActions } from '../../index'; import type { - ActionReturnType, CallSound, GlobalState, TabArgs, + ActionReturnType, GlobalState, TabArgs, } from '../../types'; import { requestNextMutation } from '../../../lib/fasterdom/fasterdom'; diff --git a/src/global/actions/ui/messages.ts b/src/global/actions/ui/messages.ts index 4209634c0..6c9d84b00 100644 --- a/src/global/actions/ui/messages.ts +++ b/src/global/actions/ui/messages.ts @@ -1,11 +1,10 @@ import type { ApiMessage } from '../../../api/types'; import type { ActionReturnType, - ActiveDownloads, GlobalState, } from '../../types'; import { MAIN_THREAD_ID } from '../../../api/types'; -import { FocusDirection } from '../../../types'; +import { type ActiveDownloads, FocusDirection } from '../../../types'; import { ANIMATION_END_DELAY, diff --git a/src/global/cache.ts b/src/global/cache.ts index 479ffc9c9..f0285cbf8 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -3,8 +3,8 @@ import { getIsHeavyAnimating, onFullyIdle } from '../lib/teact/teact'; import { addCallback, removeCallback } from '../lib/teact/teactn'; import type { ApiAvailableReaction, ApiMessage } from '../api/types'; -import type { ThreadId } from '../types'; -import type { ActionReturnType, GlobalState, MessageList } from './types'; +import type { MessageList, ThreadId } from '../types'; +import type { ActionReturnType, GlobalState } from './types'; import { MAIN_THREAD_ID } from '../api/types'; import { diff --git a/src/global/helpers/bots.ts b/src/global/helpers/bots.ts index 2140ba834..fe0556e8a 100644 --- a/src/global/helpers/bots.ts +++ b/src/global/helpers/bots.ts @@ -1,7 +1,5 @@ import type { ApiChatType, ApiPhoto } from '../../api/types'; -import type { - WebApp, -} from '../types'; +import type { WebApp } from '../../types/webapp'; import { REPLIES_USER_ID, VERIFICATION_CODES_USER_ID } from '../../config'; diff --git a/src/global/helpers/messageMedia.ts b/src/global/helpers/messageMedia.ts index b18426256..c1efde5f9 100644 --- a/src/global/helpers/messageMedia.ts +++ b/src/global/helpers/messageMedia.ts @@ -15,7 +15,7 @@ import type { ApiWebDocument, MediaContainer, } from '../../api/types'; -import type { ActiveDownloads } from '../types'; +import type { ActiveDownloads } from '../../types'; import { ApiMediaFormat } from '../../api/types'; import { diff --git a/src/global/helpers/misc.ts b/src/global/helpers/misc.ts index 4738ceaf8..b1195f135 100644 --- a/src/global/helpers/misc.ts +++ b/src/global/helpers/misc.ts @@ -1,4 +1,4 @@ -import type { ApiInputPrivacyRules, BotsPrivacyType, PrivacyVisibility } from '../../types'; +import type { ApiInputPrivacyRules, BotsPrivacyType, PrivacyVisibility } from '../../api/types'; import type { GlobalState } from '../types'; import { partition } from '../../util/iteratees'; diff --git a/src/global/reducers/bots.ts b/src/global/reducers/bots.ts index a85a3e5e4..0aeae888f 100644 --- a/src/global/reducers/bots.ts +++ b/src/global/reducers/bots.ts @@ -1,6 +1,7 @@ import type { InlineBotSettings } from '../../types'; +import type { WebApp, WebAppModalStateType } from '../../types/webapp'; import type { - GlobalState, TabArgs, WebApp, WebAppModalStateType, + GlobalState, TabArgs, } from '../types'; import { getCurrentTabId } from '../../util/establishMultitabRole'; diff --git a/src/global/reducers/chats.ts b/src/global/reducers/chats.ts index 52c99a093..3e10c4cb0 100644 --- a/src/global/reducers/chats.ts +++ b/src/global/reducers/chats.ts @@ -1,7 +1,8 @@ import type { ApiChat, ApiChatFullInfo, ApiChatMember, } from '../../api/types'; -import type { ChatListType, GlobalState } from '../types'; +import type { ChatListType } from '../../types'; +import type { GlobalState } from '../types'; import { ARCHIVED_FOLDER_ID } from '../../config'; import { areDeepEqual } from '../../util/areDeepEqual'; diff --git a/src/global/reducers/messages.ts b/src/global/reducers/messages.ts index 04d6130fc..c7cd42fc6 100644 --- a/src/global/reducers/messages.ts +++ b/src/global/reducers/messages.ts @@ -1,9 +1,17 @@ import type { ApiMessage, ApiPoll, ApiPollResult, ApiQuickReply, ApiSponsoredMessage, ApiThreadInfo, } from '../../api/types'; -import type { FocusDirection, ScrollTargetPosition, ThreadId } from '../../types'; import type { - GlobalState, MessageList, MessageListType, TabArgs, TabState, TabThread, Thread, + FocusDirection, + MessageList, + MessageListType, + ScrollTargetPosition, + TabThread, + Thread, + ThreadId, +} from '../../types'; +import type { + GlobalState, TabArgs, TabState, } from '../types'; import { MAIN_THREAD_ID } from '../../api/types'; diff --git a/src/global/reducers/payments.ts b/src/global/reducers/payments.ts index 26808a3b9..07889819a 100644 --- a/src/global/reducers/payments.ts +++ b/src/global/reducers/payments.ts @@ -5,9 +5,14 @@ import type { ApiStarsSubscription, ApiStarsTransaction, } from '../../api/types'; -import type { PaymentStep, ShippingOption } from '../../types'; import type { - GlobalState, StarsSubscriptions, StarsTransactionType, TabArgs, TabState, + PaymentStep, + ShippingOption, + StarsSubscriptions, + StarsTransactionType, +} from '../../types'; +import type { + GlobalState, TabArgs, TabState, } from '../types'; import { getCurrentTabId } from '../../util/establishMultitabRole'; diff --git a/src/global/reducers/topics.ts b/src/global/reducers/topics.ts index 21f8ede40..04cbaa5e0 100644 --- a/src/global/reducers/topics.ts +++ b/src/global/reducers/topics.ts @@ -1,5 +1,6 @@ import type { ApiTopic } from '../../api/types'; -import type { GlobalState, TopicsInfo } from '../types'; +import type { TopicsInfo } from '../../types'; +import type { GlobalState } from '../types'; import { buildCollectionByKey, omit, unique } from '../../util/iteratees'; import { diff --git a/src/global/reducers/translations.ts b/src/global/reducers/translations.ts index 9bd86e631..626df88e8 100644 --- a/src/global/reducers/translations.ts +++ b/src/global/reducers/translations.ts @@ -1,5 +1,6 @@ import type { ApiFormattedText } from '../../api/types'; -import type { GlobalState, TabArgs, TranslatedMessage } from '../types'; +import type { TranslatedMessage } from '../../types'; +import type { GlobalState, TabArgs } from '../types'; import { getCurrentTabId } from '../../util/establishMultitabRole'; import { omit } from '../../util/iteratees'; diff --git a/src/global/selectors/chats.ts b/src/global/selectors/chats.ts index a06513eeb..0ee2beac9 100644 --- a/src/global/selectors/chats.ts +++ b/src/global/selectors/chats.ts @@ -1,7 +1,8 @@ import type { ApiChat, ApiChatFullInfo, ApiChatType, } from '../../api/types'; -import type { ChatListType, GlobalState, TabArgs } from '../types'; +import type { ChatListType } from '../../types'; +import type { GlobalState, TabArgs } from '../types'; import { ALL_FOLDER_ID, ARCHIVED_FOLDER_ID, MEMBERS_LOAD_SLICE, SAVED_FOLDER_ID, SERVICE_NOTIFICATIONS_USER_ID, diff --git a/src/global/selectors/limits.ts b/src/global/selectors/limits.ts index 5fe6e0248..27238d4f0 100644 --- a/src/global/selectors/limits.ts +++ b/src/global/selectors/limits.ts @@ -1,4 +1,5 @@ -import type { ApiLimitType, GlobalState } from '../types'; +import type { ApiLimitType } from '../../api/types'; +import type { GlobalState } from '../types'; import { DEFAULT_LIMITS } from '../../config'; import { selectIsCurrentUserPremium } from './users'; diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index fcc70094e..d00b92aa5 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -8,10 +8,16 @@ import type { ApiPeer, ApiSponsoredMessage, ApiStickerSetInfo, } from '../../api/types'; -import type { ThreadId } from '../../types'; +import type { + ChatTranslatedMessages, + MessageListType, + TabThread, + Thread, + ThreadId, +} from '../../types'; import type { IAllowedAttachmentOptions } from '../helpers'; import type { - ChatTranslatedMessages, GlobalState, MessageListType, TabArgs, TabThread, Thread, + GlobalState, TabArgs, } from '../types'; import { ApiMessageEntityTypes, MAIN_THREAD_ID } from '../../api/types'; diff --git a/src/global/selectors/topics.ts b/src/global/selectors/topics.ts index 0b8ec77a2..28ff3979e 100644 --- a/src/global/selectors/topics.ts +++ b/src/global/selectors/topics.ts @@ -1,5 +1,5 @@ -import type { ThreadId } from '../../types'; -import type { GlobalState, TopicsInfo } from '../types'; +import type { ThreadId, TopicsInfo } from '../../types'; +import type { GlobalState } from '../types'; export function selectTopicsInfo(global: T, chatId: string): TopicsInfo | undefined { return global.chats.topicsInfoById[chatId]; diff --git a/src/global/types.ts b/src/global/types/actions.ts similarity index 66% rename from src/global/types.ts rename to src/global/types/actions.ts index b49c222c1..6c6ac9802 100644 --- a/src/global/types.ts +++ b/src/global/types/actions.ts @@ -1,1350 +1,95 @@ import type { - ApiAppConfig, ApiAttachBot, ApiAttachment, - ApiAvailableEffect, - ApiAvailableReaction, - ApiBoost, - ApiBoostsStatus, - ApiBotPreviewMedia, - ApiChannelMonetizationStatistics, - ApiChannelStatistics, ApiChat, ApiChatAdminRights, ApiChatBannedRights, ApiChatFolder, - ApiChatFullInfo, - ApiChatInviteInfo, - ApiChatlistExportedInvite, ApiChatlistInvite, ApiChatReactions, ApiChatType, - ApiCheckedGiftCode, - ApiCollectionInfo, - ApiConfig, ApiContact, - ApiCountry, - ApiCountryCode, - ApiError, + ApiDraft, ApiExportedInvite, ApiFormattedText, ApiGeoPoint, ApiGlobalMessageSearchType, - ApiGroupCall, - ApiGroupStatistics, ApiInputInvoice, ApiInputInvoiceStarGift, ApiInputMessageReplyInfo, ApiKeyboardButton, - ApiLanguage, - ApiMediaFormat, + ApiLimitTypeWithModal, ApiMessage, ApiMessageEntity, - ApiMissingInvitedUser, - ApiMyBoost, ApiNewPoll, ApiNotification, - ApiPaymentFormRegular, - ApiPaymentFormStars, - ApiPeerColors, - ApiPeerPhotos, - ApiPeerStories, - ApiPhoneCall, + ApiPaymentStatus, ApiPhoto, - ApiPoll, - ApiPostStatistics, - ApiPremiumGiftCodeOption, - ApiPremiumPromo, - ApiQuickReply, + ApiPremiumSection, + ApiPrivacyKey, + ApiPrivacySettings, ApiReaction, - ApiReactionKey, ApiReactionWithPaid, - ApiReceiptRegular, ApiReportReason, - ApiSavedReactionTag, ApiSendMessageAction, - ApiSession, ApiSessionData, - ApiSponsoredMessage, ApiStarGift, - ApiStarGiveawayOption, - ApiStarsAmount, ApiStarsSubscription, ApiStarsTransaction, - ApiStarTopupOption, - ApiStealthMode, ApiSticker, ApiStickerSet, ApiStickerSetInfo, ApiThemeParameters, - ApiThreadInfo, - ApiTimezone, - ApiTopic, - ApiTranscription, ApiTypePrepaidGiveaway, - ApiTypeStoryView, - ApiTypingStatus, ApiUpdate, - ApiUpdateAuthorizationStateType, - ApiUpdateConnectionStateType, ApiUser, - ApiUserCommonChats, - ApiUserFullInfo, - ApiUserGifts, ApiUserStarGift, - ApiUserStatus, ApiVideo, - ApiWallpaper, - ApiWebPage, - ApiWebSession, -} from '../api/types'; -import type { ApiCredentials } from '../components/payment/PaymentModal'; -import type { PREMIUM_FEATURE_SECTIONS } from '../config'; -import type { FoldersActions } from '../hooks/reducers/useFoldersReducer'; -import type { ReducerAction } from '../hooks/useReducer'; -import type { P2pMessage } from '../lib/secret-sauce'; -import type { - ApiPrivacyKey, - ApiPrivacySettings, - AudioOrigin, BotsPrivacyType, - ChatCreationProgress, - ChatMediaSearchParams, - EmojiKeywords, - FocusDirection, + PrivacyVisibility, +} from '../../api/types'; +import type { ApiCredentials } from '../../components/payment/PaymentModal'; +import type { FoldersActions } from '../../hooks/reducers/useFoldersReducer'; +import type { ReducerAction } from '../../hooks/useReducer'; +import type { P2pMessage } from '../../lib/secret-sauce'; +import type { + AudioOrigin, + CallSound, + ChatListType, + ConfettiParams, GlobalSearchContent, IAlbum, IAnchorPosition, - InlineBotSettings, ISettings, IThemeSettings, LoadMoreDirection, - ManagementProgress, ManagementScreens, - ManagementState, MediaViewerMedia, MediaViewerOrigin, + MessageList, + MessageListType, MiddleSearchParams, NewChatMembersProgress, - NotifyException, PaymentStep, PerformanceType, - PrivacyVisibility, - ProfileEditProgress, ProfileTabType, ScrollTargetPosition, SettingsScreens, SharedMediaType, - ShippingOption, + StarGiftInfo, + StarsTransactionType, StoryViewerOrigin, ThemeKey, ThreadId, -} from '../types'; -import type { WebAppOutboundEvent } from '../types/webapp'; -import type { SearchResultKey } from '../util/keys/searchResultKey'; -import type { DownloadableMedia } from './helpers'; - -export type MessageListType = - 'thread' - | 'pinned' - | 'scheduled'; - -export type ChatListType = 'active' | 'archived' | 'saved'; - -export type WebAppModalStateType = 'fullScreen' | 'maximized' | 'minimized'; - -export interface MessageList { - chatId: string; - threadId: ThreadId; - type: MessageListType; -} - -export interface ActiveEmojiInteraction { - id: number; - x: number; - y: number; - messageId?: number; - startSize?: number; - animatedEffect?: string; - isReversed?: boolean; -} - -export type ActiveDownloads = Record; - -export type IDimensions = { - width: number; - height: number; -}; - -export type ApiPaymentStatus = 'paid' | 'failed' | 'pending' | 'cancelled'; - -export type StarsTransactionType = 'all' | 'inbound' | 'outbound'; -export type StarsTransactionHistory = Record; -export type StarsSubscriptions = { - list: ApiStarsSubscription[]; - nextOffset?: string; - isLoading?: boolean; -}; - -export type ConfettiStyle = 'poppers' | 'top-down'; - -export type StarGiftInfo = { - userId: string; - gift: ApiStarGift; - shouldHideName?: boolean; - message?: ApiFormattedText; -}; - -export interface TabThread { - scrollOffset?: number; - replyStack?: number[]; - viewportIds?: number[]; -} - -export interface Thread { - lastScrollOffset?: number; - lastViewportIds?: number[]; - listedIds?: number[]; - outlyingLists?: number[][]; - pinnedIds?: number[]; - scheduledIds?: number[]; - editingId?: number; - editingScheduledId?: number; - editingDraft?: ApiFormattedText; - editingScheduledDraft?: ApiFormattedText; - draft?: ApiDraft; - noWebPage?: boolean; - threadInfo?: ApiThreadInfo; - firstMessageId?: number; - typingStatus?: ApiTypingStatus; -} - -export interface ServiceNotification { - id: number; - message: ApiMessage; - version?: string; - isUnread?: boolean; - isDeleted?: boolean; -} - -export interface TopicsInfo { - totalCount: number; - topicsById: Record; - listedTopicIds?: number[]; - orderedPinnedTopicIds?: number[]; -} - -export type ApiLimitType = - | 'uploadMaxFileparts' - | 'stickersFaved' - | 'savedGifs' - | 'dialogFiltersChats' - | 'dialogFilters' - | 'dialogFolderPinned' - | 'captionLength' - | 'channels' - | 'channelsPublic' - | 'aboutLength' - | 'chatlistInvites' - | 'chatlistJoined' - | 'recommendedChannels' - | 'savedDialogsPinned'; - -export type ApiLimitTypeWithModal = Exclude; - -export type ApiLimitTypeForPromo = Exclude; - -export type ApiPremiumSection = typeof PREMIUM_FEATURE_SECTIONS[number]; - -export type TranslatedMessage = { - isPending?: boolean; - text?: ApiFormattedText; -}; - -export type ChatTranslatedMessages = { - byLangCode: Record>; -}; - -export type ChatRequestedTranslations = { - toLanguage?: string; - manualMessages?: Record; -}; - -type ConfettiParams = OptionalCombine<{ - style?: ConfettiStyle; - withStars?: boolean; -}, { - top?: number; - left?: number; - width?: number; - height?: number; -}>; - -export type WebPageMediaSize = 'large' | 'small'; - -export type TabState = { - id: number; - isBlurred?: boolean; - isMasterTab: boolean; - isInactive?: boolean; - shouldPreventComposerAnimation?: boolean; - inviteHash?: string; - canInstall?: boolean; - isChatInfoShown: boolean; - isStatisticsShown?: boolean; - isLeftColumnShown: boolean; - newChatMembersProgress?: NewChatMembersProgress; - uiReadyState: 0 | 1 | 2; - shouldInit: boolean; - shouldSkipHistoryAnimations?: boolean; - - gifSearch: { - query?: string; - offset?: string; - results?: ApiVideo[]; - }; - - stickerSearch: { - query?: string; - hash?: string; - resultIds?: string[]; - }; - - shouldCloseRightColumn?: boolean; - nextProfileTab?: ProfileTabType; - forceScrollProfileTab?: boolean; - nextSettingsScreen?: SettingsScreens; - nextFoldersAction?: ReducerAction; - shareFolderScreen?: { - folderId: number; - isFromSettings?: boolean; - url?: string; - isLoading?: boolean; - }; - - isCallPanelVisible?: boolean; - multitabNextAction?: CallbackAction; - ratingPhoneCall?: ApiPhoneCall; - - messageLists: MessageList[]; - - contentToBeScheduled?: { - gif?: ApiVideo; - sticker?: ApiSticker; - poll?: ApiNewPoll; - isSilent?: boolean; - sendGrouped?: boolean; - sendCompressed?: boolean; - isInvertedMedia?: true; - }; - - activeChatFolder: number; - tabThreads: Record>; - forumPanelChatId?: string; - - focusedMessage?: { - chatId?: string; - threadId?: ThreadId; - messageId?: number; - direction?: FocusDirection; - noHighlight?: boolean; - isResizingContainer?: boolean; - quote?: string; - scrollTargetPosition?: ScrollTargetPosition; - }; - - selectedMessages?: { - chatId: string; - messageIds: number[]; - }; - - chatInviteModal?: { - hash: string; - inviteInfo: ApiChatInviteInfo; - }; - - seenByModal?: { - chatId: string; - messageId: number; - }; - - privacySettingsNoticeModal?: { - chatId: string; - isReadDate: boolean; - }; - - reactorModal?: { - chatId: string; - messageId: number; - }; - - aboutAdsModal?: { - chatId: string; - }; - - reactionPicker?: { - chatId?: string; - messageId?: number; - storyPeerId?: string; - storyId?: number; - position?: IAnchorPosition; - sendAsMessage?: boolean; - isForEffects?: boolean; - }; - - shouldPlayEffectInComposer?: true; - - inlineBots: { - isLoading: boolean; - byUsername: Record; - }; - - globalSearch: { - query?: string; - minDate?: number; - maxDate?: number; - currentContent?: GlobalSearchContent; - chatId?: string; - foundTopicIds?: number[]; - fetchingStatus?: { - chats?: boolean; - messages?: boolean; - botApps?: boolean; - }; - isClosing?: boolean; - localResults?: { - peerIds?: string[]; - }; - globalResults?: { - peerIds?: string[]; - }; - popularBotApps?: { - peerIds: string[]; - nextOffset?: string; - }; - resultsByType?: Partial>; - }; - - userSearch: { - query?: string; - fetchingStatus?: boolean; - localUserIds?: string[]; - globalUserIds?: string[]; - }; - - activeEmojiInteractions?: ActiveEmojiInteraction[]; - activeReactions: Record; - - middleSearch: { - byChatThreadKey: Record; - }; - - sharedMediaSearch: { - byChatThreadKey: Record>; - }>; - }; - - chatMediaSearch: { - byChatThreadKey: Record; - }; - - management: { - progress?: ManagementProgress; - byChatId: Record; - }; - - storyViewer: { - isRibbonShown?: boolean; - isArchivedRibbonShown?: boolean; - peerId?: string; - storyId?: number; - isMuted: boolean; - isSinglePeer?: boolean; - isSingleStory?: boolean; - isPrivate?: boolean; - isArchive?: boolean; - // Last viewed story id in current view session. - // Used for better switch animation between peers. - lastViewedByPeerIds?: Record; - isPrivacyModalOpen?: boolean; - isStealthModalOpen?: boolean; - viewModal?: { - storyId: number; - views?: ApiTypeStoryView[]; - nextOffset?: string; - isLoading?: boolean; - }; - origin?: StoryViewerOrigin; - // Copy of story list for current view session - storyList?: { - peerIds: string[]; - storyIdsByPeerId: Record; - }; - }; - - mediaViewer: { - chatId?: string; - threadId?: ThreadId; - messageId?: number; - withDynamicLoading?: boolean; - mediaIndex?: number; - isAvatarView?: boolean; - isSponsoredMessage?: boolean; - standaloneMedia?: MediaViewerMedia[]; - origin?: MediaViewerOrigin; - volume: number; - playbackRate: number; - isMuted: boolean; - isHidden?: boolean; - }; - - audioPlayer: { - chatId?: string; - messageId?: number; - threadId?: ThreadId; - origin?: AudioOrigin; - volume: number; - playbackRate: number; - isPlaybackRateActive?: boolean; - isMuted: boolean; - }; - - webPagePreview?: ApiWebPage; - - loadingThread?: { - loadingChatId: string; - loadingMessageId: number; - }; - - isShareMessageModalShown?: boolean; - - replyingMessage: { - fromChatId?: string; - messageId?: number; - quoteText?: ApiFormattedText; - toChatId?: string; - toThreadId?: ThreadId; - }; - - forwardMessages: { - fromChatId?: string; - messageIds?: number[]; - storyId?: number; - toChatId?: string; - toThreadId?: ThreadId; - withMyScore?: boolean; - noAuthors?: boolean; - noCaptions?: boolean; - }; - - pollResults: { - chatId?: string; - messageId?: number; - voters?: Record; // TODO Rename to `voterIds` - offsets?: Record; - }; - - isPaymentFormLoading?: boolean; - payment: { - inputInvoice?: ApiInputInvoice; - step?: PaymentStep; - status?: ApiPaymentStatus; - shippingOptions?: ShippingOption[]; - requestId?: string; - form?: ApiPaymentFormRegular; - stripeCredentials?: { - type: string; - id: string; - }; - smartGlocalCredentials?: { - type: string; - token: string; - }; - receipt?: ApiReceiptRegular; - error?: { - field?: string; - message?: string; - description?: string; - }; - isPaymentModalOpen?: boolean; - isExtendedMedia?: boolean; - confirmPaymentUrl?: string; - temporaryPassword?: { - value: string; - validUntil: number; - }; - url?: string; - botId?: string; - }; - starsPayment: { - form?: ApiPaymentFormStars; - subscriptionInfo?: ApiChatInviteInfo; - inputInvoice?: ApiInputInvoice; - status?: ApiPaymentStatus; - }; - - chatCreation?: { - progress: ChatCreationProgress; - error?: string; - }; - - profileEdit?: { - progress: ProfileEditProgress; - checkedUsername?: string; - isUsernameAvailable?: boolean; - error?: string; - }; - - notifications: ApiNotification[]; - dialogs: (ApiError | ApiContact)[]; - - safeLinkModalUrl?: string; - mapModal?: { - point: ApiGeoPoint; - zoom?: number; - }; - historyCalendarSelectedAt?: number; - openedStickerSetShortName?: string; - openedCustomEmojiSetIds?: string[]; - - reportAdModal?: { - chatId: string; - randomId: string; - sections: { - title: string; - subtitle?: string; - options: { - text: string; - option: string; - }[]; - }[]; - }; - - reportModal?: { - chatId?: string; - messageIds: number[]; - description: string; - peerId?: string; - subject: 'story' | 'message'; - sections: { - title?: string; - subtitle?: string; - options?: { - text: string; - option: string; - }[]; - isOptional?: boolean; - option?: string; - }[]; - }; - - activeDownloads: ActiveDownloads; - - statistics: { - byChatId: Record; - currentMessage?: ApiPostStatistics; - currentMessageId?: number; - currentStory?: ApiPostStatistics; - currentStoryId?: number; - monetization?: ApiChannelMonetizationStatistics; - }; - - newContact?: { - userId?: string; - isByPhoneNumber?: boolean; - }; - - openedGame?: { - url: string; - chatId: string; - messageId: number; - }; - - requestedDraft?: { - chatId?: string; - text: ApiFormattedText; - files?: File[]; - filter?: ApiChatType[]; - }; - - pollModal: { - isOpen: boolean; - isQuiz?: boolean; - }; - - webApps: { - activeWebAppKey?: string; - openedOrderedKeys: string[]; - sessionKeys: string[]; - openedWebApps: Record; - modalState : WebAppModalStateType; - isModalOpen: boolean; - isMoreAppsTabActive: boolean; - }; - - botTrustRequest?: { - botId: string; - type: 'game' | 'webApp' | 'botApp'; - shouldRequestWriteAccess?: boolean; - onConfirm?: CallbackAction; - }; - requestedAttachBotInstall?: { - bot: ApiAttachBot; - onConfirm?: CallbackAction; - }; - requestedAttachBotInChat?: { - bot: ApiAttachBot; - filter: ApiChatType[]; - startParam?: string; - }; - - confetti?: { - lastConfettiTime?: number; - top?: number; - left?: number; - width?: number; - height?: number; - style?: ConfettiStyle; - withStars?: boolean; - }; - wave?: { - lastWaveTime: number; - startX: number; - startY: number; - }; - - urlAuth?: { - button?: { - chatId: string; - messageId: number; - buttonId: number; - }; - request?: { - domain: string; - botId: string; - shouldRequestWriteAccess?: boolean; - }; - url: string; - }; - - premiumModal?: { - isOpen?: boolean; - promo: ApiPremiumPromo; - initialSection?: ApiPremiumSection; - fromUserId?: string; - toUserId?: string; - isGift?: boolean; - monthsAmount?: number; - isSuccess?: boolean; - }; - - giveawayModal?: { - chatId: string; - isOpen?: boolean; - gifts?: ApiPremiumGiftCodeOption[]; - selectedMemberIds?: string[]; - selectedChannelIds?: string[]; - prepaidGiveaway?: ApiTypePrepaidGiveaway; - starOptions?: ApiStarGiveawayOption[]; - }; - - deleteMessageModal?: { - message?: ApiMessage; - isSchedule?: boolean; - album?: IAlbum; - onConfirm?: NoneToVoidFunction; - }; - - isWebAppsCloseConfirmationModalOpen?: boolean; - - isGiftRecipientPickerOpen?: boolean; - - starsGiftingPickerModal?: { - isOpen?: boolean; - }; - - starsGiftModal?: { - isCompleted?: boolean; - isOpen?: boolean; - forUserId?: string; - starsGiftOptions?: ApiStarTopupOption[]; - }; - - starsTransactionModal?: { - transaction: ApiStarsTransaction; - }; - starsSubscriptionModal?: { - subscription: ApiStarsSubscription; - }; - - giftModal?: { - isCompleted?: boolean; - forUserId: string; - gifts: ApiPremiumGiftCodeOption[]; - }; - - limitReachedModal?: { - limit: ApiLimitTypeWithModal; - }; - - deleteFolderDialogModal?: number; - - createTopicPanel?: { - chatId: string; - isLoading?: boolean; - }; - - editTopicPanel?: { - chatId: string; - topicId: number; - isLoading?: boolean; - }; - - requestedTranslations: { - byChatId: Record; - }; - chatLanguageModal?: { - chatId: string; - messageId?: number; - activeLanguage?: string; - }; - - chatlistModal?: { - invite?: ApiChatlistInvite; - removal?: { - folderId: number; - suggestedPeerIds?: string[]; - }; - }; - - boostModal?: { - chatId: string; - boostStatus?: ApiBoostsStatus; - myBoosts?: ApiMyBoost[]; - }; - - boostStatistics?: { - chatId: string; - boostStatus?: ApiBoostsStatus; - isLoadingBoosters?: boolean; - nextOffset?: string; - boosts?: { - count: number; - list: ApiBoost[]; - }; - giftedBoosts?: { - count: number; - list: ApiBoost[]; - }; - }; - - monetizationStatistics?: { - chatId: string; - }; - - giftCodeModal?: { - slug: string; - message?: { - chatId: string; - messageId: number; - }; - info: ApiCheckedGiftCode; - }; - - paidReactionModal?: { - chatId: string; - messageId: number; - }; - - inviteViaLinkModal?: { - missingUsers: ApiMissingInvitedUser[]; - chatId: string; - }; - - oneTimeMediaModal?: { - message: ApiMessage; - }; - - collectibleInfoModal?: ApiCollectionInfo & { - peerId: string; - type: 'phone' | 'username'; - collectible: string; - }; - - starsBalanceModal?: { - originStarsPayment?: TabState['starsPayment']; - originGift?: StarGiftInfo; - originReaction?: { - chatId: string; - messageId: number; - amount: number; - }; - topup?: { - balanceNeeded: number; - purpose?: string; - }; - }; - - giftInfoModal?: { - userId?: string; - gift: ApiUserStarGift | ApiStarGift; - }; - - suggestedStatusModal?: { - botId: string; - webAppKey?: string; - customEmojiId: string; - duration?: number; - }; -}; - -export type GlobalState = { - isInited: boolean; - config?: ApiConfig; - appConfig?: ApiAppConfig; - peerColors?: ApiPeerColors; - timezones?: { - byId: Record; - hash: number; - }; - hasWebAuthTokenFailed?: boolean; - hasWebAuthTokenPasswordRequired?: true; - isCacheApiSupported?: boolean; - connectionState?: ApiUpdateConnectionStateType; - currentUserId?: string; - isSyncing?: boolean; - isAppUpdateAvailable?: boolean; - isElectronUpdateAvailable?: boolean; - isSynced?: boolean; - isFetchingDifference?: boolean; - leftColumnWidth?: number; - lastIsChatInfoShown?: boolean; - initialUnreadNotifications?: number; - shouldShowContextMenuHint?: boolean; - - audioPlayer: { - lastPlaybackRate: number; - isLastPlaybackRateActive?: boolean; - }; - - mediaViewer: { - lastPlaybackRate: number; - }; - - recentlyFoundChatIds?: string[]; - - twoFaSettings: { - hint?: string; - isLoading?: boolean; - error?: string; - waitingEmailCodeLength?: number; - }; - - monetizationInfo: { - isLoading?: boolean; - error?: string; - }; - - attachmentSettings: { - shouldCompress: boolean; - shouldSendGrouped: boolean; - isInvertedMedia?: true; - webPageMediaSize?: WebPageMediaSize; - }; - - attachMenu: { - hash?: string; - bots: Record; - }; - - passcode: { - isScreenLocked?: boolean; - hasPasscode?: boolean; - error?: string; - timeoutUntil?: number; - invalidAttemptsCount?: number; - invalidAttemptError?: string; - isLoading?: boolean; - }; - - // TODO Move to `auth`. - isLoggingOut?: boolean; - authState?: ApiUpdateAuthorizationStateType; - authPhoneNumber?: string; - authIsLoading?: boolean; - authIsLoadingQrCode?: boolean; - authError?: string; - authRememberMe?: boolean; - authNearestCountry?: string; - authIsCodeViaApp?: boolean; - authHint?: string; - authQrCode?: { - token: string; - expires: number; - }; - countryList: { - phoneCodes: ApiCountryCode[]; - general: ApiCountry[]; - }; - - contactList?: { - userIds: string[]; - }; - - blocked: { - ids: string[]; - totalCount: number; - }; - - users: { - byId: Record; - statusesById: Record; - // Obtained from GetFullUser / UserFullInfo - fullInfoById: Record; - previewMediaByBotId: Record; - commonChatsById: Record; - giftsById: Record; - }; - profilePhotosById: Record; - - chats: { - // TODO Replace with `Partial` to properly handle missing keys - byId: Record; - listIds: { - active?: string[]; - archived?: string[]; - saved?: string[]; - }; - orderedPinnedIds: { - active?: string[]; - archived?: string[]; - saved?: string[]; - }; - totalCount: { - all?: number; - archived?: number; - saved?: number; - }; - isFullyLoaded: { - active?: boolean; - archived?: boolean; - saved?: boolean; - }; - lastMessageIds: { - all?: Record; - saved?: Record; - }; - topicsInfoById: Record; - loadingParameters: Record; - forDiscussionIds?: string[]; - // Obtained from GetFullChat / GetFullChannel - fullInfoById: Record; - similarChannelsById: Record< - string, - { - shouldShowInChat: boolean; - similarChannelIds: string[]; - count: number; - } - >; - }; - - messages: { - byChatId: Record; - threadsById: Record; - }>; - sponsoredByChatId: Record; - pollById: Record; - }; - - stories: { - byPeerId: Record; - hasNext?: boolean; - stateHash?: string; - hasNextInArchive?: boolean; - archiveStateHash?: string; - orderedPeerIds: { - active: string[]; - archived: string[]; - }; - stealthMode: ApiStealthMode; - }; - - groupCalls: { - byId: Record; - activeGroupCallId?: string; - }; - - scheduledMessages: { - byChatId: Record; - }>; - }; - - quickReplies: { - messagesById: Record; - byId: Record; - }; - - chatFolders: { - orderedIds?: number[]; - byId: Record; - invites: Record; - recommended?: ApiChatFolder[]; - }; - - phoneCall?: ApiPhoneCall; - - fileUploads: { - byMessageKey: Record; - }; - - recentEmojis: string[]; - recentCustomEmojis: string[]; - - reactions: { - topReactions: ApiReaction[]; - recentReactions: ApiReaction[]; - defaultTags: ApiReaction[]; - effectReactions: ApiReaction[]; - availableReactions?: ApiAvailableReaction[]; - hash: { - topReactions?: string; - recentReactions?: string; - defaultTags?: string; - }; - }; - availableEffectById: Record; - starGiftsById: Record; - starGiftCategoriesByName: Record; - - stickers: { - setsById: Record; - added: { - hash?: string; - setIds?: string[]; - }; - recent: { - hash?: string; - stickers: ApiSticker[]; - }; - favorite: { - hash?: string; - stickers: ApiSticker[]; - }; - greeting: { - hash?: string; - stickers: ApiSticker[]; - }; - premium: { - hash?: string; - stickers: ApiSticker[]; - }; - featured: { - hash?: string; - setIds?: string[]; - }; - forEmoji: { - emoji?: string; - stickers?: ApiSticker[]; - hash?: string; - }; - effect: { - stickers: ApiSticker[]; - emojis: ApiSticker[]; - }; - starGifts: { - stickers: Record; - }; - }; - - customEmojis: { - added: { - hash?: string; - setIds?: string[]; - }; - lastRendered: string[]; - byId: Record; - forEmoji: { - emoji?: string; - stickers?: ApiSticker[]; - }; - featuredIds?: string[]; - statusRecent: { - hash?: string; - emojis?: ApiSticker[]; - }; - }; - - animatedEmojis?: ApiStickerSet; - animatedEmojiEffects?: ApiStickerSet; - genericEmojiEffects?: ApiStickerSet; - birthdayNumbers?: ApiStickerSet; - restrictedEmoji?: ApiStickerSet; - defaultTopicIconsId?: string; - defaultStatusIconsId?: string; - premiumGifts?: ApiStickerSet; - emojiKeywords: Record; - - gifs: { - saved: { - hash?: string; - gifs?: ApiVideo[]; - }; - }; - - topPeers: { - userIds?: string[]; - lastRequestedAt?: number; - }; - - topInlineBots: { - userIds?: string[]; - lastRequestedAt?: number; - }; - - topBotApps: { - userIds?: string[]; - lastRequestedAt?: number; - }; - - activeSessions: { - byHash: Record; - orderedHashes: string[]; - ttlDays?: number; - }; - - activeWebSessions: { - byHash: Record; - orderedHashes: string[]; - }; - - settings: { - byKey: ISettings; - performance: PerformanceType; - loadedWallpapers?: ApiWallpaper[]; - themes: Partial>; - privacy: Partial>; - notifyExceptions?: Record; - lastPremiumBandwithNotificationDate?: number; - paidReactionPrivacy?: boolean; - languages?: ApiLanguage[]; - }; - - push?: { - deviceToken: string; - subscribedAt: number; - }; - - transcriptions: Record; - trustedBotIds: string[]; - - serviceNotifications: ServiceNotification[]; - - byTabId: Record; - - archiveSettings: { - isMinimized: boolean; - isHidden: boolean; - }; - - translations: { - byChatId: Record; - }; - - savedReactionTags?: { - byKey: Record; - hash: string; - }; - - stars?: { - topupOptions: ApiStarTopupOption[]; - balance: ApiStarsAmount; - history: StarsTransactionHistory; - subscriptions?: StarsSubscriptions; - }; -}; - -export type StarGiftCategory = number | 'all' | 'limited'; - -export type CallSound = ( - 'join' | 'allowTalk' | 'leave' | 'connecting' | 'incoming' | 'end' | 'connect' | 'busy' | 'ringing' -); - -export interface RequiredActionPayloads { - apiUpdate: ApiUpdate; -} - -type Values = T[keyof T]; -export type CallbackAction = Values<{ - [ActionName in keyof (ActionPayloads)]: { - action: ActionName; - payload: (ActionPayloads)[ActionName]; - } -}>; - -export type ApiDraft = { - text?: ApiFormattedText; - replyInfo?: ApiInputMessageReplyInfo; - date?: number; - effectId?: string; - isLocal?: boolean; -}; - -export type WebApp = { - url: string; - requestUrl?: string; - botId: string; - appName?: string; - buttonText: string; - peerId?: string; - queryId?: string; - slug?: string; - replyInfo?: ApiInputMessageReplyInfo; - canSendMessages?: boolean; - isRemoveModalOpen?: boolean; - isCloseModalOpen?: boolean; - shouldConfirmClosing?: boolean; - headerColor?: string; - backgroundColor?: string; - isBackButtonVisible?: boolean; - isSettingsButtonVisible?: boolean; - plannedEvents?: WebAppOutboundEvent[]; - sendEvent?: (event: WebAppOutboundEvent) => void; - reloadFrame?: (url: string) => void; -}; + WebPageMediaSize, +} from '../../types'; +import type { + WebApp, + WebAppModalStateType, + WebAppOutboundEvent, +} from '../../types/webapp'; +import type { DownloadableMedia } from '../helpers'; +import type { TabState } from './tabState'; type WithTabId = { tabId?: number }; @@ -3674,10 +2419,14 @@ export interface ActionPayloads { } & WithTabId; } -export type RequiredGlobalState = GlobalState & { _: never }; -export type ActionReturnType = GlobalState | void | Promise; -export type TabArgs = T extends RequiredGlobalState ? [ - tabId: number, -] : [ - tabId?: number | undefined, -]; +export interface RequiredActionPayloads { + apiUpdate: ApiUpdate; +} + +type Values = T[keyof T]; +export type CallbackAction = Values<{ + [ActionName in keyof (ActionPayloads)]: { + action: ActionName; + payload: (ActionPayloads)[ActionName]; + } +}>; diff --git a/src/global/types/globalState.ts b/src/global/types/globalState.ts new file mode 100644 index 000000000..dfd53e9b6 --- /dev/null +++ b/src/global/types/globalState.ts @@ -0,0 +1,449 @@ +import type { + ApiAppConfig, + ApiAttachBot, + ApiAvailableEffect, + ApiAvailableReaction, + ApiBotPreviewMedia, + ApiChat, + ApiChatFolder, + ApiChatFullInfo, + ApiChatlistExportedInvite, + ApiConfig, + ApiCountry, + ApiCountryCode, + ApiGroupCall, + ApiLanguage, + ApiMessage, + ApiPeerColors, + ApiPeerPhotos, + ApiPeerStories, + ApiPhoneCall, + ApiPoll, + ApiPrivacyKey, + ApiPrivacySettings, + ApiQuickReply, + ApiReaction, + ApiReactionKey, + ApiSavedReactionTag, + ApiSession, + ApiSponsoredMessage, + ApiStarGift, + ApiStarsAmount, + ApiStarTopupOption, + ApiStealthMode, + ApiSticker, + ApiStickerSet, + ApiTimezone, + ApiTranscription, + ApiUpdateAuthorizationStateType, + ApiUpdateConnectionStateType, + ApiUser, + ApiUserCommonChats, + ApiUserFullInfo, + ApiUserGifts, + ApiUserStatus, + ApiVideo, + ApiWallpaper, + ApiWebSession, +} from '../../api/types'; +import type { + ChatListType, + ChatTranslatedMessages, + EmojiKeywords, + ISettings, + IThemeSettings, + NotifyException, + PerformanceType, + ServiceNotification, + StarGiftCategory, + StarsSubscriptions, + StarsTransactionHistory, + ThemeKey, + Thread, + ThreadId, + TopicsInfo, + WebPageMediaSize, +} from '../../types'; +import type { TabState } from './tabState'; + +export type GlobalState = { + isInited: boolean; + config?: ApiConfig; + appConfig?: ApiAppConfig; + peerColors?: ApiPeerColors; + timezones?: { + byId: Record; + hash: number; + }; + hasWebAuthTokenFailed?: boolean; + hasWebAuthTokenPasswordRequired?: true; + isCacheApiSupported?: boolean; + connectionState?: ApiUpdateConnectionStateType; + currentUserId?: string; + isSyncing?: boolean; + isAppUpdateAvailable?: boolean; + isElectronUpdateAvailable?: boolean; + isSynced?: boolean; + isFetchingDifference?: boolean; + leftColumnWidth?: number; + lastIsChatInfoShown?: boolean; + initialUnreadNotifications?: number; + shouldShowContextMenuHint?: boolean; + + audioPlayer: { + lastPlaybackRate: number; + isLastPlaybackRateActive?: boolean; + }; + + mediaViewer: { + lastPlaybackRate: number; + }; + + recentlyFoundChatIds?: string[]; + + twoFaSettings: { + hint?: string; + isLoading?: boolean; + error?: string; + waitingEmailCodeLength?: number; + }; + + monetizationInfo: { + isLoading?: boolean; + error?: string; + }; + + attachmentSettings: { + shouldCompress: boolean; + shouldSendGrouped: boolean; + isInvertedMedia?: true; + webPageMediaSize?: WebPageMediaSize; + }; + + attachMenu: { + hash?: string; + bots: Record; + }; + + passcode: { + isScreenLocked?: boolean; + hasPasscode?: boolean; + error?: string; + timeoutUntil?: number; + invalidAttemptsCount?: number; + invalidAttemptError?: string; + isLoading?: boolean; + }; + + // TODO Move to `auth`. + isLoggingOut?: boolean; + authState?: ApiUpdateAuthorizationStateType; + authPhoneNumber?: string; + authIsLoading?: boolean; + authIsLoadingQrCode?: boolean; + authError?: string; + authRememberMe?: boolean; + authNearestCountry?: string; + authIsCodeViaApp?: boolean; + authHint?: string; + authQrCode?: { + token: string; + expires: number; + }; + countryList: { + phoneCodes: ApiCountryCode[]; + general: ApiCountry[]; + }; + + contactList?: { + userIds: string[]; + }; + + blocked: { + ids: string[]; + totalCount: number; + }; + + users: { + byId: Record; + statusesById: Record; + // Obtained from GetFullUser / UserFullInfo + fullInfoById: Record; + previewMediaByBotId: Record; + commonChatsById: Record; + giftsById: Record; + }; + profilePhotosById: Record; + + chats: { + // TODO Replace with `Partial` to properly handle missing keys + byId: Record; + listIds: { + active?: string[]; + archived?: string[]; + saved?: string[]; + }; + orderedPinnedIds: { + active?: string[]; + archived?: string[]; + saved?: string[]; + }; + totalCount: { + all?: number; + archived?: number; + saved?: number; + }; + isFullyLoaded: { + active?: boolean; + archived?: boolean; + saved?: boolean; + }; + lastMessageIds: { + all?: Record; + saved?: Record; + }; + topicsInfoById: Record; + loadingParameters: Record; + forDiscussionIds?: string[]; + // Obtained from GetFullChat / GetFullChannel + fullInfoById: Record; + similarChannelsById: Record< + string, + { + shouldShowInChat: boolean; + similarChannelIds: string[]; + count: number; + } + >; + }; + + messages: { + byChatId: Record; + threadsById: Record; + }>; + sponsoredByChatId: Record; + pollById: Record; + }; + + stories: { + byPeerId: Record; + hasNext?: boolean; + stateHash?: string; + hasNextInArchive?: boolean; + archiveStateHash?: string; + orderedPeerIds: { + active: string[]; + archived: string[]; + }; + stealthMode: ApiStealthMode; + }; + + groupCalls: { + byId: Record; + activeGroupCallId?: string; + }; + + scheduledMessages: { + byChatId: Record; + }>; + }; + + quickReplies: { + messagesById: Record; + byId: Record; + }; + + chatFolders: { + orderedIds?: number[]; + byId: Record; + invites: Record; + recommended?: ApiChatFolder[]; + }; + + phoneCall?: ApiPhoneCall; + + fileUploads: { + byMessageKey: Record; + }; + + recentEmojis: string[]; + recentCustomEmojis: string[]; + + reactions: { + topReactions: ApiReaction[]; + recentReactions: ApiReaction[]; + defaultTags: ApiReaction[]; + effectReactions: ApiReaction[]; + availableReactions?: ApiAvailableReaction[]; + hash: { + topReactions?: string; + recentReactions?: string; + defaultTags?: string; + }; + }; + availableEffectById: Record; + starGiftsById: Record; + starGiftCategoriesByName: Record; + + stickers: { + setsById: Record; + added: { + hash?: string; + setIds?: string[]; + }; + recent: { + hash?: string; + stickers: ApiSticker[]; + }; + favorite: { + hash?: string; + stickers: ApiSticker[]; + }; + greeting: { + hash?: string; + stickers: ApiSticker[]; + }; + premium: { + hash?: string; + stickers: ApiSticker[]; + }; + featured: { + hash?: string; + setIds?: string[]; + }; + forEmoji: { + emoji?: string; + stickers?: ApiSticker[]; + hash?: string; + }; + effect: { + stickers: ApiSticker[]; + emojis: ApiSticker[]; + }; + starGifts: { + stickers: Record; + }; + }; + + customEmojis: { + added: { + hash?: string; + setIds?: string[]; + }; + lastRendered: string[]; + byId: Record; + forEmoji: { + emoji?: string; + stickers?: ApiSticker[]; + }; + featuredIds?: string[]; + statusRecent: { + hash?: string; + emojis?: ApiSticker[]; + }; + }; + + animatedEmojis?: ApiStickerSet; + animatedEmojiEffects?: ApiStickerSet; + genericEmojiEffects?: ApiStickerSet; + birthdayNumbers?: ApiStickerSet; + restrictedEmoji?: ApiStickerSet; + defaultTopicIconsId?: string; + defaultStatusIconsId?: string; + premiumGifts?: ApiStickerSet; + emojiKeywords: Record; + + gifs: { + saved: { + hash?: string; + gifs?: ApiVideo[]; + }; + }; + + topPeers: { + userIds?: string[]; + lastRequestedAt?: number; + }; + + topInlineBots: { + userIds?: string[]; + lastRequestedAt?: number; + }; + + topBotApps: { + userIds?: string[]; + lastRequestedAt?: number; + }; + + activeSessions: { + byHash: Record; + orderedHashes: string[]; + ttlDays?: number; + }; + + activeWebSessions: { + byHash: Record; + orderedHashes: string[]; + }; + + settings: { + byKey: ISettings; + performance: PerformanceType; + loadedWallpapers?: ApiWallpaper[]; + themes: Partial>; + privacy: Partial>; + notifyExceptions?: Record; + lastPremiumBandwithNotificationDate?: number; + paidReactionPrivacy?: boolean; + languages?: ApiLanguage[]; + }; + + push?: { + deviceToken: string; + subscribedAt: number; + }; + + transcriptions: Record; + trustedBotIds: string[]; + + serviceNotifications: ServiceNotification[]; + + byTabId: Record; + + archiveSettings: { + isMinimized: boolean; + isHidden: boolean; + }; + + translations: { + byChatId: Record; + }; + + savedReactionTags?: { + byKey: Record; + hash: string; + }; + + stars?: { + topupOptions: ApiStarTopupOption[]; + balance: ApiStarsAmount; + history: StarsTransactionHistory; + subscriptions?: StarsSubscriptions; + }; +}; + +export type RequiredGlobalState = GlobalState & { _: never }; +export type ActionReturnType = GlobalState | void | Promise; +export type TabArgs = T extends RequiredGlobalState ? [ + tabId: number, +] : [ + tabId?: number | undefined, +]; diff --git a/src/global/types/index.ts b/src/global/types/index.ts new file mode 100644 index 000000000..691f0ba04 --- /dev/null +++ b/src/global/types/index.ts @@ -0,0 +1,3 @@ +export type * from './globalState'; +export type * from './tabState'; +export type * from './actions'; diff --git a/src/global/types/tabState.ts b/src/global/types/tabState.ts new file mode 100644 index 000000000..49a69599f --- /dev/null +++ b/src/global/types/tabState.ts @@ -0,0 +1,711 @@ +import type { + ApiAttachBot, + ApiBoost, + ApiBoostsStatus, + ApiChannelMonetizationStatistics, + ApiChannelStatistics, + ApiChatInviteInfo, + ApiChatlistInvite, + ApiChatType, + ApiCheckedGiftCode, + ApiCollectibleInfo, + ApiContact, + ApiError, + ApiFormattedText, + ApiGeoPoint, + ApiGlobalMessageSearchType, + ApiGroupStatistics, + ApiInputInvoice, + ApiLimitTypeWithModal, + ApiMessage, + ApiMissingInvitedUser, + ApiMyBoost, + ApiNewPoll, + ApiNotification, + ApiPaymentFormRegular, + ApiPaymentFormStars, + ApiPaymentStatus, + ApiPhoneCall, + ApiPostStatistics, + ApiPremiumGiftCodeOption, + ApiPremiumPromo, + ApiPremiumSection, + ApiReactionWithPaid, + ApiReceiptRegular, + ApiStarGift, + ApiStarGiveawayOption, + ApiStarsSubscription, + ApiStarsTransaction, + ApiStarTopupOption, + ApiSticker, + ApiTypePrepaidGiveaway, + ApiTypeStoryView, + ApiUserStarGift, + ApiVideo, + ApiWebPage, +} from '../../api/types'; +import type { FoldersActions } from '../../hooks/reducers/useFoldersReducer'; +import type { ReducerAction } from '../../hooks/useReducer'; +import type { + ActiveDownloads, + ActiveEmojiInteraction, + AudioOrigin, + ChatCreationProgress, + ChatMediaSearchParams, + ChatRequestedTranslations, + ConfettiStyle, + FocusDirection, + GlobalSearchContent, + IAlbum, + IAnchorPosition, + InlineBotSettings, + ManagementProgress, + ManagementState, + MediaViewerMedia, + MediaViewerOrigin, + MessageList, + MiddleSearchParams, + NewChatMembersProgress, + PaymentStep, + ProfileEditProgress, + ProfileTabType, + ScrollTargetPosition, + SettingsScreens, + SharedMediaType, + ShippingOption, + StarGiftInfo, + StoryViewerOrigin, + TabThread, + ThreadId, +} from '../../types'; +import type { WebApp, WebAppModalStateType } from '../../types/webapp'; +import type { SearchResultKey } from '../../util/keys/searchResultKey'; +import type { CallbackAction } from './actions'; + +export type TabState = { + id: number; + isBlurred?: boolean; + isMasterTab: boolean; + isInactive?: boolean; + shouldPreventComposerAnimation?: boolean; + inviteHash?: string; + canInstall?: boolean; + isChatInfoShown: boolean; + isStatisticsShown?: boolean; + isLeftColumnShown: boolean; + newChatMembersProgress?: NewChatMembersProgress; + uiReadyState: 0 | 1 | 2; + shouldInit: boolean; + shouldSkipHistoryAnimations?: boolean; + + gifSearch: { + query?: string; + offset?: string; + results?: ApiVideo[]; + }; + + stickerSearch: { + query?: string; + hash?: string; + resultIds?: string[]; + }; + + shouldCloseRightColumn?: boolean; + nextProfileTab?: ProfileTabType; + forceScrollProfileTab?: boolean; + nextSettingsScreen?: SettingsScreens; + nextFoldersAction?: ReducerAction; + shareFolderScreen?: { + folderId: number; + isFromSettings?: boolean; + url?: string; + isLoading?: boolean; + }; + + isCallPanelVisible?: boolean; + multitabNextAction?: CallbackAction; + ratingPhoneCall?: ApiPhoneCall; + + messageLists: MessageList[]; + + contentToBeScheduled?: { + gif?: ApiVideo; + sticker?: ApiSticker; + poll?: ApiNewPoll; + isSilent?: boolean; + sendGrouped?: boolean; + sendCompressed?: boolean; + isInvertedMedia?: true; + }; + + activeChatFolder: number; + tabThreads: Record>; + forumPanelChatId?: string; + + focusedMessage?: { + chatId?: string; + threadId?: ThreadId; + messageId?: number; + direction?: FocusDirection; + noHighlight?: boolean; + isResizingContainer?: boolean; + quote?: string; + scrollTargetPosition?: ScrollTargetPosition; + }; + + selectedMessages?: { + chatId: string; + messageIds: number[]; + }; + + chatInviteModal?: { + hash: string; + inviteInfo: ApiChatInviteInfo; + }; + + seenByModal?: { + chatId: string; + messageId: number; + }; + + privacySettingsNoticeModal?: { + chatId: string; + isReadDate: boolean; + }; + + reactorModal?: { + chatId: string; + messageId: number; + }; + + aboutAdsModal?: { + chatId: string; + }; + + reactionPicker?: { + chatId?: string; + messageId?: number; + storyPeerId?: string; + storyId?: number; + position?: IAnchorPosition; + sendAsMessage?: boolean; + isForEffects?: boolean; + }; + + shouldPlayEffectInComposer?: true; + + inlineBots: { + isLoading: boolean; + byUsername: Record; + }; + + globalSearch: { + query?: string; + minDate?: number; + maxDate?: number; + currentContent?: GlobalSearchContent; + chatId?: string; + foundTopicIds?: number[]; + fetchingStatus?: { + chats?: boolean; + messages?: boolean; + botApps?: boolean; + }; + isClosing?: boolean; + localResults?: { + peerIds?: string[]; + }; + globalResults?: { + peerIds?: string[]; + }; + popularBotApps?: { + peerIds: string[]; + nextOffset?: string; + }; + resultsByType?: Partial>; + }; + + userSearch: { + query?: string; + fetchingStatus?: boolean; + localUserIds?: string[]; + globalUserIds?: string[]; + }; + + activeEmojiInteractions?: ActiveEmojiInteraction[]; + activeReactions: Record; + + middleSearch: { + byChatThreadKey: Record; + }; + + sharedMediaSearch: { + byChatThreadKey: Record>; + }>; + }; + + chatMediaSearch: { + byChatThreadKey: Record; + }; + + management: { + progress?: ManagementProgress; + byChatId: Record; + }; + + storyViewer: { + isRibbonShown?: boolean; + isArchivedRibbonShown?: boolean; + peerId?: string; + storyId?: number; + isMuted: boolean; + isSinglePeer?: boolean; + isSingleStory?: boolean; + isPrivate?: boolean; + isArchive?: boolean; + // Last viewed story id in current view session. + // Used for better switch animation between peers. + lastViewedByPeerIds?: Record; + isPrivacyModalOpen?: boolean; + isStealthModalOpen?: boolean; + viewModal?: { + storyId: number; + views?: ApiTypeStoryView[]; + nextOffset?: string; + isLoading?: boolean; + }; + origin?: StoryViewerOrigin; + // Copy of story list for current view session + storyList?: { + peerIds: string[]; + storyIdsByPeerId: Record; + }; + }; + + mediaViewer: { + chatId?: string; + threadId?: ThreadId; + messageId?: number; + withDynamicLoading?: boolean; + mediaIndex?: number; + isAvatarView?: boolean; + isSponsoredMessage?: boolean; + standaloneMedia?: MediaViewerMedia[]; + origin?: MediaViewerOrigin; + volume: number; + playbackRate: number; + isMuted: boolean; + isHidden?: boolean; + }; + + audioPlayer: { + chatId?: string; + messageId?: number; + threadId?: ThreadId; + origin?: AudioOrigin; + volume: number; + playbackRate: number; + isPlaybackRateActive?: boolean; + isMuted: boolean; + }; + + webPagePreview?: ApiWebPage; + + loadingThread?: { + loadingChatId: string; + loadingMessageId: number; + }; + + isShareMessageModalShown?: boolean; + + replyingMessage: { + fromChatId?: string; + messageId?: number; + quoteText?: ApiFormattedText; + toChatId?: string; + toThreadId?: ThreadId; + }; + + forwardMessages: { + fromChatId?: string; + messageIds?: number[]; + storyId?: number; + toChatId?: string; + toThreadId?: ThreadId; + withMyScore?: boolean; + noAuthors?: boolean; + noCaptions?: boolean; + }; + + pollResults: { + chatId?: string; + messageId?: number; + voters?: Record; // TODO Rename to `voterIds` + offsets?: Record; + }; + + isPaymentFormLoading?: boolean; + payment: { + inputInvoice?: ApiInputInvoice; + step?: PaymentStep; + status?: ApiPaymentStatus; + shippingOptions?: ShippingOption[]; + requestId?: string; + form?: ApiPaymentFormRegular; + stripeCredentials?: { + type: string; + id: string; + }; + smartGlocalCredentials?: { + type: string; + token: string; + }; + receipt?: ApiReceiptRegular; + error?: { + field?: string; + message?: string; + description?: string; + }; + isPaymentModalOpen?: boolean; + isExtendedMedia?: boolean; + confirmPaymentUrl?: string; + temporaryPassword?: { + value: string; + validUntil: number; + }; + url?: string; + botId?: string; + }; + starsPayment: { + form?: ApiPaymentFormStars; + subscriptionInfo?: ApiChatInviteInfo; + inputInvoice?: ApiInputInvoice; + status?: ApiPaymentStatus; + }; + + chatCreation?: { + progress: ChatCreationProgress; + error?: string; + }; + + profileEdit?: { + progress: ProfileEditProgress; + checkedUsername?: string; + isUsernameAvailable?: boolean; + error?: string; + }; + + notifications: ApiNotification[]; + dialogs: (ApiError | ApiContact)[]; + + safeLinkModalUrl?: string; + mapModal?: { + point: ApiGeoPoint; + zoom?: number; + }; + historyCalendarSelectedAt?: number; + openedStickerSetShortName?: string; + openedCustomEmojiSetIds?: string[]; + + reportAdModal?: { + chatId: string; + randomId: string; + sections: { + title: string; + subtitle?: string; + options: { + text: string; + option: string; + }[]; + }[]; + }; + + reportModal?: { + chatId?: string; + messageIds: number[]; + description: string; + peerId?: string; + subject: 'story' | 'message'; + sections: { + title?: string; + subtitle?: string; + options?: { + text: string; + option: string; + }[]; + isOptional?: boolean; + option?: string; + }[]; + }; + + activeDownloads: ActiveDownloads; + + statistics: { + byChatId: Record; + currentMessage?: ApiPostStatistics; + currentMessageId?: number; + currentStory?: ApiPostStatistics; + currentStoryId?: number; + monetization?: ApiChannelMonetizationStatistics; + }; + + newContact?: { + userId?: string; + isByPhoneNumber?: boolean; + }; + + openedGame?: { + url: string; + chatId: string; + messageId: number; + }; + + requestedDraft?: { + chatId?: string; + text: ApiFormattedText; + files?: File[]; + filter?: ApiChatType[]; + }; + + pollModal: { + isOpen: boolean; + isQuiz?: boolean; + }; + + webApps: { + activeWebAppKey?: string; + openedOrderedKeys: string[]; + sessionKeys: string[]; + openedWebApps: Record; + modalState : WebAppModalStateType; + isModalOpen: boolean; + isMoreAppsTabActive: boolean; + }; + + botTrustRequest?: { + botId: string; + type: 'game' | 'webApp' | 'botApp'; + shouldRequestWriteAccess?: boolean; + onConfirm?: CallbackAction; + }; + requestedAttachBotInstall?: { + bot: ApiAttachBot; + onConfirm?: CallbackAction; + }; + requestedAttachBotInChat?: { + bot: ApiAttachBot; + filter: ApiChatType[]; + startParam?: string; + }; + + confetti?: { + lastConfettiTime?: number; + top?: number; + left?: number; + width?: number; + height?: number; + style?: ConfettiStyle; + withStars?: boolean; + }; + wave?: { + lastWaveTime: number; + startX: number; + startY: number; + }; + + urlAuth?: { + button?: { + chatId: string; + messageId: number; + buttonId: number; + }; + request?: { + domain: string; + botId: string; + shouldRequestWriteAccess?: boolean; + }; + url: string; + }; + + premiumModal?: { + isOpen?: boolean; + promo: ApiPremiumPromo; + initialSection?: ApiPremiumSection; + fromUserId?: string; + toUserId?: string; + isGift?: boolean; + monthsAmount?: number; + isSuccess?: boolean; + }; + + giveawayModal?: { + chatId: string; + isOpen?: boolean; + gifts?: ApiPremiumGiftCodeOption[]; + selectedMemberIds?: string[]; + selectedChannelIds?: string[]; + prepaidGiveaway?: ApiTypePrepaidGiveaway; + starOptions?: ApiStarGiveawayOption[]; + }; + + deleteMessageModal?: { + message?: ApiMessage; + isSchedule?: boolean; + album?: IAlbum; + onConfirm?: NoneToVoidFunction; + }; + + isWebAppsCloseConfirmationModalOpen?: boolean; + + isGiftRecipientPickerOpen?: boolean; + + starsGiftingPickerModal?: { + isOpen?: boolean; + }; + + starsGiftModal?: { + isCompleted?: boolean; + isOpen?: boolean; + forUserId?: string; + starsGiftOptions?: ApiStarTopupOption[]; + }; + + starsTransactionModal?: { + transaction: ApiStarsTransaction; + }; + starsSubscriptionModal?: { + subscription: ApiStarsSubscription; + }; + + giftModal?: { + isCompleted?: boolean; + forUserId: string; + gifts: ApiPremiumGiftCodeOption[]; + }; + + limitReachedModal?: { + limit: ApiLimitTypeWithModal; + }; + + deleteFolderDialogModal?: number; + + createTopicPanel?: { + chatId: string; + isLoading?: boolean; + }; + + editTopicPanel?: { + chatId: string; + topicId: number; + isLoading?: boolean; + }; + + requestedTranslations: { + byChatId: Record; + }; + chatLanguageModal?: { + chatId: string; + messageId?: number; + activeLanguage?: string; + }; + + chatlistModal?: { + invite?: ApiChatlistInvite; + removal?: { + folderId: number; + suggestedPeerIds?: string[]; + }; + }; + + boostModal?: { + chatId: string; + boostStatus?: ApiBoostsStatus; + myBoosts?: ApiMyBoost[]; + }; + + boostStatistics?: { + chatId: string; + boostStatus?: ApiBoostsStatus; + isLoadingBoosters?: boolean; + nextOffset?: string; + boosts?: { + count: number; + list: ApiBoost[]; + }; + giftedBoosts?: { + count: number; + list: ApiBoost[]; + }; + }; + + monetizationStatistics?: { + chatId: string; + }; + + giftCodeModal?: { + slug: string; + message?: { + chatId: string; + messageId: number; + }; + info: ApiCheckedGiftCode; + }; + + paidReactionModal?: { + chatId: string; + messageId: number; + }; + + inviteViaLinkModal?: { + missingUsers: ApiMissingInvitedUser[]; + chatId: string; + }; + + oneTimeMediaModal?: { + message: ApiMessage; + }; + + collectibleInfoModal?: ApiCollectibleInfo & { + peerId: string; + type: 'phone' | 'username'; + collectible: string; + }; + + starsBalanceModal?: { + originStarsPayment?: TabState['starsPayment']; + originGift?: StarGiftInfo; + originReaction?: { + chatId: string; + messageId: number; + amount: number; + }; + topup?: { + balanceNeeded: number; + purpose?: string; + }; + }; + + giftInfoModal?: { + userId?: string; + gift: ApiUserStarGift | ApiStarGift; + }; + + suggestedStatusModal?: { + botId: string; + webAppKey?: string; + customEmojiId: string; + duration?: number; + }; +}; diff --git a/src/hooks/useHistoryBack.ts b/src/hooks/useHistoryBack.ts index e8229fc85..c2ea98684 100644 --- a/src/hooks/useHistoryBack.ts +++ b/src/hooks/useHistoryBack.ts @@ -1,5 +1,5 @@ import { useCallback, useRef } from '../lib/teact/teact'; -import { getActions } from '../lib/teact/teactn'; +import { getActions } from '../global'; import { IS_TEST } from '../config'; import { requestMeasure } from '../lib/fasterdom/fasterdom'; diff --git a/src/lib/teact/teactn.tsx b/src/lib/teact/teactn.tsx index 7352637cb..d597ba67c 100644 --- a/src/lib/teact/teactn.tsx +++ b/src/lib/teact/teactn.tsx @@ -81,7 +81,7 @@ function runCallbacks() { callbacks.forEach((cb) => cb(currentGlobal)); } -export function setGlobal(newGlobal?: GlobalState, options?: ActionOptions) { +export function setUntypedGlobal(newGlobal?: GlobalState, options?: ActionOptions) { if (typeof newGlobal === 'object' && newGlobal !== currentGlobal) { if (DEBUG) { if ( @@ -109,7 +109,7 @@ export function setGlobal(newGlobal?: GlobalState, options?: ActionOptions) { } } -export function getGlobal() { +export function getUntypedGlobal() { if (DEBUG) { currentGlobal = { ...currentGlobal, @@ -121,7 +121,7 @@ export function getGlobal() { return currentGlobal; } -export function getActions() { +export function getUntypedActions() { return actions; } @@ -134,13 +134,13 @@ let actionQueue: NoneToVoidFunction[] = []; function handleAction(name: string, payload?: ActionPayload, options?: ActionOptions) { actionQueue.push(() => { actionHandlers[name]?.forEach((handler) => { - const response = handler(DEBUG ? getGlobal() : currentGlobal, actions, payload); + const response = handler(DEBUG ? getUntypedGlobal() : currentGlobal, actions, payload); if (!response || typeof response.then === 'function') { return; } // eslint-disable-next-line eslint-multitab-tt/set-global-only-variable - setGlobal(response as GlobalState, options); + setUntypedGlobal(response as GlobalState, options); }); }); @@ -218,7 +218,7 @@ function updateContainers() { } } -export function addActionHandler(name: ActionNames, handler: ActionHandler) { +export function addUntypedActionHandler(name: ActionNames, handler: ActionHandler) { if (!actionHandlers[name]) { actionHandlers[name] = []; @@ -241,7 +241,7 @@ export function removeCallback(cb: Function) { } } -export function withGlobal( +export function withUntypedGlobal( mapStateToProps: MapStateToProps = () => ({}), activationFn?: ActivationFn, ) { @@ -330,14 +330,14 @@ export function typify< }; return { - getGlobal: getGlobal as () => T, - setGlobal: setGlobal as (state: ProjectGlobalState, options?: ActionOptions) => void, - getActions: getActions as () => ProjectActions, - addActionHandler: addActionHandler as ( + getGlobal: getUntypedGlobal as () => T, + setGlobal: setUntypedGlobal as (state: ProjectGlobalState, options?: ActionOptions) => void, + getActions: getUntypedActions as () => ProjectActions, + addActionHandler: addUntypedActionHandler as ( name: ActionName, handler: ActionHandlers[ActionName], ) => void, - withGlobal: withGlobal as ( + withGlobal: withUntypedGlobal as ( mapStateToProps: (global: ProjectGlobalState, ownProps: OwnProps) => AnyLiteral, activationFn?: (global: ProjectGlobalState, ownProps: OwnProps, stickToFirst: StickToFirstFn) => boolean, ) => (Component: FC) => FC, @@ -345,8 +345,8 @@ export function typify< } if (DEBUG) { - (window as any).getGlobal = getGlobal; - (window as any).setGlobal = setGlobal; + (window as any).getGlobal = getUntypedGlobal; + (window as any).setGlobal = setUntypedGlobal; document.addEventListener('dblclick', () => { // eslint-disable-next-line no-console diff --git a/src/types/index.ts b/src/types/index.ts index efbe8622e..48e971316 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -5,18 +5,25 @@ import type { ApiBotInlineResult, ApiBotInlineSwitchPm, ApiBotInlineSwitchWebview, - ApiChat, ApiChatInviteImporter, ApiDocument, + ApiDraft, ApiExportedInvite, ApiFakeType, + ApiFormattedText, ApiLabeledPrice, + ApiMediaFormat, ApiMessage, ApiPhoto, ApiReaction, ApiReactionWithPaid, + ApiStarGift, + ApiStarsSubscription, + ApiStarsTransaction, ApiStickerSet, - ApiUser, + ApiThreadInfo, + ApiTopic, + ApiTypingStatus, ApiVideo, } from '../api/types'; import type { SearchResultKey } from '../util/keys/searchResultKey'; @@ -134,30 +141,6 @@ export interface ISettings extends NotifySettings, Record { shouldSkipWebAppCloseConfirmation: boolean; } -export type BotsPrivacyType = 'allow' | 'disallow' | 'none'; - -export interface ApiPrivacySettings { - visibility: PrivacyVisibility; - isUnspecified?: boolean; - allowUserIds: string[]; - allowChatIds: string[]; - blockUserIds: string[]; - blockChatIds: string[]; - shouldAllowPremium?: true; - botsPrivacy: BotsPrivacyType; -} - -export interface ApiInputPrivacyRules { - visibility: PrivacyVisibility; - isUnspecified?: boolean; - allowedUsers?: ApiUser[]; - allowedChats?: ApiChat[]; - blockedUsers?: ApiUser[]; - blockedChats?: ApiChat[]; - shouldAllowPremium?: true; - botsPrivacy: BotsPrivacyType; -} - export type IAnchorPosition = { x: number; y: number; @@ -413,10 +396,6 @@ export type MiddleSearchResults = { foundIds?: SearchResultKey[]; }; -export type ApiPrivacyKey = 'phoneNumber' | 'addByPhone' | 'lastSeen' | 'profilePhoto' | 'voiceMessages' | -'forwards' | 'chatInvite' | 'phoneCall' | 'phoneP2P' | 'bio' | 'birthday' | 'gifts'; -export type PrivacyVisibility = 'everybody' | 'contacts' | 'closeFriends' | 'nonContacts' | 'nobody'; - export interface LoadingState { areAllItemsLoadedForwards: boolean; areAllItemsLoadedBackwards: boolean; @@ -530,3 +509,130 @@ export type CustomPeer = { export type UniqueCustomPeer = CustomPeer & { type: T; }; + +export type MessageListType = + 'thread' + | 'pinned' + | 'scheduled'; + +export type ChatListType = 'active' | 'archived' | 'saved'; + +export interface MessageList { + chatId: string; + threadId: ThreadId; + type: MessageListType; +} + +export interface ActiveEmojiInteraction { + id: number; + x: number; + y: number; + messageId?: number; + startSize?: number; + animatedEffect?: string; + isReversed?: boolean; +} + +export type ActiveDownloads = Record; + +export type IDimensions = { + width: number; + height: number; +}; + +export type StarsTransactionType = 'all' | 'inbound' | 'outbound'; +export type StarsTransactionHistory = Record; +export type StarsSubscriptions = { + list: ApiStarsSubscription[]; + nextOffset?: string; + isLoading?: boolean; +}; + +export type ConfettiStyle = 'poppers' | 'top-down'; + +export type StarGiftInfo = { + userId: string; + gift: ApiStarGift; + shouldHideName?: boolean; + message?: ApiFormattedText; +}; + +export interface TabThread { + scrollOffset?: number; + replyStack?: number[]; + viewportIds?: number[]; +} + +export interface Thread { + lastScrollOffset?: number; + lastViewportIds?: number[]; + listedIds?: number[]; + outlyingLists?: number[][]; + pinnedIds?: number[]; + scheduledIds?: number[]; + editingId?: number; + editingScheduledId?: number; + editingDraft?: ApiFormattedText; + editingScheduledDraft?: ApiFormattedText; + draft?: ApiDraft; + noWebPage?: boolean; + threadInfo?: ApiThreadInfo; + firstMessageId?: number; + typingStatus?: ApiTypingStatus; +} + +export interface ServiceNotification { + id: number; + message: ApiMessage; + version?: string; + isUnread?: boolean; + isDeleted?: boolean; +} + +export interface TopicsInfo { + totalCount: number; + topicsById: Record; + listedTopicIds?: number[]; + orderedPinnedTopicIds?: number[]; +} + +export type TranslatedMessage = { + isPending?: boolean; + text?: ApiFormattedText; +}; + +export type ChatTranslatedMessages = { + byLangCode: Record>; +}; + +export type ChatRequestedTranslations = { + toLanguage?: string; + manualMessages?: Record; +}; + +export type ConfettiParams = OptionalCombine<{ + style?: ConfettiStyle; + withStars?: boolean; +}, { + top?: number; + left?: number; + width?: number; + height?: number; +}>; + +export type WebPageMediaSize = 'large' | 'small'; + +export type StarGiftCategory = number | 'all' | 'limited'; + +export type CallSound = ( + 'join' | 'allowTalk' | 'leave' | 'connecting' | 'incoming' | 'end' | 'connect' | 'busy' | 'ringing' +); diff --git a/src/types/webapp.ts b/src/types/webapp.ts index 90ef41e30..1a9f79528 100644 --- a/src/types/webapp.ts +++ b/src/types/webapp.ts @@ -1,3 +1,30 @@ +import type { ApiInputMessageReplyInfo } from '../api/types'; + +export type WebAppModalStateType = 'fullScreen' | 'maximized' | 'minimized'; + +export type WebApp = { + url: string; + requestUrl?: string; + botId: string; + appName?: string; + buttonText: string; + peerId?: string; + queryId?: string; + slug?: string; + replyInfo?: ApiInputMessageReplyInfo; + canSendMessages?: boolean; + isRemoveModalOpen?: boolean; + isCloseModalOpen?: boolean; + shouldConfirmClosing?: boolean; + headerColor?: string; + backgroundColor?: string; + isBackButtonVisible?: boolean; + isSettingsButtonVisible?: boolean; + plannedEvents?: WebAppOutboundEvent[]; + sendEvent?: (event: WebAppOutboundEvent) => void; + reloadFrame?: (url: string) => void; +}; + export type PopupOptions = { title: string; message: string; diff --git a/src/util/routing.ts b/src/util/routing.ts index 5e488dfee..b2faf5f71 100644 --- a/src/util/routing.ts +++ b/src/util/routing.ts @@ -1,5 +1,4 @@ -import type { MessageListType } from '../global/types'; -import type { ThreadId } from '../types'; +import type { MessageListType, ThreadId } from '../types'; import { MAIN_THREAD_ID } from '../api/types'; import { IS_MOCKED_CLIENT } from '../config'; diff --git a/src/util/windowSize.ts b/src/util/windowSize.ts index 59706e4c4..d230a825f 100644 --- a/src/util/windowSize.ts +++ b/src/util/windowSize.ts @@ -1,4 +1,4 @@ -import type { IDimensions } from '../global/types'; +import type { IDimensions } from '../types'; import { requestMutation } from '../lib/fasterdom/fasterdom'; import { throttle } from './schedulers';