🎨 refactor(im): joinMentionSegments 用 flatMap 替代命令式 push
少一个可变 out + 命令式 forEach,意图更直观 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>im
parent
9eb221e8d2
commit
094ab44094
|
|
@ -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))]
|
||||
)
|
||||
}
|
||||
|
||||
// ==================== 引用消息 ====================
|
||||
|
|
|
|||
Loading…
Reference in New Issue