mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Redacting is now displayed for moderators in groups (#1324)
* basic implementation * sdk update * format * changelog
This commit is contained in:
@@ -718,6 +718,11 @@ class RoomProxyMock: RoomProxyProtocol {
|
|||||||
set(value) { underlyingHasUnreadNotifications = value }
|
set(value) { underlyingHasUnreadNotifications = value }
|
||||||
}
|
}
|
||||||
var underlyingHasUnreadNotifications: Bool!
|
var underlyingHasUnreadNotifications: Bool!
|
||||||
|
var ownUserID: String {
|
||||||
|
get { return underlyingOwnUserID }
|
||||||
|
set(value) { underlyingOwnUserID = value }
|
||||||
|
}
|
||||||
|
var underlyingOwnUserID: String!
|
||||||
var name: String?
|
var name: String?
|
||||||
var displayName: String?
|
var displayName: String?
|
||||||
var topic: String?
|
var topic: String?
|
||||||
@@ -1360,6 +1365,27 @@ class RoomProxyMock: RoomProxyProtocol {
|
|||||||
return uploadAvatarMediaReturnValue
|
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 {
|
class RoomTimelineProviderMock: RoomTimelineProviderProtocol {
|
||||||
var updatePublisher: AnyPublisher<TimelineProviderUpdate, Never> {
|
var updatePublisher: AnyPublisher<TimelineProviderUpdate, Never> {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
private let analytics: AnalyticsService
|
private let analytics: AnalyticsService
|
||||||
private unowned let userIndicatorController: UserIndicatorControllerProtocol
|
private unowned let userIndicatorController: UserIndicatorControllerProtocol
|
||||||
private let notificationCenterProtocol: NotificationCenterProtocol
|
private let notificationCenterProtocol: NotificationCenterProtocol
|
||||||
|
|
||||||
|
private var canCurrentUserRedact = false
|
||||||
|
|
||||||
init(timelineController: RoomTimelineControllerProtocol,
|
init(timelineController: RoomTimelineControllerProtocol,
|
||||||
mediaProvider: MediaProviderProtocol,
|
mediaProvider: MediaProviderProtocol,
|
||||||
@@ -104,7 +106,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
case .markRoomAsRead:
|
case .markRoomAsRead:
|
||||||
Task { await markRoomAsRead() }
|
Task { await markRoomAsRead() }
|
||||||
case .timelineItemMenu(let itemID):
|
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):
|
case .timelineItemMenuAction(let itemID, let action):
|
||||||
processTimelineItemMenuAction(action, itemID: itemID)
|
processTimelineItemMenuAction(action, itemID: itemID)
|
||||||
case .displayCameraPicker:
|
case .displayCameraPicker:
|
||||||
@@ -408,9 +417,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
|
|
||||||
actions.append(.copyPermalink)
|
actions.append(.copyPermalink)
|
||||||
|
|
||||||
if item.isOutgoing {
|
if canRedactItem(item) {
|
||||||
actions.append(.redact)
|
actions.append(.redact)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if !item.isOutgoing {
|
||||||
actions.append(.report)
|
actions.append(.report)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,6 +435,10 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
|
|
||||||
return .init(actions: actions, debugActions: debugActions)
|
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
|
// swiftlint:disable:next cyclomatic_complexity function_body_length
|
||||||
private func processTimelineItemMenuAction(_ action: TimelineItemMenuAction, itemID: TimelineItemIdentifier) {
|
private func processTimelineItemMenuAction(_ action: TimelineItemMenuAction, itemID: TimelineItemIdentifier) {
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ class RoomProxy: RoomProxyProtocol {
|
|||||||
innerTimelineProvider
|
innerTimelineProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ownUserID: String {
|
||||||
|
room.ownUserId()
|
||||||
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
roomTimelineObservationToken?.cancel()
|
roomTimelineObservationToken?.cancel()
|
||||||
backPaginationStateObservationToken?.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
|
// MARK: - Private
|
||||||
|
|
||||||
/// Force the timeline to load member details so it can populate sender profiles whenever we add a timeline listener
|
/// Force the timeline to load member details so it can populate sender profiles whenever we add a timeline listener
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ enum RoomProxyError: Error, Equatable {
|
|||||||
case failedSettingRoomTopic
|
case failedSettingRoomTopic
|
||||||
case failedRemovingAvatar
|
case failedRemovingAvatar
|
||||||
case failedUploadingAvatar
|
case failedUploadingAvatar
|
||||||
|
case failedCheckingPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
// sourcery: AutoMockable
|
// sourcery: AutoMockable
|
||||||
@@ -54,6 +55,7 @@ protocol RoomProxyProtocol {
|
|||||||
var canonicalAlias: String? { get }
|
var canonicalAlias: String? { get }
|
||||||
var alternativeAliases: [String] { get }
|
var alternativeAliases: [String] { get }
|
||||||
var hasUnreadNotifications: Bool { get }
|
var hasUnreadNotifications: Bool { get }
|
||||||
|
var ownUserID: String { get }
|
||||||
|
|
||||||
var name: String? { get }
|
var name: String? { get }
|
||||||
var displayName: String? { get }
|
var displayName: String? { get }
|
||||||
@@ -159,6 +161,8 @@ protocol RoomProxyProtocol {
|
|||||||
func removeAvatar() async -> Result<Void, RoomProxyError>
|
func removeAvatar() async -> Result<Void, RoomProxyError>
|
||||||
|
|
||||||
func uploadAvatar(media: MediaInfo) async -> Result<Void, RoomProxyError>
|
func uploadAvatar(media: MediaInfo) async -> Result<Void, RoomProxyError>
|
||||||
|
|
||||||
|
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError>
|
||||||
}
|
}
|
||||||
|
|
||||||
extension RoomProxyProtocol {
|
extension RoomProxyProtocol {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Moderators can now remove other people messages if they have permission in non direct rooms.
|
||||||
Reference in New Issue
Block a user