🎨 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,
resolveName: (userId: number) => string
): TipSegment[] {
const out: TipSegment[] = []
userIds.forEach((id, index) => {
if (index > 0) {
out.push(tipText(separator))
}
out.push(tipMention(id, resolveName(id)))
})
return out
return userIds.flatMap((id, index) =>
index === 0
? [tipMention(id, resolveName(id))]
: [tipText(separator), tipMention(id, resolveName(id))]
)
}
// ==================== 引用消息 ====================