🎨 refactor(im): joinMentionSegments 用 flatMap 替代命令式 push

少一个可变 out + 命令式 forEach,意图更直观

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
im
YunaiV 2026-05-07 23:59:00 +08:00
parent 9eb221e8d2
commit 094ab44094
1 changed files with 5 additions and 8 deletions

View File

@ -47,14 +47,11 @@ export function joinMentionSegments(
separator: string, separator: string,
resolveName: (userId: number) => string resolveName: (userId: number) => string
): TipSegment[] { ): TipSegment[] {
const out: TipSegment[] = [] return userIds.flatMap((id, index) =>
userIds.forEach((id, index) => { index === 0
if (index > 0) { ? [tipMention(id, resolveName(id))]
out.push(tipText(separator)) : [tipText(separator), tipMention(id, resolveName(id))]
} )
out.push(tipMention(id, resolveName(id)))
})
return out
} }
// ==================== 引用消息 ==================== // ==================== 引用消息 ====================