Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,27 @@ class RoomProxyMock: RoomProxyProtocol {
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

var canUserTriggerRoomNotificationUserIDCallsCount = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RoomScreenInteractionHandler {

private var voiceMessageRecorderObserver: AnyCancellable?
private var canCurrentUserRedactOthers = false
private var canCurrentUserRedactSelf = false
private var resumeVoiceMessagePlaybackAfterScrubbing = false

init(roomProxy: RoomProxyProtocol,
Expand Down Expand Up @@ -86,6 +87,12 @@ class RoomScreenInteractionHandler {
} else {
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),
let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else {
Expand Down Expand Up @@ -604,7 +611,7 @@ class RoomScreenInteractionHandler {
// MARK: - Private

private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool {
item.isOutgoing || (canCurrentUserRedactOthers && !roomProxy.isDirect)
item.isOutgoing ? canCurrentUserRedactSelf : canCurrentUserRedactOthers && !roomProxy.isDirect
Velin92 marked this conversation as resolved.
Show resolved Hide resolved
}

private func buildReplyInfo(for item: EventBasedTimelineItemProtocol) -> ReplyInfo {
Expand Down
11 changes: 10 additions & 1 deletion ElementX/Sources/Services/Room/RoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,16 @@ class RoomProxy: RoomProxyProtocol {
do {
return try await .success(room.canUserRedactOther(userId: userID))
} 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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ protocol RoomProxyProtocol {

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 canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-2368.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
You can't redact a message of your own if the room does not allow it.