diff --git a/Prisma.xcodeproj/project.pbxproj b/Prisma.xcodeproj/project.pbxproj index 99a9477..c1d91ed 100644 --- a/Prisma.xcodeproj/project.pbxproj +++ b/Prisma.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 2F4E23832989D51F0013F3D9 /* PrismaTestingSetup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F4E23822989D51F0013F3D9 /* PrismaTestingSetup.swift */; }; 2F4FC8D729EE69D300BFFE26 /* MockUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F4FC8D629EE69D300BFFE26 /* MockUpload.swift */; }; 2F5E32BD297E05EA003432F8 /* PrismaDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F5E32BC297E05EA003432F8 /* PrismaDelegate.swift */; }; - 2F6025CB29BBE70F0045459E /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */; }; 2FA0BFED2ACC977500E0EF83 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */; }; 2FB099AF2A875DF100B20952 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099AE2A875DF100B20952 /* FirebaseAuth */; }; 2FB099B12A875DF100B20952 /* FirebaseFirestore in Frameworks */ = {isa = PBXBuildFile; productRef = 2FB099B02A875DF100B20952 /* FirebaseFirestore */; }; @@ -74,10 +73,11 @@ A9DFE8A92ABE551400428242 /* AccountButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9DFE8A82ABE551400428242 /* AccountButton.swift */; }; A9FE7AD02AA39BAB0077B045 /* AccountSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9FE7ACF2AA39BAB0077B045 /* AccountSheet.swift */; }; AC69903E2B6C5A2F00D92970 /* PrivacyModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC69903D2B6C5A2F00D92970 /* PrivacyModule.swift */; }; + ACB5DFBA2B9F9E76004F28E6 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = ACB5DFB92B9F9E76004F28E6 /* GoogleService-Info.plist */; }; D8027E912B90655700BB9466 /* ManageDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8027E902B90655700BB9466 /* ManageDataView.swift */; }; D8F136C52B85CEED000BA7AE /* DeleteDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F136C42B85CEED000BA7AE /* DeleteDataView.swift */; }; E4C766262B72D50500C1DEDA /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C766252B72D50500C1DEDA /* WebView.swift */; }; - F83B7CBE2B8FFE6800662914 /* PrismaStandard+TimeIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = F83B7CBD2B8FFE6800662914 /* PrismaStandard+TimeIndex.swift */; }; + F83B7CBE2B8FFE6800662914 /* PrismaStandard+TimeIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = F83B7CBD2B8FFE6800662914 /* PrismaStandard+TimeIndex.swift */; }; F8AF6F9A2B5F2B1A0011C32D /* AppIcon-NoBG.png in Resources */ = {isa = PBXBuildFile; fileRef = F8AF6F992B5F2B1A0011C32D /* AppIcon-NoBG.png */; }; F8AF6F9F2B5F35400011C32D /* ChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8AF6F9E2B5F35400011C32D /* ChatView.swift */; }; F8AF6FA52B5F3AE70011C32D /* EventContextCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8AF6FA42B5F3AE70011C32D /* EventContextCard.swift */; }; @@ -116,7 +116,6 @@ 2F4E23822989D51F0013F3D9 /* PrismaTestingSetup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrismaTestingSetup.swift; sourceTree = ""; }; 2F4FC8D629EE69D300BFFE26 /* MockUpload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUpload.swift; sourceTree = ""; }; 2F5E32BC297E05EA003432F8 /* PrismaDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrismaDelegate.swift; sourceTree = ""; }; - 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; 2FA0BFEC2ACC977500E0EF83 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = ""; }; 2FAEC07F297F583900C11C42 /* Prisma.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Prisma.entitlements; sourceTree = ""; }; 2FC94CD4298B0A1D009C8209 /* Prisma.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Prisma.xctestplan; sourceTree = ""; }; @@ -157,10 +156,11 @@ A9DFE8A82ABE551400428242 /* AccountButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountButton.swift; sourceTree = ""; }; A9FE7ACF2AA39BAB0077B045 /* AccountSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSheet.swift; sourceTree = ""; }; AC69903D2B6C5A2F00D92970 /* PrivacyModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyModule.swift; sourceTree = ""; }; + ACB5DFB92B9F9E76004F28E6 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; D8027E902B90655700BB9466 /* ManageDataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageDataView.swift; sourceTree = ""; }; D8F136C42B85CEED000BA7AE /* DeleteDataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteDataView.swift; sourceTree = ""; }; E4C766252B72D50500C1DEDA /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = ""; }; - F83B7CBD2B8FFE6800662914 /* PrismaStandard+TimeIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrismaStandard+TimeIndex.swift"; sourceTree = ""; }; + F83B7CBD2B8FFE6800662914 /* PrismaStandard+TimeIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrismaStandard+TimeIndex.swift"; sourceTree = ""; }; F8AF6F992B5F2B1A0011C32D /* AppIcon-NoBG.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "AppIcon-NoBG.png"; sourceTree = ""; }; F8AF6F9E2B5F35400011C32D /* ChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatView.swift; sourceTree = ""; }; F8AF6FA42B5F3AE70011C32D /* EventContextCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventContextCard.swift; sourceTree = ""; }; @@ -237,9 +237,9 @@ 2FC9759D2978E30800BA99FE /* Supporting Files */ = { isa = PBXGroup; children = ( + ACB5DFB92B9F9E76004F28E6 /* GoogleService-Info.plist */, 2FAEC07F297F583900C11C42 /* Prisma.entitlements */, 653A258928339462005D4D48 /* Info.plist */, - 2F6025CA29BBE70F0045459E /* GoogleService-Info.plist */, 2F1AC9DE2B4E840E00C24973 /* Prisma.docc */, ); path = "Supporting Files"; @@ -611,12 +611,12 @@ files = ( 2FC3439229EE634B002D773C /* ConsentDocument.md in Resources */, F8AF6F9A2B5F2B1A0011C32D /* AppIcon-NoBG.png in Resources */, + ACB5DFBA2B9F9E76004F28E6 /* GoogleService-Info.plist in Resources */, F8AF6FAF2B5F42C40011C32D /* mid-day-en-US.json in Resources */, F8AF6FAD2B5F42C40011C32D /* end-of-day-en-US.json in Resources */, 653A255528338800005D4D48 /* Assets.xcassets in Resources */, F8AF6FAC2B5F42C40011C32D /* afternoon-en-US.json in Resources */, 2FA0BFED2ACC977500E0EF83 /* Localizable.xcstrings in Resources */, - 2F6025CB29BBE70F0045459E /* GoogleService-Info.plist in Resources */, F8AF6FAE2B5F42C40011C32D /* morning-en-US.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Prisma.xcodeproj/xcshareddata/xcschemes/Prisma.xcscheme b/Prisma.xcodeproj/xcshareddata/xcschemes/Prisma.xcscheme index e2a133b..7859492 100644 --- a/Prisma.xcodeproj/xcshareddata/xcschemes/Prisma.xcscheme +++ b/Prisma.xcodeproj/xcshareddata/xcschemes/Prisma.xcscheme @@ -95,7 +95,7 @@ + isEnabled = "YES"> diff --git a/Prisma/Chat/ChatView.swift b/Prisma/Chat/ChatView.swift index 34e0165..54dbaa9 100644 --- a/Prisma/Chat/ChatView.swift +++ b/Prisma/Chat/ChatView.swift @@ -6,36 +6,68 @@ // SPDX-License-Identifier: MIT // +import Firebase import Foundation +import SpeziAccount import SwiftUI import WebKit - struct ChatView: View { @Binding var presentingAccount: Bool + @State private var token: String? + var body: some View { NavigationStack { GeometryReader { geometry in - if let url = URL(string: "http://localhost:3000") { - WebView(url: url) - .navigationTitle("Chat") - .frame( - width: geometry.size.width, - height: geometry.size.height - ) + // Fetch JWT token asynchronously + if let token = token { + if let url = URL(string: "http://localhost:3000?token=\(token)") { // this needs to be sent to the frontend + WebView(url: url) + .navigationTitle("Chat") + .frame( + width: geometry.size.width, + height: geometry.size.height + ) + } else { + Text("Invalid URL") + } } else { - Text("Invalid URL") + ProgressView() + } + } + /* + .onChange(of: account.signedIn) { + guard account.signedIn else { + return + } + + Task { + try await self.signInWithFirebase() + } + } + */ + .task { + do { + try await self.getFirebaseIDToken() + } catch { + print("Firebase Auth failed \(error)") } } } } - + init(presentingAccount: Binding) { self._presentingAccount = presentingAccount } } +extension ChatView { + func getFirebaseIDToken() async throws { + token = try await Auth.auth().currentUser?.getIDToken() + print("token is:", token ?? "") + } +} #if DEBUG struct ChatView_Previews: PreviewProvider { diff --git a/Prisma/PushNotifications/PushNotifications.swift b/Prisma/PushNotifications/PushNotifications.swift index 706a676..bccf51e 100644 --- a/Prisma/PushNotifications/PushNotifications.swift +++ b/Prisma/PushNotifications/PushNotifications.swift @@ -48,7 +48,7 @@ class PrismaPushNotifications: NSObject, Module, NotificationHandler, Notificati func handleNotificationAction(_ response: UNNotificationResponse) async { // right now the default action is when a user taps on the notification. functionality can be expanded in the future. -// let actionIdentifier = response.actionIdentifier + _ = response.actionIdentifier if let sentTimestamp = response.notification.request.content.userInfo["sent_timestamp"] as? String { let openedTimestamp = Date().toISOFormat(timezone: TimeZone(abbreviation: "UTC")) await standard.addNotificationOpenedTimestamp(timeSent: sentTimestamp, timeOpened: openedTimestamp) @@ -85,6 +85,7 @@ class PrismaPushNotifications: NSObject, Module, NotificationHandler, Notificati func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { // Update the token in Firestore: // The standard is an actor, which protects against data races and conforms to + // immutable data practice. Therefore we get into new asynchronous context and execute Task { await standard.storeToken(token: fcmToken) diff --git a/Prisma/Resources/Localizable.xcstrings b/Prisma/Resources/Localizable.xcstrings index 0e4e1ba..2a53bb5 100644 --- a/Prisma/Resources/Localizable.xcstrings +++ b/Prisma/Resources/Localizable.xcstrings @@ -447,6 +447,9 @@ }, "Invalid URL" : { + }, + "Invalid URL" : { + }, "JAMES_LANDAY_BIO" : { "localizations" : { diff --git a/Prisma/SharedContext/FeatureFlags.swift b/Prisma/SharedContext/FeatureFlags.swift index 5239ff0..d0f118a 100644 --- a/Prisma/SharedContext/FeatureFlags.swift +++ b/Prisma/SharedContext/FeatureFlags.swift @@ -14,13 +14,13 @@ enum FeatureFlags { static let showOnboarding = CommandLine.arguments.contains("--showOnboarding") /// Disables the Firebase interactions, including the login/sign-up step and the Firebase Firestore upload. static let disableFirebase = CommandLine.arguments.contains("--disableFirebase") - #if targetEnvironment(simulator) - /// Defines if the application should connect to the local firebase emulator. Always set to true when using the iOS simulator. - static let useFirebaseEmulator = true - #else + // if targetEnvironment(simulator) + // Defines if the application should connect to the local firebase emulator. Always set to true when using the iOS simulator. + // static let useFirebaseEmulator = true + // else /// Defines if the application should connect to the local firebase emulator. Always set to true when using the iOS simulator. static let useFirebaseEmulator = CommandLine.arguments.contains("--useFirebaseEmulator") - #endif + // endif /// Adds a test task to the schedule at the current time static let testSchedule = CommandLine.arguments.contains("--testSchedule") }