84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
// Metro module 5091 (f5092).
|
|
import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore";
|
|
import StickersStore from "./StickersStore";
|
|
import { UserSettingsTypes } from "../user_settings/UserSettingsConstants";
|
|
import Durations from "../../utils/Durations";
|
|
import Frecency from "../../lib/Frecency";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c3058_5, c3058_6, handleUserSettingsProtoStoreChange;
|
|
const handleStickersStoreUpdate = function handleStickersStoreUpdate() {
|
|
if (StickersStore.isLoaded) {
|
|
c3058_6.compute();
|
|
}
|
|
};
|
|
handleUserSettingsProtoStoreChange = function handleUserSettingsProtoStoreChange() {
|
|
const stickers = UserSettingsProtoStore.frecencyWithoutFetchingLatest.stickerFrecency?.stickers;
|
|
if (stickers == null) {
|
|
return false;
|
|
}
|
|
c3058_6.overwriteHistory(Module12.mapValues(stickers, (a0) => ({
|
|
...a0,
|
|
recentUses: a0.recentUses.map(Number).filter((item) => item > 0)
|
|
})), c3058_5.pendingUsages);
|
|
};
|
|
c3058_5 = {
|
|
pendingUsages: []
|
|
};
|
|
const DAY = Durations.Millis.DAY;
|
|
c3058_6 = new Frecency({
|
|
computeBonus: () => 100,
|
|
lookupKey: (a0) => StickersStore.getStickerById(a0),
|
|
afterCompute: () => {},
|
|
numFrequentlyItems: 20
|
|
});
|
|
class StickersPersistedStore extends Module589.PersistedStore {
|
|
static displayName = "StickersPersistedStore";
|
|
static persistKey = "StickersPersistedStoreV2";
|
|
initialize(a0) {
|
|
this.waitFor(StickersStore, UserSettingsProtoStore);
|
|
if (a0 != null) {
|
|
c3058_5 = a0;
|
|
}
|
|
this.syncWith([StickersStore], handleStickersStoreUpdate);
|
|
this.syncWith([UserSettingsProtoStore], handleUserSettingsProtoStoreChange);
|
|
}
|
|
getState() {
|
|
return c3058_5;
|
|
}
|
|
hasPendingUsage() {
|
|
return c3058_5.pendingUsages.length > 0;
|
|
}
|
|
get stickerFrecencyWithoutFetchingLatest() {
|
|
return c3058_6;
|
|
}
|
|
}
|
|
const stickersPersistedStore = new StickersPersistedStore(Dispatcher, {
|
|
STICKER_TRACK_USAGE: function handleStickersUsage({ stickerIds }) {
|
|
if (stickerIds != null) {
|
|
stickerIds.forEach((stickerId) => {
|
|
c3058_6.track(stickerId);
|
|
c3058_5.pendingUsages.push({
|
|
key: stickerId,
|
|
timestamp: Date.now()
|
|
});
|
|
});
|
|
}
|
|
if (StickersStore.isLoaded) {
|
|
c3058_6.compute();
|
|
}
|
|
},
|
|
USER_SETTINGS_PROTO_UPDATE: function handleUserSettingsProtoUpdate(a0) {
|
|
const type = a0.settings.type;
|
|
const wasSaved = a0.wasSaved;
|
|
if (type === UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS && wasSaved) {
|
|
c3058_5.pendingUsages = [];
|
|
return void 0;
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
export default stickersPersistedStore;
|
|
export { DAY as STICKER_PACK_NEW_TIMESTAMP_THRESHOLD };
|