mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 04:45:08 +01:00
[Refactoring] Finally get rid of deprecated openUserInfo
This commit is contained in:
parent
6edb4c3fab
commit
8bae7c9e82
@ -834,9 +834,9 @@ export async function requestThreadInfoUpdate({
|
||||
}
|
||||
|
||||
export async function searchMessagesLocal({
|
||||
chatOrUser, type, query, topMessageId, minDate, maxDate, ...pagination
|
||||
chat, type, query, topMessageId, minDate, maxDate, ...pagination
|
||||
}: {
|
||||
chatOrUser: ApiChat | ApiUser;
|
||||
chat: ApiChat;
|
||||
type?: ApiMessageSearchType | ApiGlobalMessageSearchType;
|
||||
query?: string;
|
||||
topMessageId?: number;
|
||||
@ -873,7 +873,7 @@ export async function searchMessagesLocal({
|
||||
}
|
||||
|
||||
const result = await invokeRequest(new GramJs.messages.Search({
|
||||
peer: buildInputPeer(chatOrUser.id, chatOrUser.accessHash),
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
filter,
|
||||
q: query || '',
|
||||
topMsgId: topMessageId,
|
||||
|
@ -230,7 +230,7 @@ export async function fetchProfilePhotos(user?: ApiUser, chat?: ApiChat) {
|
||||
}
|
||||
|
||||
const result = await searchMessagesLocal({
|
||||
chatOrUser: chat!,
|
||||
chat: chat!,
|
||||
type: 'profilePhoto',
|
||||
limit: PROFILE_PHOTOS_LIMIT,
|
||||
});
|
||||
|
@ -16,13 +16,13 @@ type OwnProps = {
|
||||
const UserLink: FC<OwnProps> = ({
|
||||
className, sender, children,
|
||||
}) => {
|
||||
const { openUserInfo } = getDispatch();
|
||||
const { openChat } = getDispatch();
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
if (sender) {
|
||||
openUserInfo({ id: sender.id });
|
||||
openChat({ id: sender.id });
|
||||
}
|
||||
}, [sender, openUserInfo]);
|
||||
}, [sender, openChat]);
|
||||
|
||||
if (!sender) {
|
||||
return children;
|
||||
|
@ -23,7 +23,7 @@ type StateProps = {
|
||||
const Contact: FC<OwnProps & StateProps> = ({
|
||||
contact, user, phoneCodeList,
|
||||
}) => {
|
||||
const { openUserInfo } = getDispatch();
|
||||
const { openChat } = getDispatch();
|
||||
|
||||
const {
|
||||
firstName,
|
||||
@ -33,8 +33,8 @@ const Contact: FC<OwnProps & StateProps> = ({
|
||||
} = contact;
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
openUserInfo({ id: userId });
|
||||
}, [openUserInfo, userId]);
|
||||
openChat({ id: userId });
|
||||
}, [openChat, userId]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
@ -1,7 +1,6 @@
|
||||
import React, { useCallback } from '../../../../lib/teact/teact';
|
||||
import { getDispatch } from '../../../../lib/teact/teactn';
|
||||
|
||||
import { isUserId } from '../../../../modules/helpers';
|
||||
import { IAlbum, MediaViewerOrigin } from '../../../../types';
|
||||
import {
|
||||
ApiChat, ApiMessage, ApiUser, MAIN_THREAD_ID,
|
||||
@ -24,7 +23,7 @@ export default function useInnerHandlers(
|
||||
botSender?: ApiUser,
|
||||
) {
|
||||
const {
|
||||
openUserInfo, openChat, showNotification, focusMessage, openMediaViewer, openAudioPlayer,
|
||||
openChat, showNotification, focusMessage, openMediaViewer, openAudioPlayer,
|
||||
markMessagesRead, cancelSendingMessage, sendPollVote, openForwardMenu, focusMessageInComments,
|
||||
} = getDispatch();
|
||||
|
||||
@ -37,12 +36,8 @@ export default function useInnerHandlers(
|
||||
return;
|
||||
}
|
||||
|
||||
if (isUserId(avatarPeer.id)) {
|
||||
openUserInfo({ id: avatarPeer.id });
|
||||
} else {
|
||||
openChat({ id: avatarPeer.id });
|
||||
}
|
||||
}, [avatarPeer, openUserInfo, openChat]);
|
||||
openChat({ id: avatarPeer.id });
|
||||
}, [avatarPeer, openChat]);
|
||||
|
||||
const handleSenderClick = useCallback(() => {
|
||||
if (!senderPeer) {
|
||||
@ -53,13 +48,11 @@ export default function useInnerHandlers(
|
||||
|
||||
if (asForwarded && forwardInfo?.channelPostId) {
|
||||
focusMessage({ chatId: senderPeer.id, messageId: forwardInfo.channelPostId });
|
||||
} else if (isUserId(senderPeer.id)) {
|
||||
openUserInfo({ id: senderPeer.id });
|
||||
} else {
|
||||
openChat({ id: senderPeer.id });
|
||||
}
|
||||
}, [
|
||||
asForwarded, focusMessage, forwardInfo, lang, openChat, openUserInfo, senderPeer, showNotification,
|
||||
asForwarded, focusMessage, forwardInfo, lang, openChat, senderPeer, showNotification,
|
||||
]);
|
||||
|
||||
const handleViaBotClick = useCallback(() => {
|
||||
@ -67,8 +60,8 @@ export default function useInnerHandlers(
|
||||
return;
|
||||
}
|
||||
|
||||
openUserInfo({ id: botSender.id });
|
||||
}, [botSender, openUserInfo]);
|
||||
openChat({ id: botSender.id });
|
||||
}, [botSender, openChat]);
|
||||
|
||||
const handleReplyClick = useCallback((): void => {
|
||||
focusMessage({
|
||||
|
@ -65,7 +65,6 @@ import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
|
||||
|
||||
type OwnProps = {
|
||||
chatId: string;
|
||||
userId?: string;
|
||||
profileState: ProfileState;
|
||||
onProfileStateChange: (state: ProfileState) => void;
|
||||
};
|
||||
@ -143,7 +142,6 @@ const Profile: FC<OwnProps & StateProps> = ({
|
||||
searchMediaMessagesLocal,
|
||||
openMediaViewer,
|
||||
openAudioPlayer,
|
||||
openUserInfo,
|
||||
focusMessage,
|
||||
loadProfilePhotos,
|
||||
setNewChatMembersDialogState,
|
||||
@ -222,8 +220,8 @@ const Profile: FC<OwnProps & StateProps> = ({
|
||||
}, [profileId, openAudioPlayer]);
|
||||
|
||||
const handleMemberClick = useCallback((id: string) => {
|
||||
openUserInfo({ id });
|
||||
}, [openUserInfo]);
|
||||
openChat({ id });
|
||||
}, [openChat]);
|
||||
|
||||
const handleMessageFocus = useCallback((messageId: number) => {
|
||||
focusMessage({ chatId: profileId, messageId });
|
||||
@ -492,10 +490,9 @@ function buildInfiniteScrollItemSelector(resultType: string) {
|
||||
}
|
||||
|
||||
export default memo(withGlobal<OwnProps>(
|
||||
(global, { chatId, userId }): StateProps => {
|
||||
(global, { chatId }): StateProps => {
|
||||
const chat = selectChat(global, chatId);
|
||||
|
||||
const chatMessages = selectChatMessages(global, userId || chatId);
|
||||
const chatMessages = selectChatMessages(global, chatId);
|
||||
const { currentType: mediaSearchType, resultsByType } = selectCurrentMediaSearch(global) || {};
|
||||
const { foundIds } = (resultsByType && mediaSearchType && resultsByType[mediaSearchType]) || {};
|
||||
|
||||
@ -509,18 +506,13 @@ export default memo(withGlobal<OwnProps>(
|
||||
const areMembersHidden = hasMembersTab && chat && chat.fullInfo && !chat.fullInfo.canViewMembers;
|
||||
const canAddMembers = hasMembersTab && chat && (getHasAdminRight(chat, 'inviteUsers') || chat.isCreator);
|
||||
const canDeleteMembers = hasMembersTab && chat && (getHasAdminRight(chat, 'banUsers') || chat.isCreator);
|
||||
|
||||
const activeDownloadIds = selectActiveDownloadIds(global, chatId);
|
||||
|
||||
let hasCommonChatsTab;
|
||||
let resolvedUserId;
|
||||
let user;
|
||||
if (userId) {
|
||||
resolvedUserId = userId;
|
||||
} else if (isUserId(chatId)) {
|
||||
if (isUserId(chatId)) {
|
||||
resolvedUserId = chatId;
|
||||
}
|
||||
if (resolvedUserId) {
|
||||
user = selectUser(global, resolvedUserId);
|
||||
hasCommonChatsTab = user && !user.isSelf && !isUserBot(user);
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ type StateProps = {
|
||||
contentKey?: RightColumnContent;
|
||||
chatId?: string;
|
||||
threadId?: number;
|
||||
currentProfileUserId?: string;
|
||||
isChatSelected: boolean;
|
||||
shouldSkipHistoryAnimations?: boolean;
|
||||
nextManagementScreen?: ManagementScreens;
|
||||
@ -56,7 +55,6 @@ const RightColumn: FC<StateProps> = ({
|
||||
contentKey,
|
||||
chatId,
|
||||
threadId,
|
||||
currentProfileUserId,
|
||||
isChatSelected,
|
||||
shouldSkipHistoryAnimations,
|
||||
nextManagementScreen,
|
||||
@ -64,7 +62,6 @@ const RightColumn: FC<StateProps> = ({
|
||||
const {
|
||||
toggleChatInfo,
|
||||
toggleManagement,
|
||||
openUserInfo,
|
||||
closeLocalTextSearch,
|
||||
setStickerSearchQuery,
|
||||
setGifSearchQuery,
|
||||
@ -84,7 +81,7 @@ const RightColumn: FC<StateProps> = ({
|
||||
const isScrolledDown = profileState !== ProfileState.Profile;
|
||||
|
||||
const isOpen = contentKey !== undefined;
|
||||
const isProfile = contentKey === RightColumnContent.ChatInfo || contentKey === RightColumnContent.UserInfo;
|
||||
const isProfile = contentKey === RightColumnContent.ChatInfo;
|
||||
const isSearch = contentKey === RightColumnContent.Search;
|
||||
const isManagement = contentKey === RightColumnContent.Management;
|
||||
const isStickerSearch = contentKey === RightColumnContent.StickerSearch;
|
||||
@ -109,13 +106,6 @@ const RightColumn: FC<StateProps> = ({
|
||||
}
|
||||
toggleChatInfo(undefined, { forceSyncOnIOs: true });
|
||||
break;
|
||||
case RightColumnContent.UserInfo:
|
||||
if (isScrolledDown && shouldScrollUp) {
|
||||
setProfileState(ProfileState.Profile);
|
||||
break;
|
||||
}
|
||||
openUserInfo({ id: undefined }, { forceSyncOnIOs: true });
|
||||
break;
|
||||
case RightColumnContent.Management: {
|
||||
switch (managementScreen) {
|
||||
case ManagementScreens.Initial:
|
||||
@ -175,7 +165,7 @@ const RightColumn: FC<StateProps> = ({
|
||||
break;
|
||||
}
|
||||
}, [
|
||||
contentKey, isScrolledDown, toggleChatInfo, openUserInfo, closePollResults, setNewChatMembersDialogState,
|
||||
contentKey, isScrolledDown, toggleChatInfo, closePollResults, setNewChatMembersDialogState,
|
||||
managementScreen, toggleManagement, closeLocalTextSearch, setStickerSearchQuery, setGifSearchQuery,
|
||||
setEditingExportedInvite, chatId, setOpenedInviteInfo,
|
||||
]);
|
||||
@ -213,21 +203,18 @@ const RightColumn: FC<StateProps> = ({
|
||||
}, [isOverlaying]);
|
||||
|
||||
// We need to clear profile state and management screen state, when changing chats
|
||||
useLayoutEffectWithPrevDeps(([prevContentKey, prevChatId]) => {
|
||||
if (
|
||||
(prevContentKey === RightColumnContent.ChatInfo && contentKey === RightColumnContent.UserInfo)
|
||||
|| (prevContentKey === RightColumnContent.UserInfo && contentKey === RightColumnContent.ChatInfo)
|
||||
|| (prevChatId !== chatId)
|
||||
) {
|
||||
useLayoutEffectWithPrevDeps(([prevChatId]) => {
|
||||
if (prevChatId !== chatId ) {
|
||||
setProfileState(ProfileState.Profile);
|
||||
setManagementScreen(ManagementScreens.Initial);
|
||||
}
|
||||
}, [contentKey, chatId]);
|
||||
}, [chatId]);
|
||||
|
||||
useHistoryBack(isChatSelected && (contentKey === RightColumnContent.ChatInfo
|
||||
|| contentKey === RightColumnContent.UserInfo || contentKey === RightColumnContent.Management
|
||||
|| contentKey === RightColumnContent.AddingMembers),
|
||||
() => close(false), toggleChatInfo);
|
||||
useHistoryBack(isChatSelected && (
|
||||
contentKey === RightColumnContent.ChatInfo
|
||||
|| contentKey === RightColumnContent.Management
|
||||
|| contentKey === RightColumnContent.AddingMembers
|
||||
), () => close(false), toggleChatInfo);
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function renderContent(isActive: boolean) {
|
||||
@ -247,12 +234,10 @@ const RightColumn: FC<StateProps> = ({
|
||||
/>
|
||||
);
|
||||
case RightColumnContent.ChatInfo:
|
||||
case RightColumnContent.UserInfo:
|
||||
return (
|
||||
<Profile
|
||||
key={currentProfileUserId || chatId!}
|
||||
key={chatId!}
|
||||
chatId={chatId!}
|
||||
userId={currentProfileUserId}
|
||||
profileState={profileState}
|
||||
onProfileStateChange={setProfileState}
|
||||
/>
|
||||
@ -331,7 +316,6 @@ export default memo(withGlobal(
|
||||
contentKey: selectRightColumnContentKey(global),
|
||||
chatId,
|
||||
threadId,
|
||||
currentProfileUserId: global.users.selectedId,
|
||||
isChatSelected: Boolean(chatId && areActiveChatsLoaded),
|
||||
shouldSkipHistoryAnimations: global.shouldSkipHistoryAnimations,
|
||||
nextManagementScreen,
|
||||
|
@ -38,7 +38,7 @@ const JoinRequest: FC<OwnProps & StateProps> = ({
|
||||
serverTimeOffset,
|
||||
chatId,
|
||||
}) => {
|
||||
const { openUserInfo, hideChatJoinRequest } = getDispatch();
|
||||
const { openChat, hideChatJoinRequest } = getDispatch();
|
||||
|
||||
const buildClassName = createClassNameBuilder('JoinRequest');
|
||||
const lang = useLang();
|
||||
@ -50,7 +50,7 @@ const JoinRequest: FC<OwnProps & StateProps> = ({
|
||||
? formatTime(lang, fixedDate) : formatHumanDate(lang, fixedDate, true, false, true);
|
||||
|
||||
const handleUserClick = () => {
|
||||
openUserInfo({ id: userId });
|
||||
openChat({ id: userId });
|
||||
};
|
||||
|
||||
const handleAcceptRequest = useCallback(() => {
|
||||
|
@ -62,7 +62,7 @@ const ManageGroupMembers: FC<OwnProps & StateProps> = ({
|
||||
onScreenSelect,
|
||||
onChatMemberSelect,
|
||||
}) => {
|
||||
const { openUserInfo, setUserSearchQuery, loadContactList } = getDispatch();
|
||||
const { openChat, setUserSearchQuery, loadContactList } = getDispatch();
|
||||
const lang = useLang();
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
@ -126,9 +126,9 @@ const ManageGroupMembers: FC<OwnProps & StateProps> = ({
|
||||
onChatMemberSelect!(id, false);
|
||||
onScreenSelect!(ManagementScreens.ChatNewAdminRights);
|
||||
} else {
|
||||
openUserInfo({ id });
|
||||
openChat({ id });
|
||||
}
|
||||
}, [noAdmins, onChatMemberSelect, onScreenSelect, openUserInfo]);
|
||||
}, [noAdmins, onChatMemberSelect, onScreenSelect, openChat]);
|
||||
|
||||
const handleFilterChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setUserSearchQuery({ query: e.target.value });
|
||||
|
@ -47,7 +47,7 @@ const ManageInviteInfo: FC<OwnProps & StateProps> = ({
|
||||
showNotification,
|
||||
loadChatInviteImporters,
|
||||
loadChatInviteRequesters,
|
||||
openUserInfo,
|
||||
openChat,
|
||||
} = getDispatch();
|
||||
|
||||
const lang = useLang();
|
||||
@ -86,7 +86,7 @@ const ManageInviteInfo: FC<OwnProps & StateProps> = ({
|
||||
{importers.map((importer) => (
|
||||
<ListItem
|
||||
className="chat-item-clickable scroll-item small-icon"
|
||||
onClick={() => openUserInfo({ id: importer.userId })}
|
||||
onClick={() => openChat({ id: importer.userId })}
|
||||
>
|
||||
<PrivateChatInfo
|
||||
userId={importer.userId}
|
||||
@ -111,7 +111,7 @@ const ManageInviteInfo: FC<OwnProps & StateProps> = ({
|
||||
{requesters.map((requester) => (
|
||||
<ListItem
|
||||
className="chat-item-clickable scroll-item small-icon"
|
||||
onClick={() => openUserInfo({ id: requester.userId })}
|
||||
onClick={() => openChat({ id: requester.userId })}
|
||||
>
|
||||
<PrivateChatInfo
|
||||
userId={requester.userId}
|
||||
@ -155,7 +155,7 @@ const ManageInviteInfo: FC<OwnProps & StateProps> = ({
|
||||
<p>{lang('LinkCreatedeBy')}</p>
|
||||
<ListItem
|
||||
className="chat-item-clickable scroll-item small-icon"
|
||||
onClick={() => openUserInfo({ id: adminId })}
|
||||
onClick={() => openChat({ id: adminId })}
|
||||
>
|
||||
<PrivateChatInfo
|
||||
userId={adminId}
|
||||
|
@ -263,7 +263,7 @@ function reduceShowChatInfo(global: GlobalState): boolean {
|
||||
}
|
||||
|
||||
function reduceUsers(global: GlobalState): GlobalState['users'] {
|
||||
const { users: { byId, statusesById, selectedId } } = global;
|
||||
const { users: { byId, statusesById } } = global;
|
||||
const chatIds = (global.chats.listIds.active || []).slice(0, GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT).filter(isUserId);
|
||||
const userIds = Object.keys(byId);
|
||||
const idsToSave = chatIds.concat(userIds).slice(0, GLOBAL_STATE_CACHE_USER_LIST_LIMIT);
|
||||
@ -271,7 +271,6 @@ function reduceUsers(global: GlobalState): GlobalState['users'] {
|
||||
return {
|
||||
byId: pick(byId, idsToSave),
|
||||
statusesById: pick(statusesById, idsToSave),
|
||||
selectedId: window.innerWidth > MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN ? selectedId : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,6 @@ export type GlobalState = {
|
||||
users: {
|
||||
byId: Record<string, ApiUser>;
|
||||
statusesById: Record<string, ApiUserStatus>;
|
||||
// TODO Remove
|
||||
selectedId?: string;
|
||||
};
|
||||
|
||||
chats: {
|
||||
@ -563,7 +561,7 @@ export type ActionTypes = (
|
||||
'togglePreHistoryHidden' | 'updateChatDefaultBannedRights' | 'updateChatMemberBannedRights' | 'updateChatAdmin' |
|
||||
'acceptInviteConfirmation' |
|
||||
// users
|
||||
'loadFullUser' | 'openUserInfo' | 'loadNearestCountry' | 'loadTopUsers' | 'loadContactList' |
|
||||
'loadFullUser' | 'loadNearestCountry' | 'loadTopUsers' | 'loadContactList' |
|
||||
'loadCurrentUser' | 'updateProfile' | 'checkUsername' | 'addContact' | 'updateContact' |
|
||||
'deleteContact' | 'loadUser' | 'setUserSearchQuery' | 'loadCommonChats' |
|
||||
// chat creation
|
||||
|
@ -109,7 +109,7 @@ async function searchMessagesGlobal(
|
||||
|
||||
if (chat) {
|
||||
const localResult = await callApi('searchMessagesLocal', {
|
||||
chatOrUser: chat,
|
||||
chat,
|
||||
query,
|
||||
type,
|
||||
limit: GLOBAL_SEARCH_SLICE,
|
||||
|
@ -2,13 +2,12 @@ import {
|
||||
addReducer, getDispatch, getGlobal, setGlobal,
|
||||
} from '../../../lib/teact/teactn';
|
||||
|
||||
import { ApiChat, ApiUser, MAIN_THREAD_ID } from '../../../api/types';
|
||||
import { ApiChat, MAIN_THREAD_ID } from '../../../api/types';
|
||||
|
||||
import { MESSAGE_SEARCH_SLICE, SHARED_MEDIA_SLICE } from '../../../config';
|
||||
import { callApi } from '../../../api/gramjs';
|
||||
import {
|
||||
selectCurrentTextSearch,
|
||||
selectCurrentMediaSearchPeerId,
|
||||
selectCurrentMediaSearch,
|
||||
selectCurrentMessageList,
|
||||
selectChat,
|
||||
@ -45,13 +44,15 @@ addReducer('searchTextMessagesLocal', (global) => {
|
||||
});
|
||||
|
||||
addReducer('searchMediaMessagesLocal', (global) => {
|
||||
const peerId = selectCurrentMediaSearchPeerId(global);
|
||||
const chatOrUser = peerId
|
||||
? global.users.byId[peerId] || global.chats.byId[peerId]
|
||||
: undefined;
|
||||
const { chatId } = selectCurrentMessageList(global) || {};
|
||||
if (!chatId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const chat = selectChat(global, chatId);
|
||||
const currentSearch = selectCurrentMediaSearch(global);
|
||||
|
||||
if (!chatOrUser || !currentSearch) {
|
||||
if (!chat || !currentSearch) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ addReducer('searchMediaMessagesLocal', (global) => {
|
||||
return;
|
||||
}
|
||||
|
||||
void searchSharedMedia(chatOrUser, type, offsetId);
|
||||
void searchSharedMedia(chat, type, offsetId);
|
||||
});
|
||||
|
||||
addReducer('searchMessagesByDate', (global, actions, payload) => {
|
||||
@ -83,7 +84,7 @@ addReducer('searchMessagesByDate', (global, actions, payload) => {
|
||||
});
|
||||
|
||||
async function searchTextMessages(
|
||||
chatOrUser: ApiChat,
|
||||
chat: ApiChat,
|
||||
threadId: number,
|
||||
topMessageId?: number,
|
||||
query?: string,
|
||||
@ -94,7 +95,7 @@ async function searchTextMessages(
|
||||
}
|
||||
|
||||
const result = await callApi('searchMessagesLocal', {
|
||||
chatOrUser,
|
||||
chat,
|
||||
type: 'text',
|
||||
query,
|
||||
topMessageId,
|
||||
@ -122,19 +123,19 @@ async function searchTextMessages(
|
||||
|
||||
global = addChats(global, buildCollectionByKey(chats, 'id'));
|
||||
global = addUsers(global, buildCollectionByKey(users, 'id'));
|
||||
global = addChatMessagesById(global, chatOrUser.id, byId);
|
||||
global = updateLocalTextSearchResults(global, chatOrUser.id, threadId, newFoundIds, totalCount, nextOffsetId);
|
||||
global = addChatMessagesById(global, chat.id, byId);
|
||||
global = updateLocalTextSearchResults(global, chat.id, threadId, newFoundIds, totalCount, nextOffsetId);
|
||||
setGlobal(global);
|
||||
}
|
||||
|
||||
async function searchSharedMedia(
|
||||
chatOrUser: ApiChat | ApiUser,
|
||||
chat: ApiChat,
|
||||
type: SharedMediaType,
|
||||
offsetId?: number,
|
||||
isBudgetPreload = false,
|
||||
) {
|
||||
const result = await callApi('searchMessagesLocal', {
|
||||
chatOrUser,
|
||||
chat,
|
||||
type,
|
||||
limit: SHARED_MEDIA_SLICE * 2,
|
||||
offsetId,
|
||||
@ -160,12 +161,12 @@ async function searchSharedMedia(
|
||||
|
||||
global = addChats(global, buildCollectionByKey(chats, 'id'));
|
||||
global = addUsers(global, buildCollectionByKey(users, 'id'));
|
||||
global = addChatMessagesById(global, chatOrUser.id, byId);
|
||||
global = updateLocalMediaSearchResults(global, chatOrUser.id, type, newFoundIds, totalCount, nextOffsetId);
|
||||
global = addChatMessagesById(global, chat.id, byId);
|
||||
global = updateLocalMediaSearchResults(global, chat.id, type, newFoundIds, totalCount, nextOffsetId);
|
||||
setGlobal(global);
|
||||
|
||||
if (!isBudgetPreload) {
|
||||
searchSharedMedia(chatOrUser, type, nextOffsetId, true);
|
||||
searchSharedMedia(chat, type, nextOffsetId, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,6 @@
|
||||
import { addReducer } from '../../../lib/teact/teactn';
|
||||
|
||||
import { GlobalState } from '../../../global/types';
|
||||
|
||||
import { updateSelectedUserId, updateUserSearch } from '../../reducers';
|
||||
|
||||
addReducer('openUserInfo', (global, actions, payload) => {
|
||||
const { id } = payload!;
|
||||
|
||||
actions.openChat({ id });
|
||||
});
|
||||
|
||||
const clearSelectedUserId = (global: GlobalState) => updateSelectedUserId(global, undefined);
|
||||
|
||||
addReducer('openChat', clearSelectedUserId);
|
||||
import { updateUserSearch } from '../../reducers';
|
||||
|
||||
addReducer('setUserSearchQuery', (global, actions, payload) => {
|
||||
const { query } = payload!;
|
||||
|
@ -122,20 +122,6 @@ function getUpdatedUser(global: GlobalState, userId: string, userUpdate: Partial
|
||||
return updatedUser;
|
||||
}
|
||||
|
||||
export function updateSelectedUserId(global: GlobalState, selectedId?: string): GlobalState {
|
||||
if (global.users.selectedId === selectedId) {
|
||||
return global;
|
||||
}
|
||||
|
||||
return {
|
||||
...global,
|
||||
users: {
|
||||
...global.users,
|
||||
selectedId,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteContact(global: GlobalState, userId: string): GlobalState {
|
||||
const { byId } = global.users;
|
||||
const { userIds } = global.contactList || {};
|
||||
|
@ -17,19 +17,11 @@ export function selectCurrentTextSearch(global: GlobalState) {
|
||||
return currentSearch;
|
||||
}
|
||||
|
||||
export function selectCurrentMediaSearchPeerId(global: GlobalState) {
|
||||
const { byChatId } = global.localMediaSearch;
|
||||
const { chatId } = selectCurrentMessageList(global) || {};
|
||||
const currentProfileUserId = global.users.selectedId;
|
||||
|
||||
return currentProfileUserId && byChatId[currentProfileUserId] ? currentProfileUserId : chatId;
|
||||
}
|
||||
|
||||
export function selectCurrentMediaSearch(global: GlobalState) {
|
||||
const peerId = selectCurrentMediaSearchPeerId(global);
|
||||
if (!peerId) {
|
||||
const { chatId } = selectCurrentMessageList(global) || {};
|
||||
if (!chatId) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return global.localMediaSearch.byChatId[peerId];
|
||||
return global.localMediaSearch.byChatId[chatId];
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import { NewChatMembersProgress, RightColumnContent } from '../../types';
|
||||
import { getSystemTheme, IS_SINGLE_COLUMN_LAYOUT } from '../../util/environment';
|
||||
import { selectCurrentMessageList, selectIsPollResultsOpen } from './messages';
|
||||
import { selectCurrentTextSearch } from './localSearch';
|
||||
import { selectCurrentStickerSearch, selectCurrentGifSearch } from './symbols';
|
||||
import { selectAreActiveChatsLoaded } from './chats';
|
||||
import { selectCurrentGifSearch, selectCurrentStickerSearch } from './symbols';
|
||||
import { selectCurrentManagement } from './management';
|
||||
|
||||
export function selectIsMediaViewerOpen(global: GlobalState) {
|
||||
@ -14,42 +13,19 @@ export function selectIsMediaViewerOpen(global: GlobalState) {
|
||||
}
|
||||
|
||||
export function selectRightColumnContentKey(global: GlobalState) {
|
||||
const {
|
||||
users,
|
||||
isChatInfoShown,
|
||||
newChatMembersProgress,
|
||||
} = global;
|
||||
|
||||
const isAddingChatMembersShown = newChatMembersProgress !== NewChatMembersProgress.Closed;
|
||||
const isPollResults = selectIsPollResultsOpen(global);
|
||||
const isSearch = Boolean(!IS_SINGLE_COLUMN_LAYOUT && selectCurrentTextSearch(global));
|
||||
const isManagement = selectCurrentManagement(global);
|
||||
const stickerSearch = selectCurrentStickerSearch(global);
|
||||
const isStickerSearch = stickerSearch.query !== undefined;
|
||||
const gifSearch = selectCurrentGifSearch(global);
|
||||
const isGifSearch = gifSearch.query !== undefined;
|
||||
const { chatId: currentChatId } = selectCurrentMessageList(global) || {};
|
||||
const currentProfileUserId = users.selectedId;
|
||||
const areActiveChatsLoaded = selectAreActiveChatsLoaded(global);
|
||||
const isUserInfo = Boolean(currentProfileUserId && areActiveChatsLoaded);
|
||||
const isChatShown = Boolean(currentChatId && areActiveChatsLoaded);
|
||||
const isChatInfo = isChatShown && isChatInfoShown;
|
||||
|
||||
return isPollResults ? (
|
||||
return selectIsPollResultsOpen(global) ? (
|
||||
RightColumnContent.PollResults
|
||||
) : isSearch ? (
|
||||
) : !IS_SINGLE_COLUMN_LAYOUT && selectCurrentTextSearch(global) ? (
|
||||
RightColumnContent.Search
|
||||
) : isManagement ? (
|
||||
) : selectCurrentManagement(global) ? (
|
||||
RightColumnContent.Management
|
||||
) : isStickerSearch ? (
|
||||
) : selectCurrentStickerSearch(global).query !== undefined ? (
|
||||
RightColumnContent.StickerSearch
|
||||
) : isGifSearch ? (
|
||||
) : selectCurrentGifSearch(global).query !== undefined ? (
|
||||
RightColumnContent.GifSearch
|
||||
) : isAddingChatMembersShown ? (
|
||||
) : global.newChatMembersProgress !== NewChatMembersProgress.Closed ? (
|
||||
RightColumnContent.AddingMembers
|
||||
) : isUserInfo ? (
|
||||
RightColumnContent.UserInfo
|
||||
) : isChatInfo ? (
|
||||
) : global.isChatInfoShown && selectCurrentMessageList(global) ? (
|
||||
RightColumnContent.ChatInfo
|
||||
) : undefined;
|
||||
}
|
||||
|
@ -234,7 +234,6 @@ export enum GlobalSearchContent {
|
||||
|
||||
export enum RightColumnContent {
|
||||
ChatInfo,
|
||||
UserInfo,
|
||||
Search,
|
||||
Management,
|
||||
StickerSearch,
|
||||
|
Loading…
Reference in New Issue
Block a user