decord/alpha/source/modules/user_settings/FrecencySettingsMigrations.tsx

502 lines
17 KiB
TypeScript
Raw Normal View History

2026-10-09 10:00:15 +00:00
// Module ID: 14634
// Function ID: 14635
// Name: FrecencySettingsMigrations
2026-10-09 10:00:15 +00:00
// Dependencies: [1095, 1085, 504, 1245, 12, 1246, 510, 11, 2]
2026-07-20 16:05:17 +00:00
2026-10-09 10:00:15 +00:00
// Module 14634 (FrecencySettingsMigrations)
2026-10-03 08:58:59 +00:00
import SnowflakeUtilsDefault from "SnowflakeUtils" /* 11 */;
import get_initializedDefault from "get initialized" /* 504 */;
import Storage4 from "Storage" /* 510 */;
2026-10-03 08:58:59 +00:00
import Constants from "Constants" /* 1085 */;
2026-10-09 10:00:15 +00:00
import frecency_user_settings from "frecency_user_settings" /* 1245 */;
import user_settings_UserSettingsUtils from "user_settings/UserSettingsUtils" /* 1246 */;
2026-10-03 08:58:59 +00:00
import UserSettingsConstants from "UserSettingsConstants" /* 1095 */;
import size from "module_2" /* 2 */;
const require = globalThis.__r;
2026-10-03 08:58:59 +00:00
let format, importDefault, set;
2026-07-23 10:11:24 +00:00
2026-10-03 08:58:59 +00:00
let c3;
let closure_4;
let tmp;
const _modDef12 = tmp(12);
2026-07-20 16:05:17 +00:00
function readFavoriteGIFs(arg0) {
2026-10-03 08:58:59 +00:00
let state;
let c0 = 1;
2026-08-24 06:08:38 +00:00
importDefault = { IMAGE: "IMAGE", VIDEO: "VIDEO" };
2026-10-03 08:58:59 +00:00
const PersistedStore = require("get initialized").PersistedStore;
2026-07-20 16:05:17 +00:00
const items = [
(favorites) => {
2026-10-03 08:58:59 +00:00
let tmp2;
if (null == favorites) {
2026-10-03 08:58:59 +00:00
tmp2 = { favorites: [], timesFavorited: 0 };
const obj2 = { favorites: [], timesFavorited: 0 };
2026-07-20 16:05:17 +00:00
} else {
const _Array = Array;
tmp2 = favorites;
if (Array.isArray(favorites)) {
2026-10-03 08:58:59 +00:00
tmp2 = { favorites, timesFavorited: 0 };
const obj = { favorites, timesFavorited: 0 };
2026-07-20 16:05:17 +00:00
}
}
return tmp2;
},
(favorites) => {
let tmp = favorites;
if (!Array.isArray(favorites.favorites)) {
2026-10-03 08:58:59 +00:00
tmp = { favorites: [], timesFavorited: 0 };
const obj = { favorites: [], timesFavorited: 0 };
2026-07-20 16:05:17 +00:00
}
return tmp;
}
];
2026-07-23 10:11:24 +00:00
state = PersistedStore.migrateAndReadStoreState("GIFFavoritesStore", items).state;
2026-07-20 16:05:17 +00:00
if (null != state) {
if (0 !== state.favorites.length) {
const favorites = state.favorites;
const mapped = favorites.map((format, index) => {
2026-10-03 08:58:59 +00:00
let NONE;
const FavoriteGIF = frecency_user_settings.FavoriteGIF;
const obj2 = FavoriteGIF.create();
2026-07-20 16:05:17 +00:00
format = format.format;
if (constants.IMAGE === format) {
2026-10-09 10:00:15 +00:00
NONE = tmp(1245).GIFType.IMAGE;
2026-07-29 08:29:29 +00:00
} else if (tmp4.VIDEO === format) {
2026-10-09 10:00:15 +00:00
NONE = tmp(1245).GIFType.VIDEO;
2026-07-20 16:05:17 +00:00
} else {
const format2 = format.format;
2026-10-09 10:00:15 +00:00
NONE = tmp(1245).GIFType.NONE;
2026-07-20 16:05:17 +00:00
}
obj2.format = NONE;
2026-07-29 08:29:29 +00:00
({ src: tmp3.src, width: tmp3.width, height: tmp3.height } = format);
obj2.order = state.favorites.length - index + c0;
return { url: format.url, favorite: obj2 };
2026-07-20 16:05:17 +00:00
});
}
return [];
}
}
({ MAX_FAVORITES: c3, MAX_FAVORITE_GIFS_SIZE: closure_4 } = UserSettingsConstants);
const ID_REGEX = Constants.ID_REGEX;
2026-07-29 08:29:29 +00:00
const selectedChannelGuildFrecency = "selectedChannelGuildFrecency";
2026-10-03 08:58:59 +00:00
let obj = {
version: 2,
run(favoriteGifs) {
const arr = readFavoriteGIFs(1);
if (0 === arr.length) {
return false;
} else {
if (null == favoriteGifs.favoriteGifs) {
const FavoriteGIFs = frecency_user_settings.FavoriteGIFs;
favoriteGifs.favoriteGifs = FavoriteGIFs.create();
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
favoriteGifs.favoriteGifs.gifs = {};
for (const item10019 of arr) {
favoriteGifs.favoriteGifs.gifs[item10019.url] = item10019.favorite;
continue;
}
favoriteGifs.favoriteGifs.hideTooltip = arr.length > 2;
return true;
2026-07-20 16:05:17 +00:00
}
},
2026-10-03 08:58:59 +00:00
cleanup() {
}
};
let items = [
obj,
2026-07-29 08:29:29 +00:00
{
version: 3,
run(favoriteStickers) {
2026-10-03 08:58:59 +00:00
let tmp = importDefault;
const PersistedStore = get_initializedDefault.PersistedStore;
2026-07-29 08:29:29 +00:00
const items = [
(arg0) => {
let tmp = arg0;
if (null == arg0) {
2026-10-03 08:58:59 +00:00
tmp = { usageHistory: {}, favorites: [] };
const obj = { usageHistory: {}, favorites: [] };
2026-07-29 08:29:29 +00:00
} else {
const _Object = Object;
}
return tmp;
},
(favorites) => {
if (null != favorites) {
2026-10-03 08:58:59 +00:00
let obj;
2026-07-29 08:29:29 +00:00
const _Object = Object;
if (0 !== Object.keys(favorites).length) {
2026-10-03 08:58:59 +00:00
obj = favorites;
2026-07-29 08:29:29 +00:00
if (null == favorites.favorites) {
favorites.favorites = [];
2026-08-04 21:03:28 +00:00
obj = favorites;
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
}
2026-08-04 21:03:28 +00:00
return obj;
2026-07-20 16:05:17 +00:00
}
2026-08-04 21:03:28 +00:00
obj = { usageHistory: {}, favorites: [] };
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
];
const state = PersistedStore.migrateAndReadStoreState("StickersPersistedStore", items).state;
if (null == state) {
return false;
} else {
let flag = false;
if (state.favorites.length > 0) {
const FavoriteStickers = frecency_user_settings.FavoriteStickers;
2026-07-29 08:29:29 +00:00
favoriteStickers.favoriteStickers = FavoriteStickers.create();
2026-10-03 08:58:59 +00:00
favoriteStickers = favoriteStickers.favoriteStickers;
const tmpResult = _modDef12;
const uniqResult = tmpResult.uniq(state.favorites);
favoriteStickers.stickerIds = uniqResult.slice(0, _false);
2026-07-29 08:29:29 +00:00
flag = true;
}
2026-10-03 08:58:59 +00:00
const tmpResult2 = _modDef12;
if (tmpResult2.size(state.usageHistory) > 0) {
const StickerFrecency = frecency_user_settings.StickerFrecency;
2026-07-29 08:29:29 +00:00
favoriteStickers.stickerFrecency = StickerFrecency.create();
2026-10-03 08:58:59 +00:00
const stickerFrecency = favoriteStickers.stickerFrecency;
const obj3 = user_settings_UserSettingsUtils;
stickerFrecency.stickers = obj3.serializeUsageHistory(state.usageHistory, 100);
2026-07-29 08:29:29 +00:00
flag = true;
}
return flag;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-08-24 06:08:38 +00:00
const Storage = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage.remove("StickersPersistedStore");
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 4,
run(favoriteEmojis) {
2026-10-03 08:58:59 +00:00
const PersistedStore = get_initializedDefault.PersistedStore;
2026-07-29 08:29:29 +00:00
const items = [
() => {
const Storage = Storage4.Storage;
2026-07-29 08:29:29 +00:00
const usageHistory = Storage.get("EmojiUsageHistory") || {};
return { usageHistory };
}
];
const state = PersistedStore.migrateAndReadStoreState("EmojiStore", items).state;
if (null == state) {
return false;
} else {
let flag = false;
2026-10-03 08:58:59 +00:00
const tmp3 = null != state.favorites && state.favorites.length > 0;
2026-07-29 08:29:29 +00:00
if (tmp3) {
const FavoriteEmojis = frecency_user_settings.FavoriteEmojis;
2026-07-29 08:29:29 +00:00
favoriteEmojis.favoriteEmojis = FavoriteEmojis.create();
2026-10-03 08:58:59 +00:00
favoriteEmojis = favoriteEmojis.favoriteEmojis;
const tmpResult = _modDef12;
const uniqResult = tmpResult.uniq(state.favorites);
favoriteEmojis.emojis = uniqResult.slice(0, _false);
2026-07-29 08:29:29 +00:00
flag = true;
}
2026-10-03 08:58:59 +00:00
const tmpResult2 = _modDef12;
if (tmpResult2.size(state.usageHistory) > 0) {
const EmojiFrecency = frecency_user_settings.EmojiFrecency;
2026-07-29 08:29:29 +00:00
favoriteEmojis.emojiFrecency = EmojiFrecency.create();
2026-10-03 08:58:59 +00:00
const emojiFrecency = favoriteEmojis.emojiFrecency;
const obj3 = user_settings_UserSettingsUtils;
emojiFrecency.emojis = obj3.serializeUsageHistory(state.usageHistory, 100);
2026-07-29 08:29:29 +00:00
flag = true;
}
return flag;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-08-24 06:08:38 +00:00
const Storage = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage.remove("EmojiStore");
2026-08-24 06:08:38 +00:00
const Storage2 = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage2.remove("EmojiUsageHistory");
2026-08-24 06:08:38 +00:00
const Storage3 = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage3.remove("EmojiDiversitySurrogate");
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 6,
run(favoriteGifs) {
let length3;
if (null == favoriteGifs.favoriteGifs) {
const FavoriteGIFs = frecency_user_settings.FavoriteGIFs;
2026-07-29 08:29:29 +00:00
favoriteGifs.favoriteGifs = FavoriteGIFs.create();
}
if (null == favoriteGifs.favoriteGifs.gifs) {
favoriteGifs.favoriteGifs.gifs = {};
}
const arr = readFavoriteGIFs(1);
2026-07-29 08:29:29 +00:00
if (0 === arr.length) {
return false;
} else {
2026-10-03 08:58:59 +00:00
let tmp;
const obj = _modDef12(favoriteGifs.favoriteGifs.gifs);
2026-10-03 08:58:59 +00:00
const values = obj.values();
const sortByResult = values.sortBy("order");
const item = sortByResult.forEach((item, index) => {
const sum = arr.length + 1 + index;
item.order = sum;
2026-07-29 08:29:29 +00:00
return sum;
});
const FavoriteGIFs4 = frecency_user_settings.FavoriteGIFs;
2026-07-29 08:29:29 +00:00
let length = FavoriteGIFs4.toBinary(favoriteGifs.favoriteGifs).length;
let num = 0;
const iter = arr[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
let url = nextResult.url;
let arr2 = url;
let favorite = nextResult.favorite;
2026-10-03 08:58:59 +00:00
let tmp7 = favorite;
2026-07-29 08:29:29 +00:00
favorite.order = arr.length - num;
num = num + 1;
2026-07-20 16:05:17 +00:00
if (url in favoriteGifs.favoriteGifs.gifs) {
2026-10-03 08:58:59 +00:00
favoriteGifs.favoriteGifs.gifs[arr2].order = tmp7.order;
2026-07-20 16:05:17 +00:00
} else {
let FavoriteGIF = frecency_user_settings.FavoriteGIF;
2026-10-03 08:58:59 +00:00
let sum = FavoriteGIF.toBinary(tmp7).length + arr2.length + 7;
tmp = sum;
if (length + sum <= React3) {
length = length + tmp;
favoriteGifs.favoriteGifs.gifs[arr2] = tmp7;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
continue;
}
const FavoriteGIFs2 = frecency_user_settings.FavoriteGIFs;
2026-07-29 08:29:29 +00:00
const length2 = FavoriteGIFs2.toBinary(favoriteGifs.favoriteGifs).length;
2026-10-03 08:58:59 +00:00
if (length2 > React3) {
2026-07-29 08:29:29 +00:00
do {
let num3 = 0;
let keys = Object.keys();
if (keys !== undefined) {
2026-10-03 08:58:59 +00:00
let tmp28 = keys[tmp];
while (tmp28 !== undefined) {
delete favoriteGifs.favoriteGifs.gifs[tmp28];
2026-07-29 08:29:29 +00:00
num3 = num3 + 1;
if (10 <= num3) {
break;
}
2026-07-20 16:05:17 +00:00
}
}
let FavoriteGIFs3 = frecency_user_settings.FavoriteGIFs;
2026-07-29 08:29:29 +00:00
length3 = FavoriteGIFs3.toBinary(favoriteGifs.favoriteGifs).length;
2026-10-03 08:58:59 +00:00
} while (length3 > React3);
2026-07-29 08:29:29 +00:00
}
return true;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 7,
run(applicationCommandFrecency) {
2026-10-03 08:58:59 +00:00
const PersistedStore = get_initializedDefault.PersistedStore;
2026-07-29 08:29:29 +00:00
const state = PersistedStore.migrateAndReadStoreState("ApplicationCommandFrecency", []).state;
if (null == state) {
return false;
} else {
let flag = false;
2026-10-03 08:58:59 +00:00
const tmpResult = _modDef12;
2026-07-29 08:29:29 +00:00
if (tmpResult.size(state.usageHistory) > 0) {
const ApplicationCommandFrecency = frecency_user_settings.ApplicationCommandFrecency;
2026-07-29 08:29:29 +00:00
applicationCommandFrecency.applicationCommandFrecency = ApplicationCommandFrecency.create();
2026-10-03 08:58:59 +00:00
applicationCommandFrecency = applicationCommandFrecency.applicationCommandFrecency;
const obj = user_settings_UserSettingsUtils;
applicationCommandFrecency.applicationCommands = obj.serializeUsageHistory(state.usageHistory, 500);
2026-07-29 08:29:29 +00:00
flag = true;
}
return flag;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-08-24 06:08:38 +00:00
const Storage = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage.remove("ApplicationCommandFrecency");
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 8,
run(arg0) {
2026-10-03 08:58:59 +00:00
let closure_0 = arg0;
const PersistedStore = get_initializedDefault.PersistedStore;
const state = PersistedStore.migrateAndReadStoreState("SoundboardFavoriteStore", []).state;
2026-07-29 08:29:29 +00:00
if (null == state) {
return false;
} else {
let flag = false;
2026-10-03 08:58:59 +00:00
const tmpResult = _modDef12;
2026-07-29 08:29:29 +00:00
if (tmpResult.size(state.favoriteSounds) > 0) {
const FavoriteSoundboardSounds = frecency_user_settings.FavoriteSoundboardSounds;
2026-07-29 08:29:29 +00:00
arg0.favoriteSoundboardSounds = FavoriteSoundboardSounds.create();
2026-10-03 08:58:59 +00:00
const tmpResult2 = SnowflakeUtilsDefault;
const keys = tmpResult2.keys(state.favoriteSounds);
let item = keys.forEach((item) => {
2026-10-03 08:58:59 +00:00
set = new Set(state.favoriteSounds[item]);
item = set.forEach((item) => {
const favoriteSoundboardSounds = closure_1_0.favoriteSoundboardSounds;
2026-07-29 08:29:29 +00:00
if (favoriteSoundboardSounds != null) {
const soundIds = favoriteSoundboardSounds.soundIds;
soundIds.push(item);
2026-07-29 08:29:29 +00:00
}
});
2026-07-20 16:05:17 +00:00
});
2026-07-29 08:29:29 +00:00
flag = true;
}
return flag;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-08-24 06:08:38 +00:00
const Storage = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage.remove("SoundboardFavoriteStore");
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 9,
run(guildAndChannelFrecency) {
2026-08-24 06:08:38 +00:00
const Storage = Storage4.Storage;
2026-10-03 08:58:59 +00:00
const value = Storage.get(selectedChannelGuildFrecency);
2026-07-29 08:29:29 +00:00
if (null == value) {
return false;
} else {
for (const key10010 in value) {
2026-10-03 08:58:59 +00:00
let tmp6 = key10010;
2026-07-29 08:29:29 +00:00
if (ID_REGEX.test(key10010)) {
continue;
} else {
2026-10-03 08:58:59 +00:00
delete tmp[tmp6];
2026-07-29 08:29:29 +00:00
continue;
}
2026-07-23 10:11:24 +00:00
continue;
2026-07-20 16:05:17 +00:00
}
const GuildAndChannelFrecency = frecency_user_settings.GuildAndChannelFrecency;
2026-07-29 08:29:29 +00:00
guildAndChannelFrecency.guildAndChannelFrecency = GuildAndChannelFrecency.create();
2026-10-03 08:58:59 +00:00
guildAndChannelFrecency = guildAndChannelFrecency.guildAndChannelFrecency;
const obj = user_settings_UserSettingsUtils;
guildAndChannelFrecency.guildAndChannels = obj.serializeUsageHistory(value, 100);
2026-07-29 08:29:29 +00:00
return true;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-08-24 06:08:38 +00:00
const Storage = Storage4.Storage;
2026-07-29 08:29:29 +00:00
Storage.remove(selectedChannelGuildFrecency);
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 10,
run(emojiFrecency) {
if (null == emojiFrecency.emojiFrecency) {
return false;
} else {
let emojis = emojiFrecency.emojiFrecency.emojis;
if (emojis == null) {
emojis = {};
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let flag = false;
2026-10-03 08:58:59 +00:00
const obj2 = _modDef12;
2026-07-29 08:29:29 +00:00
if (obj2.size(emojis) > 0) {
const EmojiFrecency = frecency_user_settings.EmojiFrecency;
2026-07-29 08:29:29 +00:00
const obj = EmojiFrecency.create();
const EmojiFrecency2 = frecency_user_settings.EmojiFrecency;
2026-07-29 08:29:29 +00:00
EmojiFrecency2.mergePartial(obj, emojiFrecency.emojiFrecency);
2026-10-03 08:58:59 +00:00
const tmp3 = require;
2026-07-29 08:29:29 +00:00
if (null != emojiFrecency.emojiReactionFrecency) {
2026-10-09 10:00:15 +00:00
const EmojiFrecency3 = tmp3(1245).EmojiFrecency;
2026-07-29 08:29:29 +00:00
EmojiFrecency3.mergePartial(obj, emojiFrecency.emojiReactionFrecency);
}
emojiFrecency.emojiReactionFrecency = obj;
flag = true;
}
return flag;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
},
cleanup() {
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
{
version: 11,
run(favoriteGifs) {
if (null != favoriteGifs.favoriteGifs) {
if (null != favoriteGifs.favoriteGifs.gifs) {
let flag3 = false;
let flag2 = false;
const keys = Object.keys();
if (keys !== undefined) {
let flag = flag3;
flag2 = flag3;
while (keys[tmp] !== undefined) {
let tmp9 = favoriteGifs.favoriteGifs.gifs[tmp2];
2026-07-20 16:05:17 +00:00
flag3 = flag;
2026-07-29 08:29:29 +00:00
if (null == tmp9) {
continue;
} else {
let src = tmp9.src;
if (src.startsWith("//")) {
let _HermesInternal = HermesInternal;
tmp9.src = "https:" + tmp9.src;
flag = true;
}
let tmp3 = require;
let isMatch = tmp9.format !== frecency_user_settings.GIFType.IMAGE;
2026-07-29 08:29:29 +00:00
if (isMatch) {
let obj = /\.(webp|avif|gif)(\?|$)/i;
isMatch = obj.test(tmp9.src);
}
if (isMatch) {
2026-10-09 10:00:15 +00:00
tmp9.format = tmp3(1245).GIFType.IMAGE;
2026-07-29 08:29:29 +00:00
flag = true;
}
flag3 = flag;
continue;
}
2026-07-23 10:11:24 +00:00
continue;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
return flag2;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
return false;
},
cleanup() {
2026-07-20 16:05:17 +00:00
}
},
{
version: 12,
run(favoriteSoundboardSounds) {
if (null == favoriteSoundboardSounds.favoriteSoundboardSounds) {
return false;
} else {
favoriteSoundboardSounds = favoriteSoundboardSounds.favoriteSoundboardSounds;
const soundIds = favoriteSoundboardSounds.soundIds;
2026-10-03 08:58:59 +00:00
const orderedSoundIds = favoriteSoundboardSounds.orderedSoundIds;
const obj = _modDef12;
let tmp4 = 0 === obj.size(soundIds);
const tmp2 = importDefault;
if (!tmp4) {
const tmp2Result = tmp2(12);
tmp4 = tmp2Result.size(orderedSoundIds) > 0;
}
2026-10-03 08:58:59 +00:00
let flag = !tmp4;
if (flag) {
const items = [];
2026-10-03 08:58:59 +00:00
const favoriteSoundboardSounds2 = favoriteSoundboardSounds.favoriteSoundboardSounds;
HermesBuiltin.arraySpread(items, soundIds, 0);
favoriteSoundboardSounds2.orderedSoundIds = items;
flag = true;
}
return flag;
}
},
cleanup() {
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
];
const result = size.fileFinishedImporting("modules/user_settings/FrecencySettingsMigrations.tsx");
2026-07-20 16:05:17 +00:00
export default items;