Skip to content

Commit 0f7661b

Browse files
authored
Merge pull request #42 from v2er-app/bugfix/splash-screen-crash-fix
Fix crash when clicking Ignore/Report without login
2 parents 504c02c + 909fa4b commit 0f7661b

File tree

1 file changed

+67
-10
lines changed

1 file changed

+67
-10
lines changed

V2er/State/DataFlow/Actions/FeedDetailActions.swift

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,25 @@ struct FeedDetailActions {
5959
var id: String
6060

6161
func execute(in store: Store) async {
62+
// Check if user is logged in
63+
guard AccountState.hasSignIn() else {
64+
Toast.show("请先登录")
65+
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能收藏主题"))
66+
return
67+
}
68+
6269
let state = store.appState.feedDetailStates[id]
6370
let hadStared = state?.model.headerInfo?.hadStared ?? false
6471
Toast.show(hadStared ? "取消收藏" : "收藏中")
65-
let once = state?.model.once
72+
guard let once = state?.model.once else {
73+
Toast.show("操作失败,请刷新页面")
74+
return
75+
}
6676
let headers: Params = Headers.topicReferer(id)
6777

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

8898
func execute(in store: Store) async {
99+
// Check if user is logged in
100+
guard AccountState.hasSignIn() else {
101+
Toast.show("请先登录")
102+
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能感谢作者"))
103+
return
104+
}
105+
89106
Toast.show("发送中")
90107
let state = store.appState.feedDetailStates[id]
91-
let once = state?.model.once
108+
guard let once = state?.model.once else {
109+
Toast.show("操作失败,请刷新页面")
110+
return
111+
}
92112

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

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

118138
func execute(in store: Store) async {
139+
// Check if user is logged in
140+
guard AccountState.hasSignIn() else {
141+
Toast.show("请先登录")
142+
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能忽略主题"))
143+
return
144+
}
145+
119146
Toast.show("忽略中")
120147
let state = store.appState.feedDetailStates[id]
121-
let once = state?.model.once
148+
guard let once = state?.model.once else {
149+
Toast.show("操作失败,请刷新页面")
150+
return
151+
}
122152
let result: APIResult<FeedInfo> = await APIService.shared
123-
.htmlGet(endpoint: .ignoreTopic(id: id), ["once": once!])
153+
.htmlGet(endpoint: .ignoreTopic(id: id), ["once": once])
124154
var ignored = false
125155
if case let .success(result) = result {
126156
ignored = result?.isValid() ?? false
@@ -141,11 +171,22 @@ struct FeedDetailActions {
141171
var id: String
142172

143173
func execute(in store: Store) async {
174+
// Check if user is logged in
175+
guard AccountState.hasSignIn() else {
176+
Toast.show("请先登录")
177+
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能举报主题"))
178+
return
179+
}
180+
144181
Toast.show("举报中")
145-
let state = store.appState.feedDetailStates[id]!
182+
guard let state = store.appState.feedDetailStates[id],
183+
let reportLink = state.model.reportLink else {
184+
Toast.show("操作失败,请刷新页面")
185+
return
186+
}
146187

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

168209
func execute(in store: Store) async {
210+
// Check if user is logged in
211+
guard AccountState.hasSignIn() else {
212+
Toast.show("请先登录")
213+
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能回复主题"))
214+
return
215+
}
216+
169217
Toast.show("回复中")
170-
let state = store.appState.feedDetailStates[id]!
218+
guard let state = store.appState.feedDetailStates[id] else {
219+
Toast.show("操作失败,请刷新页面")
220+
return
221+
}
222+
223+
guard let once = state.model.once else {
224+
Toast.show("操作失败,请刷新页面")
225+
return
226+
}
227+
171228
var params: Params = Params()
172-
params["once"] = state.model.once
229+
params["once"] = once
173230
params["content"] = state.replyContent
174231

175232
let result: APIResult<FeedDetailInfo> = await APIService.shared

0 commit comments

Comments
 (0)