TeactN: Force full state return in withGlobal (#6240)

This commit is contained in:
zubiden 2025-09-19 14:35:16 +02:00 committed by Alexander Zinchuk
parent c7bf1ebd72
commit 8b1358dd8b
295 changed files with 402 additions and 410 deletions

View File

@ -250,7 +250,7 @@ const Component = ({ id, className, stateValue, onClick }: OwnProps & StateProps
);
}
export default memo(withGlobal<OwnProps>((global, { id }): StateProps => {
export default memo(withGlobal<OwnProps>((global, { id }): Complete<StateProps> => {
const stateValue = selectValue(global, id);
return {
@ -311,6 +311,7 @@ Global State is our single, app-wide store, similar to Redux or Zustand. All its
* Wrap `withGlobal` in `memo` so the component re-renders only on real data changes.
* **Don't** return new arrays or objects inside `withGlobal`; that defeats memoization.
* If you need to filter or map a list, **pass IDs as props** and do the heavy work in a `useMemo` hook.
* Force `Complete<StateProps>` return type for `withGlobal` parameter, as it ensures that all defined properties are passed.
### 3. Example Component

View File

@ -47,6 +47,10 @@ type AnyToVoidFunction = (...args: any[]) => void;
type BooleanToVoidFunction = (value: boolean) => void;
type NoneToVoidFunction = () => void;
type Complete<T> = {
[P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : (T[P] | undefined);
};
type EmojiCategory = {
id: string;
name: string;

View File

@ -250,7 +250,7 @@ const App: FC<StateProps> = ({
};
export default withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
authState: global.authState,
isScreenLocked: global.passcode?.isScreenLocked,

View File

@ -99,7 +99,7 @@ const Auth: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
authState: global.authState,
};

View File

@ -132,5 +132,7 @@ const AuthCode: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => pick(global, ['authPhoneNumber', 'authIsCodeViaApp', 'authIsLoading', 'authErrorKey']),
(global): Complete<StateProps> => (
pick(global, ['authPhoneNumber', 'authIsCodeViaApp', 'authIsLoading', 'authErrorKey']) as Complete<StateProps>
),
)(AuthCode));

View File

@ -50,5 +50,7 @@ const AuthPassword: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => pick(global, ['authIsLoading', 'authErrorKey', 'authHint']),
(global): Complete<StateProps> => (
pick(global, ['authIsLoading', 'authErrorKey', 'authHint']) as Complete<StateProps>
),
)(AuthPassword));

View File

@ -314,7 +314,7 @@ const AuthPhoneNumber: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
sharedState: { settings: { language } },
countryList: { phoneCodes: phoneCodeList },
@ -335,6 +335,6 @@ export default memo(withGlobal(
language,
phoneCodeList,
isTestServer: config?.isTestServer,
};
} as Complete<StateProps>;
},
)(AuthPhoneNumber));

View File

@ -205,7 +205,7 @@ const AuthCode = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
connectionState, authState, authQrCode,
} = global;

View File

@ -86,5 +86,7 @@ const AuthRegister: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => pick(global, ['authIsLoading', 'authErrorKey']),
(global): Complete<StateProps> => (
pick(global, ['authIsLoading', 'authErrorKey']) as Complete<StateProps>
),
)(AuthRegister));

View File

@ -182,7 +182,7 @@ function getFilteredList(countryList: ApiCountryCode[], filter = ''): ApiCountry
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { countryList: { phoneCodes: phoneCodeList } } = global;
return {
phoneCodeList,

View File

@ -57,7 +57,7 @@ const ActiveCallHeader: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const tabState = selectTabState(global);
return {
groupCall: tabState.isMasterTab ? selectActiveGroupCall(global) : undefined,

View File

@ -552,7 +552,7 @@ const GroupCall: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { groupCallId }): StateProps => {
(global, { groupCallId }): Complete<StateProps> => {
const {
connectionState, title, participants, participantsCount, chatId,
} = selectGroupCall(global, groupCallId) || {};

View File

@ -149,7 +149,7 @@ const GroupCallParticipant: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { participant }): StateProps => {
(global, { participant }): Complete<StateProps> => {
return {
peer: selectUser(global, participant.id) || selectChat(global, participant.id),
};

View File

@ -24,7 +24,6 @@ type OwnProps = {
type StateProps = {
participantsCount: number;
participants?: Record<string, TypeGroupCallParticipant>;
canInvite?: boolean;
};
const GroupCallParticipantList: FC<OwnProps & StateProps> = ({
@ -81,7 +80,7 @@ function compareParticipants(a: TypeGroupCallParticipant, b: TypeGroupCallPartic
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { participantsCount, participants } = selectActiveGroupCall(global) || {};
return {

View File

@ -250,7 +250,7 @@ const GroupCallParticipantMenu: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
isAdmin: selectIsAdminInActiveGroupCall(global),
};

View File

@ -317,7 +317,7 @@ const GroupCallParticipantVideo: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { participant }): StateProps => {
(global, { participant }): Complete<StateProps> => {
return {
user: participant.isUser ? selectUser(global, participant.id) : undefined,
chat: !participant.isUser ? selectChat(global, participant.id) : undefined,

View File

@ -104,7 +104,7 @@ const GroupCallTopPane: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => {
(global, { chatId }): Complete<StateProps> => {
const chat = selectChat(global, chatId)!;
const groupCall = selectChatGroupCall(global, chatId);
const activeGroupCallId = selectTabState(global).isMasterTab ? global.groupCalls.activeGroupCallId : undefined;

View File

@ -161,7 +161,7 @@ const MicrophoneButton: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const groupCall = selectActiveGroupCall(global);
const { connectionState } = groupCall || {};

View File

@ -363,7 +363,7 @@ const PhoneCall: FC<StateProps> = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const { phoneCall, currentUserId } = global;
const { isCallPanelVisible, isMasterTab } = selectTabState(global);
const user = selectPhoneCallUser(global);

View File

@ -728,7 +728,7 @@ function renderSeekline(
export default memo(withGlobal<OwnProps>(
(global, {
message,
}): StateProps => {
}): Complete<StateProps> => {
const webPage = selectWebPageFromMessage(global, message);
const mediaDuration = selectMessageMediaDuration(global, message);

View File

@ -115,7 +115,7 @@ function AvatarStoryCircle({
);
}
export default memo(withGlobal<OwnProps>((global, { peerId }): StateProps => {
export default memo(withGlobal<OwnProps>((global, { peerId }): Complete<StateProps> => {
const peerStories = selectPeerStories(global, peerId);
const appTheme = selectTheme(global);

View File

@ -2466,7 +2466,7 @@ const Composer: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>(
(global, {
chatId, threadId, storyId, messageListType, isMobile, type,
}): StateProps => {
}): Complete<StateProps> => {
const appConfig = global.appConfig;
const chat = selectChat(global, chatId);
const chatBot = !isSystemBot(chatId) ? selectBot(global, chatId) : undefined;

View File

@ -481,7 +481,7 @@ const CustomEmojiPicker: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatId, isStatusPicker, isReactionPicker }): StateProps => {
(global, { chatId, isStatusPicker, isReactionPicker }): Complete<StateProps> => {
const {
stickers: {
setsById: stickerSetsById,

View File

@ -83,7 +83,7 @@ const CustomEmojiSetsModal: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
canPlayAnimatedEmojis: selectCanPlayAnimatedEmojis(global),
};

View File

@ -239,7 +239,7 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chat, isSavedDialog }): StateProps => {
(global, { chat, isSavedDialog }): Complete<StateProps> => {
const isPrivateChat = isUserId(chat.id);
const isChatWithSelf = selectIsChatWithSelf(global, chat.id);
const user = isPrivateChat && selectUser(global, getPrivateChatUserId(chat)!);

View File

@ -59,7 +59,6 @@ export type OwnProps = {
type StateProps = {
chat?: ApiChat;
isGroup?: boolean;
isChannel?: boolean;
isSuperGroup?: boolean;
messageIds?: number[];
@ -492,7 +491,7 @@ const DeleteMessageModal: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
deleteMessageModal,
} = selectTabState(global);

View File

@ -288,7 +288,7 @@ const GroupChatInfo: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatId, threadId }): StateProps => {
(global, { chatId, threadId }): Complete<StateProps> => {
const chat = selectChat(global, chatId);
const threadInfo = threadId ? selectThreadInfo(global, chatId, threadId) : undefined;
const onlineCount = chat ? selectChatOnlineCount(global, chat) : undefined;

View File

@ -119,7 +119,7 @@ function MessageSummary({
}
export default memo(withGlobal<OwnProps>(
(global, { message }): StateProps => {
(global, { message }): Complete<StateProps> => {
const poll = selectPollFromMessage(global, message);
const webPage = selectWebPageFromMessage(global, message);
const storyData = message.content.storyData;

View File

@ -130,9 +130,12 @@ const PeerChip = <T,>({
};
export default memo(withGlobal<OwnProps>(
(global, { peerId, forceShowSelf }): StateProps => {
(global, { peerId, forceShowSelf }): Complete<StateProps> => {
if (!peerId) {
return {};
return {
peer: undefined,
isSavedMessages: undefined,
};
}
const peer = selectPeer(global, peerId);

View File

@ -104,7 +104,7 @@ const PinMessageModal = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => {
(global, { chatId }): Complete<StateProps> => {
const isPrivateChat = isUserId(chatId);
const isChatWithSelf = selectIsChatWithSelf(global, chatId);
const chat = selectChat(global, chatId);

View File

@ -136,7 +136,7 @@ const PrivacySettingsNoticeModal = ({ isOpen, isReadDate, user }: OwnProps & Sta
};
export default memo(
withGlobal<OwnProps>((global): StateProps => {
withGlobal<OwnProps>((global): Complete<StateProps> => {
const { chatId, isReadDate } = selectTabState(global).privacySettingsNoticeModal || {};
const user = chatId ? selectUser(global, chatId) : undefined;

View File

@ -262,7 +262,7 @@ const PrivateChatInfo: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { userId, forceShowSelf }): StateProps => {
(global, { userId, forceShowSelf }): Complete<StateProps> => {
const { isSynced } = global;
const user = userId ? selectUser(global, userId) : undefined;
const userStatus = userId ? selectUserStatus(global, userId) : undefined;

View File

@ -450,7 +450,7 @@ const ProfileInfo: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { peerId }): StateProps => {
(global, { peerId }): Complete<StateProps> => {
const user = selectUser(global, peerId);
const userFullInfo = user ? selectUserFullInfo(global, peerId) : undefined;
const userStatus = selectUserStatus(global, peerId);
@ -477,10 +477,8 @@ export default memo(withGlobal<OwnProps>(
emojiStatusSticker,
emojiStatusSlug,
profilePhotos,
...(topic && {
topic,
messagesCount: selectThreadMessagesCount(global, peerId, currentTopicId!),
}),
topic,
messagesCount: topic ? selectThreadMessagesCount(global, peerId, currentTopicId!) : undefined,
};
},
)(ProfileInfo));

View File

@ -143,7 +143,7 @@ const RecipientPicker: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
chats: {
listIds,

View File

@ -99,10 +99,12 @@ function SeenByModal({
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { chatId, messageId } = selectTabState(global).seenByModal || {};
if (!chatId || !messageId) {
return {};
return {
seenByDates: undefined,
};
}
return {

View File

@ -51,7 +51,7 @@ const SensitiveContentConfirmModal = ({
);
};
export default memo(withGlobal<OwnProps>((global): StateProps => {
export default memo(withGlobal<OwnProps>((global): Complete<StateProps> => {
const appConfig = global.appConfig;
const verifyAgeMin = appConfig.verifyAgeMin;

View File

@ -444,7 +444,7 @@ const StickerSet: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const collectibleStatuses = global.collectibleEmojiStatuses?.statuses;
return { collectibleStatuses };

View File

@ -256,7 +256,7 @@ const StickerSetModal: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { fromSticker, stickerSetShortName }): StateProps => {
(global, { fromSticker, stickerSetShortName }): Complete<StateProps> => {
const currentMessageList = selectCurrentMessageList(global);
const { chatId, threadId } = currentMessageList || {};
const chat = chatId && selectChat(global, chatId);

View File

@ -41,9 +41,9 @@ const TypingStatus: FC<OwnProps & StateProps> = ({ typingStatus, typingUser }) =
};
export default memo(withGlobal<OwnProps>(
(global, { typingStatus }): StateProps => {
(global, { typingStatus }): Complete<StateProps> => {
if (!typingStatus.userId) {
return {};
return { typingUser: undefined };
}
const typingUser = selectUser(global, typingStatus.userId);

View File

@ -171,7 +171,7 @@ const UiLoader: FC<OwnProps & StateProps> = ({
};
export default withGlobal<OwnProps>(
(global, { isMobile }): StateProps => {
(global, { isMobile }): Complete<StateProps> => {
const tabState = selectTabState(global);
return {

View File

@ -88,7 +88,7 @@ const VerificationMonetizationModal = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
twoFaSettings: {
hint: passwordHint,

View File

@ -139,7 +139,7 @@ const WebLink = ({
export default memo(withGlobal<OwnProps>(
(global, {
message,
}): StateProps => {
}): Complete<StateProps> => {
const webPage = selectWebPageFromMessage(global, message);
return {

View File

@ -134,7 +134,7 @@ const EmbeddedStoryForward: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { forwardInfo }): StateProps => {
(global, { forwardInfo }): Complete<StateProps> => {
const sender = forwardInfo.fromPeerId ? selectPeer(global, forwardInfo.fromPeerId) : undefined;
const story = forwardInfo.storyId && forwardInfo.fromPeerId
? selectPeerStory(global, forwardInfo.fromPeerId, forwardInfo.storyId) : undefined;

View File

@ -69,7 +69,7 @@ const GiftRibbon = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
theme: selectTheme(global),
};

View File

@ -229,7 +229,7 @@ const SavedGift = ({
};
export default memo(withGlobal<OwnProps>(
(global, { peerId, gift }): StateProps => {
(global, { peerId, gift }): Complete<StateProps> => {
const fromPeer = gift.fromId ? selectPeer(global, gift.fromId) : undefined;
const chat = selectChat(global, peerId);
const hasAdminRights = chat && getHasAdminRight(chat, 'postMessages');

View File

@ -98,7 +98,7 @@ function PaidMessagePrice({
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const starsUsdWithdrawRateX1000 = global.appConfig.starsUsdWithdrawRateX1000;
const starsUsdWithdrawRate = starsUsdWithdrawRateX1000 ? starsUsdWithdrawRateX1000 / 1000 : 1;
const configStarsPaidMessageCommissionPermille = global.appConfig.starsPaidMessageCommissionPermille;

View File

@ -484,7 +484,7 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatOrUserId, isSavedDialog }): StateProps => {
(global, { chatOrUserId, isSavedDialog }): Complete<StateProps> => {
const { countryList: { phoneCodes: phoneCodeList } } = global;
const chat = chatOrUserId ? selectChat(global, chatOrUserId) : undefined;

View File

@ -218,7 +218,7 @@ const UserBirthday = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { birthdayNumbers, animatedEmojiEffects } = global;
return {
birthdayNumbers,

View File

@ -117,7 +117,7 @@ const ChatFolderModal: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { byId: foldersById, orderedIds: folderOrderedIds } = global.chatFolders;
return {

View File

@ -565,7 +565,7 @@ function LeftColumn({
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const tabState = selectTabState(global);
const {
globalSearch: {

View File

@ -496,13 +496,13 @@ const Chat: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>(
(global, {
chatId, isSavedDialog, isPreview, previewMessageId,
}): StateProps => {
}): Complete<StateProps> => {
const chat = selectChat(global, chatId);
const user = selectUser(global, chatId);
if (!chat) {
return {
currentUserId: global.currentUserId!,
};
} as Complete<StateProps>;
}
const folderIds = getChatFolderIds(chatId);
@ -553,9 +553,7 @@ export default memo(withGlobal<OwnProps>(
isForumPanelOpen: selectIsForumPanelOpen(global),
canScrollDown: isSelected && messageListType === 'thread',
canChangeFolder: (global.chatFolders.orderedIds?.length || 0) > 1,
...(isOutgoing && lastMessage && {
lastMessageOutgoingStatus: selectOutgoingStatus(global, lastMessage),
}),
lastMessageOutgoingStatus: isOutgoing && lastMessage ? selectOutgoingStatus(global, lastMessage) : undefined,
user,
userStatus,
lastMessageTopic,

View File

@ -408,7 +408,7 @@ const ChatFolders: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
chatFolders: {
byId: chatFoldersById,

View File

@ -108,7 +108,7 @@ const ContactList: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { userIds: contactIds } = global.contactList || {};
const { byId: usersById, statusesById: userStatusesById } = global.users;

View File

@ -69,7 +69,7 @@ const EmptyFolder: FC<OwnProps & StateProps> = ({
);
};
export default memo(withGlobal<OwnProps>((global, { folderId, folderType }): StateProps => {
export default memo(withGlobal<OwnProps>((global, { folderId, folderType }): Complete<StateProps> => {
const chatFolder = folderId && folderType === 'folder' ? selectChatFolder(global, folderId) : undefined;
return {

View File

@ -65,7 +65,7 @@ const EmptyForum: FC<OwnProps & StateProps> = ({
);
};
export default memo(withGlobal<OwnProps>((global, { chatId }): StateProps => {
export default memo(withGlobal<OwnProps>((global, { chatId }): Complete<StateProps> => {
const chat = selectChat(global, chatId);
const canManageTopics = chat && (chat.isCreator || getHasAdminRight(chat, 'manageTopics'));

View File

@ -288,7 +288,7 @@ const ForumPanel: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const chatId = selectTabState(global).forumPanelChatId;
const chat = chatId ? selectChat(global, chatId) : undefined;
const {

View File

@ -354,7 +354,7 @@ const LeftMainHeader: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const tabState = selectTabState(global);
const {
query: searchQuery, fetchingStatus, chatId, minDate,

View File

@ -258,7 +258,7 @@ const LeftSideMenuItems = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const tabState = selectTabState(global);
const {
currentUserId, archiveSettings,

View File

@ -105,7 +105,7 @@ const StatusButton: FC<StateProps> = ({ emojiStatus, collectibleStatuses, isAcco
);
};
export default memo(withGlobal((global): StateProps => {
export default memo(withGlobal((global): Complete<StateProps> => {
const { currentUserId } = global;
const currentUser = currentUserId ? selectUser(global, currentUserId) : undefined;
const collectibleStatuses = global.collectibleEmojiStatuses?.statuses;

View File

@ -82,7 +82,7 @@ const StatusPickerMenu: FC<OwnProps & StateProps> = ({
);
};
export default memo(withGlobal<OwnProps>((global): StateProps => {
export default memo(withGlobal<OwnProps>((global): Complete<StateProps> => {
return {
areFeaturedStickersLoaded: Boolean(global.customEmojis.featuredIds?.length),
isTranslucent: selectIsContextMenuTranslucent(global),

View File

@ -131,7 +131,7 @@ const NewChatStep1: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { userIds: localContactIds } = global.contactList || {};
const {

View File

@ -222,7 +222,7 @@ const NewChatStep2: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
progress: creationProgress,
error: creationError,

View File

@ -145,7 +145,7 @@ const BotAppResults: FC<OwnProps & StateProps> = ({
);
};
export default memo(withGlobal<OwnProps>((global) => {
export default memo(withGlobal<OwnProps>((global): Complete<StateProps> => {
const globalSearch = selectTabState(global).globalSearch;
const foundIds = globalSearch.popularBotApps?.peerIds;

View File

@ -3,7 +3,7 @@ import { memo } from '../../../lib/teact/teact';
import { getActions, withGlobal } from '../../../global';
import type {
ApiChat, ApiMessage, ApiMessageOutgoingStatus,
ApiChat, ApiMessage,
ApiUser,
} from '../../../api/types';
@ -46,7 +46,6 @@ type OwnProps = {
type StateProps = {
chat?: ApiChat;
privateChatUser?: ApiUser;
lastMessageOutgoingStatus?: ApiMessageOutgoingStatus;
};
const ChatMessage: FC<OwnProps & StateProps> = ({
@ -141,10 +140,10 @@ function renderSummary(
}
export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => {
(global, { chatId }): Complete<StateProps> => {
const chat = selectChat(global, chatId);
if (!chat) {
return {};
return {} as Complete<StateProps>;
}
const privateChatUserId = getPrivateChatUserId(chat);
@ -152,7 +151,7 @@ export default memo(withGlobal<OwnProps>(
return {
chat,
...(privateChatUserId && { privateChatUser }),
privateChatUser,
};
},
)(ChatMessage));

View File

@ -167,7 +167,7 @@ const ChatMessageResults: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { byId: chatsById } = global.chats;
const { currentUserId, messages: { byChatId: globalMessagesByChatId } } = global;
const {

View File

@ -498,14 +498,14 @@ const ChatResults: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { isChannelList }): StateProps => {
(global, { isChannelList }): Complete<StateProps> => {
const { userIds: contactIds } = global.contactList || {};
const {
currentUserId, messages,
} = global;
if (!contactIds) {
return {};
return {} as Complete<StateProps>;
}
const {

View File

@ -197,7 +197,7 @@ const LeftSearch: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { currentContent, chatId } = selectTabState(global).globalSearch;
const { animationLevel } = selectSharedSettings(global);

View File

@ -158,7 +158,7 @@ const LeftSearchResultChat: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => {
(global, { chatId }): Complete<StateProps> => {
const chat = selectChat(global, chatId);
const user = selectUser(global, chatId);
const isPinned = selectIsChatPinned(global, chatId);

View File

@ -59,7 +59,7 @@ const LeftSearchResultTopic: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { chatId, topicId }): StateProps => {
(global, { chatId, topicId }): Complete<StateProps> => {
const topic = selectTopic(global, chatId, topicId);
return {

View File

@ -149,7 +149,7 @@ const PublicPostsResults = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { messages: { byChatId: globalMessagesByChatId } } = global;
const { resultsByType, searchFlood, fetchingStatus } = selectTabState(global).globalSearch;
const publicPostsResult = resultsByType?.publicPosts;

View File

@ -270,7 +270,7 @@ const PublicPostsSearchLauncher = ({
);
};
export default memo(withGlobal<OwnProps>((global): StateProps => ({
export default memo(withGlobal<OwnProps>((global): Complete<StateProps> => ({
isCurrentUserPremium: selectIsCurrentUserPremium(global),
starsBalance: global.stars?.balance?.amount || 0,
}))(PublicPostsSearchLauncher));

View File

@ -130,7 +130,7 @@ const RecentContacts: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { userIds: topUserIds } = global.topPeers;
const usersById = global.users.byId;
const { recentlyFoundChatIds } = global;

View File

@ -86,7 +86,7 @@ const BlockUserModal: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
users: {
byId: usersById,

View File

@ -226,7 +226,7 @@ function PrivacyMessages({
);
}
export default memo(withGlobal<OwnProps>((global): StateProps => {
export default memo(withGlobal<OwnProps>((global): Complete<StateProps> => {
const {
settings: {
privacy,

View File

@ -141,7 +141,7 @@ const SettingsAcceptedGift = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
settings: {
byKey: {

View File

@ -5,6 +5,7 @@ import {
import { getActions, withGlobal } from '../../../global';
import type { ApiSession } from '../../../api/types';
import type { GlobalState } from '../../../global/types';
import { formatPastTimeShort } from '../../../util/dates/dateFormat';
import getSessionIcon from './helpers/getSessionIcon';
@ -26,11 +27,7 @@ type OwnProps = {
onReset: () => void;
};
type StateProps = {
byHash: Record<string, ApiSession>;
orderedHashes: string[];
ttlDays?: number;
};
type StateProps = GlobalState['activeSessions'];
const SettingsActiveSessions: FC<OwnProps & StateProps> = ({
isActive,
@ -286,5 +283,5 @@ function getLocation(session: ApiSession) {
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => global.activeSessions,
(global): Complete<StateProps> => global.activeSessions as Complete<StateProps>,
)(SettingsActiveSessions));

View File

@ -101,7 +101,7 @@ const SettingsActiveWebsite: FC<OwnProps & StateProps> = ({
);
};
export default memo(withGlobal<OwnProps>((global, { hash }): StateProps => {
export default memo(withGlobal<OwnProps>((global, { hash }): Complete<StateProps> => {
const session = hash ? global.activeWebSessions.byHash[hash] : undefined;
const bot = session ? global.users.byId[session.botId] : undefined;

View File

@ -164,7 +164,7 @@ const SettingsActiveWebsites: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { byHash, orderedHashes } = global.activeWebSessions;
return {
byHash,

View File

@ -94,7 +94,7 @@ const SettingsCustomEmoji: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
...pick(global.settings.byKey, [
'shouldSuggestCustomEmoji',

View File

@ -161,7 +161,7 @@ const SettingsDataStorage: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return pick(global.settings.byKey, [
'canAutoLoadPhotoFromContacts',
'canAutoLoadPhotoInPrivateChats',

View File

@ -132,7 +132,7 @@ const SettingsDoNotTranslate: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
doNotTranslate,
} = global.settings.byKey;

View File

@ -301,7 +301,7 @@ const SettingsEditProfile: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { currentUserId } = global;
const {
progress, isUsernameAvailable, checkedUsername, error: editUsernameError,
@ -310,23 +310,13 @@ export default memo(withGlobal<OwnProps>(
const maxBioLength = selectCurrentLimit(global, 'aboutLength');
if (!currentUser) {
return {
progress,
checkedUsername,
isUsernameAvailable,
editUsernameError,
maxBioLength,
};
}
const {
firstName: currentFirstName,
lastName: currentLastName,
usernames,
} = currentUser;
} = currentUser || {};
const currentUserFullInfo = currentUserId ? selectUserFullInfo(global, currentUserId) : undefined;
const currentAvatarHash = getChatAvatarHash(currentUser);
const currentAvatarHash = currentUser && getChatAvatarHash(currentUser);
return {
currentAvatarHash,

View File

@ -185,7 +185,7 @@ const SettingsExperimental = ({
};
export default memo(withGlobal(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
shouldForceHttpTransport,
shouldAllowHttpTransport,

View File

@ -182,7 +182,7 @@ const SettingsGeneral: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
theme,
shouldUseSystemTheme,

View File

@ -171,7 +171,7 @@ const SettingsGeneralBackground: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const theme = selectTheme(global);
const { background, isBlurred } = selectThemeValues(global, theme) || {};
const { loadedWallpapers } = global.settings;

View File

@ -347,7 +347,7 @@ function drawHue(canvas: HTMLCanvasElement) {
}
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const theme = selectTheme(global);
const { backgroundColor } = selectThemeValues(global, theme) || {};
return {

View File

@ -181,7 +181,7 @@ const SettingsLanguage: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
canTranslate, canTranslateChats, doNotTranslate,
} = global.settings.byKey;

View File

@ -257,7 +257,7 @@ const SettingsMain: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const { currentUserId } = global;
const isGiveawayAvailable = selectIsGiveawayGiftsPurchaseAvailable(global);
const starsBalance = global.stars?.balance;

View File

@ -239,7 +239,7 @@ const SettingsNotifications: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
hasContactJoinedNotifications: Boolean(global.settings.byKey.hasContactJoinedNotifications),
hasWebNotifications: global.settings.byKey.hasWebNotifications,

View File

@ -226,7 +226,7 @@ function SettingsPerformance({
);
}
export default memo(withGlobal<OwnProps>((global): StateProps => {
export default memo(withGlobal<OwnProps>((global): Complete<StateProps> => {
return {
performanceSettings: selectPerformanceSettings(global),
};

View File

@ -461,7 +461,7 @@ const SettingsPrivacy: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
settings: {
byKey: {

View File

@ -156,7 +156,7 @@ const SettingsPrivacyBlockedUsers: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
chats: {
byId: chatsByIds,

View File

@ -74,7 +74,7 @@ const SettingsPrivacyLastSeen = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
isCurrentUserPremium: selectIsCurrentUserPremium(global),
shouldHideReadMarks: Boolean(selectShouldHideReadMarks(global)),

View File

@ -402,7 +402,7 @@ function PrivacySubsection({
}
export default memo(withGlobal<OwnProps>(
(global, { screen }): StateProps => {
(global, { screen }): Complete<StateProps> => {
let primaryPrivacy: ApiPrivacySettings | undefined;
let secondaryPrivacy: ApiPrivacySettings | undefined;
@ -468,7 +468,7 @@ export default memo(withGlobal<OwnProps>(
currentUserId: currentUserId!,
hasCurrentUserFullInfo: Boolean(currentUserFullInfo),
currentUserFallbackPhoto: currentUserFullInfo?.fallbackPhoto,
};
} as Complete<StateProps>;
}
return {

View File

@ -259,7 +259,7 @@ function getCurrentPrivacySettings(global: GlobalState, screen: SettingsScreens)
}
export default memo(withGlobal<OwnProps>(
(global, { screen }): StateProps => {
(global, { screen }): Complete<StateProps> => {
return {
currentUserId: global.currentUserId,
settings: getCurrentPrivacySettings(global, screen),

View File

@ -2,7 +2,7 @@ import type { FC } from '../../../lib/teact/teact';
import { memo, useCallback, useMemo } from '../../../lib/teact/teact';
import { getActions, withGlobal } from '../../../global';
import type { ApiAvailableReaction } from '../../../api/types';
import type { ApiAvailableReaction, ApiReaction } from '../../../api/types';
import useHistoryBack from '../../../hooks/useHistoryBack';
@ -16,7 +16,7 @@ type OwnProps = {
type StateProps = {
availableReactions?: ApiAvailableReaction[];
selectedReaction?: string;
selectedReaction?: ApiReaction;
};
const SettingsQuickReaction: FC<OwnProps & StateProps> = ({
@ -56,7 +56,7 @@ const SettingsQuickReaction: FC<OwnProps & StateProps> = ({
<RadioGroup
name="quick-reaction-settings"
options={options}
selected={selectedReaction}
selected={selectedReaction?.type === 'emoji' ? selectedReaction.emoticon : undefined}
onChange={handleChange}
withIcon
/>
@ -65,7 +65,7 @@ const SettingsQuickReaction: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global) => {
(global): Complete<StateProps> => {
const { config, reactions } = global;
return {

View File

@ -164,7 +164,7 @@ const SettingsStickers: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
...pick(global.settings.byKey, [
'shouldSuggestStickers',

View File

@ -170,7 +170,7 @@ const SettingsFoldersChatFilters: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
return {
maxChats: selectCurrentLimit(global, 'dialogFiltersChats'),
};

View File

@ -472,7 +472,7 @@ const SettingsFoldersEdit: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global, { state }): StateProps => {
(global, { state }): Complete<StateProps> => {
const { listIds } = global.chats;
const { byId, invites } = global.chatFolders;
const chatListCount = Object.values(byId).reduce((acc, el) => acc + (el.isChatList ? 1 : 0), 0);

View File

@ -416,7 +416,7 @@ const SettingsFoldersMain: FC<OwnProps & StateProps> = ({
};
export default memo(withGlobal<OwnProps>(
(global): StateProps => {
(global): Complete<StateProps> => {
const {
orderedIds: folderIds,
byId: foldersById,

Some files were not shown because too many files have changed in this diff Show More