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:
parent
0e9a997998
commit
01638ff2f7
26 changed files with 273 additions and 10 deletions
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue