feat: add AI retouch task center
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -163,6 +163,16 @@ final class MessageDetailViewModel {
|
||||
self.message = message
|
||||
}
|
||||
|
||||
/// AI 修图任务通知在详情页展示任务入口。
|
||||
var showsAIRetouchTaskAction: Bool {
|
||||
message.isAIRetouchTaskNotification
|
||||
}
|
||||
|
||||
/// 当前消息携带的 AI 修图批次 ID;缺失时由页面降级进入任务列表。
|
||||
var aiRetouchBatchId: Int? {
|
||||
message.aiRetouchBatchId
|
||||
}
|
||||
|
||||
/// 删除当前消息。
|
||||
func delete(api: any MessageCenterServing) async {
|
||||
guard message.id > 0 else {
|
||||
|
||||
Reference in New Issue
Block a user