Skip to content
Closed
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
8 changes: 7 additions & 1 deletion V2er/State/DataFlow/Actions/FeedDetailActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,15 @@ struct FeedDetailActions {
func execute(in store: Store) async {
Toast.show("举报中")
let state = store.appState.feedDetailStates[id]!

guard let reportLink = state.model.reportLink, !reportLink.isEmpty else {
Toast.show("无法举报此主题")
dispatch(ReportTopicDone(id: id, reported: false))
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 Down
2 changes: 2 additions & 0 deletions V2er/State/DataFlow/Model/FeedDetailInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ struct FeedDetailInfo: BaseModel {
let sIndex = rawReportUrl.index(of: "/report/topic/")!
let eIndex = rawReportUrl.lastIndex(of: "'")!
self.reportLink = String(rawReportUrl[sIndex..<eIndex])
} else {
self.reportLink = .empty
}

self.hasReported = root.pick("div.content div.box div.inner span.fade")
Expand Down
3 changes: 2 additions & 1 deletion V2er/View/FeedDetail/FeedDetailPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,14 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
Label("忽略", systemImage: "exclamationmark.octagon")
}
let reported = state.model.hasReported ?? false
let canReport = !(state.model.reportLink?.isEmpty ?? true)
Button {
replyIsFocused = false
dispatch(FeedDetailActions.ReportTopic(id: id))
} label: {
Label(reported ? "已举报" : "举报", systemImage: "person.crop.circle.badge.exclamationmark")
}
.disabled(reported)
.disabled(reported || !canReport)

Divider()

Expand Down
12 changes: 11 additions & 1 deletion V2erTests/V2erTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class V2erTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
13.5}
}
Copy link
Preview

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

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

The removed line contains invalid syntax 13.5} which would cause compilation errors. This appears to be a formatting issue in the diff rather than intentional code.

Copilot uses AI. Check for mistakes.


override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
Expand All @@ -23,6 +23,16 @@ class V2erTests: XCTestCase {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testReportLinkHandling() throws {
// Test that FeedDetailInfo correctly handles empty reportLink
var feedDetailInfo = FeedDetailInfo()

// When reportLink is set to empty, it should not be nil
feedDetailInfo.reportLink = .empty
XCTAssertNotNil(feedDetailInfo.reportLink)
XCTAssertTrue(feedDetailInfo.reportLink!.isEmpty)
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
Expand Down
Loading