-
Notifications
You must be signed in to change notification settings - Fork 31
Add push notifications feature #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
99 commits
Select commit
Hold shift + click to select a range
bca2e1e
add MutedWord entity
joelmuraguri 5cd2cc4
add PreferenceDao with muted words operations
joelmuraguri 017e6a4
handle db migrations
joelmuraguri af68f9a
cache muted word
joelmuraguri dc21525
add OfMutedWord operations and implementation in PrefUpdater
joelmuraguri 451c20f
implement MutedWord logic in repsoitory
joelmuraguri bece30c
code clean up
joelmuraguri 2ab6e1a
update to use datastore
joelmuraguri e0c6f0f
define MutedWordsStateHolder with repository logic
joelmuraguri 6a77fd9
define MutedWordStateHolder and sheet UI
joelmuraguri abe919a
add strings
joelmuraguri 156fcdb
add a unified moderation state for sheets
joelmuraguri 83e8639
clean up
joelmuraguri 524955d
manual DI of moderationState sheets in UI
joelmuraguri 7a6c874
add moderation menu in PostOptions sheet
joelmuraguri 0627f7f
clean up code fix
joelmuraguri 7ae1bb4
use string resource
joelmuraguri 285873a
update to Bulk update
joelmuraguri 40643b8
update to Bulk update
joelmuraguri 7de2e86
use SheetState as a mutator
joelmuraguri 62c6447
code clean up
joelmuraguri 5e730bf
Add dependencies and initial integration for push notifications on An…
tunjid 34acd39
PR feedback
tunjid 435b2d8
Make debug firebase key more obvious
tunjid e4be777
clean ups
joelmuraguri 62e1caa
update to pass state directly; remove mutator
joelmuraguri c35bc52
Decode googgle services json
tunjid 72535d7
Add notification permissions
tunjid 5e0042e
Update build action
tunjid 427c6cd
Update build script
tunjid ef8673a
Update build script
tunjid c72336d
Update build script
tunjid fb524f9
Merge pull request #746 from tunjid/tj/notifications-1
tunjid f6d1e30
Make moderation option part of post options
tunjid 50f0ebc
Fix compilation
tunjid 57b6b5e
Fix invocation of onShown
tunjid fcdf729
Remove unused imports
tunjid 4842d4f
Merge pull request #738 from tunjid/joel/moderation-muted-words-impl
tunjid b87e599
Simplify signature of NetworkMonitor.runCatchingWithNetworkRetry
tunjid 1b3b2e6
Merge pull request #747 from tunjid/tj/network-monitor-simplification
tunjid 08ff75d
Wiring of push notifications delivery
tunjid d7f69c4
PR feedback
tunjid 4abc566
PR feedback
tunjid cde0c45
PR feedback
tunjid cd6d3f3
lint
tunjid 6d55c6d
Merge pull request #748 from tunjid/tj/push-notifications-2
tunjid 9a8a790
Move push notification strings to ui:core for reuse
tunjid 71244b4
PR feedback
tunjid 09c1c56
Merge pull request #749 from tunjid/tj/push-notifications-3
tunjid 2eb1305
Add Notifier and uutilities for creating Android push ntifications
tunjid c5c881a
Update notification icon
tunjid 3e4c4cb
PR feedback
tunjid 16edbf5
Notification uri as id
tunjid ca8c55e
Merge pull request #750 from tunjid/tj/push-notifications-4
tunjid 937081b
Improve perf of parsing record uris
tunjid 4f9a55e
PR feedback
tunjid c946797
Merge pull request #752 from tunjid/tj/record-uri-perf
tunjid 386de0d
Notification processing WIP
tunjid ff966ae
Fix Notification.deepLinkPath()
tunjid a44e50b
TID timestamp extraction fix
tunjid 909787f
Search for notifications after push payload
tunjid b3772f7
lint
tunjid f9829f2
PR feedback
tunjid 9a0baef
PR feedback
tunjid 5691654
Rebase on main
tunjid dc078f1
Fix pending intent bugs
tunjid 04aedc4
Temporary RecordUri overlap
tunjid 67ef91b
Merge pull request #751 from tunjid/tj/push-notifications-5
tunjid 9c7cbbc
Disambiguate between RecordUri and EmbeddableRecordUri
tunjid d822fee
PR feedback
tunjid ec094a2
Merge pull request #753 from tunjid/tj/embeddable-records
tunjid 94d4dfe
Replace GenericUri for some uris with concrete types
tunjid 08a0d02
Merge pull request #754 from tunjid/tj/uri-cleanup
tunjid 4f9ee96
Add AppBarButton
tunjid 1a13384
ktlint
tunjid 7ee1315
PR feedback
tunjid a613edd
Merge pull request #755 from tunjid/tj/app-bar-button
tunjid 32d74c7
Implement push notifications request UI
tunjid 9eca5fc
permission rationale fixes
tunjid fc06d3e
PR feedback
tunjid b6c5845
Run ktlint
tunjid 6411fc0
Code clean up
tunjid 9c38a0a
Merge pull request #756 from tunjid/tj/push-notifications-6
tunjid a19c99f
Stronger typing for embeddable records
tunjid cff0f8b
Merge pull request #758 from tunjid/tj/embeddable-record-typing
tunjid c0dde45
Improve push notification resolution
tunjid 95ce292
Significantly clean up processing logic
tunjid b773933
PR feedback
tunjid 85d7b49
Merge pull request #759 from tunjid/tj/push-notifications-7
tunjid 0e6eac6
Update push notifications UI logic
tunjid 9fbe930
Fix typo
tunjid cf6d0ac
Merge pull request #760 from tunjid/tj/push-notifications-rationale
tunjid 9b4ea53
Add platform specific network connection error checking
tunjid 1a6f5b6
PR feedback
tunjid 92c4b43
Merge pull request #761 from tunjid/tj/platform-network-connection-ex…
tunjid e1708d7
Stop checking for notifcation unread counts in the background
tunjid a5e819a
Fix ToggleUnreadNotificationsMonitor key
tunjid 8defe5e
PR feedback
tunjid f8e0a3d
Merge pull request #762 from tunjid/tj/lifecycle-notification-observa…
tunjid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
composeApp/src/androidMain/kotlin/com/tunjid/heron/NotificationsService.kt
This file contains hidden or 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,84 @@ | ||
| /* | ||
| * Copyright 2024 Adetunji Dahunsi | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.tunjid.heron | ||
|
|
||
| import android.content.BroadcastReceiver | ||
| import android.content.Context | ||
| import android.content.Intent | ||
| import com.google.firebase.messaging.FirebaseMessagingService | ||
| import com.google.firebase.messaging.RemoteMessage | ||
| import com.tunjid.heron.scaffold.notifications.AndroidNotifier.Companion.DISMISSAL_ACTION | ||
| import com.tunjid.heron.scaffold.notifications.AndroidNotifier.Companion.DISMISSAL_INSTANT_EXTRA | ||
| import com.tunjid.heron.scaffold.notifications.NotificationAction | ||
| import com.tunjid.heron.scaffold.scaffold.AppState | ||
| import kotlin.time.ExperimentalTime | ||
| import kotlin.time.Instant | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.coroutines.withTimeout | ||
|
|
||
| class NotificationsService : FirebaseMessagingService() { | ||
|
|
||
| override fun onNewToken(token: String) = | ||
| appState.onNotificationAction(NotificationAction.RegisterToken(token = token)) | ||
|
|
||
| override fun onMessageReceived(message: RemoteMessage) { | ||
| val action = NotificationAction.HandleNotification(payload = message.data) | ||
| action.senderDid ?: return | ||
| val recordUri = action.recordUri ?: return | ||
|
|
||
| appState.onNotificationAction(action) | ||
|
|
||
| // await processing completion or timeout to prevent the app from being | ||
| // killed due to background execution limits. | ||
| try { | ||
| runBlocking { | ||
| withTimeout(AppState.NOTIFICATION_PROCESSING_TIMEOUT_SECONDS) { | ||
| appState.awaitNotificationProcessing(recordUri) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| // No logging utilities in the app at the moment due to its open source nature. | ||
| e.printStackTrace() | ||
tunjid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } finally { | ||
| appState.onNotificationAction( | ||
| NotificationAction.NotificationProcessedOrDropped(recordUri), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class NotificationDismissReceiver : BroadcastReceiver() { | ||
| @OptIn(ExperimentalTime::class) | ||
| override fun onReceive(context: Context, intent: Intent) { | ||
| if (intent.action != DISMISSAL_ACTION) return | ||
|
|
||
| val dismissedAtEpoch = intent.getLongExtra( | ||
| /* name = */ | ||
| DISMISSAL_INSTANT_EXTRA, | ||
| /* defaultValue = */ | ||
| 0, | ||
| ) | ||
| if (dismissedAtEpoch > 0) context.appState.onNotificationAction( | ||
| NotificationAction.NotificationDismissed( | ||
| dismissedAt = Instant.fromEpochMilliseconds(dismissedAtEpoch), | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private val Context.appState | ||
| get() = (applicationContext as HeronApplication).appState | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's great that you've ignored the
releaseandstaginggoogle-services.jsonfiles, thedebugversion is being committed in this pull request. It's a security best practice to avoid committing any sensitive configuration files, even for debug builds with mock data. This prevents accidental exposure of real keys and establishes a good pattern for handling secrets. I recommend ignoring allgoogle-services.jsonfiles and providing a template file instead for developers to use.