Redacting is now displayed for moderators in groups (#1324)

* basic implementation

* sdk update

* format

* changelog
This commit is contained in:
Mauro 2023-07-18 15:51:27 +02:00 committed by GitHub
parent 55892eb05b
commit 19ecf906e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 3 deletions

View File

@ -718,6 +718,11 @@ class RoomProxyMock: RoomProxyProtocol {
set(value) { underlyingHasUnreadNotifications = value }
}
var underlyingHasUnreadNotifications: Bool!
var ownUserID: String {
get { return underlyingOwnUserID }
set(value) { underlyingOwnUserID = value }
}
var underlyingOwnUserID: String!
var name: String?
var displayName: String?
var topic: String?
@ -1360,6 +1365,27 @@ class RoomProxyMock: RoomProxyProtocol {
return uploadAvatarMediaReturnValue
}
}
//MARK: - canUserRedact
var canUserRedactUserIDCallsCount = 0
var canUserRedactUserIDCalled: Bool {
return canUserRedactUserIDCallsCount > 0
}
var canUserRedactUserIDReceivedUserID: String?
var canUserRedactUserIDReceivedInvocations: [String] = []
var canUserRedactUserIDReturnValue: Result<Bool, RoomProxyError>!
var canUserRedactUserIDClosure: ((String) async -> Result<Bool, RoomProxyError>)?
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError> {
canUserRedactUserIDCallsCount += 1
canUserRedactUserIDReceivedUserID = userID
canUserRedactUserIDReceivedInvocations.append(userID)
if let canUserRedactUserIDClosure = canUserRedactUserIDClosure {
return await canUserRedactUserIDClosure(userID)
} else {
return canUserRedactUserIDReturnValue
}
}
}
class RoomTimelineProviderMock: RoomTimelineProviderProtocol {
var updatePublisher: AnyPublisher<TimelineProviderUpdate, Never> {

View File

@ -34,6 +34,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
private let analytics: AnalyticsService
private unowned let userIndicatorController: UserIndicatorControllerProtocol
private let notificationCenterProtocol: NotificationCenterProtocol
private var canCurrentUserRedact = false
init(timelineController: RoomTimelineControllerProtocol,
mediaProvider: MediaProviderProtocol,
@ -104,7 +106,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
case .markRoomAsRead:
Task { await markRoomAsRead() }
case .timelineItemMenu(let itemID):
showTimelineItemActionMenu(for: itemID)
Task {
if case let .success(value) = await roomProxy.canUserRedact(userID: roomProxy.ownUserID) {
canCurrentUserRedact = value
} else {
canCurrentUserRedact = false
}
showTimelineItemActionMenu(for: itemID)
}
case .timelineItemMenuAction(let itemID, let action):
processTimelineItemMenuAction(action, itemID: itemID)
case .displayCameraPicker:
@ -408,9 +417,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
actions.append(.copyPermalink)
if item.isOutgoing {
if canRedactItem(item) {
actions.append(.redact)
} else {
}
if !item.isOutgoing {
actions.append(.report)
}
@ -424,6 +435,10 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
return .init(actions: actions, debugActions: debugActions)
}
private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool {
item.isOutgoing || (canCurrentUserRedact && !roomProxy.isDirect)
}
// swiftlint:disable:next cyclomatic_complexity function_body_length
private func processTimelineItemMenuAction(_ action: TimelineItemMenuAction, itemID: TimelineItemIdentifier) {

View File

@ -55,6 +55,10 @@ class RoomProxy: RoomProxyProtocol {
innerTimelineProvider
}
var ownUserID: String {
room.ownUserId()
}
deinit {
roomTimelineObservationToken?.cancel()
backPaginationStateObservationToken?.cancel()
@ -647,6 +651,15 @@ class RoomProxy: RoomProxyProtocol {
}
}
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError> {
do {
return try await .success(room.canUserRedact(userId: userID))
} catch {
MXLog.error("Failed checking if the user can redact with error: \(error)")
return .failure(.failedCheckingPermission)
}
}
// MARK: - Private
/// Force the timeline to load member details so it can populate sender profiles whenever we add a timeline listener

View File

@ -41,6 +41,7 @@ enum RoomProxyError: Error, Equatable {
case failedSettingRoomTopic
case failedRemovingAvatar
case failedUploadingAvatar
case failedCheckingPermission
}
// sourcery: AutoMockable
@ -54,6 +55,7 @@ protocol RoomProxyProtocol {
var canonicalAlias: String? { get }
var alternativeAliases: [String] { get }
var hasUnreadNotifications: Bool { get }
var ownUserID: String { get }
var name: String? { get }
var displayName: String? { get }
@ -159,6 +161,8 @@ protocol RoomProxyProtocol {
func removeAvatar() async -> Result<Void, RoomProxyError>
func uploadAvatar(media: MediaInfo) async -> Result<Void, RoomProxyError>
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError>
}
extension RoomProxyProtocol {

1
changelog.d/1321.bugfix Normal file
View File

@ -0,0 +1 @@
Moderators can now remove other people messages if they have permission in non direct rooms.