mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-01 16:05:39 +00:00
fix: skip saved accounts without a server when picking an account id
This commit is contained in:
@@ -49,6 +49,14 @@ describe('generateAccountId', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('registry entries without a server', () => {
|
||||
it('are skipped instead of throwing', () => {
|
||||
setKnownAccounts([{ id: 'u@example.org@mail.example.org', username: 'u@example.org' } as never]);
|
||||
expect(generateAccountId('u@example.org', 'https://mail.example.org')).toBe('u@example.org@mail.example.org');
|
||||
expect(generateAccountId('u@example.org', 'https://mail.example.org:8443')).toBe('u@example.org@mail.example.org:8443');
|
||||
});
|
||||
});
|
||||
|
||||
describe('a new default-port account next to a kept host-only id', () => {
|
||||
const legacy = { id: 'u@example.org@mail.example.org', username: 'u@example.org', serverUrl: 'https://mail.example.org:8120' };
|
||||
|
||||
|
||||
@@ -96,11 +96,13 @@ export function generateAccountId(username: string, serverUrl: string): string {
|
||||
if (id === legacy) {
|
||||
const explicit = `${id}:${defaultPortOf(serverUrl)}`;
|
||||
if (knownAccounts.some((a) => a.id === explicit)) return explicit;
|
||||
const taken = knownAccounts.some((a) => a.id === id && `${a.username}@${serverHostLabel(a.serverUrl)}` !== id);
|
||||
const taken = knownAccounts.some((a) => a.id === id && !!a.serverUrl
|
||||
&& `${a.username}@${serverHostLabel(a.serverUrl)}` !== id);
|
||||
return taken ? explicit : id;
|
||||
}
|
||||
const kept = knownAccounts.find((a) => a.id === legacy
|
||||
&& a.username === username
|
||||
&& !!a.serverUrl
|
||||
&& `${a.username}@${serverHostLabel(a.serverUrl)}` === id);
|
||||
return kept ? kept.id : id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user