Add missing personas on load

ac8c2799b8f85d502b00eca982847e5e796975b3

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +15 -3Ignore whitespace
public/scripts/personas.js+15 -3
@@ -191,6 +191,18 @@ function getUserAvatarBlock(avatarId) {
191191}
192192
193193/**
194+ * Initialize missing personas in the power user settings.
195+ * @param {string[]} avatarsList List of avatar file names
196+ */
197+function addMissingPersonas(avatarsList) {
198+ for (const persona of avatarsList) {
199+ if (!power_user.personas[persona]) {
200+ initPersona(persona, '[Unnamed Persona]', '');
201+ }
202+ }
203+}
204+
205+/**
194206 * Gets a list of user avatars.
195207 * @param {boolean} doRender Whether to render the list
196208 * @param {string} openPageAt Item to be opened at
@@ -212,6 +224,8 @@ export async function getUserAvatars(doRender = true, openPageAt = '') {
212224 return allEntities;
213225 }
214226
227+ // If any persona is missing from the power user settings, we add it
228+ addMissingPersonas(allEntities);
215229 // Before printing the personas, we check if we should enable/disable search sorting
216230 verifyPersonaSearchSortRule();
217231
@@ -1586,11 +1600,9 @@ async function migrateNonPersonaUser() {
15861600 return;
15871601 }
15881602
1589- power_user.personas[user_avatar] = name1;
1603+ initPersona(user_avatar, name1, '');
1590- void getOrCreatePersonaDescriptor();
15911604 setPersonaDescription();
15921605 await getUserAvatars(true, user_avatar);
1593- saveSettingsDebounced();
15941606}
15951607
15961608export async function initPersonas() {