mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3444 Chats | Enhancement | Bookmark flow updates (#2399)
This commit is contained in:
parent
191b675fc9
commit
1d8501f7a0
20 changed files with 282 additions and 15 deletions
|
@ -15,6 +15,7 @@ import com.anytypeio.anytype.core_models.DeviceNetworkType
|
|||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.LinkPreview
|
||||
import com.anytypeio.anytype.core_models.ManifestInfo
|
||||
import com.anytypeio.anytype.core_models.NodeUsageInfo
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
|
@ -1092,4 +1093,12 @@ class BlockMiddleware(
|
|||
override suspend fun setDataViewProperties(command: Command.SetDataViewProperties): Payload {
|
||||
return middleware.setDataViewProperties(command)
|
||||
}
|
||||
|
||||
override suspend fun getLinkPreview(url: Url): LinkPreview {
|
||||
return middleware.getLinkPreview(url)
|
||||
}
|
||||
|
||||
override suspend fun createObjectFromUrl(space: SpaceId, url: Url): ObjectWrapper.Basic {
|
||||
return middleware.createObjectFromUrl(space = space, url = url)
|
||||
}
|
||||
}
|
|
@ -22,9 +22,11 @@ import com.anytypeio.anytype.core_models.DeviceNetworkType
|
|||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.LinkPreview
|
||||
import com.anytypeio.anytype.core_models.ManifestInfo
|
||||
import com.anytypeio.anytype.core_models.NodeUsageInfo
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
|
||||
import com.anytypeio.anytype.core_models.ObjectView
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
|
@ -64,6 +66,7 @@ import com.anytypeio.anytype.middleware.mappers.core
|
|||
import com.anytypeio.anytype.middleware.mappers.mw
|
||||
import com.anytypeio.anytype.middleware.mappers.parse
|
||||
import com.anytypeio.anytype.middleware.mappers.toCore
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreLinkPreview
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModel
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModelSearchResults
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModels
|
||||
|
@ -2990,6 +2993,28 @@ class Middleware @Inject constructor(
|
|||
logResponseIfDebug(response, time)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun getLinkPreview(url: Url): LinkPreview {
|
||||
val request = Rpc.LinkPreview.Request(url = url)
|
||||
logRequestIfDebug(request)
|
||||
val (response, time) = measureTimedValue { service.linkPreview(request) }
|
||||
logResponseIfDebug(response, time)
|
||||
return response.linkPreview?.toCoreLinkPreview() ?: throw Exception("MW return empty link preview")
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun createObjectFromUrl(space: SpaceId, url: Url) : ObjectWrapper.Basic {
|
||||
val request = Rpc.Object.CreateFromUrl.Request(
|
||||
url = url,
|
||||
spaceId = space.id,
|
||||
objectTypeUniqueKey = ObjectTypeUniqueKeys.BOOKMARK
|
||||
)
|
||||
logRequestIfDebug(request)
|
||||
val (response, time) = measureTimedValue { service.objectCreateFromUrl(request) }
|
||||
logResponseIfDebug(response, time)
|
||||
return ObjectWrapper.Basic(response.details.orEmpty())
|
||||
}
|
||||
|
||||
private fun logRequestIfDebug(request: Any) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
logger.logRequest(request).also {
|
||||
|
|
|
@ -112,4 +112,6 @@ typealias MP2PStatus = anytype.Event.P2PStatus.Status
|
|||
typealias MP2PStatusUpdate = P2PStatus.Update
|
||||
typealias MSyncStatusUpdate = Space.SyncStatus.Update
|
||||
|
||||
typealias MDeviceNetworkType = anytype.model.DeviceNetworkType
|
||||
typealias MDeviceNetworkType = anytype.model.DeviceNetworkType
|
||||
|
||||
typealias MLinkPreview = anytype.model.LinkPreview
|
|
@ -3,7 +3,6 @@ package com.anytypeio.anytype.middleware.mappers
|
|||
import anytype.ResponseEvent
|
||||
import anytype.Rpc
|
||||
import anytype.model.Account
|
||||
import anytype.model.ChatState
|
||||
import anytype.model.NameserviceNameType
|
||||
import anytype.model.ParticipantPermissions
|
||||
import anytype.model.Restrictions
|
||||
|
@ -28,6 +27,7 @@ import com.anytypeio.anytype.core_models.DVViewerType
|
|||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ImportErrorCode
|
||||
import com.anytypeio.anytype.core_models.LinkPreview
|
||||
import com.anytypeio.anytype.core_models.ManifestInfo
|
||||
import com.anytypeio.anytype.core_models.NodeUsage
|
||||
import com.anytypeio.anytype.core_models.NodeUsageInfo
|
||||
|
@ -1207,4 +1207,14 @@ fun Rpc.Relation.ListWithValue.Response.ResponseItem.toCoreModel(): RelationList
|
|||
key = RelationKey(key = relationKey),
|
||||
counter = counter
|
||||
)
|
||||
}
|
||||
|
||||
fun MLinkPreview.toCoreLinkPreview(): LinkPreview {
|
||||
return LinkPreview(
|
||||
url = url,
|
||||
faviconUrl = faviconUrl,
|
||||
imageUrl = imageUrl,
|
||||
description = description,
|
||||
title = title
|
||||
)
|
||||
}
|
|
@ -637,4 +637,10 @@ interface MiddlewareService {
|
|||
|
||||
@Throws(Exception::class)
|
||||
fun pushNotificationRegisterToken(request: Rpc.PushNotification.RegisterToken.Request): Rpc.PushNotification.RegisterToken.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun linkPreview(request: Rpc.LinkPreview.Request) : Rpc.LinkPreview.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun objectCreateFromUrl(request: Rpc.Object.CreateFromUrl.Request): Rpc.Object.CreateFromUrl.Response
|
||||
}
|
|
@ -2586,4 +2586,30 @@ class MiddlewareServiceImplementation @Inject constructor(
|
|||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun linkPreview(request: Rpc.LinkPreview.Request): Rpc.LinkPreview.Response {
|
||||
val encoded = Service.linkPreview(
|
||||
Rpc.LinkPreview.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.LinkPreview.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.LinkPreview.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun objectCreateFromUrl(request: Rpc.Object.CreateFromUrl.Request): Rpc.Object.CreateFromUrl.Response {
|
||||
val encoded = Service.objectCreateFromUrl(
|
||||
Rpc.Object.CreateFromUrl.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.Object.CreateFromUrl.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.Object.CreateFromUrl.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue