feat: add AI retouch task center

This commit is contained in:
2026-08-14 15:06:57 +08:00
parent 0f3b26991e
commit 30bfe0313f
26 changed files with 3679 additions and 50 deletions
@@ -30,6 +30,37 @@ enum MessageJSONValue: Decodable, Hashable, Sendable {
self = .object(try container.decode([String: MessageJSONValue].self))
}
}
/// 将消息字段转换为合法的正整数标识;兼容后端返回数字或数字字符串。
var positiveInt: Int? {
let value: Int?
switch self {
case let .number(number):
guard number.isFinite, number.rounded() == number else { return nil }
value = Int(exactly: number)
case let .string(string):
value = Int(string.trimmingCharacters(in: .whitespacesAndNewlines))
default:
value = nil
}
guard let value, value > 0 else { return nil }
return value
}
/// 返回对象类型的原始键值。
var objectValue: [String: MessageJSONValue]? {
switch self {
case let .object(value):
return value
case let .string(value):
guard let data = value.data(using: .utf8),
let decoded = try? JSONDecoder().decode(MessageJSONValue.self, from: data)
else { return nil }
return decoded.objectValue
default:
return nil
}
}
}
/// 消息未读数量响应,用于同步首页红点和桌面图标角标。
@@ -203,6 +234,20 @@ struct MessageItem: Decodable, Hashable, Sendable {
return MessageDateFormatter.formatDateTime(createdAt) ?? createdAt
}
/// 是否为 AI 修图任务通知;人工修图的 `type = 10` 不属于该类型。
var isAIRetouchTaskNotification: Bool {
type == 14
}
/// AI 修图批次 ID,兼容 `extra_data` 直接字段及 `extra_data.data` 包装结构。
var aiRetouchBatchId: Int? {
guard isAIRetouchTaskNotification, let extraData else { return nil }
if let batchId = extraData["ai_retouch_batch_id"]?.positiveInt {
return batchId
}
return extraData["data"]?.objectValue?["ai_retouch_batch_id"]?.positiveInt
}
/// 返回已读状态的消息副本。
func markedRead() -> MessageItem {
MessageItem(