Add missing personas on load
| @@ -191,6 +191,18 @@ function getUserAvatarBlock(avatarId) { | ||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
| 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 | +/** | |
| 194 | 206 | * Gets a list of user avatars. |
| 195 | 207 | * @param {boolean} doRender Whether to render the list |
| 196 | 208 | * @param {string} openPageAt Item to be opened at |
| @@ -212,6 +224,8 @@ export async function getUserAvatars(doRender = true, openPageAt = '') { | ||
| 212 | 224 | return allEntities; |
| 213 | 225 | } |
| 214 | 226 | |
| 227 | + // If any persona is missing from the power user settings, we add it | |
| 228 | + addMissingPersonas(allEntities); | |
| 215 | 229 | // Before printing the personas, we check if we should enable/disable search sorting |
| 216 | 230 | verifyPersonaSearchSortRule(); |
| 217 | 231 | |
| @@ -1586,11 +1600,9 @@ async function migrateNonPersonaUser() { | ||
| 1586 | 1600 | return; |
| 1587 | 1601 | } |
| 1588 | 1602 | |
| 1589 | - power_user.personas[user_avatar] = name1; | |
| 1603 | + initPersona(user_avatar, name1, ''); | |
| 1590 | - void getOrCreatePersonaDescriptor(); | |
| 1591 | 1604 | setPersonaDescription(); |
| 1592 | 1605 | await getUserAvatars(true, user_avatar); |
| 1593 | - saveSettingsDebounced(); | |
| 1594 | 1606 | } |
| 1595 | 1607 | |
| 1596 | 1608 | export async function initPersonas() { |