|
|
@ -23,12 +23,12 @@ final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelega
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
private lazy var addMembersButton: Button = {
|
|
|
|
private lazy var addMembersButton: Button = {
|
|
|
|
let result = Button(style: .prominentOutline, size: .large)
|
|
|
|
let result = Button(style: .prominentOutline, size: .large)
|
|
|
|
result.setTitle("Add Members", for: UIControl.State.normal)
|
|
|
|
result.setTitle("Add Members", for: UIControl.State.normal)
|
|
|
|
result.addTarget(self, action: #selector(addMembers), for: UIControl.Event.touchUpInside)
|
|
|
|
result.addTarget(self, action: #selector(addMembers), for: UIControl.Event.touchUpInside)
|
|
|
|
result.contentEdgeInsets = UIEdgeInsets(top: 0, leading: Values.mediumSpacing, bottom: 0, trailing: Values.mediumSpacing)
|
|
|
|
result.contentEdgeInsets = UIEdgeInsets(top: 0, leading: Values.mediumSpacing, bottom: 0, trailing: Values.mediumSpacing)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
@objc private lazy var tableView: UITableView = {
|
|
|
|
@objc private lazy var tableView: UITableView = {
|
|
|
|
let result = UITableView()
|
|
|
|
let result = UITableView()
|
|
|
@ -141,13 +141,14 @@ final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelega
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "UserCell") as! UserCell
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "UserCell") as! UserCell
|
|
|
|
let publicKey = members[indexPath.row]
|
|
|
|
let publicKey = members[indexPath.row]
|
|
|
|
cell.publicKey = publicKey
|
|
|
|
cell.publicKey = publicKey
|
|
|
|
|
|
|
|
cell.accessory = !canBeRemoved(publicKey) ? .lock : .none
|
|
|
|
cell.update()
|
|
|
|
cell.update()
|
|
|
|
return cell
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
|
|
|
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
|
|
|
let publicKey = members[indexPath.row]
|
|
|
|
let publicKey = members[indexPath.row]
|
|
|
|
return publicKey != getUserHexEncodedPublicKey()
|
|
|
|
return canBeRemoved(publicKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
|
|
|
|
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
|
|
|
@ -286,4 +287,16 @@ final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelega
|
|
|
|
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil))
|
|
|
|
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil))
|
|
|
|
presentAlert(alert)
|
|
|
|
presentAlert(alert)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func canBeRemoved(_ publicKey: String) -> Bool {
|
|
|
|
|
|
|
|
return !isAdmin(publicKey) && !isCurrentUser(publicKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func isAdmin(_ publicKey: String) -> Bool {
|
|
|
|
|
|
|
|
return thread.groupModel.groupAdminIds.contains(publicKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func isCurrentUser(_ publicKey: String) -> Bool {
|
|
|
|
|
|
|
|
return publicKey == getUserHexEncodedPublicKey()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|