From 88f89cc918cc961bb592c059f1226731386dee03 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Sun, 26 Jul 2026 22:33:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20textValue=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BB=93=E6=9E=84=E5=8C=96=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Services/Feishu/FeishuModels.swift | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Sources/Services/Feishu/FeishuModels.swift b/Sources/Services/Feishu/FeishuModels.swift index d4fc4d4..9c140a4 100644 --- a/Sources/Services/Feishu/FeishuModels.swift +++ b/Sources/Services/Feishu/FeishuModels.swift @@ -96,6 +96,26 @@ enum JSONValue: Decodable { return nil } + /// Display text for Feishu fields whose values are represented as + /// structured content, such as text fields (`[{"type": "text", "text": "..."}]`). + var textValue: String? { + switch self { + case let .string(value): + return value + case let .number(value): + return String(value) + case let .bool(value): + return String(value) + case let .array(items): + let text = items.compactMap(\.textValue).joined() + return text.isEmpty ? nil : text + case let .object(fields): + return fields["text"]?.textValue ?? fields["name"]?.textValue + case .null: + return nil + } + } + var firstUserName: String? { guard case let .array(items) = self else { return nil } for item in items { @@ -142,21 +162,16 @@ enum BugMapper { case let .number(number): return number case let .bool(bool): return bool case let .array(array): - return array.compactMap { item -> String? in - if case let .object(fields) = item { - return fields["name"]?.stringValue - } - return item.stringValue - } + return array.compactMap(\.textValue) case let .object(object): - return object["name"]?.stringValue ?? object["text"]?.stringValue + return object["name"]?.textValue ?? object["text"]?.textValue case .null: return nil } } private static func stringValue(in fields: [String: JSONValue], key: String) -> String? { - fields[key]?.stringValue + fields[key]?.textValue } private static func userName(in fields: [String: JSONValue], key: String) -> String? {