Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions V2er/State/DataFlow/Actions/FeedDetailActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,10 @@ struct FeedDetailActions {
let success: Bool
}

struct ReplyToUser: Action {
var target: Reducer = R
var id: String
var userName: String
}

Comment on lines +386 to +391
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

This action should validate that the user is logged in before allowing the reply flow, similar to other actions in this file. Consider converting this to an AwaitAction with an execute method that checks AccountState.hasSignIn() and shows a login prompt if needed, following the pattern established in ThankReply (line 338-377), ReplyTopic (line 205-236), and other similar actions.

Suggested change
struct ReplyToUser: Action {
var target: Reducer = R
var id: String
var userName: String
}
struct ReplyToUser: AwaitAction {
var target: Reducer = R
var id: String
var userName: String
func execute(in store: Store) async {
// Ensure the user is logged in before starting the reply flow
guard AccountState.hasSignIn() else {
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能回复"))
return
}
// User is logged in; proceed with the original reply-to-user behavior
dispatch(ReplyToUserReady(id: id, userName: userName))
}
}
struct ReplyToUserReady: Action {
var target: Reducer = R
var id: String
var userName: String
}

Copilot uses AI. Check for mistakes.
}
1 change: 1 addition & 0 deletions V2er/State/DataFlow/State/FeedDetailState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct FeedDetailState: FluxState {
var ignored: Bool = false
var replyContent: String = .empty
var replySortType: ReplySortType = .byTime
var shouldFocusReply: Bool = false
}

typealias FeedDetailStates=[String : FeedDetailState]
6 changes: 6 additions & 0 deletions V2er/View/FeedDetail/FeedDetailPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
dismiss()
}
}
.onChange(of: state.shouldFocusReply) { shouldFocus in
if shouldFocus {
replyIsFocused = true
store.appState.feedDetailStates[instanceId]?.shouldFocusReply = false
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

Directly mutating the state outside of the reducer breaks the Redux-like unidirectional data flow pattern. While this pattern appears elsewhere in the codebase (e.g., line 316, 343), it's an anti-pattern. The proper approach is to dispatch an action to reset the flag. Consider creating a FeedDetailActions.ResetReplyFocus action to handle this, or alternatively, use a one-time effect that doesn't require resetting the state flag.

Suggested change
store.appState.feedDetailStates[instanceId]?.shouldFocusReply = false

Copilot uses AI. Check for mistakes.
}
}
.onAppear {
dispatch(FeedDetailActions.FetchData.Start(id: instanceId, feedId: initData?.id, autoLoad: !state.hasLoadedOnce))
}
Expand Down
3 changes: 3 additions & 0 deletions V2er/View/FeedDetail/FeedDetailReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func feedDetailStateReducer(_ states: FeedDetailStates, _ action: Action) -> (Fe
} else {
Toast.show("感谢发送失败")
}
case let action as FeedDetailActions.ReplyToUser:
state.replyContent = "@\(action.userName) "
state.shouldFocusReply = true
Comment on lines +121 to +122
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The action should prevent users from replying to themselves, similar to the validation in ThankReply action at line 353-356. Add a check using AccountState.isSelf(userName: action.userName) to prevent this scenario.

Suggested change
state.replyContent = "@\(action.userName) "
state.shouldFocusReply = true
if AccountState.isSelf(userName: action.userName) {
Toast.show("不能回复自己")
} else {
state.replyContent = "@\(action.userName) "
state.shouldFocusReply = true
}

Copilot uses AI. Check for mistakes.
default:
break;
}
Expand Down
8 changes: 8 additions & 0 deletions V2er/View/FeedDetail/ReplyItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ struct ReplyItemView: View {
}
}
.padding(.horizontal, 12)
.contentShape(Rectangle())
.contextMenu {
Button {
dispatch(FeedDetailActions.ReplyToUser(id: topicId, userName: info.userName))
} label: {
Label("回复", systemImage: "arrowshape.turn.up.left")
}
}
.sheet(isPresented: $showingSafari) {
if let url = safariURL {
SafariView(url: url)
Expand Down
Loading