From e4d1925436c4fe7d4a5e39f2f3b69dbceefd1787 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 7 May 2021 15:18:57 +1000 Subject: [PATCH] Show confirmation dialog --- Session.xcodeproj/project.pbxproj | 4 ++ .../ConversationVC+Interaction.swift | 11 +++ .../Views & Modals/JoinOpenGroupModal.swift | 68 +++++++++++++++++++ .../Messages/Signal/TSMessage.m | 2 + 4 files changed, 85 insertions(+) create mode 100644 Session/Conversations/Views & Modals/JoinOpenGroupModal.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 6cc48e38b..dc09384c8 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -202,6 +202,7 @@ B866CE112581C1A900535CC4 /* Sodium+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3E7134E251C867C009649BB /* Sodium+Conversion.swift */; }; B86BD08423399ACF000F5AE3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08323399ACF000F5AE3 /* Modal.swift */; }; B86BD08623399CEF000F5AE3 /* SeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B86BD08523399CEF000F5AE3 /* SeedModal.swift */; }; + B875885A264503A6000E60D0 /* JoinOpenGroupModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8758859264503A6000E60D0 /* JoinOpenGroupModal.swift */; }; B8783E9E23EB948D00404FB8 /* UILabel+Interaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8783E9D23EB948D00404FB8 /* UILabel+Interaction.swift */; }; B879D449247E1BE300DB3608 /* PathVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B879D448247E1BE300DB3608 /* PathVC.swift */; }; B87EF17126367CF800124B3C /* FileServerAPIV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87EF17026367CF800124B3C /* FileServerAPIV2.swift */; }; @@ -1198,6 +1199,7 @@ B86BD08323399ACF000F5AE3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = ""; }; B86BD08523399CEF000F5AE3 /* SeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedModal.swift; sourceTree = ""; }; B87588582644CA9D000E60D0 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = ""; }; + B8758859264503A6000E60D0 /* JoinOpenGroupModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JoinOpenGroupModal.swift; sourceTree = ""; }; B8783E9D23EB948D00404FB8 /* UILabel+Interaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+Interaction.swift"; sourceTree = ""; }; B879D448247E1BE300DB3608 /* PathVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathVC.swift; sourceTree = ""; }; B879D44A247E1D9200DB3608 /* PathStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathStatusView.swift; sourceTree = ""; }; @@ -2139,6 +2141,7 @@ B8F5F72225F1B4CA003BF8D4 /* DownloadAttachmentModal.swift */, C3A76A8C25DB83F90074CB90 /* PermissionMissingModal.swift */, B821494525D4D6FF009C0F2A /* URLModal.swift */, + B8758859264503A6000E60D0 /* JoinOpenGroupModal.swift */, B821494E25D4E163009C0F2A /* BodyTextView.swift */, B82149B725D60393009C0F2A /* BlockedModal.swift */, C374EEE125DA26740073A857 /* LinkPreviewModal.swift */, @@ -4927,6 +4930,7 @@ B85357C323A1BD1200AAF6CD /* SeedVC.swift in Sources */, 45B5360E206DD8BB00D61655 /* UIResponder+OWS.swift in Sources */, B8D84ECF25E3108A005A043E /* ExpandingAttachmentsButton.swift in Sources */, + B875885A264503A6000E60D0 /* JoinOpenGroupModal.swift in Sources */, B8CCF6432397711F0091D419 /* SettingsVC.swift in Sources */, C354E75A23FE2A7600CE22E3 /* BaseVC.swift in Sources */, 3441FD9F21A3604F00BB9542 /* BackupRestoreViewController.swift in Sources */, diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 1dbdfea19..61d2c37bf 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -447,6 +447,9 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc // Scroll to the source of the reply guard let indexPath = viewModel.ensureLoadWindowContainsQuotedReply(reply) else { return } messagesTableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.middle, animated: true) + } else if let message = viewItem.interaction as? TSIncomingMessage, let name = message.openGroupInvitationName, + let url = message.openGroupInvitationURL { + joinOpenGroup(name: name, url: url) } default: break } @@ -555,6 +558,14 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc present(urlModal, animated: true, completion: nil) } + func joinOpenGroup(name: String, url: String) { + // Open groups can be unsafe, so always ask the user whether they want to join one + let joinOpenGroupModal = JoinOpenGroupModal(name: name, url: url) + joinOpenGroupModal.modalPresentationStyle = .overFullScreen + joinOpenGroupModal.modalTransitionStyle = .crossDissolve + present(joinOpenGroupModal, animated: true, completion: nil) + } + func handleReplyButtonTapped(for viewItem: ConversationViewItem) { reply(viewItem) } diff --git a/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift b/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift new file mode 100644 index 000000000..58bd69644 --- /dev/null +++ b/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift @@ -0,0 +1,68 @@ + +final class JoinOpenGroupModal : Modal { + private let name: String + private let url: String + + // MARK: Lifecycle + init(name: String, url: String) { + self.name = name + self.url = url + super.init(nibName: nil, bundle: nil) + } + + override init(nibName: String?, bundle: Bundle?) { + preconditionFailure("Use init(name:url:) instead.") + } + + required init?(coder: NSCoder) { + preconditionFailure("Use init(name:url:) instead.") + } + + override func populateContentView() { + // Title + let titleLabel = UILabel() + titleLabel.textColor = Colors.text + titleLabel.font = .boldSystemFont(ofSize: Values.largeFontSize) + titleLabel.text = "Join \(name)?" + titleLabel.textAlignment = .center + // Message + let messageLabel = UILabel() + messageLabel.textColor = Colors.text + messageLabel.font = .systemFont(ofSize: Values.smallFontSize) + let message = "Are you sure you want to join the \(name) open group?"; + let attributedMessage = NSMutableAttributedString(string: message) + attributedMessage.addAttributes([ .font : UIFont.boldSystemFont(ofSize: Values.smallFontSize) ], range: (message as NSString).range(of: name)) + messageLabel.attributedText = attributedMessage + messageLabel.numberOfLines = 0 + messageLabel.lineBreakMode = .byWordWrapping + messageLabel.textAlignment = .center + // Join button + let joinButton = UIButton() + joinButton.set(.height, to: Values.mediumButtonHeight) + joinButton.layer.cornerRadius = Modal.buttonCornerRadius + joinButton.backgroundColor = Colors.buttonBackground + joinButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize) + joinButton.setTitleColor(Colors.text, for: UIControl.State.normal) + joinButton.setTitle("Join", for: UIControl.State.normal) + joinButton.addTarget(self, action: #selector(openURL), for: UIControl.Event.touchUpInside) + // Button stack view + let buttonStackView = UIStackView(arrangedSubviews: [ cancelButton, joinButton ]) + buttonStackView.axis = .horizontal + buttonStackView.spacing = Values.mediumSpacing + buttonStackView.distribution = .fillEqually + // Main stack view + let mainStackView = UIStackView(arrangedSubviews: [ titleLabel, messageLabel, buttonStackView ]) + mainStackView.axis = .vertical + mainStackView.spacing = Values.largeSpacing + contentView.addSubview(mainStackView) + mainStackView.pin(.leading, to: .leading, of: contentView, withInset: Values.largeSpacing) + mainStackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing) + contentView.pin(.trailing, to: .trailing, of: mainStackView, withInset: Values.largeSpacing) + contentView.pin(.bottom, to: .bottom, of: mainStackView, withInset: Values.largeSpacing) + } + + // MARK: Interaction + @objc private func openURL() { + + } +} diff --git a/SessionMessagingKit/Messages/Signal/TSMessage.m b/SessionMessagingKit/Messages/Signal/TSMessage.m index 8ea5f61c2..5b0634fe8 100644 --- a/SessionMessagingKit/Messages/Signal/TSMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSMessage.m @@ -346,6 +346,8 @@ const NSUInteger kOversizeTextMessageSizeThreshold = 2 * 1024; return bodyDescription; } else if (attachmentDescription.length > 0) { return attachmentDescription; + } else if (self.openGroupInvitationName != nil) { + return @"😎 Open group invitation"; } else { // TODO: We should do better here. return @"";