Files
real-e-party-iOS/YuMi/E-P/NewMoments/Services/EPMomentAPISwiftHelper.swift
edwinQQQ 3a12a18687 feat: 添加点赞功能支持及 Swift API Helper 集成
主要变更:
1. 在 EPMomentAPISwiftHelper 中新增点赞/取消点赞功能,支持动态 ID 和用户 UID。
2. 更新 EPMomentCell 以使用新的 Swift API Helper 进行点赞操作,简化点赞逻辑。
3. 优化点赞状态和数量的更新逻辑,确保用户界面及时反映点赞结果。

此更新旨在提升用户互动体验,简化点赞操作流程。
2025-10-14 19:06:44 +08:00

112 lines
4.0 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.

//
// 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)
}
/// /
/// - Parameters:
/// - dynamicId: ID
/// - isLike: true=false=
/// - likedUid: UID
/// - worldId: ID
/// - completion:
/// - failure: (, )
@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, "用户未登录")
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 ?? "点赞操作失败")
}
}, dynamicId: dynamicId, uid: uid, status: status, likedUid: likedUid, worldId: worldIdStr)
}
}