This commit is contained in:
anlicheng 2025-04-15 16:18:08 +08:00
parent 6b3273ad2f
commit d0209d298b
5 changed files with 26 additions and 3 deletions

View File

@ -61,6 +61,13 @@ struct API {
return await doRequest(request: request, as: T.self)
}
//
static func getFlowNum<T: Codable>(userId: String, as: T.Type) async -> APIResponse<T> {
let request = URLRequest(url: URL(string: baseUrl + "/api/follow_num?user_id=\(userId)")!)
return await doRequest(request: request, as: T.self)
}
//
static func loadMoreUpdateDramas<T: Codable>(userId: String, mode: LoadMode, id: Int, as: T.Type) async -> APIResponse<T> {
let request = URLRequest(url: URL(string: baseUrl + "/api/load_more_dramas?user_id=\(userId)&mode=\(mode.rawValue)&id=\(id)")!)

View File

@ -28,7 +28,7 @@ struct FlexImage: View {
let cacheManager = CacheManager.shared
if let data = cacheManager.readFileContents(urlString: urlString) {
print("url: \(urlString), hit cache")
//print("url: \(urlString), hit cache")
self.mode = .local(data)
} else {
self.mode = .remote(urlString)

View File

@ -52,6 +52,9 @@ struct IndexMainView: View {
}
)
.zIndex(1)
.task {
await indexModel.reloadFollowNum(userId: userId)
}
}
.padding([.leading, .trailing], 15)
.frame(height: 50)

View File

@ -145,6 +145,19 @@ final class IndexModel {
self.isLoaded = true
}
func reloadFollowNum(userId: String) async {
let response = await API.getFlowNum(userId: userId, as: Int.self)
switch response {
case .error(let code, let message):
print("reloadFollowNum get error: \(code), message: \(message)")
case .result(let follow_num):
await MainActor.run {
self.follow_num = follow_num >= 100 ? "99+" : "\(follow_num)"
}
}
self.isLoaded = true
}
func setFixedDrameGroup(groupId: String) {
if let newFixedDramaGroup = self.updateDramaGroups.first(where: {$0.group_id == groupId}),
newFixedDramaGroup.group_id != self.fixedDramaGroup?.group_id {

View File

@ -146,9 +146,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//let userInfo = notification.request.content.userInfo
let userInfo = notification.request.content.userInfo
//
//handleRemoteNotification(userInfo: userInfo)
handleRemoteNotification(userInfo: userInfo)
//
completionHandler([.banner, .sound])