Small cleanup

This commit is contained in:
Benoit Marty 2022-06-01 18:15:50 +02:00 committed by Benoit Marty
parent bbbeb4b283
commit 45768c5251

View File

@ -26,8 +26,6 @@ import androidx.lifecycle.ProcessLifecycleOwner
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.squareup.moshi.Json import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.BuildConfig import im.vector.app.BuildConfig
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
@ -48,6 +46,7 @@ import org.matrix.android.sdk.api.logger.LoggerTag
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.getRoom
import org.matrix.android.sdk.api.session.room.getTimelineEvent import org.matrix.android.sdk.api.session.room.getTimelineEvent
import org.matrix.android.sdk.api.util.MatrixJsonParser
import org.unifiedpush.android.connector.MessagingReceiver import org.unifiedpush.android.connector.MessagingReceiver
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -113,20 +112,15 @@ class VectorMessagingReceiver : MessagingReceiver() {
vectorDataStore.incrementPushCounter() vectorDataStore.incrementPushCounter()
} }
val moshi: Moshi = Moshi.Builder() val moshi = MatrixJsonParser.getMoshi()
.add(KotlinJsonAdapterFactory()) val notification: Notification = if (unifiedPushHelper.isEmbeddedDistributor()) {
.build() moshi.adapter(Notification::class.java).fromJson(sMessage)
lateinit var notification: Notification
if (unifiedPushHelper.isEmbeddedDistributor()) {
notification = moshi.adapter(Notification::class.java)
.fromJson(sMessage) ?: return
} else { } else {
val data = moshi.adapter(UnifiedPushMessage::class.java) val data = moshi.adapter(UnifiedPushMessage::class.java).fromJson(sMessage)
.fromJson(sMessage) ?: return data?.notification?.also {
notification = data.notification it.unread = it.counts.unread
notification.unread = notification.counts.unread
} }
} ?: return Unit.also { Timber.w("Invalid received data") }
// Diagnostic Push // Diagnostic Push
if (notification.eventId == PushersManager.TEST_EVENT_ID) { if (notification.eventId == PushersManager.TEST_EVENT_ID) {