Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 67 additions & 10 deletions V2er/State/DataFlow/Actions/FeedDetailActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,25 @@ struct FeedDetailActions {
var id: String

func execute(in store: Store) async {
// Check if user is logged in
guard AccountState.hasSignIn() else {
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能收藏主题"))
Comment on lines +64 to +65
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The login prompt logic is duplicated across all actions. Consider extracting this into a shared helper method to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

return
}

let state = store.appState.feedDetailStates[id]
let hadStared = state?.model.headerInfo?.hadStared ?? false
Toast.show(hadStared ? "取消收藏" : "收藏中")
let once = state?.model.once
guard let once = state?.model.once else {
Toast.show("操作失败,请刷新页面")
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message '操作失败,请刷新页面' is duplicated multiple times. Consider defining this as a constant to ensure consistency and easier maintenance.

Copilot uses AI. Check for mistakes.

return
}
let headers: Params = Headers.topicReferer(id)

let result: APIResult<FeedDetailInfo> = await APIService.shared
.htmlGet(endpoint: hadStared ? .unStarTopic(id: id): .starTopic(id: id),
["once": once!],
["once": once],
requestHeaders: headers)
dispatch(StarTopicDone(id: id, hadStared: hadStared, result: result))
}
Expand All @@ -86,12 +96,22 @@ struct FeedDetailActions {
var id: String

func execute(in store: Store) async {
// Check if user is logged in
guard AccountState.hasSignIn() else {
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能感谢作者"))
return
}

Toast.show("发送中")
let state = store.appState.feedDetailStates[id]
let once = state?.model.once
guard let once = state?.model.once else {
Toast.show("操作失败,请刷新页面")
return
}

let step1Result: APIResult<SimpleModel> = await APIService.shared
.post(endpoint: .thanksAuthor(id: id), ["once": once!])
.post(endpoint: .thanksAuthor(id: id), ["once": once])

var success: Bool = false
var toast = "感谢发送失败"
Expand All @@ -116,11 +136,21 @@ struct FeedDetailActions {
var id: String

func execute(in store: Store) async {
// Check if user is logged in
guard AccountState.hasSignIn() else {
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能忽略主题"))
return
}

Toast.show("忽略中")
let state = store.appState.feedDetailStates[id]
let once = state?.model.once
guard let once = state?.model.once else {
Toast.show("操作失败,请刷新页面")
return
}
let result: APIResult<FeedInfo> = await APIService.shared
.htmlGet(endpoint: .ignoreTopic(id: id), ["once": once!])
.htmlGet(endpoint: .ignoreTopic(id: id), ["once": once])
var ignored = false
if case let .success(result) = result {
ignored = result?.isValid() ?? false
Expand All @@ -141,11 +171,22 @@ struct FeedDetailActions {
var id: String

func execute(in store: Store) async {
// Check if user is logged in
guard AccountState.hasSignIn() else {
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能举报主题"))
return
}

Toast.show("举报中")
let state = store.appState.feedDetailStates[id]!
guard let state = store.appState.feedDetailStates[id],
let reportLink = state.model.reportLink else {
Toast.show("操作失败,请刷新页面")
return
}

let result: APIResult<DailyInfo> = await APIService.shared
.htmlGet(endpoint: .general(url: state.model.reportLink!),
.htmlGet(endpoint: .general(url: reportLink),
requestHeaders: Headers.TINY_REFERER)
var reported = false
if case let .success(result) = result {
Expand All @@ -166,10 +207,26 @@ struct FeedDetailActions {
var id: String

func execute(in store: Store) async {
// Check if user is logged in
guard AccountState.hasSignIn() else {
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能回复主题"))
return
}

Toast.show("回复中")
let state = store.appState.feedDetailStates[id]!
guard let state = store.appState.feedDetailStates[id] else {
Toast.show("操作失败,请刷新页面")
return
}

guard let once = state.model.once else {
Toast.show("操作失败,请刷新页面")
return
}

var params: Params = Params()
params["once"] = state.model.once
params["once"] = once
params["content"] = state.replyContent

let result: APIResult<FeedDetailInfo> = await APIService.shared
Expand Down
Loading