Fix macOS timeline context menu missing the Remove item. (#2830)

The necessary permissions were only being checked when presenting the long press menu.
This commit is contained in:
Doug
2024-05-10 21:38:11 +01:00
committed by GitHub
parent ae06226cbc
commit 178797a178
4 changed files with 25 additions and 17 deletions
@@ -84,23 +84,16 @@ class RoomScreenInteractionHandler {
self.appSettings = appSettings
self.analyticsService = analyticsService
pollInteractionHandler = PollInteractionHandler(analyticsService: analyticsService, roomProxy: roomProxy)
// Set initial values for redacting from the macOS context menu.
Task { await updatePermissions() }
}
// MARK: Timeline Item Action Menu
func displayTimelineItemActionMenu(for itemID: TimelineItemIdentifier) {
Task {
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
canCurrentUserRedactOthers = value
} else {
canCurrentUserRedactOthers = false
}
if case let .success(value) = await roomProxy.canUserRedactOwn(userID: roomProxy.ownUserID) {
canCurrentUserRedactSelf = value
} else {
canCurrentUserRedactSelf = false
}
await updatePermissions()
guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID),
let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else {
@@ -607,6 +600,20 @@ class RoomScreenInteractionHandler {
// MARK: - Private
private func updatePermissions() async {
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
canCurrentUserRedactOthers = value
} else {
canCurrentUserRedactOthers = false
}
if case let .success(value) = await roomProxy.canUserRedactOwn(userID: roomProxy.ownUserID) {
canCurrentUserRedactSelf = value
} else {
canCurrentUserRedactSelf = false
}
}
private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool {
item.isOutgoing ? canCurrentUserRedactSelf : canCurrentUserRedactOthers && !roomProxy.isDirect
}
@@ -814,7 +814,7 @@ extension RoomScreenViewModel {
}
private struct RoomContextKey: EnvironmentKey {
@MainActor static let defaultValue = RoomScreenViewModel.mock.context
@MainActor static let defaultValue: RoomScreenViewModel.Context? = nil
}
private struct FocussedEventID: EnvironmentKey {
@@ -823,7 +823,7 @@ private struct FocussedEventID: EnvironmentKey {
extension EnvironmentValues {
/// Used to access and inject the room context without observing it
var roomContext: RoomScreenViewModel.Context {
var roomContext: RoomScreenViewModel.Context? {
get { self[RoomContextKey.self] }
set { self[RoomContextKey.self] = newValue }
}