Update MentionCandidateSelectionView for group chat changes

pull/57/head
Niels Andriesse 6 years ago
parent 0f5ac64363
commit 1d8bb5fa8a

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

@ -1093,7 +1093,12 @@ const CGFloat kMaxTextViewHeight = 98;
- (void)showMentionCandidateSelectionViewFor:(NSArray<LKMention *> *)mentionCandidates in:(TSThread *)thread - (void)showMentionCandidateSelectionViewFor:(NSArray<LKMention *> *)mentionCandidates in:(TSThread *)thread
{ {
self.mentionCandidateSelectionView.hasGroupContext = thread.isGroupThread; // Must happen before setting the users __block LKGroupChat *groupChat;
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
groupChat = [LKDatabaseUtilities getGroupChatForThreadID:thread.uniqueId transaction:transaction];
}];
self.mentionCandidateSelectionView.publicChatServer = groupChat.server;
[self.mentionCandidateSelectionView setPublicChatServerID:groupChat.channel];
self.mentionCandidateSelectionView.mentionCandidates = mentionCandidates; self.mentionCandidateSelectionView.mentionCandidates = mentionCandidates;
self.mentionCandidateSelectionViewSizeConstraint.constant = 6 + MIN(mentionCandidates.count, 4) * 52; self.mentionCandidateSelectionViewSizeConstraint.constant = 6 + MIN(mentionCandidates.count, 4) * 52;
[self setNeedsLayout]; [self setNeedsLayout];

Loading…
Cancel
Save