decord/source/stores/FrecencyStore.tsx

217 lines
6.1 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 6809
// Function ID: 6810
2026-07-29 08:29:29 +00:00
// Name: handleChannelSelect
2026-08-24 06:08:38 +00:00
// Dependencies: [1340, 1391, 1910, 1980, 4201, 676, 685, 4561, 12, 589, 709, 2]
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
// Module 6809 (handleChannelSelect)
import applyDefault from "apply" /* 12 */;
import initializeDefault from "initialize" /* 589 */;
import dispatcherDefault from "dispatcher" /* 709 */;
import DEFAULT_FRECENCYDefault from "DEFAULT_FRECENCY" /* 4561 */;
import closure_2 from "handleConnectionClosedOrResumed" /* 1340 */;
import closure_3 from "ensureGuildLoaded" /* 1391 */;
import closure_4 from "createGuildRecordFromRust" /* 1910 */;
import closure_5 from "handleConnectionOpen" /* 1980 */;
import closure_6 from "handleConnectionOpen" /* 4201 */;
import { ID_REGEX } from "ME" /* 676 */;
import { UserSettingsTypes } from "MAX_FAVORITES" /* 685 */;
2026-07-20 16:05:17 +00:00
function handleChannelSelect(arg0) {
({ guildId, channelId } = arg0);
let flag = false;
2026-07-29 08:29:29 +00:00
if (channelId !== c10) {
let tmp2 = channelId;
if (channelId == null) {
tmp2 = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
c10 = tmp2;
2026-07-20 16:05:17 +00:00
let isMatch = null != channelId;
if (isMatch) {
isMatch = ID_REGEX.test(channelId);
}
let flag2 = false;
if (isMatch) {
2026-08-24 06:08:38 +00:00
closure_9.track(channelId);
2026-07-29 08:29:29 +00:00
const pendingUsages = closure_13.pendingUsages;
let obj = { key: null, timestamp: null };
obj[0] = channelId;
2026-07-20 16:05:17 +00:00
const _Date = Date;
2026-07-29 08:29:29 +00:00
obj[1] = Date.now();
2026-07-20 16:05:17 +00:00
pendingUsages.push(obj);
flag2 = true;
}
flag = flag2;
}
let tmp10 = flag;
2026-07-29 08:29:29 +00:00
if (guildId !== c11) {
let tmp12 = guildId;
if (guildId == null) {
tmp12 = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
c11 = tmp12;
2026-07-20 16:05:17 +00:00
let isMatch1 = null != guildId;
if (isMatch1) {
isMatch1 = ID_REGEX.test(guildId);
}
if (isMatch1) {
2026-08-24 06:08:38 +00:00
closure_9.track(guildId);
2026-07-29 08:29:29 +00:00
const pendingUsages1 = closure_13.pendingUsages;
obj = { key: null, timestamp: null };
obj[0] = guildId;
2026-07-20 16:05:17 +00:00
const _Date2 = Date;
2026-07-29 08:29:29 +00:00
obj[1] = Date.now();
2026-07-20 16:05:17 +00:00
pendingUsages1.push(obj);
flag = true;
}
tmp10 = flag;
}
return tmp10;
}
function initFrecency() {
const guildAndChannelFrecency = obj.frecencyWithoutFetchingLatest.guildAndChannelFrecency;
let guildAndChannels;
2026-07-29 08:29:29 +00:00
if (guildAndChannelFrecency != null) {
2026-07-20 16:05:17 +00:00
guildAndChannels = guildAndChannelFrecency.guildAndChannels;
}
if (null == guildAndChannels) {
return false;
} else {
2026-08-24 06:08:38 +00:00
obj = applyDefault;
closure_9.overwriteHistory(obj.mapValues(guildAndChannels, (recentUses) => {
2026-07-20 16:05:17 +00:00
const obj = {};
const merged = Object.assign(recentUses);
recentUses = recentUses.recentUses;
const mapped = recentUses.map(Number);
2026-07-29 08:29:29 +00:00
obj.recentUses = mapped.filter((arg0) => arg0 > 0);
2026-07-20 16:05:17 +00:00
return obj;
2026-07-29 08:29:29 +00:00
}), closure_13.pendingUsages);
2026-07-20 16:05:17 +00:00
}
}
let obj = {
computeBonus() {
return 100;
},
computeWeight(arg0) {
let num = 100;
if (0 !== arg0) {
if (arg0 < 1) {
if (arg0 < 2) {
if (arg0 < 4) {
num = 1;
if (arg0 >= 7) {
num = 10;
}
} else {
num = 30;
}
} else {
num = 50;
}
} else {
num = 70;
}
}
return num;
},
2026-07-29 08:29:29 +00:00
lookupKey(id) {
guild = guild.getGuild(id);
if (guild == null) {
guild = authStore.getChannel(id);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (guild == null) {
guild = authStore.getChannel(authStore.getDMFromUserId(id));
2026-07-20 16:05:17 +00:00
}
return guild;
},
afterCompute() {
},
numFrequentlyItems: 100,
maxSamples: 10
};
2026-08-24 06:08:38 +00:00
let closure_9 = new DEFAULT_FRECENCYDefault(obj);
2026-07-29 08:29:29 +00:00
let c10 = null;
let c11 = null;
let closure_13 = { pendingUsages: [] };
2026-08-24 06:08:38 +00:00
const PersistedStore = initializeDefault.PersistedStore;
2026-07-29 08:29:29 +00:00
class FrecencyStore extends PersistedStore {
}
const prototype = FrecencyStore.prototype;
prototype["initialize"] = function initialize(pendingUsages) {
const self = this;
2026-08-24 06:08:38 +00:00
this.waitFor(closure_3, closure_4, closure_5, closure_6, closure_2);
2026-07-29 08:29:29 +00:00
if (null != pendingUsages) {
pendingUsages = pendingUsages.pendingUsages;
pendingUsages.pendingUsages = pendingUsages.filter((key) => {
let isMatch = null != key;
if (isMatch) {
isMatch = regex.test(key.key);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return isMatch;
});
2026-08-24 06:08:38 +00:00
closure_13 = pendingUsages;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
const items = [closure_2];
2026-07-29 08:29:29 +00:00
self.syncWith(items, initFrecency);
};
prototype["getState"] = function getState() {
return closure_13;
};
prototype["hasPendingUsage"] = function hasPendingUsage() {
return closure_13.pendingUsages.length > 0;
};
Object.defineProperty(prototype, "frecencyWithoutFetchingLatest", {
get: function frecencyWithoutFetchingLatest() {
return closure_9;
},
set: undefined
});
prototype["getFrequentlyWithoutFetchingLatest"] = function getFrequentlyWithoutFetchingLatest() {
2026-08-24 06:08:38 +00:00
return closure_9.frequently;
2026-07-29 08:29:29 +00:00
};
prototype["getScoreWithoutFetchingLatest"] = function getScoreWithoutFetchingLatest(id) {
2026-08-24 06:08:38 +00:00
let num = closure_9.getFrecency(id);
2026-07-29 08:29:29 +00:00
if (num == null) {
num = 0;
}
return num;
};
prototype["getScoreForDMWithoutFetchingLatest"] = function getScoreForDMWithoutFetchingLatest(id) {
const dMFromUserId = authStore.getDMFromUserId(id);
let num = 0;
if (null != dMFromUserId) {
const self = this;
num = this.getScoreWithoutFetchingLatest(dMFromUserId);
}
return num;
};
prototype["getMaxScore"] = function getMaxScore() {
return 1000;
};
prototype["getBonusScore"] = function getBonusScore() {
return 100;
};
prototype["getVersion"] = function getVersion() {
2026-08-24 06:08:38 +00:00
return closure_9.version;
2026-07-29 08:29:29 +00:00
};
FrecencyStore.displayName = "FrecencyStore";
FrecencyStore.persistKey = "FrecencyStore";
2026-07-20 16:05:17 +00:00
obj = {
CHANNEL_SELECT: handleChannelSelect,
VOICE_CHANNEL_SELECT: handleChannelSelect,
USER_SETTINGS_PROTO_UPDATE: function handleUserSettingsProtoUpdate(settings) {
let flag = !tmp;
if (!(settings.settings.type !== UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS || !settings.wasSaved)) {
2026-07-29 08:29:29 +00:00
closure_13.pendingUsages = [];
2026-07-20 16:05:17 +00:00
flag = true;
}
return flag;
}
};
2026-08-24 06:08:38 +00:00
const frecencyStore = new FrecencyStore(dispatcherDefault, obj);
let tmp2 = new DEFAULT_FRECENCYDefault(obj);
const result = require("set").fileFinishedImporting("stores/FrecencyStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default frecencyStore;
2026-07-20 16:05:17 +00:00
export const MAX_NUM_SELECTED_ITEMS = 100;