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

DROID-318 Tech | Enhancement | MW 0.22.1 (#2538)

This commit is contained in:
Evgenii Kozlov 2022-08-18 17:49:57 +03:00 committed by GitHub
parent 8e722e2f1d
commit 8c5ddd67ac
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 190 additions and 100 deletions

View file

@ -331,7 +331,7 @@ data class Block(
val relationKey: String,
val type: Type
) {
enum class Type { ASC, DESC }
enum class Type { ASC, DESC, CUSTOM }
}
data class Filter(

View file

@ -3,6 +3,6 @@ package com.anytypeio.anytype.core_models
data class FeaturesConfig(
val enableDataView: Boolean? = null,
val enableDebug: Boolean? = null,
val enableChannelSwitch: Boolean? = null,
val enablePrereleaseChannel: Boolean? = null,
val enableSpaces: Boolean? = null
)

View file

@ -11,7 +11,7 @@ class DefaultFeaturesConfigProvider : FeaturesConfigProvider {
private var config: FeaturesConfig = FeaturesConfig(
enableDataView = false,
enableDebug = false,
enableChannelSwitch = false,
enablePrereleaseChannel = false,
enableSpaces = false
)
@ -26,7 +26,7 @@ class DefaultFeaturesConfigProvider : FeaturesConfigProvider {
config = FeaturesConfig(
enableDataView = enableDataView,
enableDebug = enableDebug,
enableChannelSwitch = enableChannelSwitch,
enablePrereleaseChannel = enableChannelSwitch,
enableSpaces = enableSpaces
)
}

View file

@ -20,7 +20,7 @@ fun FeaturesConfigEntity.toDomain(): FeaturesConfig {
return FeaturesConfig(
enableDataView = enableDataView,
enableDebug = enableDebug,
enableChannelSwitch = enableChannelSwitch,
enablePrereleaseChannel = enableChannelSwitch,
enableSpaces = enableSpaces
)
}

View file

@ -86,7 +86,7 @@ ext {
// Anytype
middleware_version = 'v0.21.4'
middleware_version = 'v0.22.1'
mainApplication = [
kotlin: "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version",

View file

@ -29,7 +29,7 @@ class LaunchAccount(
featuresConfigProvider.set(
enableDataView = setup.features.enableDataView ?: false,
enableDebug = setup.features.enableDebug ?: false,
enableChannelSwitch = setup.features.enableChannelSwitch ?: false,
enableChannelSwitch = setup.features.enablePrereleaseChannel ?: false,
enableSpaces = setup.features.enableSpaces ?: false
)
configStorage.set(config = setup.config)

View file

@ -27,7 +27,7 @@ class ResumeAccount(
featuresConfigProvider.set(
enableDataView = setup.features.enableDataView ?: false,
enableDebug = setup.features.enableDebug ?: false,
enableChannelSwitch = setup.features.enableChannelSwitch ?: false,
enableChannelSwitch = setup.features.enablePrereleaseChannel ?: false,
enableSpaces = setup.features.enableSpaces ?: false
)
configStorage.set(config = setup.config)

View file

@ -27,7 +27,7 @@ class StartAccount(
featuresConfigProvider.set(
enableDataView = setup.features.enableDataView ?: false,
enableDebug = setup.features.enableDebug ?: false,
enableChannelSwitch = setup.features.enableChannelSwitch ?: false,
enableChannelSwitch = setup.features.enablePrereleaseChannel ?: false,
enableSpaces = setup.features.enableSpaces ?: false
)
configStorage.set(config = setup.config)

View file

@ -80,7 +80,7 @@ class StartAccountTest {
val featuresConfig = FeaturesConfig(
enableDataView = false,
enableDebug = false,
enableChannelSwitch = false
enablePrereleaseChannel = false
)
repo.stub {
@ -132,7 +132,7 @@ class StartAccountTest {
val featuresConfig = FeaturesConfig(
enableDataView = false,
enableDebug = false,
enableChannelSwitch = false
enablePrereleaseChannel = false
)
repo.stub {
@ -175,7 +175,7 @@ class StartAccountTest {
val featuresConfig = FeaturesConfig(
enableDataView = null,
enableDebug = null,
enableChannelSwitch = null
enablePrereleaseChannel = null
)
repo.stub {
@ -225,7 +225,7 @@ class StartAccountTest {
val featuresConfig = FeaturesConfig(
enableDataView = true,
enableDebug = false,
enableChannelSwitch = true
enablePrereleaseChannel = true
)
repo.stub {

View file

@ -27,7 +27,7 @@ fun Rpc.Account.Create.Response.toAccountSetup() : AccountSetup {
features = FeaturesConfig(
enableDataView = configuration.enableDataview,
enableDebug = configuration.enableDebug,
enableChannelSwitch = configuration.enableReleaseChannelSwitch,
enablePrereleaseChannel = configuration.enablePrereleaseChannel,
enableSpaces = configuration.enableSpaces
),
config = Config(
@ -59,7 +59,7 @@ fun Rpc.Account.Select.Response.toAccountSetup(): AccountSetup {
features = FeaturesConfig(
enableDataView = configuration.enableDataview,
enableDebug = configuration.enableDebug,
enableChannelSwitch = configuration.enableReleaseChannelSwitch,
enablePrereleaseChannel = configuration.enablePrereleaseChannel,
enableSpaces = configuration.enableSpaces
),
config = Config(

View file

@ -868,7 +868,8 @@ class Middleware(
val response = service.objectOpen(request)
if (BuildConfig.DEBUG) logResponse(response)
return response.event.toPayload()
return response.objectView?.toPayload()
?: throw IllegalStateException("Object view was null")
}
@Throws(Exception::class)
@ -1112,7 +1113,8 @@ class Middleware(
val response = service.objectOpen(request)
if (BuildConfig.DEBUG) logResponse(response)
return response.event.toPayload()
return response.objectView?.toPayload()
?: throw IllegalStateException("Object view was null")
}
@Throws(Exception::class)
@ -1566,8 +1568,7 @@ class Middleware(
if (BuildConfig.DEBUG) logRequest(request)
val response = service.objectShow(request)
if (BuildConfig.DEBUG) logResponse(response)
return response.event.toPayload()
return response.objectView?.toPayload() ?: throw IllegalStateException("Object view was null")
}
@Throws(Exception::class)
@ -1702,5 +1703,4 @@ class Middleware(
val message = "<=== " + any::class.java.canonicalName + ":" + "\n" + any.toString()
Timber.d(message)
}
}

View file

@ -14,7 +14,6 @@ class MiddlewareEventChannel(
private fun filter(msg: anytype.Event.Message): Boolean {
// TODO move to class property, also we should log non filtered events
val events = listOf(
msg.objectShow,
msg.blockAdd,
msg.blockSetText,
msg.blockSetChildrenIds,

View file

@ -19,28 +19,6 @@ fun anytype.Event.Message.toCoreModels(
blocks = event.blocks.toCoreModels()
)
}
objectShow != null -> {
val event = objectShow
checkNotNull(event)
val type = event.type.toCoreModel()
Event.Command.ShowObject(
context = context,
root = event.rootId,
blocks = event.blocks.toCoreModels(
types = mapOf(event.rootId to type)
),
details = Block.Details(
event.details.associate { details ->
details.id to details.details.toCoreModel()
}
),
type = type,
objectTypes = event.objectTypes.map { it.toCoreModels() },
relations = event.relations.map { it.toCoreModels() },
objectRestrictions = event.restrictions?.object_?.mapNotNull { it.toCoreModel() }.orEmpty(),
dataViewRestrictions = event.restrictions?.dataview?.map { it.toCoreModel() }.orEmpty()
)
}
blockSetText != null -> {
val event = blockSetText
checkNotNull(event)

View file

@ -4,6 +4,7 @@ typealias MAccount = anytype.model.Account
typealias MAccountStatus = anytype.model.Account.Status
typealias MAccountStatusType = anytype.model.Account.StatusType
typealias MBlock = anytype.model.Block
typealias MObjectView = anytype.model.ObjectView
typealias MBText = anytype.model.Block.Content.Text
typealias MBTextStyle = anytype.model.Block.Content.Text.Style
typealias MBMarks = anytype.model.Block.Content.Text.Marks

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.middleware.mappers
import anytype.ResponseEvent
import anytype.Rpc
import anytype.model.ObjectInfo
import anytype.model.ObjectInfoWithLinks
import anytype.model.ObjectLinksInfo
@ -22,6 +23,32 @@ fun ResponseEvent?.toPayload(): Payload {
)
}
fun MObjectView.toPayload() : Payload {
val type = type.toCoreModel()
return Payload(
context = rootId,
events = listOf(
Event.Command.ShowObject(
context = rootId,
root = rootId,
blocks = blocks.toCoreModels(
types = mapOf(rootId to type)
),
details = Block.Details(
details.associate { details ->
details.id to details.details.toCoreModel()
}
),
type = type,
objectTypes = objectTypes.map { it.toCoreModels() },
relations = relations.map { it.toCoreModels() },
objectRestrictions = restrictions?.object_?.mapNotNull { it.toCoreModel() }.orEmpty(),
dataViewRestrictions = restrictions?.dataview?.map { it.toCoreModel() }.orEmpty()
)
)
)
}
// ---------------------- BLOCKS ------------------------
fun List<MBlock>.toCoreModels(
@ -514,6 +541,7 @@ fun MDVSort.toCoreModels(): Block.Content.DataView.Sort = DVSort(
fun MDVSortType.toCoreModels(): DVSortType = when (this) {
MDVSortType.Asc -> DVSortType.ASC
MDVSortType.Desc -> DVSortType.DESC
MDVSortType.Custom -> DVSortType.CUSTOM
}

View file

@ -338,6 +338,7 @@ fun Block.Content.DataView.Sort.toMiddlewareModel(): MDVSort =
fun Block.Content.DataView.Sort.Type.toMiddlewareModel(): MDVSortType = when (this) {
Block.Content.DataView.Sort.Type.ASC -> MDVSortType.Asc
Block.Content.DataView.Sort.Type.DESC -> MDVSortType.Desc
Block.Content.DataView.Sort.Type.CUSTOM -> MDVSortType.Custom
}
fun Block.Content.DataView.Filter.toMiddlewareModel(): MDVFilter =

View file

@ -2,6 +2,7 @@ package com.anytypeio.anytype
import anytype.model.Block
import com.anytypeio.anytype.core_models.Event
import com.anytypeio.anytype.core_models.ThemeColor
import com.anytypeio.anytype.middleware.EventProxy
import com.anytypeio.anytype.middleware.interactor.MiddlewareEventChannel
import com.anytypeio.anytype.middleware.mappers.MSmartBlockType
@ -33,14 +34,16 @@ class MiddlewareEventChannelTest {
fun `should filter event by context and pass it downstream`() {
val context = MockDataFactory.randomUuid()
val id = MockDataFactory.randomUuid()
val msg = anytype.Event.Object.Show(
rootId = context,
blocks = emptyList(),
type = MSmartBlockType.Page
val msg = anytype.Event.Block.Set.BackgroundColor(
id = id,
backgroundColor = ThemeColor.YELLOW.code
)
val message = anytype.Event.Message(objectShow = msg)
val message = anytype.Event.Message(
blockSetBackgroundColor = msg
)
val event = anytype.Event(contextId = context, messages = listOf(message))
@ -49,10 +52,10 @@ class MiddlewareEventChannelTest {
}
val expected = listOf(
Event.Command.ShowObject(
root = context,
blocks = emptyList(),
context = context
Event.Command.GranularChange(
id = id,
context = context,
backgroundColor = ThemeColor.YELLOW.code
)
)
@ -71,12 +74,13 @@ class MiddlewareEventChannelTest {
val context = MockDataFactory.randomUuid()
val msg = anytype.Event.Object.Show(
rootId = MockDataFactory.randomString(),
blocks = emptyList()
val msg = anytype.Event.Block.Set.BackgroundColor(
backgroundColor = ThemeColor.YELLOW.code
)
val message = anytype.Event.Message(objectShow = msg)
val message = anytype.Event.Message(
blockSetBackgroundColor = msg
)
val event = anytype.Event(contextId = MockDataFactory.randomUuid(), messages = listOf(message))
@ -98,14 +102,16 @@ class MiddlewareEventChannelTest {
fun `should pass event downstream if context for filtering is not provided`() {
val context = MockDataFactory.randomUuid()
val id = MockDataFactory.randomUuid()
val msg = anytype.Event.Object.Show(
rootId = context,
blocks = emptyList(),
type = MSmartBlockType.Page
val msg = anytype.Event.Block.Set.BackgroundColor(
id = id,
backgroundColor = ThemeColor.YELLOW.code
)
val message = anytype.Event.Message(objectShow = msg)
val message = anytype.Event.Message(
blockSetBackgroundColor = msg
)
val event = anytype.Event(contextId = context, messages = listOf(message))
@ -114,10 +120,10 @@ class MiddlewareEventChannelTest {
}
val expected = listOf(
Event.Command.ShowObject(
root = context,
blocks = emptyList(),
context = context
Event.Command.GranularChange(
id = id,
context = context,
backgroundColor = ThemeColor.YELLOW.code
)
)

View file

@ -532,6 +532,7 @@ fun Markup.Mark.mark(): Block.Content.Text.Mark = when (this) {
fun Block.Content.DataView.Sort.Type.toView(): Viewer.SortType = when (this) {
Block.Content.DataView.Sort.Type.ASC -> Viewer.SortType.ASC
Block.Content.DataView.Sort.Type.DESC -> Viewer.SortType.DESC
Block.Content.DataView.Sort.Type.CUSTOM -> Viewer.SortType.CUSTOM
}
fun DVFilterOperator.toView(): Viewer.FilterOperator = when (this) {
@ -600,6 +601,7 @@ fun SortingExpression.toDomain(): DVSort = DVSort(
type = when (type) {
Viewer.SortType.ASC -> Block.Content.DataView.Sort.Type.ASC
Viewer.SortType.DESC -> Block.Content.DataView.Sort.Type.DESC
Viewer.SortType.CUSTOM -> Block.Content.DataView.Sort.Type.CUSTOM
}
)

View file

@ -127,7 +127,7 @@ sealed class Viewer {
}
}
enum class SortType { ASC, DESC }
enum class SortType { ASC, DESC, CUSTOM }
enum class FilterOperator { And, Or }
sealed class Filter {

View file

@ -8,6 +8,14 @@ import "localstore.proto";
import "events.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/descriptor.proto";
// To disable authorization in specific method use no_auth option inside Request of that method
extend google.protobuf.MessageOptions {
optional bool no_auth = 7777;
}
/*
* Rpc is a namespace, that agregates all of the service commands between client and middleware.
* Structure: Topic > Subtopic > Subsub... > Action > (Request, Response).
@ -97,6 +105,7 @@ message Rpc {
* Front-end-to-middleware request to create a new wallet
*/
message Request {
option (no_auth) = true;
string rootPath = 1; // Path to a wallet directory
}
@ -128,6 +137,8 @@ message Rpc {
* Front end to middleware request-to-recover-a wallet with this mnemonic and a rootPath
*/
message Request {
option (no_auth) = true;
string rootPath = 1; // Path to a wallet directory
string mnemonic = 2; // Mnemonic of a wallet to recover
}
@ -177,13 +188,57 @@ message Rpc {
}
}
message CreateSession {
message Request {
option (no_auth) = true;
string mnemonic = 1;
}
message Response {
Error error = 1;
string token = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
}
}
}
}
message CloseSession {
message Request {
string token = 1;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
}
}
}
}
}
message Account {
message Config {
bool enableDataview = 1;
bool enableDebug = 2;
bool enableReleaseChannelSwitch = 3;
bool enablePrereleaseChannel = 3;
bool enableSpaces = 4;
google.protobuf.Struct extra = 100;
@ -194,6 +249,8 @@ message Rpc {
* Front end to middleware request-to-create-an account
*/
message Request {
option (no_auth) = true;
string name = 1; // Account name
oneof avatar {
string avatarLocalPath = 2; // Path to an image, that will be used as an avatar of this account
@ -304,6 +361,7 @@ message Rpc {
* User can select an account from those, that came with an AccountAdd events
*/
message Request {
option (no_auth) = true;
string id = 1; // Id of a selected account
string rootPath = 2; // Root path is optional, set if this is a first request
}
@ -613,7 +671,7 @@ message Rpc {
message Response {
Error error = 1;
ResponseEvent event = 2;
model.ObjectView objectView = 2;
message Error {
Code code = 1;
@ -664,7 +722,7 @@ message Rpc {
message Response {
Error error = 1;
ResponseEvent event = 2;
model.ObjectView objectView = 2;
message Error {
Code code = 1;
@ -839,6 +897,7 @@ message Rpc {
Error error = 1;
string objectId = 2;
ResponseEvent event = 3;
model.ObjectView objectView = 4;
message Error {
Code code = 1;
@ -1927,7 +1986,7 @@ message Rpc {
message Response {
Error error = 1;
Event.Object.Show objectShow = 2;
model.ObjectView objectView = 2;
History.Version version = 3;
string traceId = 4;
@ -4632,6 +4691,7 @@ message Rpc {
message Metrics {
message SetParameters {
message Request {
option (no_auth) = true;
string platform = 1;
}
@ -4730,3 +4790,7 @@ message Rpc {
message Empty {
}
message StreamRequest {
string token = 1;
}

View file

@ -29,7 +29,6 @@ message Event {
Object.Relations.Remove objectRelationsRemove = 53;
Object.Remove objectRemove = 54;
Object.Show objectShow = 30;
Object.Subscription.Add subscriptionAdd = 60;
Object.Subscription.Remove subscriptionRemove = 61;
@ -205,31 +204,6 @@ message Event {
}
}
/*
* Works with a smart blocks: Page, Dashboard
* Dashboard opened, click on a page, Rpc.Block.open, Block.ShowFullscreen(PageBlock)
*/
message Show {
string rootId = 1; // Root block id
repeated anytype.model.Block blocks = 2; // dependent simple blocks (descendants)
repeated Object.Details.Set details = 3; // details for the current and dependent objects
model.SmartBlockType type = 4;
message RelationWithValuePerObject {
string objectId = 1;
repeated anytype.model.RelationWithValue relations = 2;
}
repeated anytype.model.ObjectType objectTypes = 5; // objectTypes contains ONLY to get layouts for the actual and all dependent objects. Relations are currently omitted // todo: switch to other pb model
repeated anytype.model.Relation relations = 7; // combined relations of object's type + extra relations. If object doesn't has some relation key in the details this means client should hide it and only suggest when adding existing one
anytype.model.Restrictions restrictions = 8; // object restrictions
HistorySize history = 9;
message HistorySize {
int32 undo = 1;
int32 redo = 2;
}
}
message Remove {
// notifies that objects were removed

View file

@ -314,11 +314,12 @@ message Block {
repeated Sort sorts = 4;
repeated Filter filters = 5;
repeated Relation relations = 6; // relations fields/columns options, also used to provide the order
string coverRelationKey = 7; // Relation used for cover in gallery
string coverRelationKey = 7; // Relation used for cover in gallery
bool hideIcon = 8; // Hide icon near name
Size cardSize = 9; // Gallery card size
bool coverFit = 10; // Image fits container
string groupRelationKey = 11;
string groupRelationKey = 11; // Group view by this relationKey
bool groupBackgroundColors = 12; // Enable backgrounds in groups
enum Type {
Table = 0;
@ -361,10 +362,12 @@ message Block {
message Sort {
string RelationKey = 1;
Type type = 2;
repeated google.protobuf.Value customOrder = 3;
enum Type {
Asc = 0;
Desc = 1;
Custom = 2;
}
}
@ -426,6 +429,7 @@ message Block {
string groupId = 1;
int32 index = 2;
bool hidden = 3;
string backgroundColor = 4;
}
message ObjectOrder {
@ -518,7 +522,7 @@ message Account {
message Config {
bool enableDataview = 1;
bool enableDebug = 2;
bool enableReleaseChannelSwitch = 3;
bool enablePrereleaseChannel = 3;
bool enableSpaces = 4;
google.protobuf.Struct extra = 100;
@ -750,4 +754,37 @@ message InternalFlag {
editorSelectType = 1;
editorSelectTemplate = 2;
}
}
/*
* Works with a smart blocks: Page, Dashboard
* Dashboard opened, click on a page, Rpc.Block.open, Block.ShowFullscreen(PageBlock)
*/
message ObjectView {
string rootId = 1; // Root block id
repeated Block blocks = 2; // dependent simple blocks (descendants)
repeated DetailsSet details = 3; // details for the current and dependent objects
SmartBlockType type = 4;
message DetailsSet {
string id = 1; // context objectId
google.protobuf.Struct details = 2; // can not be a partial state. Should replace client details state
repeated string subIds = 3;
}
message RelationWithValuePerObject {
string objectId = 1;
repeated RelationWithValue relations = 2;
}
repeated ObjectType objectTypes = 5; // objectTypes contains ONLY to get layouts for the actual and all dependent objects. Relations are currently omitted // todo: switch to other pb model
repeated Relation relations = 7; // combined relations of object's type + extra relations. If object doesn't has some relation key in the details this means client should hide it and only suggest when adding existing one
Restrictions restrictions = 8; // object restrictions
HistorySize history = 9;
message HistorySize {
int32 undo = 1;
int32 redo = 2;
}
}

View file

@ -44,6 +44,6 @@ fun StubFeatureConfig(
) : FeaturesConfig = FeaturesConfig(
enableDataView = enableDataView,
enableDebug = enableDebug,
enableChannelSwitch = enableChannelSwitch,
enablePrereleaseChannel = enableChannelSwitch,
enableSpaces = enableSpaces
)