Cleanup
This commit is contained in:
committed by
Benoit Marty
parent
c52ad084e9
commit
41e0249fbf
@@ -21,8 +21,8 @@ import com.google.firebase.messaging.RemoteMessage
|
||||
import io.element.android.libraries.architecture.bindings
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||
import io.element.android.libraries.push.impl.PushersManager
|
||||
import io.element.android.libraries.push.impl.push.PushHandler
|
||||
import io.element.android.libraries.push.impl.log.pushLoggerTag
|
||||
import io.element.android.libraries.push.impl.push.PushHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -33,12 +33,8 @@ private val loggerTag = LoggerTag("Firebase", pushLoggerTag)
|
||||
|
||||
class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
||||
@Inject lateinit var pushersManager: PushersManager
|
||||
|
||||
@Inject
|
||||
lateinit var pushParser: FirebasePushParser
|
||||
|
||||
@Inject
|
||||
lateinit var pushHandler: PushHandler
|
||||
@Inject lateinit var pushParser: FirebasePushParser
|
||||
@Inject lateinit var pushHandler: PushHandler
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
|
||||
@@ -56,8 +52,10 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
|
||||
|
||||
override fun onMessageReceived(message: RemoteMessage) {
|
||||
Timber.tag(loggerTag.value).d("New Firebase message")
|
||||
pushParser.parse(message.data).let {
|
||||
pushHandler.handle(it)
|
||||
coroutineScope.launch {
|
||||
pushParser.parse(message.data).let {
|
||||
pushHandler.handle(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,20 +32,19 @@ import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.push.api.store.PushDataStore
|
||||
import io.element.android.libraries.push.impl.PushersManager
|
||||
import io.element.android.libraries.push.impl.clientsecret.PushClientSecret
|
||||
import io.element.android.libraries.push.impl.log.pushLoggerTag
|
||||
import io.element.android.libraries.push.impl.notifications.NotifiableEventResolver
|
||||
import io.element.android.libraries.push.impl.notifications.NotificationActionIds
|
||||
import io.element.android.libraries.push.impl.notifications.NotificationDrawerManager
|
||||
import io.element.android.libraries.push.impl.log.pushLoggerTag
|
||||
import io.element.android.libraries.push.impl.store.DefaultPushDataStore
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
private val loggerTag = LoggerTag("Push", pushLoggerTag)
|
||||
private val loggerTag = LoggerTag("PushHandler", pushLoggerTag)
|
||||
|
||||
class PushHandler @Inject constructor(
|
||||
private val notificationDrawerManager: NotificationDrawerManager,
|
||||
@@ -73,16 +72,14 @@ class PushHandler @Inject constructor(
|
||||
*
|
||||
* @param pushData the data received in the push.
|
||||
*/
|
||||
fun handle(pushData: PushData) {
|
||||
suspend fun handle(pushData: PushData) {
|
||||
Timber.tag(loggerTag.value).d("## handling pushData")
|
||||
|
||||
if (buildMeta.lowPrivacyLoggingEnabled) {
|
||||
Timber.tag(loggerTag.value).d("## pushData: $pushData")
|
||||
}
|
||||
|
||||
runBlocking {
|
||||
defaultPushDataStore.incrementPushCounter()
|
||||
}
|
||||
defaultPushDataStore.incrementPushCounter()
|
||||
|
||||
// Diagnostic Push
|
||||
if (pushData.eventId == PushersManager.TEST_EVENT_ID) {
|
||||
@@ -91,6 +88,7 @@ class PushHandler @Inject constructor(
|
||||
return
|
||||
}
|
||||
|
||||
// TODO EAx Should be per user
|
||||
if (!pushDataStore.areNotificationEnabledForDevice()) {
|
||||
Timber.tag(loggerTag.value).i("Notification are disabled for this device")
|
||||
return
|
||||
@@ -141,7 +139,7 @@ class PushHandler @Inject constructor(
|
||||
// Restore session
|
||||
val session = matrixAuthenticationService.restoreSession(SessionId(userId)).getOrNull() ?: return
|
||||
// TODO EAx, no need for a session?
|
||||
val notificationData = session.use {
|
||||
val notificationData = session.let {// TODO Use make the app crashes
|
||||
it.notificationService().getNotification(
|
||||
userId = userId,
|
||||
roomId = pushData.roomId,
|
||||
|
||||
@@ -23,7 +23,9 @@ import io.element.android.libraries.architecture.bindings
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||
import io.element.android.libraries.push.api.model.BackgroundSyncMode
|
||||
import io.element.android.libraries.push.api.store.PushDataStore
|
||||
import io.element.android.libraries.push.impl.*
|
||||
import io.element.android.libraries.push.impl.PushersManager
|
||||
import io.element.android.libraries.push.impl.UnifiedPushHelper
|
||||
import io.element.android.libraries.push.impl.UnifiedPushStore
|
||||
import io.element.android.libraries.push.impl.log.pushLoggerTag
|
||||
import io.element.android.libraries.push.impl.push.PushHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -64,10 +66,12 @@ class VectorUnifiedPushMessagingReceiver : MessagingReceiver() {
|
||||
*/
|
||||
override fun onMessage(context: Context, message: ByteArray, instance: String) {
|
||||
Timber.tag(loggerTag.value).d("New message")
|
||||
pushParser.parse(message)?.let {
|
||||
pushHandler.handle(it)
|
||||
} ?: run {
|
||||
Timber.tag(loggerTag.value).w("Invalid received data Json format")
|
||||
coroutineScope.launch {
|
||||
pushParser.parse(message)?.let {
|
||||
pushHandler.handle(it)
|
||||
} ?: run {
|
||||
Timber.tag(loggerTag.value).w("Invalid received data Json format")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user