Add missing personas on load

ac8c2799b8f85d502b00eca982847e5e796975b3

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

1 files changed, +15 -3Showing whitespace changes
public/scripts/personas.js+15 -3
@@ -191,6 +191,18 @@ function getUserAvatarBlock(avatarId) {
191}191}
192192
193/**193/**
194 * Initialize missing personas in the power user settings.
195 * @param {string[]} avatarsList List of avatar file names
196 */
197function addMissingPersonas(avatarsList) {
198 for (const persona of avatarsList) {
199 if (!power_user.personas[persona]) {
200 initPersona(persona, '[Unnamed Persona]', '');
201 }
202 }
203}
204
205/**
194 * Gets a list of user avatars.206 * Gets a list of user avatars.
195 * @param {boolean} doRender Whether to render the list207 * @param {boolean} doRender Whether to render the list
196 * @param {string} openPageAt Item to be opened at208 * @param {string} openPageAt Item to be opened at
@@ -212,6 +224,8 @@ export async function getUserAvatars(doRender = true, openPageAt = '') {
212 return allEntities;224 return allEntities;
213 }225 }
214226
227 // If any persona is missing from the power user settings, we add it
228 addMissingPersonas(allEntities);
215 // Before printing the personas, we check if we should enable/disable search sorting229 // Before printing the personas, we check if we should enable/disable search sorting
216 verifyPersonaSearchSortRule();230 verifyPersonaSearchSortRule();
217231
@@ -1586,11 +1600,9 @@ async function migrateNonPersonaUser() {
1586 return;1600 return;
1587 }1601 }
15881602
1589 power_user.personas[user_avatar] = name1;1603 initPersona(user_avatar, name1, '');
1590 void getOrCreatePersonaDescriptor();
1591 setPersonaDescription();1604 setPersonaDescription();
1592 await getUserAvatars(true, user_avatar);1605 await getUserAvatars(true, user_avatar);
1593 saveSettingsDebounced();
1594}1606}
15951607
1596export async function initPersonas() {1608export async function initPersonas() {