405 lines
11 KiB
TypeScript
405 lines
11 KiB
TypeScript
// Metro module 9597 (f9598).
|
|
import LocaleStore from "../modules/user_settings/LocaleStore";
|
|
import GIFPickerViewStore from "../stores/views/GIFPickerViewStore";
|
|
import { AnalyticEvents, Endpoints, GIFPickerResultTypes, SearchTypes } from "../Constants";
|
|
import { MAX_FAVORITE_GIFS_SIZE, UserSettingsDelay } from "../modules/user_settings/UserSettingsConstants";
|
|
import AppAnalyticsUtils from "../modules/app_analytics/AppAnalyticsUtils";
|
|
import { calculateAnalyticsMetadata } from "../utils/GIFPickerUtils";
|
|
import { HTTP } from "../_bundle/sendRequest";
|
|
import Dispatcher from "../Dispatcher";
|
|
import Module12 from "../_bundle/Module12";
|
|
import { v4 } from "../_bundle/Module514";
|
|
import URLUtils from "../utils/URLUtils";
|
|
import { isAttachmentUrl, removeSignedUrlParameters, isExternalProxiedAttachmentUrl } from "../modules/messages/SignedAttachmentLinkUtils";
|
|
import { FrecencyUserSettingsActionCreators } from "../modules/user_settings/UserSettingsProtoActionCreators";
|
|
import { GIFType, FavoriteGIFs } from "../_bundle/Module1341";
|
|
import AlertActionCreators from "./AlertActionCreators";
|
|
import { intl, t } from "../intl/index.native";
|
|
import AnalyticsUtils from "../utils/AnalyticsUtils";
|
|
let c6339_11, gif_provider, c6339_14, c6339_15;
|
|
const doSearchRequest = function doSearchRequest(a0, a1, a2) {
|
|
let modifiers;
|
|
const query = a0;
|
|
const limit = a2;
|
|
const startTime = Date.now();
|
|
if (a1 != null) {
|
|
const r16 = {};
|
|
r16[a1] = 1;
|
|
modifiers = r16;
|
|
} else {
|
|
modifiers = {};
|
|
}
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_STARTED, {
|
|
search_type: SearchTypes.GIF,
|
|
load_id: GIFPickerViewStore.getAnalyticsID(),
|
|
num_modifiers: Object.keys(modifiers).length,
|
|
modifiers,
|
|
gif_provider
|
|
});
|
|
HTTP.get({
|
|
url: Endpoints.GIFS_SEARCH,
|
|
query: {
|
|
q: a0,
|
|
media_format: GIFPickerViewStore.getSelectedFormat(),
|
|
locale: LocaleStore.locale,
|
|
limit: a2
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
}).then(({ body }) => {
|
|
const r7 = {
|
|
startTime,
|
|
limit
|
|
};
|
|
const { startTime: startTime3, ...rest } = r7;
|
|
const r13 = {
|
|
offset: 0,
|
|
limit: null,
|
|
totalResults: body.length
|
|
};
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_RESULT_VIEWED, {
|
|
...calculateAnalyticsMetadata(GIFPickerViewStore.getAnalyticsID(), a1, {
|
|
...r13,
|
|
...rest,
|
|
results: body.length
|
|
}),
|
|
...startTime3 == null ? {} : {
|
|
load_duration_ms: Date.now() - startTime3
|
|
},
|
|
gif_provider
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY_SUCCESS",
|
|
query,
|
|
items: body
|
|
});
|
|
}, () => Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY_FAILURE",
|
|
query
|
|
}));
|
|
};
|
|
c6339_11 = /-/g;
|
|
gif_provider = "klipy";
|
|
c6339_14 = Module12.debounce(doSearchRequest, 250);
|
|
c6339_15 = /\.(webp|avif|gif)(\?|$)/i;
|
|
export function trackSearchStart(a0) {
|
|
let modifiers;
|
|
if (a0 != null) {
|
|
const r2 = {};
|
|
r2[a0] = 1;
|
|
modifiers = r2;
|
|
} else {
|
|
modifiers = {};
|
|
}
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_STARTED, {
|
|
search_type: SearchTypes.GIF,
|
|
load_id: GIFPickerViewStore.getAnalyticsID(),
|
|
num_modifiers: Object.keys(modifiers).length,
|
|
modifiers,
|
|
gif_provider
|
|
});
|
|
}
|
|
export function trackSearchResultViewed(a0, a1, r5 = {}) {
|
|
const { startTime: startTime3, ...rest } = r5;
|
|
const r12 = {
|
|
offset: 0,
|
|
limit: null,
|
|
totalResults: a0.length
|
|
};
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_RESULT_VIEWED, {
|
|
...calculateAnalyticsMetadata(GIFPickerViewStore.getAnalyticsID(), a1, {
|
|
...r12,
|
|
...rest,
|
|
results: a0.length
|
|
}),
|
|
...startTime3 == null ? {} : {
|
|
load_duration_ms: Date.now() - startTime3
|
|
},
|
|
gif_provider
|
|
});
|
|
}
|
|
export function search(a0, a1, r3 = false) {
|
|
if (a0 === "") {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY",
|
|
query: ""
|
|
});
|
|
} else {
|
|
const r10 = arguments[3];
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY",
|
|
query: a0
|
|
});
|
|
if (r3) {
|
|
doSearchRequest(a0, a1, r10);
|
|
} else {
|
|
c6339_14(a0, a1, r10);
|
|
}
|
|
}
|
|
}
|
|
export function fetchSuggestions(a0) {
|
|
const query2 = a0;
|
|
if (a0 !== "" && a0 != null) {
|
|
HTTP.get({
|
|
url: Endpoints.GIFS_SUGGEST,
|
|
query: {
|
|
q: a0,
|
|
limit: 5,
|
|
locale: LocaleStore.locale
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
}).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_SUGGESTIONS_SUCCESS",
|
|
query: query2,
|
|
items: result.body
|
|
});
|
|
});
|
|
}
|
|
}
|
|
export function resetSearch() {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY",
|
|
query: ""
|
|
});
|
|
}
|
|
export function trackSelectGIF({ type, index, offset, limit: limit3, results, totalResults, query: query3, gifId }) {
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_RESULT_SELECTED, {
|
|
...calculateAnalyticsMetadata(GIFPickerViewStore.getAnalyticsID(), type, {
|
|
offset,
|
|
limit: limit3,
|
|
results,
|
|
totalResults
|
|
}),
|
|
index_num: index,
|
|
source_object: "GIF Picker",
|
|
query: query3
|
|
});
|
|
if (gifId != null) {
|
|
HTTP.post({
|
|
url: Endpoints.GIFS_SELECT,
|
|
body: {
|
|
id: gifId,
|
|
q: query3
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
}
|
|
}
|
|
export function initializeSearch() {
|
|
const analyticsID = v4().replace(c6339_11, "");
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_OPENED, {
|
|
search_type: SearchTypes.GIF,
|
|
load_id: analyticsID
|
|
});
|
|
Dispatcher.wait(() => {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_INITIALIZE",
|
|
analyticsID
|
|
});
|
|
});
|
|
}
|
|
export function fetchTrending() {
|
|
HTTP.get({
|
|
url: Endpoints.GIFS_TRENDING,
|
|
query: {
|
|
locale: LocaleStore.locale,
|
|
media_format: GIFPickerViewStore.getSelectedFormat()
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
}).then(({ body }) => {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_TRENDING_FETCH_SUCCESS",
|
|
trendingCategories: body.categories,
|
|
trendingGIFPreview: body.gifs[0]
|
|
});
|
|
});
|
|
}
|
|
export function fetchTrendingGIFs(a0) {
|
|
let modifiers;
|
|
const limit2 = a0;
|
|
const startTime2 = Date.now();
|
|
const TRENDING_GIFS = GIFPickerResultTypes.TRENDING_GIFS;
|
|
if (TRENDING_GIFS != null) {
|
|
const r17 = {};
|
|
r17[TRENDING_GIFS] = 1;
|
|
modifiers = r17;
|
|
} else {
|
|
modifiers = {};
|
|
}
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_STARTED, {
|
|
search_type: SearchTypes.GIF,
|
|
load_id: GIFPickerViewStore.getAnalyticsID(),
|
|
num_modifiers: Object.keys(modifiers).length,
|
|
modifiers,
|
|
gif_provider
|
|
});
|
|
HTTP.get({
|
|
url: Endpoints.GIFS_TRENDING_GIFS,
|
|
query: {
|
|
media_format: GIFPickerViewStore.getSelectedFormat(),
|
|
locale: LocaleStore.locale,
|
|
limit: a0
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
}).then(({ body }) => {
|
|
const TRENDING_GIFS = GIFPickerResultTypes.TRENDING_GIFS;
|
|
const r6 = {
|
|
startTime: startTime2,
|
|
limit: limit2
|
|
};
|
|
const { startTime: startTime3, ...rest } = r6;
|
|
const r12 = {
|
|
offset: 0,
|
|
limit: null,
|
|
totalResults: body.length
|
|
};
|
|
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.SEARCH_RESULT_VIEWED, {
|
|
...calculateAnalyticsMetadata(GIFPickerViewStore.getAnalyticsID(), TRENDING_GIFS, {
|
|
...r12,
|
|
...rest,
|
|
results: body.length
|
|
}),
|
|
...startTime3 == null ? {} : {
|
|
load_duration_ms: Date.now() - startTime3
|
|
},
|
|
gif_provider
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY_SUCCESS",
|
|
items: body
|
|
});
|
|
}, () => {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_QUERY_FAILURE"
|
|
});
|
|
});
|
|
}
|
|
export function gifUrlKey(a0) {
|
|
let r3 = a0;
|
|
const r11 = URLUtils.toURLSafe(a0);
|
|
let r12 = a0;
|
|
if (r11 != null) {
|
|
if (isAttachmentUrl(r11)) {
|
|
r3 = removeSignedUrlParameters(r11).toString();
|
|
}
|
|
r12 = r3;
|
|
}
|
|
return r12;
|
|
}
|
|
export function addFavoriteGIF(c17331_0) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteGifs", (a0) => {
|
|
let r51;
|
|
let r26 = Module12.max(Object.values(a0.gifs).map((item) => item.order));
|
|
if (r26 == null) {
|
|
r26 = 0;
|
|
}
|
|
if (!(/\.(mp4|webm)(\?|$)/i.test(c17331_0.src) && (c17331_0.gifSrc != null && (c17331_0.gifSrc !== "" && c17331_0.gifSrc !== c17331_0.src)))) {
|
|
const r14 = URLUtils.toURLSafe(c17331_0.src);
|
|
r51 = r14 != null && (isExternalProxiedAttachmentUrl(r14) || isAttachmentUrl(r14)) && c17331_0.gifSrc != null ? c17331_0.gifSrc : c17331_0.src;
|
|
} else {
|
|
r51 = c17331_0.gifSrc;
|
|
}
|
|
const r15 = URLUtils.toURLSafe(c17331_0.src);
|
|
const r56 = r15 != null && (isExternalProxiedAttachmentUrl(r15) || isAttachmentUrl(r15));
|
|
let r65 = r51;
|
|
if (r56) {
|
|
const r68 = c6339_15.test(r51);
|
|
r65 = r51;
|
|
if (r68) {
|
|
const r72 = URLUtils.toURLSafe(r51);
|
|
let r73 = r51;
|
|
if (r72 != null) {
|
|
const r18 = r72.pathname.toLowerCase();
|
|
const r16 = r18.endsWith(".webp");
|
|
let r80 = r18.endsWith(".avif");
|
|
const r82 = r18.endsWith(".gif");
|
|
if (!(!r16 && (!r80 && !r82))) {
|
|
if (!r80) {
|
|
r80 = r82;
|
|
}
|
|
if (r80) {
|
|
r72.searchParams.set("format", "webp");
|
|
}
|
|
r72.searchParams.set("animated", "true");
|
|
r51 = r72.toString();
|
|
}
|
|
r73 = r51;
|
|
}
|
|
r65 = r73;
|
|
}
|
|
}
|
|
const r96 = r65.startsWith("//");
|
|
const r97 = r65;
|
|
const r98 = r96 ? `https:${r97}` : r97;
|
|
const r104 = c6339_15.test(r98);
|
|
const src = r98;
|
|
const format = r104 ? GIFType.IMAGE : c17331_0.format;
|
|
const gifs = a0.gifs;
|
|
let url = c17331_0.url;
|
|
const r116 = URLUtils.toURLSafe(url);
|
|
let r117 = url;
|
|
if (r116 != null) {
|
|
if (isAttachmentUrl(r116)) {
|
|
url = removeSignedUrlParameters(r116).toString();
|
|
}
|
|
r117 = url;
|
|
}
|
|
gifs[r117] = {
|
|
...c17331_0,
|
|
src,
|
|
format,
|
|
order: r26 + 1
|
|
};
|
|
if (FavoriteGIFs.toBinary(a0).length > MAX_FAVORITE_GIFS_SIZE) {
|
|
AlertActionCreators.show({
|
|
title: intl.string(t["+XYXtZ"]),
|
|
body: intl.string(t.YSDH9n)
|
|
});
|
|
return false;
|
|
}
|
|
const total_num_favorited = Module12.size(a0.gifs);
|
|
if (total_num_favorited > 2) {
|
|
a0.hideTooltip = true;
|
|
}
|
|
AnalyticsUtils.track(AnalyticEvents.GIF_FAVORITED, {
|
|
total_num_favorited
|
|
});
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
export function removeFavoriteGIF(c17332_0) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteGifs", (a0) => {
|
|
const r0 = c17332_0 in a0.gifs;
|
|
const gifs = a0.gifs;
|
|
if (r0) {
|
|
delete gifs[c17332_0];
|
|
} else {
|
|
const r9 = URLUtils.toURLSafe(c17332_0);
|
|
delete gifs[r9 != null ? isAttachmentUrl(r9) ? removeSignedUrlParameters(r9).toString() : c17332_0 : c17332_0];
|
|
}
|
|
AnalyticsUtils.track(AnalyticEvents.GIF_UNFAVORITED, {
|
|
total_num_favorited: Module12.size(a0.gifs)
|
|
});
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
export function fetchTrendingSearchTerms() {
|
|
HTTP.get({
|
|
url: Endpoints.GIFS_TRENDING_SEARCH,
|
|
query: {
|
|
limit: 5,
|
|
locale: LocaleStore.locale
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
}).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "GIF_PICKER_TRENDING_SEARCH_TERMS_SUCCESS",
|
|
items: result.body
|
|
});
|
|
});
|
|
}
|