Compare commits
No commits in common. "9479eb2f22058554a2194c75512bfa6eef35c503" and "c84ee6d630f3a7befcf991a137a401e1b3540a69" have entirely different histories.
9479eb2f22
...
c84ee6d630
@ -37,35 +37,13 @@ struct API {
|
||||
// 服务器地址
|
||||
static let baseUrl = "https://dimensionhub.s5s8.com"
|
||||
|
||||
// 发送设备的token到服务
|
||||
static func appInit<T: Codable>(userId: String, as: T.Type) async -> APIResponse<T> {
|
||||
let device = await UIDevice.current
|
||||
let system = "\(await device.systemName):\(await device.systemVersion)"
|
||||
|
||||
let parameters: [String:Any] = [
|
||||
"user_id": userId,
|
||||
"system": system,
|
||||
"lang": NSLocale.preferredLanguages.first ?? "",
|
||||
"vendorId": await UIDevice.current.identifierForVendor?.uuidString ?? ""
|
||||
]
|
||||
let request = postRequest(url: "/api/appInit", params: parameters)
|
||||
|
||||
return await doRequest(request: request, as: T.self)
|
||||
}
|
||||
|
||||
static func userEvent<T: Codable>(userId: String, event: String, as: T.Type) async -> APIResponse<T> {
|
||||
// Convert parameters to JSON data
|
||||
let parameters: [String:Any] = [
|
||||
"user_id": userId,
|
||||
"event": event
|
||||
]
|
||||
let request = postRequest(url: "/api/event", params: parameters)
|
||||
|
||||
return await doRequest(request: request, as: T.self)
|
||||
}
|
||||
|
||||
// 发送设备的token到服务
|
||||
static func sendDeviceTokenToServer<T: Codable>(userId: String, token: String, as: T.Type) async -> APIResponse<T> {
|
||||
// Create the request
|
||||
var request = URLRequest(url: URL(string: baseUrl + "/api/device_token")!)
|
||||
request.httpMethod = "POST"
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
// Convert parameters to JSON data
|
||||
let parameters: [String:Any] = [
|
||||
"user_id": userId,
|
||||
@ -76,7 +54,8 @@ struct API {
|
||||
"vendorId": await UIDevice.current.identifierForVendor?.uuidString ?? ""
|
||||
]
|
||||
]
|
||||
let request = postRequest(url: "/api/device_token", params: parameters)
|
||||
let jsonData = try! JSONSerialization.data(withJSONObject: parameters, options: [])
|
||||
request.httpBody = jsonData
|
||||
|
||||
return await doRequest(request: request, as: T.self)
|
||||
}
|
||||
@ -155,20 +134,15 @@ struct API {
|
||||
}
|
||||
|
||||
static func resetUserUnreadNum<T: Codable>(userId: String, dramaIds: [Int], as: T.Type) async -> APIResponse<T> {
|
||||
let request = postRequest(url: "/api/reset_unread_num?user_id=\(userId)", params: ["drama_ids": dramaIds])
|
||||
let jsonData = try! JSONSerialization.data(withJSONObject: ["drama_ids": dramaIds], options: [])
|
||||
|
||||
return await doRequest(request: request, as: T.self)
|
||||
}
|
||||
|
||||
private static func postRequest(url: String, params: [String:Any]) -> URLRequest {
|
||||
var request = URLRequest(url: URL(string: baseUrl + url)!)
|
||||
let url = URL(string: baseUrl + "/api/reset_unread_num?user_id=\(userId)")!
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "POST"
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let jsonData = try! JSONSerialization.data(withJSONObject: params, options: [])
|
||||
request.httpBody = jsonData
|
||||
|
||||
return request
|
||||
return await doRequest(request: request, as: T.self)
|
||||
}
|
||||
|
||||
// 执行http请求
|
||||
|
||||
@ -64,7 +64,6 @@ struct DetailView: View {
|
||||
FollowButtonView(dramaStatus: status) { followStatus in
|
||||
Task.detached {
|
||||
await self.clickFollowButton(followStatus: followStatus)
|
||||
_ = await API.userEvent(userId: self.userId, event: "click_follow_button", as: String.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,7 +120,6 @@ struct DetailView: View {
|
||||
}
|
||||
.task {
|
||||
await detailModel.loadData(userId: self.userId, id: self.id, channelName: self.channelName)
|
||||
_ = await API.userEvent(userId: self.userId, event: "view_detail:\(self.id)", as: String.self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,6 @@ struct FollowListView: View {
|
||||
.frame(width: 370)
|
||||
.task {
|
||||
self.num = await self.followModel.loadData(userId: self.userId)
|
||||
_ = await API.userEvent(userId: self.userId, event: "view_follow_list", as: String.self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,9 +57,6 @@ struct IndexMainView: View {
|
||||
.highPriorityGesture(
|
||||
TapGesture().onEnded {
|
||||
appNavigation.append(dest: .followList(num: Int(indexModel.follow_num) ?? 0))
|
||||
Task {
|
||||
_ = await API.userEvent(userId: self.userId, event: "click_follow_list", as: String.self)
|
||||
}
|
||||
}
|
||||
)
|
||||
.zIndex(1)
|
||||
@ -139,8 +136,6 @@ struct IndexMainView: View {
|
||||
|
||||
let loadNum = await self.indexModel.loadPrevUpdateDramasTask(userId: self.userId)
|
||||
self.hasMoreNewest = loadNum > 3
|
||||
|
||||
_ = await API.userEvent(userId: self.userId, event: "load_prev", as: String.self)
|
||||
}
|
||||
}
|
||||
.onChange(of: scrollID) { _, newValue in
|
||||
@ -193,13 +188,8 @@ struct IndexMainView: View {
|
||||
|
||||
let num = await indexModel.loadMoreUpdateDramasTask(userId: self.userId)
|
||||
self.hasMoreOldest = num > 3
|
||||
|
||||
_ = await API.userEvent(userId: self.userId, event: "load_more", as: String.self)
|
||||
}
|
||||
}
|
||||
.task {
|
||||
_ = await API.userEvent(userId: self.userId, event: "view_index", as: String.self)
|
||||
}
|
||||
.onAppear {
|
||||
Task { @MainActor in
|
||||
await self.indexModel.loadData(userId: self.userId)
|
||||
@ -244,7 +234,6 @@ extension IndexMainView {
|
||||
|
||||
struct MixGroupLabelView: View {
|
||||
@EnvironmentObject var appNav: AppNavigation
|
||||
@Environment(\.userId) private var userId
|
||||
|
||||
let fixedDramaGroup: IndexModel.UpdateDramaGroup?
|
||||
let onTap: () -> Void
|
||||
@ -253,9 +242,6 @@ extension IndexMainView {
|
||||
HStack(alignment: .center) {
|
||||
Button(action: {
|
||||
appNav.append(dest: .search)
|
||||
Task {
|
||||
_ = await API.userEvent(userId: self.userId, event: "click_search_button", as: String.self)
|
||||
}
|
||||
}) {
|
||||
Image(systemName: "magnifyingglass")
|
||||
.font(.system(size: 20))
|
||||
|
||||
@ -51,7 +51,6 @@ struct ListView: View {
|
||||
.navigationTitle(detailModel.name)
|
||||
.task {
|
||||
await detailModel.loadData(userId: self.userId, id: self.id, selectedChannelIdx: self.selectedChannelIdx)
|
||||
_ = await API.userEvent(userId: self.userId, event: "view_list:\(self.id)", as: String.self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -65,9 +65,6 @@ struct SearchView: View {
|
||||
ToolbarItem(placement: .principal) {
|
||||
SearchBar(isFirstResponder: $isFocused, searchText: $searchText) {
|
||||
doSearch()
|
||||
Task {
|
||||
_ = await API.userEvent(userId: self.userId, event: "search:\(self.searchText)", as: String.self)
|
||||
}
|
||||
}
|
||||
.frame(width: UIScreen.main.bounds.width * 0.8)
|
||||
.id(toolbarID)
|
||||
|
||||
@ -79,15 +79,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
self.handleAppRefresh(task: task)
|
||||
}
|
||||
|
||||
let userId = KeychainHelper.getPersistentUserId()
|
||||
|
||||
self.appInit(userId: userId)
|
||||
|
||||
Task.detached {
|
||||
await self.registerForPushNotifications()
|
||||
|
||||
// 更新未读消息数
|
||||
let unreadDramaIds = await self.getSystemUnreadDramaIds()
|
||||
let userId = KeychainHelper.getPersistentUserId()
|
||||
let response = await API.resetUserUnreadNum(userId: userId, dramaIds: unreadDramaIds, as: String.self)
|
||||
switch response {
|
||||
case .result(let result):
|
||||
@ -105,22 +102,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private func appInit(userId: String) {
|
||||
Task {
|
||||
let response = await API.appInit(userId: userId, as: String.self)
|
||||
switch response {
|
||||
case .result(let result):
|
||||
NSLog("appInit result is: \(result)")
|
||||
case .error(let errorCode, let message):
|
||||
NSLog("appInit error_code: \(errorCode), message: \(message)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleAppRefresh(task: BGTask) {
|
||||
self.scheduleAppRefresh()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user