mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1882 Sharing Extension | Enhancement | Add origin source when adding content from sharing extension (#713)
This commit is contained in:
parent
e8af8c958b
commit
33215bae63
9 changed files with 52 additions and 18 deletions
|
@ -0,0 +1,12 @@
|
|||
package com.anytypeio.anytype.core_models
|
||||
|
||||
enum class ObjectOrigin(val code: Int) {
|
||||
NONE(0),
|
||||
CLIPBOARD(1),
|
||||
DRAG_AND_DROP(2),
|
||||
IMPORT(3),
|
||||
WEB_CLIPPER(4),
|
||||
SHARING_EXTENSION(5),
|
||||
USE_CASE(6),
|
||||
BUILT_IN(7)
|
||||
}
|
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVSort
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.FileLimits
|
||||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
|
@ -209,10 +208,12 @@ class BlockDataRepository(
|
|||
|
||||
override suspend fun createBookmarkObject(
|
||||
space: Id,
|
||||
url: Url
|
||||
url: Url,
|
||||
details: Struct
|
||||
): Id = remote.createBookmarkObject(
|
||||
space = space,
|
||||
url = url
|
||||
url = url,
|
||||
details = details
|
||||
)
|
||||
|
||||
override suspend fun fetchBookmarkObject(ctx: Id, url: Url) = remote.fetchBookmarkObject(
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVSort
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.FileLimits
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.NodeUsageInfo
|
||||
|
@ -72,7 +71,7 @@ interface BlockRemote {
|
|||
suspend fun uploadBlock(command: Command.UploadBlock): Payload
|
||||
suspend fun setupBookmark(command: Command.SetupBookmark): Payload
|
||||
suspend fun createAndFetchBookmarkBlock(command: Command.CreateBookmark): Payload
|
||||
suspend fun createBookmarkObject(space: Id, url: Url): Id
|
||||
suspend fun createBookmarkObject(space: Id, url: Url, details: Struct): Id
|
||||
suspend fun fetchBookmarkObject(ctx: Id, url: Url)
|
||||
suspend fun undo(command: Command.Undo): Payload
|
||||
suspend fun importUseCaseSkip(space: Id)
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVSort
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.FileLimits
|
||||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
|
@ -127,7 +126,7 @@ interface BlockRepository {
|
|||
/**
|
||||
* Creates bookmark object from url and returns its id.
|
||||
*/
|
||||
suspend fun createBookmarkObject(space: Id, url: Url): Id
|
||||
suspend fun createBookmarkObject(space: Id, url: Url, details: Struct): Id
|
||||
|
||||
suspend fun fetchBookmarkObject(ctx: Id, url: Url)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.anytypeio.anytype.domain.objects
|
||||
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.Url
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
|
@ -16,12 +17,14 @@ class CreateBookmarkObject @Inject constructor(
|
|||
override suspend fun run(params: Params) = safe {
|
||||
repo.createBookmarkObject(
|
||||
space = params.space,
|
||||
url = params.url
|
||||
url = params.url,
|
||||
details = params.details
|
||||
)
|
||||
}
|
||||
|
||||
data class Params(
|
||||
val space: Id,
|
||||
val url: Url
|
||||
val url: Url,
|
||||
val details: Struct = emptyMap()
|
||||
)
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.anytypeio.anytype.core_models.Id
|
|||
import com.anytypeio.anytype.core_models.NO_VALUE
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
|
||||
import com.anytypeio.anytype.core_models.Position
|
||||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.core_models.primitives.TypeKey
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
|
@ -25,7 +26,7 @@ class CreatePrefilledNote @Inject constructor(
|
|||
space = SpaceId(params.space),
|
||||
template = null,
|
||||
internalFlags = emptyList(),
|
||||
prefilled = emptyMap()
|
||||
prefilled = params.details
|
||||
)
|
||||
)
|
||||
repo.create(
|
||||
|
@ -42,5 +43,9 @@ class CreatePrefilledNote @Inject constructor(
|
|||
return obj.id
|
||||
}
|
||||
|
||||
data class Params(val space: Id, val text: String)
|
||||
data class Params(
|
||||
val space: Id,
|
||||
val text: String,
|
||||
val details: Struct
|
||||
)
|
||||
}
|
|
@ -10,7 +10,6 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVSort
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.FileLimits
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
import com.anytypeio.anytype.core_models.NodeUsageInfo
|
||||
|
@ -174,10 +173,11 @@ class BlockMiddleware(
|
|||
): Payload = middleware.blockBookmarkCreateAndFetch(command)
|
||||
|
||||
override suspend fun createBookmarkObject(
|
||||
space: Id, url: Url
|
||||
space: Id, url: Url, details: Struct
|
||||
): Id = middleware.objectCreateBookmark(
|
||||
space = space,
|
||||
url = url
|
||||
url = url,
|
||||
details = details
|
||||
)
|
||||
|
||||
override suspend fun fetchBookmarkObject(
|
||||
|
|
|
@ -903,9 +903,16 @@ class Middleware @Inject constructor(
|
|||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun objectCreateBookmark(space: Id, url: Url): Id {
|
||||
fun objectCreateBookmark(
|
||||
space: Id,
|
||||
url: Url,
|
||||
details: Struct
|
||||
): Id {
|
||||
val request = Rpc.Object.CreateBookmark.Request(
|
||||
details = mapOf(Relations.SOURCE to url),
|
||||
details = buildMap {
|
||||
put(Relations.SOURCE, url)
|
||||
putAll(details)
|
||||
},
|
||||
spaceId = space
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
|
|
|
@ -4,7 +4,9 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anytypeio.anytype.core_models.NO_VALUE
|
||||
import com.anytypeio.anytype.core_models.ObjectOrigin
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_utils.ext.msg
|
||||
import com.anytypeio.anytype.domain.base.fold
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
|
@ -75,7 +77,10 @@ class AddToAnytypeViewModel(
|
|||
createBookmarkObject(
|
||||
CreateBookmarkObject.Params(
|
||||
space = targetSpace,
|
||||
url = url
|
||||
url = url,
|
||||
details = mapOf(
|
||||
Relations.ORIGIN to ObjectOrigin.SHARING_EXTENSION.code.toDouble()
|
||||
)
|
||||
)
|
||||
).process(
|
||||
success = { obj ->
|
||||
|
@ -107,7 +112,10 @@ class AddToAnytypeViewModel(
|
|||
createPrefilledNote.async(
|
||||
CreatePrefilledNote.Params(
|
||||
text = text,
|
||||
space = targetSpace
|
||||
space = targetSpace,
|
||||
details = mapOf(
|
||||
Relations.ORIGIN to ObjectOrigin.SHARING_EXTENSION.code.toDouble()
|
||||
)
|
||||
)
|
||||
).fold(
|
||||
onSuccess = { result ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue