FederationInvitationCell.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. protocol FederationInvitationCellDelegate: AnyObject {
  6. func federationInvitationCellAccept(_ cell: FederationInvitationCell, invitation: FederationInvitation)
  7. func federationInvitationCellReject(_ cell: FederationInvitationCell, invitation: FederationInvitation)
  8. }
  9. class FederationInvitationCell: UITableViewCell {
  10. public weak var delegate: FederationInvitationCellDelegate?
  11. @IBOutlet weak var conversationNameLabel: UILabel!
  12. @IBOutlet weak var detailsLabel: UILabel!
  13. @IBOutlet weak var rejectButton: NCButton!
  14. @IBOutlet weak var acceptButton: NCButton!
  15. private var federationInvitation: FederationInvitation?
  16. override func awakeFromNib() {
  17. super.awakeFromNib()
  18. self.selectionStyle = .none
  19. }
  20. override func prepareForReuse() {
  21. super.prepareForReuse()
  22. self.conversationNameLabel.text = ""
  23. self.detailsLabel.text = ""
  24. self.federationInvitation = nil
  25. self.setEnabledState()
  26. }
  27. public func setupForInvitation(invitation: FederationInvitation) {
  28. self.federationInvitation = invitation
  29. self.conversationNameLabel.text = invitation.remoteConversationName ?? ""
  30. self.detailsLabel.text = String(format: NSLocalizedString("from %@ at %@", comment: "from Alice at nextcloud.local"),
  31. invitation.inviterDisplayName ?? NSLocalizedString("Unknown", comment: ""),
  32. invitation.remoteServer ?? NSLocalizedString("Unknown", comment: ""))
  33. self.acceptButton.setTitle(NSLocalizedString("Accept", comment: ""), for: .normal)
  34. self.rejectButton.setTitle(NSLocalizedString("Reject", comment: ""), for: .normal)
  35. self.acceptButton.setButtonStyle(style: .primary)
  36. self.rejectButton.setButtonStyle(style: .secondary)
  37. self.acceptButton.setButtonAction(target: self, selector: #selector(acceptButtonPressed))
  38. self.rejectButton.setButtonAction(target: self, selector: #selector(rejectButtonPressed))
  39. }
  40. public func setDisabledState() {
  41. self.contentView.isUserInteractionEnabled = false
  42. self.contentView.alpha = 0.5
  43. }
  44. public func setEnabledState() {
  45. self.contentView.isUserInteractionEnabled = true
  46. self.contentView.alpha = 1
  47. }
  48. @objc
  49. func acceptButtonPressed() {
  50. if let federationInvitation {
  51. self.delegate?.federationInvitationCellAccept(self, invitation: federationInvitation)
  52. }
  53. }
  54. @objc
  55. func rejectButtonPressed() {
  56. if let federationInvitation {
  57. self.delegate?.federationInvitationCellReject(self, invitation: federationInvitation)
  58. }
  59. }
  60. }