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? {