217 lines
6.9 KiB
TypeScript
217 lines
6.9 KiB
TypeScript
// Metro module 10110 (f10111).
|
|
import { getSearchQueryFromTokens, tokenizeQuery, searchModeToSearchQueryParams, getGuildIdFromSearchContext, setIncludeNSFW, getSearchContextId } from "./SearchUtils";
|
|
import SearchTabsFetchManager from "./managers/SearchTabsFetchManager";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import convertServerThreadMember from "../threads/convertServerThreadMember";
|
|
import SearchFetchManager from "./managers/SearchFetchManager";
|
|
import { FrecencyUserSettingsActionCreators } from "../user_settings/UserSettingsProtoActionCreators";
|
|
const r13 = {
|
|
fetchTabMessages: function fetchTabMessages({ searchContext, searchTabs, searchQueryString, pagination, trackExactTotalHits, getId, getLimit, onFetchStart, onFetchSuccess, searchMode }) {
|
|
let guildIdFromSearchContext, ids;
|
|
guildIdFromSearchContext = void 0;
|
|
ids = void 0;
|
|
const searchQueryFromTokens = getSearchQueryFromTokens(tokenizeQuery(searchQueryString));
|
|
if (Array.isArray(searchQueryFromTokens.pinned)) {
|
|
searchQueryFromTokens.pinned = searchQueryFromTokens.pinned.some((item) => item === true);
|
|
}
|
|
const searchQuery = {
|
|
...searchQueryFromTokens,
|
|
...searchModeToSearchQueryParams(searchMode)
|
|
};
|
|
guildIdFromSearchContext = getGuildIdFromSearchContext(searchContext);
|
|
if (guildIdFromSearchContext != null) {
|
|
setIncludeNSFW(searchQuery, guildIdFromSearchContext);
|
|
}
|
|
const r63 = SearchTabsFetchManager.create({
|
|
id: getSearchContextId(searchContext),
|
|
searchContext,
|
|
searchQuery,
|
|
searchTabs,
|
|
getLimit,
|
|
pagination,
|
|
trackExactTotalHits
|
|
});
|
|
if (onFetchStart != null) {
|
|
onFetchStart({
|
|
searchContext,
|
|
searchQueryString,
|
|
searchQuery
|
|
});
|
|
}
|
|
ids = searchTabs.map((searchTab) => getId(searchTab));
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_START",
|
|
ids
|
|
});
|
|
r63.fetch(({ body }) => {
|
|
const tabEntries = Object.entries(body.tabs);
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_SUCCESS",
|
|
guildId: guildIdFromSearchContext,
|
|
data: tabEntries.map((tabEntry) => {
|
|
const [r23, r24] = tabEntry;
|
|
const id = getId(r23);
|
|
const cursor = r24.cursor;
|
|
const cursor2 = cursor != null ? Module12.isEmpty(cursor) ? null : cursor : cursor;
|
|
let channels = r24.channels;
|
|
if (channels == null) {
|
|
channels = [];
|
|
}
|
|
let threads = r24.threads;
|
|
if (threads == null) {
|
|
threads = [];
|
|
}
|
|
let members = r24.members;
|
|
if (members == null) {
|
|
members = [];
|
|
}
|
|
return {
|
|
id,
|
|
analyticsId: body.analytics_id,
|
|
totalResults: r24.total_results,
|
|
cursor: cursor2,
|
|
messages: r24.messages,
|
|
channels,
|
|
threads,
|
|
members: members.map((member) => convertServerThreadMember(member)),
|
|
doingHistoricalIndex: body.doing_deep_historical_index,
|
|
documentsIndexed: body.documents_indexed
|
|
};
|
|
})
|
|
});
|
|
if (onFetchSuccess != null) {
|
|
onFetchSuccess({
|
|
searchContext,
|
|
tabEntries
|
|
});
|
|
}
|
|
}, () => {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_INDEXING",
|
|
ids
|
|
});
|
|
}, (a0) => {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_FAILURE",
|
|
ids,
|
|
error: a0
|
|
});
|
|
});
|
|
return true;
|
|
},
|
|
fetchMessages: function fetchMessages({ searchContext: searchContext2, searchQueryString, pagination, searchMode, searchEverywhere, onFetchStart }) {
|
|
const searchQuery = {
|
|
...getSearchQueryFromTokens(tokenizeQuery(searchQueryString)),
|
|
...searchModeToSearchQueryParams(searchMode),
|
|
offset: pagination.offset
|
|
};
|
|
const guildIdFromSearchContext2 = getGuildIdFromSearchContext(searchContext2);
|
|
if (guildIdFromSearchContext2 != null) {
|
|
setIncludeNSFW(searchQuery, guildIdFromSearchContext2);
|
|
}
|
|
if (searchEverywhere) {
|
|
searchQuery.search_everywhere = true;
|
|
}
|
|
const searchContextId = getSearchContextId(searchContext2);
|
|
const r51 = SearchFetchManager.create({
|
|
id: searchContextId,
|
|
searchType: searchContext2.type,
|
|
searchQuery
|
|
});
|
|
if (onFetchStart != null) {
|
|
onFetchStart({
|
|
searchContext: searchContext2,
|
|
searchQueryString,
|
|
searchQuery
|
|
});
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_START",
|
|
ids: [searchContextId]
|
|
});
|
|
r51.fetch((a0) => {
|
|
let threads = a0.body.threads;
|
|
if (threads == null) {
|
|
threads = [];
|
|
}
|
|
let members = a0.body.members;
|
|
if (members == null) {
|
|
members = [];
|
|
}
|
|
const r16 = {
|
|
id: searchContextId,
|
|
analyticsId: a0.body.analytics_id,
|
|
totalResults: a0.body.total_results,
|
|
messages: a0.body.messages,
|
|
threads,
|
|
members: members.map((member) => convertServerThreadMember(member)),
|
|
doingHistoricalIndex: a0.body.doing_deep_historical_index,
|
|
documentsIndexed: a0.body.documents_indexed,
|
|
channels: null,
|
|
cursor: null
|
|
};
|
|
let channels = a0.body.channels;
|
|
if (channels == null) {
|
|
channels = [];
|
|
}
|
|
r16.channels = channels;
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_SUCCESS",
|
|
guildId: guildIdFromSearchContext2,
|
|
data: [r16]
|
|
});
|
|
}, () => {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_INDEXING",
|
|
ids: [searchContextId]
|
|
});
|
|
}, (a0) => {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_FAILURE",
|
|
ids: [searchContextId],
|
|
error: a0
|
|
});
|
|
});
|
|
},
|
|
clearSearchRecentMessages: function clearSearchRecentMessages() {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_RECENT_MESSAGES_CLEAR"
|
|
});
|
|
},
|
|
clearAllSearchMesssages: function clearAllSearchMesssages() {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_CLEAR_ALL"
|
|
});
|
|
},
|
|
clearSearchMessages: function clearSearchMessages(a0) {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_MESSAGES_CLEAR",
|
|
id: a0
|
|
});
|
|
},
|
|
initializeAutocomplete: function initializeAutocomplete(a0) {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_AUTOCOMPLETE_INITIALIZE",
|
|
searchContext: a0
|
|
});
|
|
},
|
|
updateAutocompleteQuery: function updateAutocompleteQuery({ searchContext: searchContext2, tokens, queryString, cursorScope }) {
|
|
if (queryString.trim().length > 0) {
|
|
FrecencyUserSettingsActionCreators.loadIfNecessary();
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_AUTOCOMPLETE_QUERY_UPDATE",
|
|
searchContext: searchContext2,
|
|
tokens,
|
|
cursorScope
|
|
});
|
|
},
|
|
markSearchTokensRefreshed: function markSearchTokensRefreshed() {
|
|
Dispatcher.dispatch({
|
|
type: "SEARCH_TOKENS_REFRESHED"
|
|
});
|
|
}
|
|
};
|
|
export default r13;
|