fix user-scoped options not being loaded

main
Cogent Apps 2023-04-29 18:30:29 +00:00
parent 8f9ec46f9e
commit 4cf0915670
2 changed files with 9 additions and 6 deletions

View File

@ -81,16 +81,18 @@ export class ChatManager extends EventEmitter {
});
this.search = new Search(this);
this.options = new OptionsManager(this.doc, pluginMetadata);
this.options.on('update', (...args) => this.emit('plugin-options-update', ...args));
// connect new doc to persistance, scoped to the current username
this.provider = new IndexeddbPersistence('chats:' + username, this.doc.root);
this.provider.whenSynced.then(() => {
this.doc.getChatIDs().map(id => this.emit(id));
this.emit('update');
this.doc.emit('ready');
this.options.reloadOptions();
});
this.options = new OptionsManager(this.doc, pluginMetadata);
this.options.on('update', (...args) => this.emit('plugin-options-update', ...args));
pluginRunner(
'init',
pluginID => createBasicPluginContext(pluginID, this.options),

View File

@ -22,11 +22,11 @@ export class OptionsManager extends EventEmitter {
this.optionGroups = [...globalOptions, ...this.pluginMetadata];
// Load options from localStorage and YChats
this.loadOptions();
this.reloadOptions();
// Listen for update events on the broadcast channel
broadcastChannel.onmessage = (event: MessageEvent) => {
this.loadOptions();
this.reloadOptions();
if (event.data?.groupID) {
this.emit('update', event.data.groupID);
@ -52,6 +52,7 @@ export class OptionsManager extends EventEmitter {
this.optionsCache.set(key, value);
} else if (option.scope === "user") {
const key = cacheKey(groupID, option.id);
console.log(`loading option ${groupID}.${option.id} from YDoc into cache (${key})`);
const value = this.yDoc.getOption(groupID, option.id) || option.defaultValue;
this.optionsCache.set(key, value);
} else {
@ -62,7 +63,7 @@ export class OptionsManager extends EventEmitter {
}
}
private loadOptions() {
public reloadOptions() {
// Load browser and user-scoped options
this.optionGroups.forEach(group => {
group.options.forEach(option => {