Files
汉秋 703078352c 从 iOS 17 Observation 迁移至 iOS 16 兼容的 Combine 架构
将最低部署版本降至 iOS 16,以 ObservableObject 替换 @Observable,新增导航与 UI 兼容层,并补充登录冒烟 UI 测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 10:16:35 +08:00

74 lines
2.1 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MessageCenterAPI.swift
// suixinkan
//
// Created by Codex on 2026/6/25.
//
import Foundation
import Combine
///
@MainActor
protocol MessageCenterServing {
/// 使 last_id
func messageList(lastId: Int, limit: Int, unread: Int) async throws -> MessageListResponse
///
func messageRead(id: Int) async throws
///
func messageDelete(id: Int) async throws
}
@MainActor
/// API
final class MessageCenterAPI {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
/// 使 last_id
func messageList(lastId: Int = 0, limit: Int = 20, unread: Int = 0) async throws -> MessageListResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/msg/list",
queryItems: [
URLQueryItem(name: "last_id", value: String(max(lastId, 0))),
URLQueryItem(name: "limit", value: String(max(limit, 1))),
URLQueryItem(name: "unread", value: String(max(unread, 0)))
]
)
)
}
///
func messageRead(id: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/msg/read",
queryItems: [URLQueryItem(name: "id", value: String(id))],
body: EmptyPayload()
)
)
}
///
func messageDelete(id: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/msg/delete",
body: MessageDeleteRequest(id: id)
)
)
}
}
extension MessageCenterAPI: MessageCenterServing {}