Files
suixinkan_ios_new/suixinkan/Features/MessageCenter/API/MessageCenterAPI.swift
汉秋 26f4d0e671 Migrate from iOS 17 Observation to iOS 16-compatible Combine architecture.
Lower deployment target to iOS 16, replace @Observable with ObservableObject, add navigation and UI compatibility shims, and include login smoke UI tests.

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

74 lines
2.1 KiB
Swift
Raw 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 {}