Files
bundesmessenger-ios/Riot/Modules/ContextMenu/ActionProviders/RoomActionProvider.swift
T
Frank Rotermund 67df1a3e95 chore: FOSS Merge 1.27.11 (MESSENGER-7276)
Merge commit 'af0b6d4be985d9f26e5111d3fa01389c7321949f' into feature/7276_FOSS_Merge_1_27_11

# Conflicts:
#	Config/AppVersion.xcconfig
#	Gemfile.lock
#	IDETemplateMacros.plist
#	Podfile
#	Podfile.lock
#	README.md
#	Riot/Modules/Authentication/AuthenticationCoordinator.swift
#	Riot/Modules/Room/CellData/RoomBubbleCellData.m
#	Riot/target.yml
#	RiotNSE/NotificationService.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionModels.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionViewModel.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/Coordinator/AuthenticationServerSelectionCoordinator.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/View/AuthenticationServerSelectionScreen.swift
#	RiotSwiftUI/Modules/Room/CompletionSuggestion/Service/CompletionSuggestionService.swift
#	fastlane/Fastfile
2025-05-16 14:06:20 +02:00

177 lines
6.5 KiB
Swift

//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import UIKit
/// `RoomActionProvider` provides the menu for `MXRoom` instances
@available(iOS 13.0, *)
class RoomActionProvider: RoomActionProviderProtocol {
// MARK: - Properties
private let service: RoomContextActionService
// MARK: - Setup
init(service: RoomContextActionService) {
self.service = service
}
// MARK: - RoomActionProviderProtocol
var menu: UIMenu {
if service.isRoomJoined {
// bwi use our set of actions
if BWIBuildSettings.shared.bwiFilteredContextMenu {
if service.roomId == PersonalNotesDefaultService(mxSession: service.session).personalNotesRoomId() {
return UIMenu(children: [
self.hidePersonalNotesAction
])
} else {
return UIMenu(children: [
self.notificationsAction,
self.favouriteAction,
self.leaveAction
])
}
} else {
var children = service.hasUnread ? [self.markAsReadAction] : []
children.append(contentsOf: [
self.directChatAction,
self.notificationsAction,
self.favouriteAction,
self.lowPriorityAction,
self.leaveAction
])
return UIMenu(children: children)
}
} else {
if service.roomMembership == .invite {
return UIMenu(children: [
self.acceptInviteAction,
self.declineInviteAction
])
} else {
return UIMenu(children: [
self.joinAction
])
}
}
}
// MARK: - Private
private var directChatAction: UIAction {
return UIAction(
title: service.isRoomDirect ? VectorL10n.homeContextMenuMakeRoom : VectorL10n.homeContextMenuMakeDm,
image: UIImage(systemName: service.isRoomDirect ? "person.crop.circle.badge.xmark" : "person.circle")) { [weak self] action in
guard let self = self else { return }
self.service.isRoomDirect = !self.service.isRoomDirect
}
}
private var notificationsAction: UIAction {
let notificationsImage: UIImage?
let notificationsTitle: String
if BuildSettings.showNotificationsV2 {
notificationsTitle = VectorL10n.homeContextMenuNotifications
notificationsImage = UIImage(systemName: "bell")
} else {
notificationsTitle = service.isRoomMuted ? VectorL10n.homeContextMenuUnmute : VectorL10n.homeContextMenuMute
notificationsImage = UIImage(systemName: service.isRoomMuted ? "bell.slash": "bell")
}
return UIAction(
title: notificationsTitle,
image: notificationsImage) { [weak self] action in
guard let self = self else { return }
self.service.isRoomMuted = !self.service.isRoomMuted
}
}
private var favouriteAction: UIAction {
return UIAction(
title: self.service.isRoomFavourite ? VectorL10n.homeContextMenuUnfavourite : VectorL10n.homeContextMenuFavourite,
image: UIImage(systemName: self.service.isRoomFavourite ? "star.slash" : "star")) { [weak self] action in
guard let self = self else { return }
self.service.isRoomFavourite = !self.service.isRoomFavourite
}
}
// bwi #4802
private var hidePersonalNotesAction: UIAction {
return UIAction(
title: BWIL10n.homeContextMenuPersonalNotes,
image: UIImage(systemName: "star.slash")) { _ in
PersonalNotesSettings().personalNotesVisible = false
NotificationCenter.default.post(name: AllChatsLayoutSettingsManager.didUpdateSettings, object: self)
}
}
private var lowPriorityAction: UIAction {
return UIAction(
title: self.service.isRoomLowPriority ? VectorL10n.homeContextMenuNormalPriority : VectorL10n.homeContextMenuLowPriority,
image: UIImage(systemName: self.service.isRoomLowPriority ? "arrow.up" : "arrow.down")) { [weak self] action in
guard let self = self else { return }
self.service.isRoomLowPriority = !self.service.isRoomLowPriority
}
}
private var markAsReadAction: UIAction {
return UIAction(
title: VectorL10n.homeContextMenuMarkAsRead,
image: UIImage(systemName: "envelope.open")) { [weak self] action in
guard let self = self else { return }
self.service.markAsRead()
}
}
private var markAsUnreadAction: UIAction {
return UIAction(
title: VectorL10n.homeContextMenuMarkAsUnread,
image: UIImage(systemName: "envelope.badge")) { [weak self] action in
guard let self = self else { return }
self.service.markAsUnread()
}
}
private var leaveAction: UIAction {
let image = UIImage(systemName: "rectangle.righthalf.inset.fill.arrow.right")
let action = UIAction(title: VectorL10n.homeContextMenuLeave, image: image) { [weak self] action in
guard let self = self else { return }
self.service.leaveRoom(promptUser: true)
}
action.attributes = .destructive
return action
}
private var acceptInviteAction: UIAction {
return UIAction(
title: VectorL10n.accept) { [weak self] action in
guard let self = self else { return }
self.service.joinRoom()
}
}
private var declineInviteAction: UIAction {
let action = UIAction(
title: VectorL10n.decline) { [weak self] action in
guard let self = self else { return }
self.service.leaveRoom(promptUser: false)
}
action.attributes = .destructive
return action
}
private var joinAction: UIAction {
return UIAction(
title: BWIL10n.join) { [weak self] action in
guard let self = self else { return }
self.service.joinRoom()
}
}
}