1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3636 Notifications | Firebase messaging service implementation (#2383)

This commit is contained in:
Konstantin Ivanov 2025-05-07 18:02:03 +02:00 committed by GitHub
parent 0e9a997998
commit 01638ff2f7
Signed by: github
GPG key ID: B5690EEEBB952194
26 changed files with 273 additions and 10 deletions

View file

@ -96,4 +96,8 @@ class AuthMiddleware(
override suspend fun debugExportLogs(dir: String): String {
return middleware.debugExportLogs(dir)
}
override suspend fun registerDeviceToken(command: Command.RegisterDeviceToken) {
middleware.registerDeviceToken(command = command)
}
}

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.middleware.interactor
import anytype.Event
import com.anytypeio.anytype.data.auth.event.PushKeyRemoteChannel
import com.anytypeio.anytype.data.auth.status.SyncAndP2PStatusEventsStore
import com.anytypeio.anytype.middleware.EventProxy
import java.io.IOException
@ -17,10 +18,14 @@ class EventHandler @Inject constructor(
private val logger: MiddlewareProtobufLogger,
private val scope: CoroutineScope,
private val channel: EventHandlerChannel,
private val syncP2PStore: SyncAndP2PStatusEventsStore
private val syncP2PStore: SyncAndP2PStatusEventsStore,
private val pushKeyRemoteChannel: PushKeyRemoteChannel
) : EventProxy {
init {
scope.launch {
pushKeyRemoteChannel.start()
}
scope.launch {
syncP2PStore.start()
}

View file

@ -2,6 +2,7 @@ package com.anytypeio.anytype.middleware.interactor
import anytype.Rpc
import anytype.Rpc.Chat.ReadMessages.ReadType
import anytype.Rpc.PushNotification.RegisterToken.Platform
import anytype.model.Block
import anytype.model.ParticipantPermissionChange
import anytype.model.Range
@ -2978,6 +2979,17 @@ class Middleware @Inject constructor(
return response.event.toPayload()
}
@Throws(Exception::class)
fun registerDeviceToken(command: Command.RegisterDeviceToken) {
val request = Rpc.PushNotification.RegisterToken.Request(
token = command.token,
platform = Platform.Android
)
logRequestIfDebug(request)
val (response, time) = measureTimedValue { service.pushNotificationRegisterToken(request) }
logResponseIfDebug(response, time)
}
private fun logRequestIfDebug(request: Any) {
if (BuildConfig.DEBUG) {
logger.logRequest(request).also {

View file

@ -634,4 +634,7 @@ interface MiddlewareService {
@Throws(Exception::class)
fun blockDataViewRelationSet(request: Rpc.BlockDataview.Relation.Set.Request): Rpc.BlockDataview.Relation.Set.Response
@Throws(Exception::class)
fun pushNotificationRegisterToken(request: Rpc.PushNotification.RegisterToken.Request): Rpc.PushNotification.RegisterToken.Response
}

View file

@ -2573,4 +2573,17 @@ class MiddlewareServiceImplementation @Inject constructor(
return response
}
}
override fun pushNotificationRegisterToken(request: Rpc.PushNotification.RegisterToken.Request): Rpc.PushNotification.RegisterToken.Response {
val encoded = Service.pushNotificationRegisterToken(
Rpc.PushNotification.RegisterToken.Request.ADAPTER.encode(request)
)
val response = Rpc.PushNotification.RegisterToken.Response.ADAPTER.decode(encoded)
val error = response.error
if (error != null && error.code != Rpc.PushNotification.RegisterToken.Response.Error.Code.NULL) {
throw Exception(error.description)
} else {
return response
}
}
}