Skip to content

Commit c36176a

Browse files
Add ability to report a collection
Contributes to IOS-736
1 parent 49703d4 commit c36176a

6 files changed

Lines changed: 39 additions & 14 deletions

File tree

Mastodon/In Progress New Layout and Datamodel/Common Components/Common Actions on Statuses and Accounts/MastodonMenuAction.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ extension CollectionViewModel {
399399
.navigationalAction(.share([collection.url]))
400400
]),
401401
.init(.blockingOptions, items: [
402-
.relationshipAction(.reportUser),
402+
.collectionAction(.reportCollection),
403403
.relationshipAction(.blockUser)
404404
])
405405
].compactMap { $0 }
@@ -417,7 +417,7 @@ extension CollectionViewModel {
417417
return [
418418
navigations,
419419
.init(.blockingOptions, items: [
420-
.relationshipAction(.reportUser),
420+
.collectionAction(.reportCollection),
421421
.relationshipAction(.blockUser)
422422
])
423423
].compactMap { $0 }
@@ -901,6 +901,14 @@ extension MastodonAccount {
901901
@MainActor
902902
func reportViewModel(withStatus status: MastodonStatus?, relationship: MastodonAccount.Relationship) -> ReportViewModel? {
903903
guard let legacyRelationship = relationship.info?._legacyEntity, let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value else { return nil }
904-
return ReportViewModel(context: AppContext.shared, authenticationBox: authBox, account: _legacyEntity, relationship: legacyRelationship, status: status, contentDisplayMode: .neverConceal)
904+
return ReportViewModel(context: AppContext.shared, authenticationBox: authBox, account: _legacyEntity, relationship: legacyRelationship, status: status, collection: nil, contentDisplayMode: .neverConceal)
905+
}
906+
}
907+
908+
extension MastodonAccount {
909+
@MainActor
910+
func reportViewModel(withCollection collection: Mastodon.Entity.Collection, relationship: MastodonAccount.Relationship) -> ReportViewModel? {
911+
guard let legacyRelationship = relationship.info?._legacyEntity, let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value else { return nil }
912+
return ReportViewModel(context: AppContext.shared, authenticationBox: authBox, account: _legacyEntity, relationship: legacyRelationship, status: nil, collection: collection, contentDisplayMode: .neverConceal)
905913
}
906914
}

Mastodon/In Progress New Layout and Datamodel/Common Components/Common Actions on Statuses and Accounts/MastodonPostMenuAction.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum MastodonPostMenuAction: String {
8989
case removeQuote
9090
case blockUser
9191
case unblockUser
92-
case reportUser
92+
case reportPost
9393

9494
// DELETE
9595
case deletePost
@@ -120,7 +120,7 @@ enum MastodonPostMenuAction: String {
120120
case .blockUser, .unblockUser:
121121
true
122122

123-
case .reportUser:
123+
case .reportPost:
124124
false
125125

126126
case .deletePost:
@@ -151,7 +151,7 @@ enum MastodonPostMenuAction: String {
151151
case .blockUser, .unblockUser:
152152
false
153153

154-
case .reportUser:
154+
case .reportPost:
155155
false
156156

157157
case .deletePost, .removeQuote:
@@ -177,7 +177,7 @@ enum MastodonPostMenuAction: String {
177177
PostAction.bookmark.systemIconName(filled: true)
178178
case .translatePost, .showOriginalLanguage:
179179
"character.book.closed"
180-
case .reportUser:
180+
case .reportPost:
181181
"flag"
182182
case .follow:
183183
"person.badge.plus"
@@ -233,7 +233,7 @@ enum MastodonPostMenuAction: String {
233233
return L10n.Common.Controls.Actions.TranslatePost.title(language)
234234
case .showOriginalLanguage:
235235
return L10n.Common.Controls.Status.Translation.showOriginal
236-
case .reportUser:
236+
case .reportPost:
237237
return L10n.Common.Controls.Actions.reportUser(username)
238238
case .follow:
239239
return L10n.Common.Controls.Actions.follow(username)
@@ -268,7 +268,7 @@ enum MastodonPostMenuAction: String {
268268

269269
var isDestructive: Bool {
270270
switch self {
271-
case .blockUser, .reportUser, .deletePost, .removeQuote:
271+
case .blockUser, .reportPost, .deletePost, .removeQuote:
272272
return true
273273
default:
274274
return false
@@ -309,7 +309,7 @@ enum MastodonPostMenuAction: String {
309309
defensiveActions = [
310310
isQuotingMe ? .removeQuote : nil,
311311
info.iAmBlockingThem ? .unblockUser : .blockUser,
312-
.reportUser
312+
.reportPost
313313
].compactMap { $0 }
314314
} else {
315315
relationshipActions = nil
@@ -355,7 +355,7 @@ enum MastodonPostMenuAction: String {
355355
defensiveActions = [
356356
isQuotingMe ? .removeQuote : nil,
357357
info.iAmBlockingThem ? .unblockUser : .blockUser,
358-
.reportUser
358+
.reportPost
359359
].compactMap { $0 }
360360
} else {
361361
relationshipActions = []

Mastodon/In Progress New Layout and Datamodel/Common Components/Views/TimelineRowViews/CollectionRowView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ struct CollectionRowView: View {
182182
func doMenuAction(_ action: MastodonMenuAction.CollectionMenuAction, navigator: MastodonNavigationRouter) async throws {
183183
switch action {
184184
case .reportCollection:
185-
// TODO: implement
186-
assertionFailure("reportCollection is not yet implemented")
185+
guard let relationship = relationshipViewModel.relationship, let account = authorAccount else { return }
186+
guard let reportViewModel = account.reportViewModel(withCollection: collection, relationship: relationship) else { return }
187+
navigator.presentModal(.legacy(scene: .report(viewModel: reportViewModel), transition: .modal(animated: true, completion: nil)))
187188
case .removeMyself:
188189
if let meItem = collection.items.first(where: { $0.account_id == AuthenticationServiceProvider.shared.currentActiveUser.value?.userID }) {
189190
doRemoveMe(meItemID: meItem.id, navigator: navigator)

Mastodon/In Progress New Layout and Datamodel/Timeline/TimelineListViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,7 @@ extension TimelineListViewModel: MastodonPostMenuActionHandler {
31213121
case .removeQuote:
31223122
try await doRemoveQuote(from: actionablePost, askFirst: true, navigator: navigator)
31233123

3124-
case .reportUser:
3124+
case .reportPost:
31253125
guard let relationship = try await APIService.shared.relationship(forAccountIds: [author.id], authenticationBox: authenticatedUser).value.first else { throw PostActionFailure.noRelationshipInfo }
31263126
let accountToReport = try await APIService.shared.accountInfo(domain: authenticatedUser.domain, userID: author.id, authorization: authenticatedUser.userAuthorization)
31273127

@@ -3134,6 +3134,7 @@ extension TimelineListViewModel: MastodonPostMenuActionHandler {
31343134
account: accountToReport,
31353135
relationship: relationship,
31363136
status: statusEntity == nil ? nil : MastodonStatus(entity: statusEntity!, showDespiteContentWarning: true),
3137+
collection: nil,
31373138
contentDisplayMode: .neverConceal
31383139
)
31393140
navigator.presentModal(.legacy(scene: .report(viewModel: reportViewModel), transition: .modal(animated: true, completion: nil)))

Mastodon/Scene/Report/Report/ReportViewModel.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ReportViewModel {
2828
let account: Mastodon.Entity.Account
2929
let relationship: Mastodon.Entity.Relationship
3030
let status: MastodonStatus?
31+
let collection: Mastodon.Entity.Collection?
3132

3233
// output
3334
@Published var isReporting = false
@@ -40,6 +41,7 @@ class ReportViewModel {
4041
account: Mastodon.Entity.Account,
4142
relationship: Mastodon.Entity.Relationship,
4243
status: MastodonStatus?,
44+
collection: Mastodon.Entity.Collection?,
4345
contentDisplayMode: StatusView.ContentDisplayMode
4446
) {
4547
self.contentDisplayMode = contentDisplayMode
@@ -48,6 +50,7 @@ class ReportViewModel {
4850
self.account = account
4951
self.relationship = relationship
5052
self.status = status
53+
self.collection = collection
5154
self.reportReasonViewModel = ReportReasonViewModel(context: context)
5255
self.reportServerRulesViewModel = ReportServerRulesViewModel(context: context)
5356
self.reportStatusViewModel = ReportStatusViewModel(context: context, authenticationBox: authenticationBox, account: account, status: status)
@@ -115,9 +118,17 @@ extension ReportViewModel {
115118
return nil
116119
}
117120
}()
121+
122+
// collections can be reported from the menu but will not be shown in the user interface for now
123+
let collectionIDs: [Mastodon.Entity.Collection.ID]? = {
124+
guard let collection = self.collection else { return nil }
125+
return [collection.id]
126+
}()
127+
118128
let query = Mastodon.API.Reports.FileReportQuery(
119129
accountID: account.id,
120130
statusIDs: statusIDs,
131+
collectionIDs: collectionIDs,
121132
comment: comment,
122133
forward: true,
123134
category: {

MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Report.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public extension Mastodon.API.Reports {
6868
class FileReportQuery: Codable, PostQuery {
6969
public let accountID: Mastodon.Entity.Account.ID
7070
public var statusIDs: [Mastodon.Entity.Status.ID]?
71+
public var collectionIDs: [Mastodon.Entity.Collection.ID]?
7172
public var comment: String?
7273
public let forward: Bool?
7374

@@ -77,6 +78,7 @@ public extension Mastodon.API.Reports {
7778
enum CodingKeys: String, CodingKey {
7879
case accountID = "account_id"
7980
case statusIDs = "status_ids"
81+
case collectionIDs = "collection_ids"
8082
case comment
8183
case forward
8284
case category
@@ -93,13 +95,15 @@ public extension Mastodon.API.Reports {
9395
public init(
9496
accountID: Mastodon.Entity.Account.ID,
9597
statusIDs: [Mastodon.Entity.Status.ID]?,
98+
collectionIDs: [Mastodon.Entity.Collection.ID]?,
9699
comment: String?,
97100
forward: Bool?,
98101
category: Category?,
99102
ruleIDs: [Mastodon.Entity.Instance.Rule.ID]?
100103
) {
101104
self.accountID = accountID
102105
self.statusIDs = statusIDs
106+
self.collectionIDs = collectionIDs
103107
self.comment = comment
104108
self.forward = forward
105109
self.category = category

0 commit comments

Comments
 (0)