Profile: Fix stuck shared media loader after search (#5154)
This commit is contained in:
parent
5c9c5f0cd8
commit
eb07c8d02f
@ -1168,9 +1168,9 @@ export async function fetchDiscussionMessage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function searchMessagesInChat({
|
export async function searchMessagesInChat({
|
||||||
chat, isSavedDialog, savedTag, type, query = '', threadId, minDate, maxDate, ...pagination
|
peer, isSavedDialog, savedTag, type, query = '', threadId, minDate, maxDate, ...pagination
|
||||||
}: {
|
}: {
|
||||||
chat: ApiChat;
|
peer: ApiPeer;
|
||||||
isSavedDialog?: boolean;
|
isSavedDialog?: boolean;
|
||||||
savedTag?: ApiReaction;
|
savedTag?: ApiReaction;
|
||||||
type?: ApiMessageSearchType | ApiGlobalMessageSearchType;
|
type?: ApiMessageSearchType | ApiGlobalMessageSearchType;
|
||||||
@ -1208,11 +1208,11 @@ export async function searchMessagesInChat({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const peer = buildInputPeer(chat.id, chat.accessHash);
|
const inputPeer = buildInputPeer(peer.id, peer.accessHash);
|
||||||
|
|
||||||
const result = await invokeRequest(new GramJs.messages.Search({
|
const result = await invokeRequest(new GramJs.messages.Search({
|
||||||
peer: isSavedDialog ? new GramJs.InputPeerSelf() : peer,
|
peer: isSavedDialog ? new GramJs.InputPeerSelf() : inputPeer,
|
||||||
savedPeerId: isSavedDialog ? peer : undefined,
|
savedPeerId: isSavedDialog ? inputPeer : undefined,
|
||||||
savedReaction: savedTag && [buildInputReaction(savedTag)],
|
savedReaction: savedTag && [buildInputReaction(savedTag)],
|
||||||
topMsgId: threadId !== MAIN_THREAD_ID && !isSavedDialog ? Number(threadId) : undefined,
|
topMsgId: threadId !== MAIN_THREAD_ID && !isSavedDialog ? Number(threadId) : undefined,
|
||||||
filter,
|
filter,
|
||||||
@ -1221,7 +1221,7 @@ export async function searchMessagesInChat({
|
|||||||
maxDate,
|
maxDate,
|
||||||
...pagination,
|
...pagination,
|
||||||
}), {
|
}), {
|
||||||
abortControllerChatId: chat.id,
|
abortControllerChatId: peer.id,
|
||||||
abortControllerThreadId: threadId,
|
abortControllerThreadId: threadId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -274,7 +274,7 @@ export async function fetchProfilePhotos({
|
|||||||
if (chat?.isRestricted) return undefined;
|
if (chat?.isRestricted) return undefined;
|
||||||
|
|
||||||
const result = await searchMessagesInChat({
|
const result = await searchMessagesInChat({
|
||||||
chat: chat!,
|
peer,
|
||||||
type: 'profilePhoto',
|
type: 'profilePhoto',
|
||||||
limit,
|
limit,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type {
|
import type {
|
||||||
ApiChat, ApiGlobalMessageSearchType, ApiMessage, ApiTopic,
|
ApiChat, ApiGlobalMessageSearchType, ApiMessage, ApiPeer, ApiTopic,
|
||||||
ApiUserStatus,
|
ApiUserStatus,
|
||||||
} from '../../../api/types';
|
} from '../../../api/types';
|
||||||
import type { ActionReturnType, GlobalState, TabArgs } from '../../types';
|
import type { ActionReturnType, GlobalState, TabArgs } from '../../types';
|
||||||
@ -11,6 +11,7 @@ import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
|||||||
import { throttle } from '../../../util/schedulers';
|
import { throttle } from '../../../util/schedulers';
|
||||||
import { callApi } from '../../../api/gramjs';
|
import { callApi } from '../../../api/gramjs';
|
||||||
import { isChatChannel, isChatGroup, toChannelId } from '../../helpers/chats';
|
import { isChatChannel, isChatGroup, toChannelId } from '../../helpers/chats';
|
||||||
|
import { isApiPeerChat } from '../../helpers/peers';
|
||||||
import { addActionHandler, getGlobal, setGlobal } from '../../index';
|
import { addActionHandler, getGlobal, setGlobal } from '../../index';
|
||||||
import {
|
import {
|
||||||
addMessages,
|
addMessages,
|
||||||
@ -21,7 +22,7 @@ import {
|
|||||||
updateTopics,
|
updateTopics,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import {
|
import {
|
||||||
selectChat, selectChatByUsername, selectChatMessage, selectCurrentGlobalSearchQuery, selectTabState,
|
selectChat, selectChatByUsername, selectChatMessage, selectCurrentGlobalSearchQuery, selectPeer, selectTabState,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
|
|
||||||
const searchThrottled = throttle((cb) => cb(), 500, false);
|
const searchThrottled = throttle((cb) => cb(), 500, false);
|
||||||
@ -98,8 +99,8 @@ addActionHandler('searchMessagesGlobal', (global, actions, payload): ActionRetur
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chat = chatId ? selectChat(global, chatId) : undefined;
|
const chat = chatId ? selectPeer(global, chatId) : undefined;
|
||||||
const offsetPeer = nextOffsetPeerId ? selectChat(global, nextOffsetPeerId) : undefined;
|
const offsetPeer = nextOffsetPeerId ? selectPeer(global, nextOffsetPeerId) : undefined;
|
||||||
|
|
||||||
searchMessagesGlobal(global, {
|
searchMessagesGlobal(global, {
|
||||||
query,
|
query,
|
||||||
@ -107,7 +108,7 @@ addActionHandler('searchMessagesGlobal', (global, actions, payload): ActionRetur
|
|||||||
offsetRate: nextOffsetRate,
|
offsetRate: nextOffsetRate,
|
||||||
offsetId: nextOffsetId,
|
offsetId: nextOffsetId,
|
||||||
offsetPeer,
|
offsetPeer,
|
||||||
chat,
|
peer: chat,
|
||||||
tabId,
|
tabId,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -146,14 +147,14 @@ async function searchMessagesGlobal<T extends GlobalState>(global: T, params: {
|
|||||||
type: ApiGlobalMessageSearchType;
|
type: ApiGlobalMessageSearchType;
|
||||||
offsetRate?: number;
|
offsetRate?: number;
|
||||||
offsetId?: number;
|
offsetId?: number;
|
||||||
offsetPeer?: ApiChat;
|
offsetPeer?: ApiPeer;
|
||||||
chat?: ApiChat;
|
peer?: ApiPeer;
|
||||||
maxDate?: number;
|
maxDate?: number;
|
||||||
minDate?: number;
|
minDate?: number;
|
||||||
tabId: TabArgs<T>[0];
|
tabId: TabArgs<T>[0];
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
query = '', type, offsetRate, offsetId, offsetPeer, chat, maxDate, minDate, tabId = getCurrentTabId(),
|
query = '', type, offsetRate, offsetId, offsetPeer, peer, maxDate, minDate, tabId = getCurrentTabId(),
|
||||||
} = params;
|
} = params;
|
||||||
let result: {
|
let result: {
|
||||||
messages: ApiMessage[];
|
messages: ApiMessage[];
|
||||||
@ -168,9 +169,9 @@ async function searchMessagesGlobal<T extends GlobalState>(global: T, params: {
|
|||||||
|
|
||||||
let messageLink: ApiMessage | undefined;
|
let messageLink: ApiMessage | undefined;
|
||||||
|
|
||||||
if (chat) {
|
if (peer) {
|
||||||
const inChatResultRequest = callApi('searchMessagesInChat', {
|
const inChatResultRequest = callApi('searchMessagesInChat', {
|
||||||
chat,
|
peer,
|
||||||
query,
|
query,
|
||||||
type,
|
type,
|
||||||
limit: GLOBAL_SEARCH_SLICE,
|
limit: GLOBAL_SEARCH_SLICE,
|
||||||
@ -178,8 +179,9 @@ async function searchMessagesGlobal<T extends GlobalState>(global: T, params: {
|
|||||||
minDate,
|
minDate,
|
||||||
maxDate,
|
maxDate,
|
||||||
});
|
});
|
||||||
const topicsRequest = chat.isForum ? callApi('fetchTopics', {
|
const isChat = isApiPeerChat(peer);
|
||||||
chat,
|
const topicsRequest = isChat && peer.isForum ? callApi('fetchTopics', {
|
||||||
|
chat: peer,
|
||||||
query,
|
query,
|
||||||
limit: GLOBAL_TOPIC_SEARCH_SLICE,
|
limit: GLOBAL_TOPIC_SEARCH_SLICE,
|
||||||
}) : undefined;
|
}) : undefined;
|
||||||
@ -258,7 +260,7 @@ async function searchMessagesGlobal<T extends GlobalState>(global: T, params: {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (result.topics) {
|
if (result.topics) {
|
||||||
global = updateTopics(global, chat!.id, result.totalTopicsCount!, result.topics);
|
global = updateTopics(global, peer!.id, result.totalTopicsCount!, result.topics);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedTopics = result.topics?.map(({ id }) => id).sort((a, b) => b - a);
|
const sortedTopics = result.topics?.map(({ id }) => id).sort((a, b) => b - a);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type {
|
|||||||
ChatMediaSearchParams, ChatMediaSearchSegment, LoadingState, SharedMediaType, ThreadId,
|
ChatMediaSearchParams, ChatMediaSearchSegment, LoadingState, SharedMediaType, ThreadId,
|
||||||
} from '../../../types';
|
} from '../../../types';
|
||||||
import type { ActionReturnType, GlobalState, TabArgs } from '../../types';
|
import type { ActionReturnType, GlobalState, TabArgs } from '../../types';
|
||||||
import { type ApiChat, MAIN_THREAD_ID } from '../../../api/types';
|
import { type ApiPeer, MAIN_THREAD_ID } from '../../../api/types';
|
||||||
import { LoadMoreDirection } from '../../../types';
|
import { LoadMoreDirection } from '../../../types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -34,6 +34,7 @@ import {
|
|||||||
selectCurrentMessageList,
|
selectCurrentMessageList,
|
||||||
selectCurrentMiddleSearch,
|
selectCurrentMiddleSearch,
|
||||||
selectCurrentSharedMediaSearch,
|
selectCurrentSharedMediaSearch,
|
||||||
|
selectPeer,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
|
|
||||||
const MEDIA_PRELOAD_OFFSET = 9;
|
const MEDIA_PRELOAD_OFFSET = 9;
|
||||||
@ -49,9 +50,9 @@ addActionHandler('performMiddleSearch', async (global, actions, payload): Promis
|
|||||||
const isSavedDialog = getIsSavedDialog(chatId, threadId, currentUserId);
|
const isSavedDialog = getIsSavedDialog(chatId, threadId, currentUserId);
|
||||||
const realChatId = isSavedDialog ? String(threadId) : chatId;
|
const realChatId = isSavedDialog ? String(threadId) : chatId;
|
||||||
|
|
||||||
const chat = realChatId ? selectChat(global, realChatId) : undefined;
|
const peer = realChatId ? selectPeer(global, realChatId) : undefined;
|
||||||
let currentSearch = selectCurrentMiddleSearch(global, tabId);
|
let currentSearch = selectCurrentMiddleSearch(global, tabId);
|
||||||
if (!chat) {
|
if (!peer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ addActionHandler('performMiddleSearch', async (global, actions, payload): Promis
|
|||||||
let result;
|
let result;
|
||||||
if (type === 'chat') {
|
if (type === 'chat') {
|
||||||
result = await callApi('searchMessagesInChat', {
|
result = await callApi('searchMessagesInChat', {
|
||||||
chat,
|
peer,
|
||||||
type: 'text',
|
type: 'text',
|
||||||
query: isHashtag ? `#${query}` : query,
|
query: isHashtag ? `#${query}` : query,
|
||||||
threadId,
|
threadId,
|
||||||
@ -138,7 +139,7 @@ addActionHandler('performMiddleSearch', async (global, actions, payload): Promis
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultChatId = isSavedDialog ? currentUserId : chat.id;
|
const resultChatId = isSavedDialog ? currentUserId : peer.id;
|
||||||
|
|
||||||
global = addUserStatuses(global, userStatusesById);
|
global = addUserStatuses(global, userStatusesById);
|
||||||
global = addMessages(global, messages);
|
global = addMessages(global, messages);
|
||||||
@ -187,10 +188,10 @@ addActionHandler('searchSharedMediaMessages', (global, actions, payload): Action
|
|||||||
const isSavedDialog = getIsSavedDialog(chatId, threadId, global.currentUserId);
|
const isSavedDialog = getIsSavedDialog(chatId, threadId, global.currentUserId);
|
||||||
const realChatId = isSavedDialog ? String(threadId) : chatId;
|
const realChatId = isSavedDialog ? String(threadId) : chatId;
|
||||||
|
|
||||||
const chat = selectChat(global, realChatId);
|
const peer = selectPeer(global, realChatId);
|
||||||
const currentSearch = selectCurrentSharedMediaSearch(global, tabId);
|
const currentSearch = selectCurrentSharedMediaSearch(global, tabId);
|
||||||
|
|
||||||
if (!chat || !currentSearch) {
|
if (!peer || !currentSearch) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +203,7 @@ addActionHandler('searchSharedMediaMessages', (global, actions, payload): Action
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void searchSharedMedia(global, chat, threadId, type, offsetId, undefined, isSavedDialog, tabId);
|
void searchSharedMedia(global, peer, threadId, type, offsetId, undefined, isSavedDialog, tabId);
|
||||||
});
|
});
|
||||||
addActionHandler('searchChatMediaMessages', (global, actions, payload): ActionReturnType => {
|
addActionHandler('searchChatMediaMessages', (global, actions, payload): ActionReturnType => {
|
||||||
const {
|
const {
|
||||||
@ -273,7 +274,7 @@ addActionHandler('searchMessagesByDate', async (global, actions, payload): Promi
|
|||||||
|
|
||||||
async function searchSharedMedia<T extends GlobalState>(
|
async function searchSharedMedia<T extends GlobalState>(
|
||||||
global: T,
|
global: T,
|
||||||
chat: ApiChat,
|
peer: ApiPeer,
|
||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
type: SharedMediaType,
|
type: SharedMediaType,
|
||||||
offsetId?: number,
|
offsetId?: number,
|
||||||
@ -281,10 +282,10 @@ async function searchSharedMedia<T extends GlobalState>(
|
|||||||
isSavedDialog?: boolean,
|
isSavedDialog?: boolean,
|
||||||
...[tabId = getCurrentTabId()]: TabArgs<T>
|
...[tabId = getCurrentTabId()]: TabArgs<T>
|
||||||
) {
|
) {
|
||||||
const resultChatId = isSavedDialog ? global.currentUserId! : chat.id;
|
const resultChatId = isSavedDialog ? global.currentUserId! : peer.id;
|
||||||
|
|
||||||
const result = await callApi('searchMessagesInChat', {
|
const result = await callApi('searchMessagesInChat', {
|
||||||
chat,
|
peer,
|
||||||
type,
|
type,
|
||||||
limit: SHARED_MEDIA_SLICE * 2,
|
limit: SHARED_MEDIA_SLICE * 2,
|
||||||
threadId,
|
threadId,
|
||||||
@ -318,7 +319,7 @@ async function searchSharedMedia<T extends GlobalState>(
|
|||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
|
|
||||||
if (!isBudgetPreload) {
|
if (!isBudgetPreload) {
|
||||||
void searchSharedMedia(global, chat, threadId, type, nextOffsetId, true, isSavedDialog, tabId);
|
void searchSharedMedia(global, peer, threadId, type, nextOffsetId, true, isSavedDialog, tabId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +416,7 @@ function calcLoadingState(
|
|||||||
|
|
||||||
async function searchChatMedia<T extends GlobalState>(
|
async function searchChatMedia<T extends GlobalState>(
|
||||||
global: T,
|
global: T,
|
||||||
chat: ApiChat,
|
peer: ApiPeer,
|
||||||
threadId: ThreadId,
|
threadId: ThreadId,
|
||||||
currentMediaMessageId: number,
|
currentMediaMessageId: number,
|
||||||
chatMediaSearchParams: ChatMediaSearchParams,
|
chatMediaSearchParams: ChatMediaSearchParams,
|
||||||
@ -441,13 +442,13 @@ async function searchChatMedia<T extends GlobalState>(
|
|||||||
const offsetId = calcChatMediaSearchOffsetId(direction, currentMediaMessageId, currentSegment);
|
const offsetId = calcChatMediaSearchOffsetId(direction, currentMediaMessageId, currentSegment);
|
||||||
const addOffset = calcChatMediaSearchAddOffset(direction, limit);
|
const addOffset = calcChatMediaSearchAddOffset(direction, limit);
|
||||||
|
|
||||||
const resultChatId = isSavedDialog ? global.currentUserId! : chat.id;
|
const resultChatId = isSavedDialog ? global.currentUserId! : peer.id;
|
||||||
|
|
||||||
global = setChatMediaSearchLoading(global, resultChatId, threadId, true, tabId);
|
global = setChatMediaSearchLoading(global, resultChatId, threadId, true, tabId);
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
|
|
||||||
const result = await callApi('searchMessagesInChat', {
|
const result = await callApi('searchMessagesInChat', {
|
||||||
chat,
|
peer,
|
||||||
type: 'media',
|
type: 'media',
|
||||||
limit,
|
limit,
|
||||||
threadId,
|
threadId,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user