mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Fixes #4222 - Hide timeline item actions that the user's power level does not allow
This commit is contained in:
committed by
Stefan Ceriu
parent
f04f3e74a7
commit
ccb0fc7de0
@@ -140,6 +140,7 @@ class TimelineMediaPreviewViewModel: TimelineMediaPreviewViewModelType {
|
|||||||
state.currentItemActions = switch state.currentItem {
|
state.currentItemActions = switch state.currentItem {
|
||||||
case .media(let mediaItem):
|
case .media(let mediaItem):
|
||||||
TimelineItemMenuActionProvider(timelineItem: mediaItem.timelineItem,
|
TimelineItemMenuActionProvider(timelineItem: mediaItem.timelineItem,
|
||||||
|
canCurrentUserSendMessage: timelineContext.viewState.canCurrentUserSendMessage,
|
||||||
canCurrentUserRedactSelf: timelineContext.viewState.canCurrentUserRedactSelf,
|
canCurrentUserRedactSelf: timelineContext.viewState.canCurrentUserRedactSelf,
|
||||||
canCurrentUserRedactOthers: timelineContext.viewState.canCurrentUserRedactOthers,
|
canCurrentUserRedactOthers: timelineContext.viewState.canCurrentUserRedactOthers,
|
||||||
canCurrentUserPin: timelineContext.viewState.canCurrentUserPin,
|
canCurrentUserPin: timelineContext.viewState.canCurrentUserPin,
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ struct TimelineViewState: BindableState {
|
|||||||
var timelineState: TimelineState // check the doc before changing this
|
var timelineState: TimelineState // check the doc before changing this
|
||||||
|
|
||||||
var ownUserID: String
|
var ownUserID: String
|
||||||
|
var canCurrentUserSendMessage = false
|
||||||
var canCurrentUserRedactOthers = false
|
var canCurrentUserRedactOthers = false
|
||||||
var canCurrentUserRedactSelf = false
|
var canCurrentUserRedactSelf = false
|
||||||
var canCurrentUserPin = false
|
var canCurrentUserPin = false
|
||||||
|
|||||||
@@ -404,6 +404,12 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func updatePermissions() async {
|
private func updatePermissions() async {
|
||||||
|
if case let .success(value) = await roomProxy.canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage) {
|
||||||
|
state.canCurrentUserSendMessage = value
|
||||||
|
} else {
|
||||||
|
state.canCurrentUserSendMessage = false
|
||||||
|
}
|
||||||
|
|
||||||
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
|
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
|
||||||
state.canCurrentUserRedactOthers = value
|
state.canCurrentUserRedactOthers = value
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -342,6 +342,7 @@ struct TimelineItemMenu_Previews: PreviewProvider, TestablePreview {
|
|||||||
deliveryStatus: TimelineItemDeliveryStatus? = nil) -> (EventBasedTimelineItemProtocol, TimelineItemMenuActions)! {
|
deliveryStatus: TimelineItemDeliveryStatus? = nil) -> (EventBasedTimelineItemProtocol, TimelineItemMenuActions)! {
|
||||||
guard var item = makeItem(itemType: itemType) else { return nil }
|
guard var item = makeItem(itemType: itemType) else { return nil }
|
||||||
let provider = TimelineItemMenuActionProvider(timelineItem: item,
|
let provider = TimelineItemMenuActionProvider(timelineItem: item,
|
||||||
|
canCurrentUserSendMessage: true,
|
||||||
canCurrentUserRedactSelf: true,
|
canCurrentUserRedactSelf: true,
|
||||||
canCurrentUserRedactOthers: false,
|
canCurrentUserRedactOthers: false,
|
||||||
canCurrentUserPin: true,
|
canCurrentUserPin: true,
|
||||||
|
|||||||
+3
-2
@@ -10,6 +10,7 @@ import Foundation
|
|||||||
@MainActor
|
@MainActor
|
||||||
struct TimelineItemMenuActionProvider {
|
struct TimelineItemMenuActionProvider {
|
||||||
let timelineItem: RoomTimelineItemProtocol
|
let timelineItem: RoomTimelineItemProtocol
|
||||||
|
let canCurrentUserSendMessage: Bool
|
||||||
let canCurrentUserRedactSelf: Bool
|
let canCurrentUserRedactSelf: Bool
|
||||||
let canCurrentUserRedactOthers: Bool
|
let canCurrentUserRedactOthers: Bool
|
||||||
let canCurrentUserPin: Bool
|
let canCurrentUserPin: Bool
|
||||||
@@ -47,7 +48,7 @@ struct TimelineItemMenuActionProvider {
|
|||||||
actions.append(.endPoll(pollStartID: eventID))
|
actions.append(.endPoll(pollStartID: eventID))
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.canBeRepliedTo {
|
if item.canBeRepliedTo, canCurrentUserSendMessage {
|
||||||
if let messageItem = item as? EventBasedMessageTimelineItemProtocol {
|
if let messageItem = item as? EventBasedMessageTimelineItemProtocol {
|
||||||
actions.append(.reply(isThread: messageItem.properties.isThreaded))
|
actions.append(.reply(isThread: messageItem.properties.isThreaded))
|
||||||
} else {
|
} else {
|
||||||
@@ -63,7 +64,7 @@ struct TimelineItemMenuActionProvider {
|
|||||||
actions.append(.forward(itemID: item.id))
|
actions.append(.forward(itemID: item.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.isEditable {
|
if item.isEditable, canCurrentUserSendMessage {
|
||||||
if item.supportsMediaCaption {
|
if item.supportsMediaCaption {
|
||||||
if item.hasMediaCaption {
|
if item.hasMediaCaption {
|
||||||
actions.append(.editCaption)
|
actions.append(.editCaption)
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
let provider = TimelineItemMenuActionProvider(timelineItem: timelineItem,
|
let provider = TimelineItemMenuActionProvider(timelineItem: timelineItem,
|
||||||
|
canCurrentUserSendMessage: context.viewState.canCurrentUserSendMessage,
|
||||||
canCurrentUserRedactSelf: context.viewState.canCurrentUserRedactSelf,
|
canCurrentUserRedactSelf: context.viewState.canCurrentUserRedactSelf,
|
||||||
canCurrentUserRedactOthers: context.viewState.canCurrentUserRedactOthers,
|
canCurrentUserRedactOthers: context.viewState.canCurrentUserRedactOthers,
|
||||||
canCurrentUserPin: context.viewState.canCurrentUserPin,
|
canCurrentUserPin: context.viewState.canCurrentUserPin,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ struct TimelineView: View {
|
|||||||
.sheet(item: $timelineContext.debugInfo) { TimelineItemDebugView(info: $0) }
|
.sheet(item: $timelineContext.debugInfo) { TimelineItemDebugView(info: $0) }
|
||||||
.sheet(item: $timelineContext.actionMenuInfo) { info in
|
.sheet(item: $timelineContext.actionMenuInfo) { info in
|
||||||
let actions = TimelineItemMenuActionProvider(timelineItem: info.item,
|
let actions = TimelineItemMenuActionProvider(timelineItem: info.item,
|
||||||
|
canCurrentUserSendMessage: timelineContext.viewState.canCurrentUserSendMessage,
|
||||||
canCurrentUserRedactSelf: timelineContext.viewState.canCurrentUserRedactSelf,
|
canCurrentUserRedactSelf: timelineContext.viewState.canCurrentUserRedactSelf,
|
||||||
canCurrentUserRedactOthers: timelineContext.viewState.canCurrentUserRedactOthers,
|
canCurrentUserRedactOthers: timelineContext.viewState.canCurrentUserRedactOthers,
|
||||||
canCurrentUserPin: timelineContext.viewState.canCurrentUserPin,
|
canCurrentUserPin: timelineContext.viewState.canCurrentUserPin,
|
||||||
|
|||||||
Reference in New Issue
Block a user