Saved preferences, a change listener and the reply question.
A MessagingRegistry.
const registry = createMessagingRegistry({
preferences: load(),
onChange: (prefs) => save(prefs),
});
registry.register(createPrivateMessagesProvider(deps));
registry.register(createLegacyMessagesProvider(deps));
registry.enable('private');
registry.setOrder(['legacy', 'private']);
registry.preferences().defaultProvider; // 'private': the first one that is enabled
Create the shell's provider registry.
The registry owns one backend per enabled provider and hands out a single composite backend for the NAP
dmservice. Preferences restored at construction are applied lazily: a provider that appears in the savedenabledlist is started the moment it is registered, if it is available. One that cannot run yet (nobody is signed in, say) reports why throughlist(), stays in the savedenabledlist, and is started the next time the registry is read after it became available. Switching it off forgets it.Providers are kept in the user's order. A provider joins the end of it when it is registered, unless the saved order already places it. The first enabled provider in the order is the default: a message to someone new leaves through it, and when it cannot reach them the next one is tried.
When a one-to-one message would leave through a provider other than the one its recipient last wrote through, the reply rule decides:
theirsfollows the correspondent,minekeeps the order's pick, andask(the default) puts the question toaskReply, whose answer can settle it for that person or for everyone.close()closes every backend without touching the preferences, so a shutdown never erases what the user chose. A closed registry is not reused.