Message List: Fix old messages loading when opening shared media (#2638)
This commit is contained in:
parent
9fd73e86d6
commit
a956de12f0
@ -35,11 +35,9 @@ import {
|
|||||||
selectTheme,
|
selectTheme,
|
||||||
selectActiveDownloadIds,
|
selectActiveDownloadIds,
|
||||||
selectUser,
|
selectUser,
|
||||||
selectListedIds,
|
|
||||||
} from '../../global/selectors';
|
} from '../../global/selectors';
|
||||||
import { captureEvents, SwipeDirection } from '../../util/captureEvents';
|
import { captureEvents, SwipeDirection } from '../../util/captureEvents';
|
||||||
import { getSenderName } from '../left/search/helpers/getSenderName';
|
import { getSenderName } from '../left/search/helpers/getSenderName';
|
||||||
import { pickTruthy } from '../../util/iteratees';
|
|
||||||
import useCacheBuster from '../../hooks/useCacheBuster';
|
import useCacheBuster from '../../hooks/useCacheBuster';
|
||||||
import useProfileViewportIds from './hooks/useProfileViewportIds';
|
import useProfileViewportIds from './hooks/useProfileViewportIds';
|
||||||
import useProfileState from './hooks/useProfileState';
|
import useProfileState from './hooks/useProfileState';
|
||||||
@ -82,7 +80,6 @@ type StateProps = {
|
|||||||
currentUserId?: string;
|
currentUserId?: string;
|
||||||
resolvedUserId?: string;
|
resolvedUserId?: string;
|
||||||
messagesById?: Record<number, ApiMessage>;
|
messagesById?: Record<number, ApiMessage>;
|
||||||
messageIds?: number[];
|
|
||||||
foundIds?: number[];
|
foundIds?: number[];
|
||||||
mediaSearchType?: SharedMediaType;
|
mediaSearchType?: SharedMediaType;
|
||||||
hasCommonChatsTab?: boolean;
|
hasCommonChatsTab?: boolean;
|
||||||
@ -124,7 +121,6 @@ const Profile: FC<OwnProps & StateProps> = ({
|
|||||||
currentUserId,
|
currentUserId,
|
||||||
messagesById,
|
messagesById,
|
||||||
foundIds,
|
foundIds,
|
||||||
messageIds,
|
|
||||||
mediaSearchType,
|
mediaSearchType,
|
||||||
hasCommonChatsTab,
|
hasCommonChatsTab,
|
||||||
hasMembersTab,
|
hasMembersTab,
|
||||||
@ -178,10 +174,6 @@ const Profile: FC<OwnProps & StateProps> = ({
|
|||||||
const renderingActiveTab = activeTab > tabs.length - 1 ? tabs.length - 1 : activeTab;
|
const renderingActiveTab = activeTab > tabs.length - 1 ? tabs.length - 1 : activeTab;
|
||||||
const tabType = tabs[renderingActiveTab].type as ProfileTabType;
|
const tabType = tabs[renderingActiveTab].type as ProfileTabType;
|
||||||
|
|
||||||
const chatMessages = useMemo(() => {
|
|
||||||
return messageIds && messagesById ? pickTruthy(messagesById, messageIds) : {};
|
|
||||||
}, [messagesById, messageIds]);
|
|
||||||
|
|
||||||
const [resultType, viewportIds, getMore, noProfileInfo] = useProfileViewportIds(
|
const [resultType, viewportIds, getMore, noProfileInfo] = useProfileViewportIds(
|
||||||
loadMoreMembers,
|
loadMoreMembers,
|
||||||
loadCommonChats,
|
loadCommonChats,
|
||||||
@ -193,7 +185,7 @@ const Profile: FC<OwnProps & StateProps> = ({
|
|||||||
usersById,
|
usersById,
|
||||||
userStatusesById,
|
userStatusesById,
|
||||||
chatsById,
|
chatsById,
|
||||||
chatMessages,
|
messagesById,
|
||||||
foundIds,
|
foundIds,
|
||||||
lastSyncTime,
|
lastSyncTime,
|
||||||
topicId,
|
topicId,
|
||||||
@ -311,7 +303,7 @@ const Profile: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderContent() {
|
function renderContent() {
|
||||||
if (!viewportIds || !canRenderContent || !chatMessages) {
|
if (!viewportIds || !canRenderContent || !messagesById) {
|
||||||
const noSpinner = isFirstTab && !canRenderContent;
|
const noSpinner = isFirstTab && !canRenderContent;
|
||||||
const forceRenderHiddenMembers = Boolean(resultType === 'members' && areMembersHidden);
|
const forceRenderHiddenMembers = Boolean(resultType === 'members' && areMembersHidden);
|
||||||
|
|
||||||
@ -363,20 +355,20 @@ const Profile: FC<OwnProps & StateProps> = ({
|
|||||||
teactFastList
|
teactFastList
|
||||||
>
|
>
|
||||||
{resultType === 'media' ? (
|
{resultType === 'media' ? (
|
||||||
(viewportIds as number[])!.map((id) => chatMessages[id] && (
|
(viewportIds as number[])!.map((id) => messagesById[id] && (
|
||||||
<Media
|
<Media
|
||||||
key={id}
|
key={id}
|
||||||
message={chatMessages[id]}
|
message={messagesById[id]}
|
||||||
isProtected={isChatProtected || chatMessages[id].isProtected}
|
isProtected={isChatProtected || messagesById[id].isProtected}
|
||||||
observeIntersection={observeIntersectionForMedia}
|
observeIntersection={observeIntersectionForMedia}
|
||||||
onClick={handleSelectMedia}
|
onClick={handleSelectMedia}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : resultType === 'documents' ? (
|
) : resultType === 'documents' ? (
|
||||||
(viewportIds as number[])!.map((id) => chatMessages[id] && (
|
(viewportIds as number[])!.map((id) => messagesById[id] && (
|
||||||
<Document
|
<Document
|
||||||
key={id}
|
key={id}
|
||||||
message={chatMessages[id]}
|
message={messagesById[id]}
|
||||||
withDate
|
withDate
|
||||||
smaller
|
smaller
|
||||||
className="scroll-item"
|
className="scroll-item"
|
||||||
@ -386,45 +378,45 @@ const Profile: FC<OwnProps & StateProps> = ({
|
|||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : resultType === 'links' ? (
|
) : resultType === 'links' ? (
|
||||||
(viewportIds as number[])!.map((id) => chatMessages[id] && (
|
(viewportIds as number[])!.map((id) => messagesById[id] && (
|
||||||
<WebLink
|
<WebLink
|
||||||
key={id}
|
key={id}
|
||||||
message={chatMessages[id]}
|
message={messagesById[id]}
|
||||||
isProtected={isChatProtected || chatMessages[id].isProtected}
|
isProtected={isChatProtected || messagesById[id].isProtected}
|
||||||
observeIntersection={observeIntersectionForMedia}
|
observeIntersection={observeIntersectionForMedia}
|
||||||
onMessageClick={handleMessageFocus}
|
onMessageClick={handleMessageFocus}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : resultType === 'audio' ? (
|
) : resultType === 'audio' ? (
|
||||||
(viewportIds as number[])!.map((id) => chatMessages[id] && (
|
(viewportIds as number[])!.map((id) => messagesById[id] && (
|
||||||
<Audio
|
<Audio
|
||||||
key={id}
|
key={id}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
message={chatMessages[id]}
|
message={messagesById[id]}
|
||||||
origin={AudioOrigin.SharedMedia}
|
origin={AudioOrigin.SharedMedia}
|
||||||
date={chatMessages[id].date}
|
date={messagesById[id].date}
|
||||||
lastSyncTime={lastSyncTime}
|
lastSyncTime={lastSyncTime}
|
||||||
className="scroll-item"
|
className="scroll-item"
|
||||||
onPlay={handlePlayAudio}
|
onPlay={handlePlayAudio}
|
||||||
onDateClick={handleMessageFocus}
|
onDateClick={handleMessageFocus}
|
||||||
canDownload={!isChatProtected && !chatMessages[id].isProtected}
|
canDownload={!isChatProtected && !messagesById[id].isProtected}
|
||||||
isDownloading={activeDownloadIds.includes(id)}
|
isDownloading={activeDownloadIds.includes(id)}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : resultType === 'voice' ? (
|
) : resultType === 'voice' ? (
|
||||||
(viewportIds as number[])!.map((id) => chatMessages[id] && (
|
(viewportIds as number[])!.map((id) => messagesById[id] && (
|
||||||
<Audio
|
<Audio
|
||||||
key={id}
|
key={id}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
message={chatMessages[id]}
|
message={messagesById[id]}
|
||||||
senderTitle={getSenderName(lang, chatMessages[id], chatsById, usersById)}
|
senderTitle={getSenderName(lang, messagesById[id], chatsById, usersById)}
|
||||||
origin={AudioOrigin.SharedMedia}
|
origin={AudioOrigin.SharedMedia}
|
||||||
date={chatMessages[id].date}
|
date={messagesById[id].date}
|
||||||
lastSyncTime={lastSyncTime}
|
lastSyncTime={lastSyncTime}
|
||||||
className="scroll-item"
|
className="scroll-item"
|
||||||
onPlay={handlePlayAudio}
|
onPlay={handlePlayAudio}
|
||||||
onDateClick={handleMessageFocus}
|
onDateClick={handleMessageFocus}
|
||||||
canDownload={!isChatProtected && !chatMessages[id].isProtected}
|
canDownload={!isChatProtected && !messagesById[id].isProtected}
|
||||||
isDownloading={activeDownloadIds.includes(id)}
|
isDownloading={activeDownloadIds.includes(id)}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
@ -538,7 +530,6 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
const messagesById = selectChatMessages(global, chatId);
|
const messagesById = selectChatMessages(global, chatId);
|
||||||
const { currentType: mediaSearchType, resultsByType } = selectCurrentMediaSearch(global) || {};
|
const { currentType: mediaSearchType, resultsByType } = selectCurrentMediaSearch(global) || {};
|
||||||
const { foundIds } = (resultsByType && mediaSearchType && resultsByType[mediaSearchType]) || {};
|
const { foundIds } = (resultsByType && mediaSearchType && resultsByType[mediaSearchType]) || {};
|
||||||
const messageIds = selectListedIds(global, chatId, topicId || MAIN_THREAD_ID);
|
|
||||||
|
|
||||||
const { byId: usersById, statusesById: userStatusesById } = global.users;
|
const { byId: usersById, statusesById: userStatusesById } = global.users;
|
||||||
const { byId: chatsById } = global.chats;
|
const { byId: chatsById } = global.chats;
|
||||||
@ -570,7 +561,6 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
resolvedUserId,
|
resolvedUserId,
|
||||||
messagesById,
|
messagesById,
|
||||||
foundIds,
|
foundIds,
|
||||||
messageIds,
|
|
||||||
mediaSearchType,
|
mediaSearchType,
|
||||||
hasCommonChatsTab,
|
hasCommonChatsTab,
|
||||||
hasMembersTab,
|
hasMembersTab,
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import {
|
|||||||
addChatMessagesById,
|
addChatMessagesById,
|
||||||
addChats,
|
addChats,
|
||||||
addUsers,
|
addUsers,
|
||||||
updateListedIds,
|
|
||||||
updateLocalMediaSearchResults,
|
updateLocalMediaSearchResults,
|
||||||
updateLocalTextSearchResults,
|
updateLocalTextSearchResults,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
@ -176,7 +175,6 @@ async function searchSharedMedia<T extends GlobalState>(
|
|||||||
global = addUsers(global, buildCollectionByKey(users, 'id'));
|
global = addUsers(global, buildCollectionByKey(users, 'id'));
|
||||||
global = addChatMessagesById(global, chat.id, byId);
|
global = addChatMessagesById(global, chat.id, byId);
|
||||||
global = updateLocalMediaSearchResults(global, chat.id, threadId, type, newFoundIds, totalCount, nextOffsetId, tabId);
|
global = updateLocalMediaSearchResults(global, chat.id, threadId, type, newFoundIds, totalCount, nextOffsetId, tabId);
|
||||||
global = updateListedIds(global, chat.id, threadId, newFoundIds);
|
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
|
|
||||||
if (!isBudgetPreload) {
|
if (!isBudgetPreload) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user