From b8f82c98eb815e00dbd5e2eb60d70bda1b3555b7 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 19 Feb 2021 14:30:16 +1100 Subject: [PATCH] Show moderator icons in open groups --- Session.xcodeproj/project.pbxproj | 12 +++++------ Session/Conversations V2/ConversationVC.swift | 5 ++--- .../Input View/MentionSelectionView.swift | 5 +---- .../Message Cells/VisibleMessageCell.swift | 20 ++++++++++++++++--- .../Loki/Crown.imageset/Contents.json | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 82fc2a3d7..e0792cb66 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -5331,7 +5331,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 178; + CURRENT_PROJECT_VERSION = 179; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5400,7 +5400,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 178; + CURRENT_PROJECT_VERSION = 179; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -5461,7 +5461,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 178; + CURRENT_PROJECT_VERSION = 179; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -5531,7 +5531,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 178; + CURRENT_PROJECT_VERSION = 179; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -6416,7 +6416,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 178; + CURRENT_PROJECT_VERSION = 179; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -6484,7 +6484,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 178; + CURRENT_PROJECT_VERSION = 179; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/Session/Conversations V2/ConversationVC.swift b/Session/Conversations V2/ConversationVC.swift index c26499b7d..ead607a55 100644 --- a/Session/Conversations V2/ConversationVC.swift +++ b/Session/Conversations V2/ConversationVC.swift @@ -1,14 +1,13 @@ // TODO // • Tapping replies -// • Moderator icons +// • Disappearing messages timer +// • Brendan no likey buttons above text field // • Slight paging glitch // • Image detail VC transition glitch // • Photo rounding -// • Disappearing messages timer // • Scroll button behind mentions view // • Remaining search glitchiness -// • Brendan no likey buttons above text field final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversationSettingsViewDelegate, ConversationSearchControllerDelegate, UITableViewDataSource, UITableViewDelegate { let thread: TSThread diff --git a/Session/Conversations V2/Input View/MentionSelectionView.swift b/Session/Conversations V2/Input View/MentionSelectionView.swift index 3debdc275..103781879 100644 --- a/Session/Conversations V2/Input View/MentionSelectionView.swift +++ b/Session/Conversations V2/Input View/MentionSelectionView.swift @@ -89,10 +89,7 @@ private extension MentionSelectionView { // MARK: Components private lazy var profilePictureView = ProfilePictureView() - private lazy var moderatorIconImageView: UIImageView = { - let result = UIImageView(image: #imageLiteral(resourceName: "Crown")) - return result - }() + private lazy var moderatorIconImageView = UIImageView(image: #imageLiteral(resourceName: "Crown")) private lazy var displayNameLabel: UILabel = { let result = UILabel() diff --git a/Session/Conversations V2/Message Cells/VisibleMessageCell.swift b/Session/Conversations V2/Message Cells/VisibleMessageCell.swift index ea2a90d0a..f79f631d8 100644 --- a/Session/Conversations V2/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations V2/Message Cells/VisibleMessageCell.swift @@ -59,6 +59,8 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewV2Delegate { return result }() + private lazy var moderatorIconImageView = UIImageView(image: #imageLiteral(resourceName: "Crown")) + lazy var bubbleView: UIView = { let result = UIView() result.layer.cornerRadius = VisibleMessageCell.smallCornerRadius @@ -151,6 +153,12 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewV2Delegate { profilePictureViewLeftConstraint.isActive = true profilePictureViewWidthConstraint.isActive = true profilePictureView.pin(.bottom, to: .bottom, of: self, withInset: -1) + // Moderator icon image view + moderatorIconImageView.set(.width, to: 20) + moderatorIconImageView.set(.height, to: 20) + addSubview(moderatorIconImageView) + moderatorIconImageView.pin(.trailing, to: .trailing, of: profilePictureView, withInset: 1) + moderatorIconImageView.pin(.bottom, to: .bottom, of: profilePictureView, withInset: 4.5) // Bubble view addSubview(bubbleView) bubbleViewLeftConstraint1.isActive = true @@ -202,6 +210,13 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewV2Delegate { if let senderSessionID = senderSessionID { profilePictureView.update(for: senderSessionID) } + if let thread = thread as? TSGroupThread, thread.isOpenGroup, + let openGroup = Storage.shared.getOpenGroup(for: thread.uniqueId!), let senderSessionID = senderSessionID { + let isUserModerator = OpenGroupAPI.isUserModerator(senderSessionID, for: openGroup.channel, on: openGroup.server) + moderatorIconImageView.isHidden = !isUserModerator || profilePictureView.isHidden + } else { + moderatorIconImageView.isHidden = true + } // Bubble view bubbleViewLeftConstraint1.isActive = (direction == .incoming) bubbleViewLeftConstraint1.constant = isGroupThread ? VisibleMessageCell.groupThreadHSpacing : VisibleMessageCell.contactThreadHSpacing @@ -542,8 +557,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewV2Delegate { .foregroundColor : textColor, .font : UIFont.systemFont(ofSize: getFontSize(for: viewItem)) ] - var attributedText = NSMutableAttributedString(attributedString: MentionUtilities.highlightMentions(in: message.body ?? "", isOutgoingMessage: isOutgoing, threadID: viewItem.interaction.uniqueThreadId, attributes: attributes)) - + let attributedText = NSMutableAttributedString(attributedString: MentionUtilities.highlightMentions(in: message.body ?? "", isOutgoingMessage: isOutgoing, threadID: viewItem.interaction.uniqueThreadId, attributes: attributes)) if let searchText = searchText, searchText.count >= ConversationSearchController.kMinimumSearchTextLength { let normalizedSearchText = FullTextSearchFinder.normalize(text: searchText) do { @@ -555,7 +569,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewV2Delegate { attributedText.addAttribute(.foregroundColor, value: UIColor.black, range: match.range) } } catch { - + // Do nothing } } result.attributedText = attributedText diff --git a/Session/Meta/Images.xcassets/Loki/Crown.imageset/Contents.json b/Session/Meta/Images.xcassets/Loki/Crown.imageset/Contents.json index f3c747220..93dc7834c 100644 --- a/Session/Meta/Images.xcassets/Loki/Crown.imageset/Contents.json +++ b/Session/Meta/Images.xcassets/Loki/Crown.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "Crown.pdf", + "filename" : "crown.pdf", "idiom" : "universal" } ],