fix(chat): 气泡间距 6dp;来源文案按角色区分「来自 / 发送至」
主人发的显示「来自 X」,昔涟发的显示「发送至 X」。
This commit is contained in:
1 parent
01b5f980a5
commit
6323f89b5b
2 files changed
+16
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package top.yeij.cyrene.ui.chat
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -51,6 +52,7 @@ fun MessageBubble(message: HistoryMessageDto) {
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 14.dp),
|
||||
horizontalAlignment = if (isUser) Alignment.End else Alignment.Start,
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
// 来源角标放在消息组顶部,明确标注下面这一组气泡来自哪里
|
||||
if (source != null) {
|
||||
|
||||
@@ -13,24 +13,30 @@ private val platformLabels = mapOf(
|
||||
|
||||
/**
|
||||
* 来源角标(S1.3):每条消息默认显示来源。
|
||||
* 优先用 `deviceId` 区分具体端,再回落到 `platform`;两者都没有则返回 null(不显示)。
|
||||
* - 主人发的 → 「来自 X」(从哪一端发出)
|
||||
* - 昔涟发的 → 「发送至 X」(回到哪一端)
|
||||
* 优先用 `deviceId` 区分具体端,再回落到 `platform`;两者都没有则不显示。
|
||||
*/
|
||||
fun messageSourceLabel(message: HistoryMessageDto): String? {
|
||||
val name = sourceName(message) ?: return null
|
||||
val verb = if (message.role == "assistant") "发送至" else "来自"
|
||||
return "$verb $name"
|
||||
}
|
||||
|
||||
private fun sourceName(message: HistoryMessageDto): String? {
|
||||
val deviceId = message.deviceId
|
||||
if (!deviceId.isNullOrBlank()) {
|
||||
if (deviceId.startsWith("voiceassist")) return "来自安卓"
|
||||
if (deviceId.startsWith("voiceassist")) return "安卓"
|
||||
if (deviceId.startsWith("web:")) {
|
||||
val browser = deviceId.removePrefix("web:").substringBefore(':')
|
||||
return "来自 Web($browser)"
|
||||
return "Web($browser)"
|
||||
}
|
||||
// IM 端 deviceId 形如 <平台名>:<配置id>:<uid>,只取平台名做友好显示
|
||||
platformLabels[deviceId.substringBefore(':')]?.let { return "来自 $it" }
|
||||
return "来自 $deviceId"
|
||||
platformLabels[deviceId.substringBefore(':')]?.let { return it }
|
||||
return deviceId
|
||||
}
|
||||
|
||||
val platform = message.platform
|
||||
if (!platform.isNullOrBlank()) {
|
||||
return "来自 ${platformLabels[platform] ?: platform}"
|
||||
}
|
||||
if (!platform.isNullOrBlank()) return platformLabels[platform] ?: platform
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user