mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +00:00
update pindms
This commit is contained in:
parent
5e616fc146
commit
ff95a51dd7
2 changed files with 20 additions and 7 deletions
|
@ -28,19 +28,18 @@ const OLD_CATEGORY_KEY = "BetterPinDMsCategories-";
|
||||||
export let categories: Category[] = [];
|
export let categories: Category[] = [];
|
||||||
|
|
||||||
export async function saveCats(cats: Category[]) {
|
export async function saveCats(cats: Category[]) {
|
||||||
const { id } = UserStore.getCurrentUser();
|
settings.store.data = cats;
|
||||||
await DataStore.set(CATEGORY_BASE_KEY + id, cats);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function init() {
|
export async function init() {
|
||||||
const id = UserStore.getCurrentUser()?.id;
|
const id = UserStore.getCurrentUser()?.id;
|
||||||
await initCategories(id);
|
await initCategories();
|
||||||
await migrateData(id);
|
await migrateData(id);
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initCategories(userId: string) {
|
export async function initCategories() {
|
||||||
categories = await DataStore.get<Category[]>(CATEGORY_BASE_KEY + userId) ?? [];
|
categories = settings.store.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCategory(id: string) {
|
export function getCategory(id: string) {
|
||||||
|
@ -207,13 +206,22 @@ async function migrateOldCategories(userId: string) {
|
||||||
await DataStore.set(CATEGORY_MIGRATED_KEY, true);
|
await DataStore.set(CATEGORY_MIGRATED_KEY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function migrateFromDatastore(userId: string) {
|
||||||
|
const cats = await DataStore.get<Category[]>(CATEGORY_BASE_KEY + userId);
|
||||||
|
if (cats !== undefined) settings.store.data = cats;
|
||||||
|
}
|
||||||
|
|
||||||
export async function migrateData(userId: string) {
|
export async function migrateData(userId: string) {
|
||||||
|
if (settings.store.data.length > 0) return;
|
||||||
const m1 = await DataStore.get(CATEGORY_MIGRATED_KEY), m2 = await DataStore.get(CATEGORY_MIGRATED_PINDMS_KEY);
|
const m1 = await DataStore.get(CATEGORY_MIGRATED_KEY), m2 = await DataStore.get(CATEGORY_MIGRATED_PINDMS_KEY);
|
||||||
if (m1 && m2) return;
|
if (m1 && m2) {
|
||||||
|
return await migrateFromDatastore(userId);
|
||||||
|
}
|
||||||
|
|
||||||
// want to migrate the old categories first and then slove any conflicts with the PinDMs pins
|
// want to migrate the old categories first and then slove any conflicts with the PinDMs pins
|
||||||
if (!m1) await migrateOldCategories(userId);
|
if (!m1) await migrateOldCategories(userId);
|
||||||
if (!m2) await migratePinDMs();
|
if (!m2) await migratePinDMs();
|
||||||
|
if (settings.store.data.length === 0) await migrateFromDatastore(userId);
|
||||||
|
|
||||||
await saveCats(categories);
|
await saveCats(categories);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,12 @@ export const settings = definePluginSettings({
|
||||||
description: "Collapse DM sections",
|
description: "Collapse DM sections",
|
||||||
default: false,
|
default: false,
|
||||||
onChange: () => forceUpdate()
|
onChange: () => forceUpdate()
|
||||||
}
|
},
|
||||||
|
data: {
|
||||||
|
type: OptionType.ARRAY,
|
||||||
|
hidden: true,
|
||||||
|
description: "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
|
|
Loading…
Reference in a new issue