Files
real-e-party-iOS/YuMi/E-P/NewMoments/Services/EPMomentAPISwiftHelper.swift
edwinQQQ c8173bf034 refactor: 移除 Core Data 相关代码并添加新的消息列表视图控制器
主要变更:
1. 从 AppDelegate 中移除 Core Data 相关的属性和方法,简化应用结构。
2. 新增 EPBaseListViewController 作为消息列表的基础类,提供通用的表视图功能。
3. 添加 EPMessageListVC、EPFriendListVC、EPFollowingListVC 和 EPFansListVC,分别用于展示消息、朋友、关注和粉丝列表。
4. 引入 EPMessageSegmentView 以支持消息主界面的分段控制。

此更新旨在提升代码的可维护性,简化数据管理,并增强用户界面的功能性和交互性。
2025-10-20 11:25:33 +08:00

96 lines
3.3 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.

// Created by AI on 2025-10-11.
import Foundation
@objc class EPMomentAPISwiftHelper: NSObject {
@objc func fetchLatestMomentsWithNextID(
_ nextID: String,
completion: @escaping ([MomentsInfoModel], String) -> Void,
failure: @escaping (Int, String) -> Void
) {
let pageSize = "20"
let types = "0,2"
NSLog("[EPMomentAPISwiftHelper] 🔄 开始请求动态列表nextID=\(nextID.isEmpty ? "(首页)" : nextID)")
Api.momentsLatestList({ (data, code, msg) in
NSLog("[EPMomentAPISwiftHelper] 📥 收到响应code=\(code)")
if code == 200, let dict = data?.data as? NSDictionary {
NSLog("[EPMomentAPISwiftHelper] 📦 开始解析数据字典")
if let listInfo = MomentsListInfoModel.mj_object(withKeyValues: dict) {
let dynamicList = listInfo.dynamicList
let nextDynamicId = listInfo.nextDynamicId
NSLog("[EPMomentAPISwiftHelper] ✅ 解析成功dynamicList.count=\(dynamicList.count), nextDynamicId=\(nextDynamicId)")
completion(dynamicList, nextDynamicId)
} else {
NSLog("[EPMomentAPISwiftHelper] ⚠️ 解析失败,返回空数组")
completion([], "")
}
} else {
NSLog("[EPMomentAPISwiftHelper] ❌ 请求失败code=\(code), msg=\(msg ?? "无错误信息")")
failure(Int(code), msg ?? YMLocalizedString("error.request_failed"))
}
}, dynamicId: nextID, pageSize: pageSize, types: types)
}
@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, YMLocalizedString("error.not_logged_in"))
return
}
// NOTE: XPMonentsPublishViewController
Api.momentsPublish({ (data, code, msg) in
if code == 200 {
completion()
} else {
failure(Int(code), msg ?? YMLocalizedString("error.publish_failed"))
}
}, uid: uid, type: type, worldId: "", content: content, resList: resList)
}
@objc func likeMoment(
dynamicId: String,
isLike: Bool,
likedUid: String,
worldId: Int,
completion: @escaping () -> Void,
failure: @escaping (Int, String) -> Void
) {
guard let uid = AccountInfoStorage.instance().getUid() else {
failure(-1, YMLocalizedString("error.not_logged_in"))
return
}
let status = isLike ? "1" : "0"
let worldIdStr = String(format: "%ld", worldId)
Api.momentsLike({ (data, code, msg) in
if code == 200 {
completion()
} else {
failure(Int(code), msg ?? YMLocalizedString("error.like_failed"))
}
}, dynamicId: dynamicId, uid: uid, status: status, likedUid: likedUid, worldId: worldIdStr)
}
}