refactor: eliminate remaining duplicate blocks across draft streams and tests

This commit is contained in:
Peter Steinberger
2026-02-21 23:56:58 +00:00
parent abf3dfc375
commit ad1c07e7c0
16 changed files with 316 additions and 199 deletions

View File

@@ -148,6 +148,19 @@ function resolveCaseInsensitiveAccount<T>(
]
);
}
function resolveDefaultToCaseInsensitiveAccount(params: {
channel?:
| {
accounts?: Record<string, { defaultTo?: string }>;
defaultTo?: string;
}
| undefined;
accountId?: string | null;
}): string | undefined {
const account = resolveCaseInsensitiveAccount(params.channel?.accounts, params.accountId);
return (account?.defaultTo ?? params.channel?.defaultTo)?.trim() || undefined;
}
// Channel docks: lightweight channel metadata/behavior for shared code paths.
//
// Rules:
@@ -331,15 +344,7 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
const channel = cfg.channels?.irc as
| { accounts?: Record<string, { defaultTo?: string }>; defaultTo?: string }
| undefined;
const normalized = normalizeAccountId(accountId);
const account =
channel?.accounts?.[normalized] ??
channel?.accounts?.[
Object.keys(channel?.accounts ?? {}).find(
(key) => key.toLowerCase() === normalized.toLowerCase(),
) ?? ""
];
return (account?.defaultTo ?? channel?.defaultTo)?.trim() || undefined;
return resolveDefaultToCaseInsensitiveAccount({ channel, accountId });
},
},
groups: {
@@ -412,15 +417,7 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
const channel = cfg.channels?.googlechat as
| { accounts?: Record<string, { defaultTo?: string }>; defaultTo?: string }
| undefined;
const normalized = normalizeAccountId(accountId);
const account =
channel?.accounts?.[normalized] ??
channel?.accounts?.[
Object.keys(channel?.accounts ?? {}).find(
(key) => key.toLowerCase() === normalized.toLowerCase(),
) ?? ""
];
return (account?.defaultTo ?? channel?.defaultTo)?.trim() || undefined;
return resolveDefaultToCaseInsensitiveAccount({ channel, accountId });
},
},
groups: {