generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notification status to firebase (#36)
# Timestamp Notification Status to Firebase, Update Notification Handling ## ♻️ Current situation & Problem With the release of Spezi 1.2, new support for Notifications was added, breaking the current implementation of push notifications. Additionally, we required support for notification handling on the client side, for background, foreground, and user-actions regarding notifications. To log data about notification status, such as "received" and "opened", these handlers were necessary, alongside updates to the standard for the delivery of timestamps to firestore and dealing with notifications for the path. "Sent" status is logged to firestore on the server side. ## ⚙️ Release Notes Updates - Migrated to Spezi 1.2 and updated support for notifications, as outlined in the [Spezi documentation](https://swiftpackageindex.com/stanfordspezi/spezi/1.2.0/documentation/spezi/notifications). This required updating many of the functions and ordering of necessary steps to conform to the FirebaseMessaging protocol. - New support for using `getPath()` in `PrismaStandard` for anything related to the notifications collection in firestore, as well as the type of data "logs" or schedule" - Extended the standard for PushNotifications, adding functions for `addNotificationOpened()` and `addNotificationReceived()` to Firestore - Added new support for specifying timezones to the `.toISOFormat()` method extension of the `Date()` class Next Steps - Currently, notification handling distinguishes between foreground notifications and clicking on the notification, meaning that in firestore "opening" and "receiving" can't happen at the same time. Will follow up with the Spezi team on how to get this to work ## 📚 Documentation *Please ensure that you properly document any additions in conformance to [Spezi Documentation Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).* *You can use this section to describe your solution, but we encourage contributors to document your reasoning and changes using in-line documentation.* ## ✅ Testing *Please ensure that the PR meets the testing requirements set by CodeCov and that new functionality is appropriately tested.* *This section describes important information about the tests and why some elements might not be testable.* ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - [ x] I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md). --------- Co-authored-by: Paul Schmiedmayer <[email protected]>
- Loading branch information
1 parent
2873e1e
commit f41a4ce
Showing
14 changed files
with
139 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,6 +322,9 @@ | |
}, | ||
"Invalid URL" : { | ||
|
||
}, | ||
"Invalid URL" : { | ||
|
||
}, | ||
"JAMES_LANDAY_BIO" : { | ||
"localizations" : { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// This source file is part of the Stanford Prisma Application based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// Created by Bryant Jimenez on 2/22/24. | ||
// | ||
|
||
import FirebaseFirestore | ||
import Foundation | ||
|
||
extension PrismaStandard { | ||
/// Stores the timestamp when a notification was received by | ||
/// the user's device to the specific notification document. | ||
/// | ||
/// - Parameter timestamp: The time which the notification was received by the device | ||
func addNotificationReceivedTimestamp(timeSent: String, timeReceived: String) async { | ||
// path = user_id/notifications/data/logs/YYYY-MM-DDThh:mm:ss.mss | ||
let path: String | ||
do { | ||
path = try await getPath(module: .notifications("logs")) + "\(timeSent)" | ||
} catch { | ||
print("Failed to define path: \(error.localizedDescription)") | ||
return | ||
} | ||
|
||
// try push to Firestore. | ||
do { | ||
try await Firestore.firestore().document(path).setData(["received": timeReceived]) | ||
} catch { | ||
print("Failed to set data in Firestore: \(error.localizedDescription)") | ||
} | ||
} | ||
|
||
|
||
/// Stores the timestamp when a notification was opened by | ||
/// the user to the specific notification document. | ||
func addNotificationOpenedTimestamp(timeSent: String, timeOpened: String) async { | ||
// path = user_id/notifications/data/logs/YYYY-MM-DDThh:mm:ss.mss | ||
let path: String | ||
do { | ||
path = try await getPath(module: .notifications("logs")) + "\(timeSent)" | ||
} catch { | ||
print("Failed to define path: \(error.localizedDescription)") | ||
return | ||
} | ||
|
||
// try push to Firestore. | ||
do { | ||
try await Firestore.firestore().document(path).setData(["opened": timeOpened]) | ||
} catch { | ||
print("Failed to set data in Firestore: \(error.localizedDescription)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.