


























@@ -51,23 +51,23 @@ type ChannelSetupPromotionSurface = {
51515252const BUNDLED_CHANNELS_WITHOUT_SETUP_PROMOTION_SURFACE = new Set(["whatsapp"]);
535354-function getChannelSetupPromotionSurface(
54+function asPromotionSurface(setup: unknown): ChannelSetupPromotionSurface | null {
55+return setup && typeof setup === "object" ? (setup as ChannelSetupPromotionSurface) : null;
56+}
57+58+function getLoadedChannelSetupPromotionSurface(
5559channelKey: string,
56-opts?: { loadBundledFallback?: boolean },
5760): ChannelSetupPromotionSurface | null {
58-if (
59-opts?.loadBundledFallback &&
60-BUNDLED_CHANNELS_WITHOUT_SETUP_PROMOTION_SURFACE.has(channelKey)
61-) {
62-return getLoadedChannelPlugin(channelKey)?.setup ?? null;
63-}
64-const setup =
65-getLoadedChannelPlugin(channelKey)?.setup ??
66-(opts?.loadBundledFallback ? getBundledChannelPlugin(channelKey)?.setup : undefined);
67-if (!setup || typeof setup !== "object") {
61+return asPromotionSurface(getLoadedChannelPlugin(channelKey)?.setup);
62+}
63+64+function getBundledChannelSetupPromotionSurface(
65+channelKey: string,
66+): ChannelSetupPromotionSurface | null {
67+if (BUNDLED_CHANNELS_WITHOUT_SETUP_PROMOTION_SURFACE.has(channelKey)) {
6868return null;
6969}
70-return setup as ChannelSetupPromotionSurface;
70+return asPromotionSurface(getBundledChannelPlugin(channelKey)?.setup);
7171}
72727373function isStaticSingleAccountPromotionKey(key: string): boolean {
@@ -81,10 +81,16 @@ export function shouldMoveSingleAccountChannelKey(params: {
8181if (isStaticSingleAccountPromotionKey(params.key)) {
8282return true;
8383}
84-const contractKeys = getChannelSetupPromotionSurface(params.channelKey, {
85-loadBundledFallback: true,
86-})?.singleAccountKeysToMove;
87-if (contractKeys?.includes(params.key)) {
84+const loadedContractKeys = getLoadedChannelSetupPromotionSurface(
85+params.channelKey,
86+)?.singleAccountKeysToMove;
87+if (loadedContractKeys?.includes(params.key)) {
88+return true;
89+}
90+const bundledContractKeys = getBundledChannelSetupPromotionSurface(
91+params.channelKey,
92+)?.singleAccountKeysToMove;
93+if (bundledContractKeys?.includes(params.key)) {
8894return true;
8995}
9096return false;
@@ -104,26 +110,33 @@ export function resolveSingleAccountKeysToMove(params: {
104110return [];
105111}
106112107-let setupSurface: ChannelSetupPromotionSurface | null | undefined;
108-const resolveSetupSurface = () => {
109-setupSurface ??= getChannelSetupPromotionSurface(params.channelKey, {
110-loadBundledFallback: true,
111-});
112-return setupSurface;
113+let loadedSetupSurface: ChannelSetupPromotionSurface | null | undefined;
114+const resolveLoadedSetupSurface = () => {
115+loadedSetupSurface ??= getLoadedChannelSetupPromotionSurface(params.channelKey);
116+return loadedSetupSurface;
117+};
118+let bundledSetupSurface: ChannelSetupPromotionSurface | null | undefined;
119+const resolveBundledSetupSurface = () => {
120+bundledSetupSurface ??= getBundledChannelSetupPromotionSurface(params.channelKey);
121+return bundledSetupSurface;
113122};
114123115124const keysToMove = entries.filter((key) => {
116125if (isStaticSingleAccountPromotionKey(key)) {
117126return true;
118127}
119-return Boolean(resolveSetupSurface()?.singleAccountKeysToMove?.includes(key));
128+return Boolean(
129+resolveLoadedSetupSurface()?.singleAccountKeysToMove?.includes(key) ||
130+resolveBundledSetupSurface()?.singleAccountKeysToMove?.includes(key),
131+);
120132});
121133if (!hasNamedAccounts || keysToMove.length === 0) {
122134return keysToMove;
123135}
124136125137const namedAccountPromotionKeys =
126-setupSurface?.namedAccountPromotionKeys ?? resolveSetupSurface()?.namedAccountPromotionKeys;
138+resolveLoadedSetupSurface()?.namedAccountPromotionKeys ??
139+resolveBundledSetupSurface()?.namedAccountPromotionKeys;
127140if (!namedAccountPromotionKeys) {
128141return keysToMove;
129142}
@@ -142,10 +155,14 @@ export function resolveSingleAccountPromotionTarget(params: {
142155);
143156return matchedAccountId ?? normalizedTargetAccountId;
144157};
145-const surface = getChannelSetupPromotionSurface(params.channelKey, {
146-loadBundledFallback: true,
147-});
148-const resolved = surface?.resolveSingleAccountPromotionTarget?.({
158+const loadedSurface = getLoadedChannelSetupPromotionSurface(params.channelKey);
159+const bundledSurface = loadedSurface?.resolveSingleAccountPromotionTarget
160+ ? undefined
161+ : getBundledChannelSetupPromotionSurface(params.channelKey);
162+const resolvePromotionTarget =
163+loadedSurface?.resolveSingleAccountPromotionTarget ??
164+bundledSurface?.resolveSingleAccountPromotionTarget;
165+const resolved = resolvePromotionTarget?.({
149166channel: params.channel,
150167});
151168const normalizedResolved = normalizeOptionalString(resolved);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。