diff --git a/Session/Home/New Conversation/NewMessageScreen.swift b/Session/Home/New Conversation/NewMessageScreen.swift index 01a871c65..db775ec00 100644 --- a/Session/Home/New Conversation/NewMessageScreen.swift +++ b/Session/Home/New Conversation/NewMessageScreen.swift @@ -1,10 +1,130 @@ // Copyright © 2024 Rangeproof Pty Ltd. All rights reserved. import SwiftUI +import SessionUIKit +import SessionMessagingKit +import SessionUtilitiesKit struct NewMessageScreen: View { + @EnvironmentObject var host: HostWrapper + + @State var tabIndex = 0 + @State private var accountIdOrONS: String = "" + @State private var errorString: String? = nil + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + ZStack(alignment: .topLeading) { + VStack( + spacing: 0 + ){ + CustomTopTabBar( + tabIndex: $tabIndex, + tabTitles: [ + "new_message_screen_enter_account_id_tab_title".localized(), + "vc_create_private_chat_scan_qr_code_tab_title".localized() + ] + ).frame(maxWidth: .infinity) + + if tabIndex == 0 { + EnterAccountIdScreen( + accountIdOrONS: $accountIdOrONS, + error: $errorString + ) + } + else { + ScanQRCodeScreen( + $accountIdOrONS, + error: $errorString, + continueAction: continueWithAccountId + ) + } + } + } + .backgroundColor(themeColor: .backgroundSecondary) + } + + fileprivate func startNewPrivateChatIfPossible(with hexEncodedPublicKey: String, onError: (() -> ())?) { + if !KeyPair.isValidHexEncodedPublicKey(candidate: hexEncodedPublicKey) { + errorString = "invalid_account_id_from_qr_code_message".localized() + } + else { + SessionApp.presentConversationCreatingIfNeeded( + for: hexEncodedPublicKey, + variant: .contact, + dismissing: self.host.controller, + animated: false + ) + } + } + + func continueWithAccountId(onError: (() -> ())?) { + let hexEncodedPublicKey = accountIdOrONS + startNewPrivateChatIfPossible(with: hexEncodedPublicKey, onError: onError) + } +} + +struct EnterAccountIdScreen: View { + @Binding var accountIdOrONS: String + @Binding var error: String? + + var body: some View { + VStack( + alignment: .center, + spacing: Values.mediumSpacing + ) { + SessionTextField( + $accountIdOrONS, + placeholder: "new_message_screen_enter_account_id_hint".localized(), + error: $error + ) + + if error?.isEmpty != true { + ZStack { + if #available(iOS 14.0, *) { + Text("\("new_message_screen_enter_account_id_explanation".localized())\(Image(systemName: "questionmark.circle"))") + .font(.system(size: Values.verySmallFontSize)) + .foregroundColor(themeColor: .textSecondary) + .multilineTextAlignment(.center) + } else { + Text("new_message_screen_enter_account_id_explanation".localized()) + .font(.system(size: Values.verySmallFontSize)) + .foregroundColor(themeColor: .textSecondary) + .multilineTextAlignment(.center) + } + } + .padding(.horizontal, Values.smallSpacing) + .padding(.top, -50) + .onTapGesture { + if let url: URL = URL(string: "https://sessionapp.zendesk.com/hc/en-us/articles/4439132747033-How-do-Session-ID-usernames-work-") { + UIApplication.shared.open(url) + } + } + } + + if !accountIdOrONS.isEmpty { + Button { + + } label: { + Text("next".localized()) + .bold() + .font(.system(size: Values.smallFontSize)) + .foregroundColor(themeColor: .sessionButton_text) + .frame( + maxWidth: .infinity, + maxHeight: Values.largeButtonHeight, + alignment: .center + ) + .overlay( + Capsule() + .stroke(themeColor: .sessionButton_border) + ) + } + .padding(.horizontal, Values.massiveSpacing) + } + + Spacer() + } + .padding(.all, Values.largeSpacing) } } diff --git a/Session/Home/New Conversation/StartConversationScreen.swift b/Session/Home/New Conversation/StartConversationScreen.swift index e81bdb2ca..979f7c8ad 100644 --- a/Session/Home/New Conversation/StartConversationScreen.swift +++ b/Session/Home/New Conversation/StartConversationScreen.swift @@ -23,7 +23,10 @@ struct StartConversationScreen: View { image: "Message", title: "vc_create_private_chat_title".localized() ) { - + let viewController: SessionHostingViewController = SessionHostingViewController(rootView: NewMessageScreen()) + viewController.setNavBarTitle("vc_create_private_chat_title".localized()) + viewController.setUpDismissingButton(on: .right) + self.host.controller?.navigationController?.pushViewController(viewController, animated: true) } Line(color: .borderSeparator) diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 2656b32da..105722746 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -874,3 +874,6 @@ The point that a message will disappear in a disappearing message update message "account_id_qr_code_explanation" = "Friends can message you by scanning your QR code."; "start_conversation_screen_title" = "Start Conversation"; "invite_a_friend_explanation" = "Invite your friend to chat with you on Session by sharing your Account ID with them"; +"new_message_screen_enter_account_id_tab_title" = "Enter Account ID"; +"new_message_screen_enter_account_id_hint" = "Enter Account ID or ONS"; +"new_message_screen_enter_account_id_explanation" = "Start a new conversation by entering your friend's Account ID, ONS or scanning their QR code."; diff --git a/Session/Settings/QRCodeScreen.swift b/Session/Settings/QRCodeScreen.swift index 24f98d358..f1e398955 100644 --- a/Session/Settings/QRCodeScreen.swift +++ b/Session/Settings/QRCodeScreen.swift @@ -78,6 +78,8 @@ struct MyQRCodeScreen: View { .font(.system(size: Values.verySmallFontSize)) .foregroundColor(themeColor: .textSecondary) .multilineTextAlignment(.center) + + Spacer() } .padding(.horizontal, Values.mediumSpacing) .padding(.all, Values.veryLargeSpacing)