Only show report action for other people's posts

This commit is contained in:
Shadowfacts 2023-01-17 15:37:03 -05:00
parent 6f006adbc1
commit 5f19adf2d0
1 changed files with 46 additions and 44 deletions

View File

@ -172,7 +172,8 @@ extension MenuActionProvider {
func actionsForStatus(_ status: StatusMO, source: PopoverSource, includeStatusButtonActions: Bool = true) -> [UIMenuElement] { func actionsForStatus(_ status: StatusMO, source: PopoverSource, includeStatusButtonActions: Bool = true) -> [UIMenuElement] {
guard let mastodonController = mastodonController else { return [] } guard let mastodonController = mastodonController else { return [] }
guard let accountID = mastodonController.accountInfo?.id else { guard let accountID = mastodonController.accountInfo?.id,
let account = mastodonController.account else {
// user is logged out // user is logged out
return [ return [
openInSafariAction(url: status.url!), openInSafariAction(url: status.url!),
@ -230,15 +231,7 @@ extension MenuActionProvider {
}), at: 1) }), at: 1)
} }
var actionsSection: [UIAction] = [ var actionsSection: [UIAction] = []
createAction(identifier: "report", title: "Report", systemImageName: "flag", handler: { [weak self] _ in
let report = EditedReport(accountID: status.account.id)
report.statusIDs = [status.id]
let view = ReportView(report: report, mastodonController: mastodonController)
let host = UIHostingController(rootView: view)
self?.navigationDelegate?.present(host, animated: true)
})
]
if includeStatusButtonActions { if includeStatusButtonActions {
actionsSection.insert(createAction(identifier: "reply", title: "Reply", systemImageName: "arrowshape.turn.up.left", handler: { [weak self] (_) in actionsSection.insert(createAction(identifier: "reply", title: "Reply", systemImageName: "arrowshape.turn.up.left", handler: { [weak self] (_) in
@ -247,7 +240,6 @@ extension MenuActionProvider {
}), at: 0) }), at: 0)
} }
if let account = mastodonController.account {
// only allow muting conversations that either current user posted or is participating in (technically, is mentioned, since that's the best we can do) // only allow muting conversations that either current user posted or is participating in (technically, is mentioned, since that's the best we can do)
if status.account.id == account.id || status.mentions.contains(where: { $0.id == account.id }) { if status.account.id == account.id || status.mentions.contains(where: { $0.id == account.id }) {
let muted = status.muted let muted = status.muted
@ -283,7 +275,6 @@ extension MenuActionProvider {
}) })
})) }))
} }
}
if status.poll != nil { if status.poll != nil {
actionsSection.insert(createAction(identifier: "refresh", title: "Refresh Poll", systemImageName: "arrow.clockwise", handler: { [weak self] (_) in actionsSection.insert(createAction(identifier: "refresh", title: "Refresh Poll", systemImageName: "arrow.clockwise", handler: { [weak self] (_) in
@ -304,6 +295,17 @@ extension MenuActionProvider {
}), at: 0) }), at: 0)
} }
// can only report other people's posts
if account.id != status.account.id {
actionsSection.append(createAction(identifier: "report", title: "Report", systemImageName: "flag", handler: { [weak self] _ in
let report = EditedReport(accountID: status.account.id)
report.statusIDs = [status.id]
let view = ReportView(report: report, mastodonController: mastodonController)
let host = UIHostingController(rootView: view)
self?.navigationDelegate?.present(host, animated: true)
}))
}
var shareSection: [UIAction] = [] var shareSection: [UIAction] = []
if let url = status.url { if let url = status.url {
shareSection.append(openInSafariAction(url: url)) shareSection.append(openInSafariAction(url: url))