App now prevents redacting own messages if there is no permission (#2368)

This commit is contained in:
Mauro
2024-01-23 12:05:30 +01:00
committed by GitHub
parent 31286c75fc
commit 30a0561251
5 changed files with 42 additions and 2 deletions
@@ -2180,6 +2180,27 @@ class RoomProxyMock: RoomProxyProtocol {
return canUserRedactOtherUserIDReturnValue return canUserRedactOtherUserIDReturnValue
} }
} }
//MARK: - canUserRedactOwn
var canUserRedactOwnUserIDCallsCount = 0
var canUserRedactOwnUserIDCalled: Bool {
return canUserRedactOwnUserIDCallsCount > 0
}
var canUserRedactOwnUserIDReceivedUserID: String?
var canUserRedactOwnUserIDReceivedInvocations: [String] = []
var canUserRedactOwnUserIDReturnValue: Result<Bool, RoomProxyError>!
var canUserRedactOwnUserIDClosure: ((String) async -> Result<Bool, RoomProxyError>)?
func canUserRedactOwn(userID: String) async -> Result<Bool, RoomProxyError> {
canUserRedactOwnUserIDCallsCount += 1
canUserRedactOwnUserIDReceivedUserID = userID
canUserRedactOwnUserIDReceivedInvocations.append(userID)
if let canUserRedactOwnUserIDClosure = canUserRedactOwnUserIDClosure {
return await canUserRedactOwnUserIDClosure(userID)
} else {
return canUserRedactOwnUserIDReturnValue
}
}
//MARK: - canUserTriggerRoomNotification //MARK: - canUserTriggerRoomNotification
var canUserTriggerRoomNotificationUserIDCallsCount = 0 var canUserTriggerRoomNotificationUserIDCallsCount = 0
@@ -52,6 +52,7 @@ class RoomScreenInteractionHandler {
private var voiceMessageRecorderObserver: AnyCancellable? private var voiceMessageRecorderObserver: AnyCancellable?
private var canCurrentUserRedactOthers = false private var canCurrentUserRedactOthers = false
private var canCurrentUserRedactSelf = false
private var resumeVoiceMessagePlaybackAfterScrubbing = false private var resumeVoiceMessagePlaybackAfterScrubbing = false
init(roomProxy: RoomProxyProtocol, init(roomProxy: RoomProxyProtocol,
@@ -86,6 +87,12 @@ class RoomScreenInteractionHandler {
} else { } else {
canCurrentUserRedactOthers = false canCurrentUserRedactOthers = false
} }
if case let .success(value) = await roomProxy.canUserRedactOwn(userID: roomProxy.ownUserID) {
canCurrentUserRedactSelf = value
} else {
canCurrentUserRedactSelf = false
}
guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID), guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID),
let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else { let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else {
@@ -604,7 +611,7 @@ class RoomScreenInteractionHandler {
// MARK: - Private // MARK: - Private
private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool { private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool {
item.isOutgoing || (canCurrentUserRedactOthers && !roomProxy.isDirect) item.isOutgoing ? canCurrentUserRedactSelf : canCurrentUserRedactOthers && !roomProxy.isDirect
} }
private func buildReplyInfo(for item: EventBasedTimelineItemProtocol) -> ReplyInfo { private func buildReplyInfo(for item: EventBasedTimelineItemProtocol) -> ReplyInfo {
+10 -1
View File
@@ -332,7 +332,16 @@ class RoomProxy: RoomProxyProtocol {
do { do {
return try await .success(room.canUserRedactOther(userId: userID)) return try await .success(room.canUserRedactOther(userId: userID))
} catch { } catch {
MXLog.error("Failed checking if the user can redact with error: \(error)") MXLog.error("Failed checking if the user can redact others with error: \(error)")
return .failure(.failedCheckingPermission)
}
}
func canUserRedactOwn(userID: String) async -> Result<Bool, RoomProxyError> {
do {
return try await .success(room.canUserRedactOwn(userId: userID))
} catch {
MXLog.error("Failed checking if the user can redact self with error: \(error)")
return .failure(.failedCheckingPermission) return .failure(.failedCheckingPermission)
} }
} }
@@ -99,6 +99,8 @@ protocol RoomProxyProtocol {
func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError> func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError>
func canUserRedactOwn(userID: String) async -> Result<Bool, RoomProxyError>
func canUserTriggerRoomNotification(userID: String) async -> Result<Bool, RoomProxyError> func canUserTriggerRoomNotification(userID: String) async -> Result<Bool, RoomProxyError>
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError> func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
+1
View File
@@ -0,0 +1 @@
You can't redact a message of your own if the room does not allow it.