From 1d8bb5fa8a85de26c9c4c8f709eb3c36e93c817e Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 14 Oct 2019 13:55:03 +1100 Subject: [PATCH] Update MentionCandidateSelectionView for group chat changes --- .../Loki/MentionCandidateSelectionView.swift | 23 +++++++++++++++---- .../ConversationInputToolbar.m | 7 +++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Signal/src/Loki/MentionCandidateSelectionView.swift b/Signal/src/Loki/MentionCandidateSelectionView.swift index c7fa86ad4..b6c1798ed 100644 --- a/Signal/src/Loki/MentionCandidateSelectionView.swift +++ b/Signal/src/Loki/MentionCandidateSelectionView.swift @@ -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 + } } } } diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 4839430a9..141f448df 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -1093,7 +1093,12 @@ const CGFloat kMaxTextViewHeight = 98; - (void)showMentionCandidateSelectionViewFor:(NSArray *)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.mentionCandidateSelectionViewSizeConstraint.constant = 6 + MIN(mentionCandidates.count, 4) * 52; [self setNeedsLayout];