UnifiedPush WIP
This commit is contained in:
parent
8f565edb0a
commit
287fca5438
33 changed files with 376 additions and 215 deletions
|
|
@ -23,5 +23,6 @@ object FirebaseConfig {
|
|||
*/
|
||||
const val pusher_http_url: String = "https://matrix.org/_matrix/push/v1/notify"
|
||||
|
||||
const val internalName = "NOTIFICATION_METHOD_FIREBASE"
|
||||
const val index = 0
|
||||
const val name = "Firebase"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class FirebaseNewTokenHandler @Inject constructor(
|
|||
// Register the pusher for all the sessions
|
||||
sessionStore.getAllSessions().toUserList().forEach { userId ->
|
||||
val userDataStore = userPushStoreFactory.create(userId)
|
||||
if (userDataStore.getNotificationMethod() == FirebaseConfig.internalName) {
|
||||
if (userDataStore.getPushProviderName() == FirebaseConfig.name) {
|
||||
matrixAuthenticationService.restoreSession(SessionId(userId)).getOrNull()?.use { client ->
|
||||
pusherSubscriber.registerPusher(client, firebaseToken, FirebaseConfig.pusher_http_url)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.element.android.libraries.push.providers.firebase
|
|||
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.push.providers.api.Distributor
|
||||
import io.element.android.libraries.push.providers.api.PushProvider
|
||||
import io.element.android.libraries.push.providers.api.PusherSubscriber
|
||||
import timber.log.Timber
|
||||
|
|
@ -30,20 +31,27 @@ class FirebasePushProvider @Inject constructor(
|
|||
private val firebaseTroubleshooter: FirebaseTroubleshooter,
|
||||
private val pusherSubscriber: PusherSubscriber,
|
||||
) : PushProvider {
|
||||
override val index = 0
|
||||
override val index = FirebaseConfig.index
|
||||
override val name = FirebaseConfig.name
|
||||
|
||||
override fun getDistributorNames(): List<String> {
|
||||
// Must return an non-empty list for now
|
||||
return listOf("unused")
|
||||
override fun getDistributors(): List<Distributor> {
|
||||
return listOf(Distributor("Firebase", "Firebase"))
|
||||
}
|
||||
|
||||
override suspend fun registerWith(matrixClient: MatrixClient, distributorName: String) {
|
||||
override suspend fun registerWith(matrixClient: MatrixClient, distributor: Distributor, clientSecret: String) {
|
||||
val pushKey = firebaseStore.getFcmToken() ?: return Unit.also {
|
||||
Timber.tag(loggerTag.value).w("Unable to register pusher, Firebase token is not known.")
|
||||
}
|
||||
pusherSubscriber.registerPusher(matrixClient, pushKey, FirebaseConfig.pusher_http_url)
|
||||
}
|
||||
|
||||
override suspend fun unregister(matrixClient: MatrixClient) {
|
||||
val pushKey = firebaseStore.getFcmToken() ?: return Unit.also {
|
||||
Timber.tag(loggerTag.value).w("Unable to unregister pusher, Firebase token is not known.")
|
||||
}
|
||||
pusherSubscriber.unregisterPusher(matrixClient, pushKey, FirebaseConfig.pusher_http_url)
|
||||
}
|
||||
|
||||
override suspend fun troubleshoot(): Result<Unit> {
|
||||
return firebaseTroubleshooter.troubleshoot()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue