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