178 lines
4.6 KiB
TypeScript
178 lines
4.6 KiB
TypeScript
// Metro module 5099 (f5100).
|
|
import UserSettingsProtoStore from "../modules/user_settings/UserSettingsProtoStore";
|
|
import ChannelStore from "./ChannelStore";
|
|
import GuildStore from "./GuildStore";
|
|
import SelectedChannelStore from "./SelectedChannelStore";
|
|
import SelectedGuildStore from "./SelectedGuildStore";
|
|
import { ID_REGEX } from "../Constants";
|
|
import { UserSettingsTypes } from "../modules/user_settings/UserSettingsConstants";
|
|
import Frecency from "../lib/Frecency";
|
|
import Module12 from "../_bundle/Module12";
|
|
import Module589 from "../_bundle/Module589";
|
|
import Dispatcher from "../Dispatcher";
|
|
let c3067_9, c3067_10, c3067_11, initFrecency, c3067_13;
|
|
const handleChannelSelect = function handleChannelSelect({ guildId, channelId }) {
|
|
const r10 = c3067_10;
|
|
let r1 = false;
|
|
if (channelId !== r10) {
|
|
let r11 = channelId;
|
|
if (r11 == null) {
|
|
r11 = null;
|
|
}
|
|
c3067_10 = r11;
|
|
const r12 = channelId != null && ID_REGEX.test(channelId);
|
|
let r0 = false;
|
|
if (r12) {
|
|
c3067_9.track(channelId);
|
|
c3067_13.pendingUsages.push({
|
|
key: channelId,
|
|
timestamp: Date.now()
|
|
});
|
|
r0 = true;
|
|
}
|
|
r1 = r0;
|
|
}
|
|
const r24 = c3067_11;
|
|
let r25 = r1;
|
|
if (guildId !== r24) {
|
|
let r27 = guildId;
|
|
if (r27 == null) {
|
|
r27 = null;
|
|
}
|
|
c3067_11 = r27;
|
|
if (guildId != null && ID_REGEX.test(guildId)) {
|
|
c3067_9.track(guildId);
|
|
c3067_13.pendingUsages.push({
|
|
key: guildId,
|
|
timestamp: Date.now()
|
|
});
|
|
r1 = true;
|
|
}
|
|
r25 = r1;
|
|
}
|
|
return r25;
|
|
};
|
|
initFrecency = function initFrecency() {
|
|
const guildAndChannels = UserSettingsProtoStore.frecencyWithoutFetchingLatest.guildAndChannelFrecency?.guildAndChannels;
|
|
if (guildAndChannels == null) {
|
|
return false;
|
|
}
|
|
c3067_9.overwriteHistory(Module12.mapValues(guildAndChannels, (a0) => ({
|
|
...a0,
|
|
recentUses: a0.recentUses.map(Number).filter((item) => item > 0)
|
|
})), c3067_13.pendingUsages);
|
|
};
|
|
c3067_9 = new Frecency({
|
|
computeBonus: () => 100,
|
|
computeWeight: (a0) => {
|
|
let r0;
|
|
L9: {
|
|
r0 = 100;
|
|
if (a0 !== 0) {
|
|
if (a0 >= 1) {
|
|
const r3 = a0 < 2;
|
|
r0 = 70;
|
|
if (r3) {
|
|
break L9;
|
|
}
|
|
}
|
|
if (a0 >= 2) {
|
|
const r8 = a0 < 4;
|
|
r0 = 50;
|
|
if (r8) {
|
|
break L9;
|
|
}
|
|
}
|
|
if (a0 >= 4) {
|
|
const r11 = a0 < 7;
|
|
r0 = 30;
|
|
if (r11) {
|
|
break L9;
|
|
}
|
|
}
|
|
r0 = a0 >= 7 ? 10 : 1;
|
|
}
|
|
}
|
|
return r0;
|
|
},
|
|
lookupKey: (a0) => {
|
|
let r6 = GuildStore.getGuild(a0);
|
|
if (r6 == null) {
|
|
r6 = ChannelStore.getChannel(a0);
|
|
}
|
|
if (r6 == null) {
|
|
r6 = ChannelStore.getChannel(ChannelStore.getDMFromUserId(a0));
|
|
}
|
|
return r6;
|
|
},
|
|
afterCompute: () => {},
|
|
numFrequentlyItems: 100,
|
|
maxSamples: 10
|
|
});
|
|
c3067_10 = null;
|
|
c3067_11 = null;
|
|
c3067_13 = {
|
|
pendingUsages: []
|
|
};
|
|
class FrecencyStore extends Module589.PersistedStore {
|
|
static displayName = "FrecencyStore";
|
|
static persistKey = "FrecencyStore";
|
|
initialize(a0) {
|
|
this.waitFor(ChannelStore, GuildStore, SelectedChannelStore, SelectedGuildStore, UserSettingsProtoStore);
|
|
if (a0 != null) {
|
|
a0.pendingUsages = a0.pendingUsages.filter((pendingUsage) => pendingUsage != null && ID_REGEX.test(pendingUsage.key));
|
|
c3067_13 = a0;
|
|
}
|
|
this.syncWith([UserSettingsProtoStore], initFrecency);
|
|
}
|
|
getState() {
|
|
return c3067_13;
|
|
}
|
|
hasPendingUsage() {
|
|
return c3067_13.pendingUsages.length > 0;
|
|
}
|
|
get frecencyWithoutFetchingLatest() {
|
|
return c3067_9;
|
|
}
|
|
getFrequentlyWithoutFetchingLatest() {
|
|
return c3067_9.frequently;
|
|
}
|
|
getScoreWithoutFetchingLatest(a0) {
|
|
let r6 = c3067_9.getFrecency(a0);
|
|
if (r6 == null) {
|
|
r6 = 0;
|
|
}
|
|
return r6;
|
|
}
|
|
getScoreForDMWithoutFetchingLatest(a0) {
|
|
const dMFromUserId = ChannelStore.getDMFromUserId(a0);
|
|
return dMFromUserId != null ? this.getScoreWithoutFetchingLatest(dMFromUserId) : 0;
|
|
}
|
|
getMaxScore() {
|
|
return 1000;
|
|
}
|
|
getBonusScore() {
|
|
return 100;
|
|
}
|
|
getVersion() {
|
|
return c3067_9.version;
|
|
}
|
|
}
|
|
const frecencyStore = new FrecencyStore(Dispatcher, {
|
|
CHANNEL_SELECT: handleChannelSelect,
|
|
VOICE_CHANNEL_SELECT: handleChannelSelect,
|
|
USER_SETTINGS_PROTO_UPDATE: function handleUserSettingsProtoUpdate(a0) {
|
|
const type = a0.settings.type;
|
|
const wasSaved = a0.wasSaved;
|
|
const r0 = type !== UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS || !wasSaved;
|
|
let r1 = !r0;
|
|
if (!r0) {
|
|
c3067_13.pendingUsages = [];
|
|
r1 = true;
|
|
}
|
|
return r1;
|
|
}
|
|
});
|
|
export default frecencyStore;
|
|
export const MAX_NUM_SELECTED_ITEMS = 100;
|