|
|
|
@ -4,9 +4,16 @@
|
|
|
|
|
@objc(LKMentionCandidateSelectionView)
|
|
|
|
|
final class MentionCandidateSelectionView : UIView, UITableViewDataSource, UITableViewDelegate {
|
|
|
|
|
@objc var mentionCandidates: [Mention] = [] { didSet { tableView.reloadData() } }
|
|
|
|
|
@objc var hasGroupContext = false
|
|
|
|
|
@objc var publicChatServer: String?
|
|
|
|
|
var publicChatServerID: UInt64?
|
|
|
|
|
@objc var delegate: MentionCandidateSelectionViewDelegate?
|
|
|
|
|
|
|
|
|
|
// MARK: Convenience
|
|
|
|
|
@objc(setPublicChatServerID:)
|
|
|
|
|
func setPublicChatServerID(to publicChatServerID: UInt64) {
|
|
|
|
|
self.publicChatServerID = publicChatServerID != 0 ? publicChatServerID : nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: Components
|
|
|
|
|
@objc lazy var tableView: UITableView = { // TODO: Make this private
|
|
|
|
|
let result = UITableView()
|
|
|
|
@ -44,7 +51,8 @@ final class MentionCandidateSelectionView : UIView, UITableViewDataSource, UITab
|
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! Cell
|
|
|
|
|
let mentionCandidate = mentionCandidates[indexPath.row]
|
|
|
|
|
cell.mentionCandidate = mentionCandidate
|
|
|
|
|
cell.hasGroupContext = hasGroupContext
|
|
|
|
|
cell.publicChatServer = publicChatServer
|
|
|
|
|
cell.publicChatServerID = publicChatServerID
|
|
|
|
|
return cell
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -61,7 +69,8 @@ private extension MentionCandidateSelectionView {
|
|
|
|
|
|
|
|
|
|
final class Cell : UITableViewCell {
|
|
|
|
|
var mentionCandidate = Mention(hexEncodedPublicKey: "", displayName: "") { didSet { update() } }
|
|
|
|
|
var hasGroupContext = false
|
|
|
|
|
var publicChatServer: String?
|
|
|
|
|
var publicChatServerID: UInt64?
|
|
|
|
|
|
|
|
|
|
// MARK: Components
|
|
|
|
|
private lazy var profilePictureImageView = AvatarImageView()
|
|
|
|
@ -121,8 +130,12 @@ private extension MentionCandidateSelectionView {
|
|
|
|
|
displayNameLabel.text = mentionCandidate.displayName
|
|
|
|
|
let profilePicture = OWSContactAvatarBuilder(signalId: mentionCandidate.hexEncodedPublicKey, colorName: .blue, diameter: 36).build()
|
|
|
|
|
profilePictureImageView.image = profilePicture
|
|
|
|
|
let isUserModerator = LokiGroupChatAPI.isUserModerator(mentionCandidate.hexEncodedPublicKey, for: 1, on: "https://chat.lokinet.org") // FIXME: Mentions need to work for every kind of chat
|
|
|
|
|
moderatorIconImageView.isHidden = !isUserModerator || !hasGroupContext
|
|
|
|
|
if let publicChatServer = publicChatServer, let publicChatServerID = publicChatServerID {
|
|
|
|
|
let isUserModerator = LokiGroupChatAPI.isUserModerator(mentionCandidate.hexEncodedPublicKey, for: publicChatServerID, on: publicChatServer)
|
|
|
|
|
moderatorIconImageView.isHidden = !isUserModerator
|
|
|
|
|
} else {
|
|
|
|
|
moderatorIconImageView.isHidden = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|