123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- //
- // SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- // SPDX-License-Identifier: GPL-3.0-or-later
- //
- @objcMembers class BannedActorTableViewController: UITableViewController, BannedActorCellDelegate {
- private let bannedActorCellIdentifier = "BannedActorCell"
- private var bannedActors: [BannedActor] = []
- var room: NCRoom
- var backgroundView: PlaceholderView = PlaceholderView(for: .grouped)
- var modifyingViewIndicator = UIActivityIndicatorView()
- init(room: NCRoom) {
- self.room = room
- super.init(style: .insetGrouped)
- }
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- self.navigationController?.navigationBar.isTranslucent = false
- self.navigationItem.title = NSLocalizedString("Banned users and guests", comment: "")
- self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCAppBranding.themeTextColor()]
- self.navigationController?.navigationBar.tintColor = NCAppBranding.themeTextColor()
- self.navigationController?.navigationBar.barTintColor = NCAppBranding.themeColor()
- self.tabBarController?.tabBar.tintColor = NCAppBranding.themeColor()
- let themeColor: UIColor = NCAppBranding.themeColor()
- let appearance = UINavigationBarAppearance()
- appearance.configureWithOpaqueBackground()
- appearance.backgroundColor = themeColor
- appearance.titleTextAttributes = [.foregroundColor: NCAppBranding.themeTextColor()]
- self.navigationItem.standardAppearance = appearance
- self.navigationItem.compactAppearance = appearance
- self.navigationItem.scrollEdgeAppearance = appearance
- self.tableView.register(UINib(nibName: bannedActorCellIdentifier, bundle: nil), forCellReuseIdentifier: bannedActorCellIdentifier)
- self.tableView.backgroundView = backgroundView
- self.backgroundView.placeholderView.isHidden = true
- self.backgroundView.placeholderTextView.text = NSLocalizedString("No banned users or guests", comment: "")
- self.backgroundView.setImage(UIImage(systemName: "person.badge.minus"))
- self.backgroundView.loadingView.startAnimating()
- self.modifyingViewIndicator.color = NCAppBranding.themeTextColor()
- }
- override func viewWillAppear(_ animated: Bool) {
- self.getData()
- }
- func getData() {
- let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
- NCAPIController.sharedInstance().listBans(for: activeAccount.accountId, in: room.token) { [weak self] bannedActors in
- guard let self else { return }
- self.bannedActors = bannedActors ?? []
- self.backgroundView.loadingView.stopAnimating()
- self.backgroundView.loadingView.isHidden = true
- self.backgroundView.placeholderView.isHidden = !self.bannedActors.isEmpty
- self.tableView.reloadData()
- self.hideActivityIndicator()
- }
- }
- func showActivityIndicator() {
- self.modifyingViewIndicator.startAnimating()
- self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: modifyingViewIndicator)
- }
- func hideActivityIndicator() {
- self.modifyingViewIndicator.stopAnimating()
- self.navigationItem.leftBarButtonItem = nil
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return bannedActors.count
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- guard let cell = self.tableView.dequeueReusableCell(withIdentifier: bannedActorCellIdentifier, for: indexPath) as? BannedActorCell
- else { return UITableViewCell() }
- let bannedActor = self.bannedActors[indexPath.row]
- cell.setupFor(bannedActor: bannedActor)
- cell.delegate = self
- return cell
- }
- func bannedActorCellUnbanActor(_ cell: BannedActorCell, bannedActor: BannedActor) {
- self.showActivityIndicator()
- cell.setDisabledState()
- let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
- NCAPIController.sharedInstance().unbanActor(for: activeAccount.accountId, in: self.room.token, with: bannedActor.banId) { [weak self] success in
- if !success {
- NotificationPresenter.shared().present(text: NSLocalizedString("Failed to unban selected entry", comment: ""), dismissAfterDelay: 5.0, includedStyle: .error)
- }
- self?.getData()
- }
- }
- }
|