// // EPMomentAPISwiftHelper.swift // YuMi // // Created by AI on 2025-10-11. // import Foundation /// 动态 API 封装(Swift 现代化版本) /// 统一封装列表获取和发布功能,完全替代 OC 版本 @objc class EPMomentAPISwiftHelper: NSObject { /// 拉取最新动态列表 /// - Parameters: /// - nextID: 下一页 ID,首次传空字符串 /// - completion: 成功回调 (动态列表, 下一页ID) /// - failure: 失败回调 (错误码, 错误信息) @objc func fetchLatestMomentsWithNextID( _ nextID: String, completion: @escaping ([MomentsInfoModel], String) -> Void, failure: @escaping (Int, String) -> Void ) { let pageSize = "20" let types = "0,2" // 图片+文字 Api.momentsLatestList({ (data, code, msg) in if code == 200, let dict = data?.data as? NSDictionary { // 从返回数据中提取原始 dictionary 数组 if let listArray = dict["dynamicList"] as? NSArray { // MJExtension 在 Swift 中的正确用法(返回 NSMutableArray) let modelsArray = MomentsInfoModel.mj_objectArray(withKeyValuesArray: listArray) let nextID = dict["nextDynamicId"] as? String ?? "" // 将 NSMutableArray 转换为 NSArray 传递给 OC completion(modelsArray as? [MomentsInfoModel] ?? [], nextID) } else { completion([], "") } } else { failure(Int(code), msg ?? "请求失败") } }, dynamicId: nextID, pageSize: pageSize, types: types) } /// 发布动态 /// - Parameters: /// - type: "0"=纯文本, "2"=图片 /// - content: 文本内容 /// - resList: 图片信息数组 /// - completion: 成功回调 /// - failure: 失败回调 (错误码, 错误信息) @objc func publishMoment( type: String, content: String, resList: [[String: Any]], completion: @escaping () -> Void, failure: @escaping (Int, String) -> Void ) { guard let uid = AccountInfoStorage.instance().getUid() else { failure(-1, "用户未登录") return } // worldId 传空字符串(话题功能不实现) // NOTE: 旧版本 XPMonentsPublishViewController 包含话题选择功能 // 但实际业务中话题功能使用率低,新版本暂不实现 // 如需实现参考: YuMi/Modules/YMMonents/View/XPMonentsPublishTopicView Api.momentsPublish({ (data, code, msg) in if code == 200 { completion() } else { failure(Int(code), msg ?? "发布失败") } }, uid: uid, type: type, worldId: "", content: content, resList: resList) } }