Improve push notifications (#4896)
Besides the refactoring these improvements: * Track last push distributor and reset settings and subscription on any incompatible change (ie. uninstall) * Only update (push) notification settings on server if needed * Allow to only fetch notifications for one account (the one for which a push message was received) This is (also) the revival of https://github.com/tuskyapp/Tusky/pull/3642 It's not really well tested so far. (Ie. with two or more accounts or two or more push providers.)
This commit is contained in:
parent
f95dbe82b0
commit
6450af6edb
14 changed files with 274 additions and 127 deletions
|
|
@ -27,6 +27,7 @@ import com.keylesspalace.tusky.appstore.NewNotificationsEvent
|
|||
import com.keylesspalace.tusky.appstore.NotificationsLoadingEvent
|
||||
import com.keylesspalace.tusky.components.systemnotifications.NotificationService
|
||||
import com.keylesspalace.tusky.db.AccountManager
|
||||
import com.keylesspalace.tusky.db.entity.AccountEntity
|
||||
import com.keylesspalace.tusky.entity.Emoji
|
||||
import com.keylesspalace.tusky.entity.Notification
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
|
|
@ -97,10 +98,10 @@ class MainViewModel @Inject constructor(
|
|||
|
||||
shareShortcutHelper.updateShortcuts()
|
||||
|
||||
setupNotifications()
|
||||
setupNotifications(activeAccount)
|
||||
},
|
||||
{ throwable ->
|
||||
Log.w(TAG, "Failed to fetch user info.", throwable)
|
||||
Log.e(TAG, "Failed to fetch user info.", throwable)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -160,15 +161,24 @@ class MainViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun setupNotifications() {
|
||||
notificationService.createNotificationChannelsForAccount(activeAccount)
|
||||
fun setupNotifications(account: AccountEntity? = null) {
|
||||
// TODO this is only called on full app (re) start; so changes in-between (push distributor uninstalled/subscription changed, or
|
||||
// notifications fully disabled) will get unnoticed; and also an app restart cannot be easily triggered by the user.
|
||||
|
||||
if (notificationService.areNotificationsEnabled()) {
|
||||
if (account != null) {
|
||||
// TODO it's quite odd to separate channel creation (for an account) from the "is enabled by channels" question below
|
||||
|
||||
notificationService.createNotificationChannelsForAccount(account)
|
||||
}
|
||||
|
||||
if (notificationService.areNotificationsEnabledBySystem()) {
|
||||
viewModelScope.launch {
|
||||
notificationService.enablePushNotificationsWithFallback()
|
||||
notificationService.setupNotifications(account)
|
||||
}
|
||||
} else {
|
||||
notificationService.disableAllNotifications()
|
||||
viewModelScope.launch {
|
||||
notificationService.disableAllNotifications()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue