mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
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:
@@ -115,6 +115,7 @@ extension RoomProxyMock {
|
|||||||
}
|
}
|
||||||
canUserInviteUserIDReturnValue = .success(configuration.canUserInvite)
|
canUserInviteUserIDReturnValue = .success(configuration.canUserInvite)
|
||||||
canUserRedactOtherUserIDReturnValue = .success(false)
|
canUserRedactOtherUserIDReturnValue = .success(false)
|
||||||
|
canUserRedactOwnUserIDReturnValue = .success(false)
|
||||||
canUserKickUserIDClosure = { [weak self] userID in
|
canUserKickUserIDClosure = { [weak self] userID in
|
||||||
.success(self?.membersPublisher.value.first { $0.userID == userID }?.role ?? .user != .user)
|
.success(self?.membersPublisher.value.first { $0.userID == userID }?.role ?? .user != .user)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,23 +84,16 @@ class RoomScreenInteractionHandler {
|
|||||||
self.appSettings = appSettings
|
self.appSettings = appSettings
|
||||||
self.analyticsService = analyticsService
|
self.analyticsService = analyticsService
|
||||||
pollInteractionHandler = PollInteractionHandler(analyticsService: analyticsService, roomProxy: roomProxy)
|
pollInteractionHandler = PollInteractionHandler(analyticsService: analyticsService, roomProxy: roomProxy)
|
||||||
|
|
||||||
|
// Set initial values for redacting from the macOS context menu.
|
||||||
|
Task { await updatePermissions() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Timeline Item Action Menu
|
// MARK: Timeline Item Action Menu
|
||||||
|
|
||||||
func displayTimelineItemActionMenu(for itemID: TimelineItemIdentifier) {
|
func displayTimelineItemActionMenu(for itemID: TimelineItemIdentifier) {
|
||||||
Task {
|
Task {
|
||||||
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
|
await updatePermissions()
|
||||||
canCurrentUserRedactOthers = value
|
|
||||||
} 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),
|
guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID),
|
||||||
let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else {
|
let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else {
|
||||||
@@ -607,6 +600,20 @@ class RoomScreenInteractionHandler {
|
|||||||
|
|
||||||
// MARK: - Private
|
// 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 {
|
private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool {
|
||||||
item.isOutgoing ? canCurrentUserRedactSelf : canCurrentUserRedactOthers && !roomProxy.isDirect
|
item.isOutgoing ? canCurrentUserRedactSelf : canCurrentUserRedactOthers && !roomProxy.isDirect
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -814,7 +814,7 @@ extension RoomScreenViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private struct RoomContextKey: EnvironmentKey {
|
private struct RoomContextKey: EnvironmentKey {
|
||||||
@MainActor static let defaultValue = RoomScreenViewModel.mock.context
|
@MainActor static let defaultValue: RoomScreenViewModel.Context? = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct FocussedEventID: EnvironmentKey {
|
private struct FocussedEventID: EnvironmentKey {
|
||||||
@@ -823,7 +823,7 @@ private struct FocussedEventID: EnvironmentKey {
|
|||||||
|
|
||||||
extension EnvironmentValues {
|
extension EnvironmentValues {
|
||||||
/// Used to access and inject the room context without observing it
|
/// Used to access and inject the room context without observing it
|
||||||
var roomContext: RoomScreenViewModel.Context {
|
var roomContext: RoomScreenViewModel.Context? {
|
||||||
get { self[RoomContextKey.self] }
|
get { self[RoomContextKey.self] }
|
||||||
set { self[RoomContextKey.self] = newValue }
|
set { self[RoomContextKey.self] = newValue }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct RoomTimelineItemView: View {
|
struct RoomTimelineItemView: View {
|
||||||
@Environment(\.roomContext) var context: RoomScreenViewModel.Context
|
@Environment(\.roomContext) var context
|
||||||
@ObservedObject var viewState: RoomTimelineItemViewState
|
@ObservedObject var viewState: RoomTimelineItemViewState
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -25,10 +25,10 @@ struct RoomTimelineItemView: View {
|
|||||||
.animation(.elementDefault, value: viewState.type)
|
.animation(.elementDefault, value: viewState.type)
|
||||||
.environment(\.timelineGroupStyle, viewState.groupStyle)
|
.environment(\.timelineGroupStyle, viewState.groupStyle)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
context.send(viewAction: .itemAppeared(itemID: viewState.identifier))
|
context?.send(viewAction: .itemAppeared(itemID: viewState.identifier))
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
context.send(viewAction: .itemDisappeared(itemID: viewState.identifier))
|
context?.send(viewAction: .itemDisappeared(itemID: viewState.identifier))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ struct RoomTimelineItemView: View {
|
|||||||
case .poll(let item):
|
case .poll(let item):
|
||||||
PollRoomTimelineView(timelineItem: item)
|
PollRoomTimelineView(timelineItem: item)
|
||||||
case .voice(let item):
|
case .voice(let item):
|
||||||
VoiceMessageRoomTimelineView(timelineItem: item, playerState: context.viewState.audioPlayerStateProvider?(item.id) ?? AudioPlayerState(id: .timelineItemIdentifier(item.id), duration: 0))
|
VoiceMessageRoomTimelineView(timelineItem: item, playerState: context?.viewState.audioPlayerStateProvider?(item.id) ?? AudioPlayerState(id: .timelineItemIdentifier(item.id), duration: 0))
|
||||||
case .callInvite(let item):
|
case .callInvite(let item):
|
||||||
CallInviteRoomTimelineView(timelineItem: item)
|
CallInviteRoomTimelineView(timelineItem: item)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user