101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
// Metro module 5698 (f5699).
|
|
import EmbeddedActivitiesStore from "../activities/EmbeddedActivitiesStore";
|
|
import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore";
|
|
import { FREQUENCY_ITEM_LIMIT } from "./ApplicationConstants";
|
|
import { UserSettingsTypes } from "../user_settings/UserSettingsConstants";
|
|
import { ApplicationCommandType } from "../../flow/Server";
|
|
import Frecency from "../../lib/Frecency";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c3532_5, c3532_6, c3532_7;
|
|
const handleUserSettingsProtoStoreChange = function handleUserSettingsProtoStoreChange() {
|
|
let r9 = UserSettingsProtoStore.frecencyWithoutFetchingLatest.applicationFrecency?.applications;
|
|
if (r9 == null) {
|
|
r9 = {};
|
|
}
|
|
c3532_7.overwriteHistory(Module12.mapValues(r9, (a0) => ({
|
|
...a0,
|
|
recentUses: a0.recentUses.map(Number).filter((item) => item > 0)
|
|
})), c3532_6.pendingUsages);
|
|
};
|
|
c3532_5 = [ApplicationCommandType.CHAT, ApplicationCommandType.PRIMARY_ENTRY_POINT];
|
|
c3532_6 = {
|
|
pendingUsages: []
|
|
};
|
|
c3532_7 = new Frecency({
|
|
computeBonus: () => 100,
|
|
lookupKey: (a0) => a0,
|
|
afterCompute: () => {},
|
|
numFrequentlyItems: FREQUENCY_ITEM_LIMIT
|
|
});
|
|
class ApplicationFrecencyStore extends Module589.PersistedStore {
|
|
static displayName = "ApplicationFrecencyStore";
|
|
static persistKey = "ApplicationFrecency";
|
|
initialize(a0) {
|
|
if (a0 != null) {
|
|
c3532_6 = a0;
|
|
}
|
|
this.waitFor(EmbeddedActivitiesStore, UserSettingsProtoStore);
|
|
this.syncWith([UserSettingsProtoStore], handleUserSettingsProtoStoreChange);
|
|
}
|
|
getState() {
|
|
return c3532_6;
|
|
}
|
|
hasPendingUsage() {
|
|
return c3532_6.pendingUsages.length > 0;
|
|
}
|
|
getApplicationFrecencyWithoutLoadingLatest() {
|
|
return c3532_7;
|
|
}
|
|
getScoreWithoutLoadingLatest(a0) {
|
|
let r6 = c3532_7.getScore(a0);
|
|
if (r6 == null) {
|
|
r6 = 0;
|
|
}
|
|
return r6;
|
|
}
|
|
getTopApplicationsWithoutLoadingLatest() {
|
|
return c3532_7.frequently;
|
|
}
|
|
}
|
|
const applicationFrecencyStore = new ApplicationFrecencyStore(Dispatcher, {
|
|
APPLICATION_COMMAND_USED: function handleApplicationCommandUsed({ command }) {
|
|
let r12 = !!c3532_5.includes(command.type);
|
|
if (r12) {
|
|
const isLaunching = EmbeddedActivitiesStore.getLaunchState(command.applicationId)?.isLaunching;
|
|
let r19 = !isLaunching;
|
|
if (!isLaunching) {
|
|
const applicationId = command.applicationId;
|
|
c3532_6.pendingUsages.push({
|
|
key: applicationId,
|
|
timestamp: Date.now()
|
|
});
|
|
c3532_7.track(applicationId);
|
|
c3532_7.compute();
|
|
r19 = void 0;
|
|
}
|
|
r12 = r19;
|
|
}
|
|
return r12;
|
|
},
|
|
EMBEDDED_ACTIVITY_OPEN: function handleEmbeddedActivityOpen({ applicationId }) {
|
|
c3532_6.pendingUsages.push({
|
|
key: applicationId,
|
|
timestamp: Date.now()
|
|
});
|
|
c3532_7.track(applicationId);
|
|
c3532_7.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) {
|
|
c3532_6.pendingUsages = [];
|
|
return void 0;
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
export default applicationFrecencyStore;
|