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

Updated library and protos. (#90)

This commit is contained in:
ubu 2019-12-19 13:59:21 +03:00 committed by GitHub
parent 58c97727e8
commit 3a0e62241f
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 206 additions and 149 deletions

View file

@ -97,6 +97,7 @@ class BlockMiddleware(
content = extractLayout(block)
)
}
/*
Models.Block.ContentCase.IMAGE -> {
BlockEntity(
id = block.id,
@ -107,6 +108,7 @@ class BlockMiddleware(
)
)
}
*/
else -> {
null
}
@ -151,6 +153,7 @@ class BlockMiddleware(
content = extractLayout(block)
)
}
/*
Models.Block.ContentCase.IMAGE -> {
BlockEntity(
id = block.id,
@ -161,6 +164,7 @@ class BlockMiddleware(
)
)
}
*/
else -> {
null
}
@ -228,6 +232,7 @@ class BlockMiddleware(
content = extractLayout(block)
)
}
/*
Models.Block.ContentCase.IMAGE -> {
BlockEntity(
id = block.id,
@ -238,6 +243,7 @@ class BlockMiddleware(
)
)
}
*/
else -> {
throw IllegalStateException("Unexpected content: ${block.contentCase}")
}

View file

@ -232,9 +232,8 @@ public class Middleware {
Block.Create.Request request = Block.Create.Request
.newBuilder()
.setContextId(parentId)
.setParentId(parentId)
.setBlock(block)
.setPosition(Models.Block.Position.After)
.setPosition(Models.Block.Position.Inner)
.build();
byte[] encodedRequest = request.toByteArray();
@ -300,7 +299,7 @@ public class Middleware {
.addAllMarks(marks)
.build();
Block.Set.Text.Editable.Request request = Block.Set.Text.Editable.Request
Block.Set.Text.TText.Request request = Block.Set.Text.TText.Request
.newBuilder()
.setContextId(contextId)
.setBlockId(blockId)
@ -314,9 +313,9 @@ public class Middleware {
byte[] encodedResponse = Lib.blockSetTextText(encodedRequest);
Block.Set.Text.Editable.Response response = Block.Set.Text.Editable.Response.parseFrom(encodedResponse);
Block.Set.Text.TText.Response response = Block.Set.Text.TText.Response.parseFrom(encodedResponse);
if (response.getError() != null && response.getError().getCode() != Block.Set.Text.Editable.Response.Error.Code.NULL) {
if (response.getError() != null && response.getError().getCode() != Block.Set.Text.TText.Response.Error.Code.NULL) {
throw new Exception(response.getError().getDescription());
}
}
@ -341,8 +340,7 @@ public class Middleware {
.newBuilder()
.setContextId(contextId)
.setTargetId(targetId)
.setParentId(contextId)
.setPosition(Models.Block.Position.After)
.setPosition(Models.Block.Position.Bottom)
.setBlock(block)
.build();

View file

@ -12,14 +12,66 @@ import "google/protobuf/struct.proto";
* Response message from a middleware.
*/
message Rpc {
message ExternalDrop {
message Files {
message Request {
string contextId = 1;
string focusedBlockId = 2; // can be null
repeated string localFilePaths = 3;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
message Content {
message Request {
string contextId = 1;
string focusedBlockId = 2; // can be null
bytes content = 3; // TODO
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
}
message BlockList {
message Move {
message Request {
string contextId = 1;
repeated string blockIds = 2;
string dropTargetId = 3;
anytype.model.Block.Position position = 4;
string targetContextId = 3;
string dropTargetId = 4;
anytype.model.Block.Position position = 5;
}
message Response {
@ -72,6 +124,31 @@ message Rpc {
* Namespace, that agregates subtopics and actions, that relates to blocks.
*/
message Block {
message Replace {
message Request {
string contextId = 1;
string blockId = 2;
anytype.model.Block block = 3;
}
message Response {
Error error = 1;
string blockId = 2;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
message Split {
message Request {
string contextId = 1;
@ -81,6 +158,7 @@ message Rpc {
message Response {
Error error = 1;
string blockId = 2;
message Error {
Code code = 1;
@ -120,14 +198,20 @@ message Rpc {
}
}
/*
* Makes block copy by given id and paste it to shown place
*/
message Duplicate {
message Request {
string contextId = 1;
string blockId = 2;
string contextId = 1; // id of the context block
string targetId = 2; // id of the closest block
string blockId = 3; // id of block for duplicate
anytype.model.Block.Position position = 4;
}
message Response {
Error error = 1;
string blockId = 2;
message Error {
Code code = 1;
@ -146,16 +230,14 @@ message Rpc {
message Copy {
message Request {
string contextId = 1;
string focusedBlockId = 2;
anytype.model.Range selectedTextRange = 3;
repeated string selectedBlocks = 4;
repeated string blockIds = 2;
}
message Response {
Error error = 1;
string clipboardText = 2;
string clipboardHtml = 3;
string clipboardAny = 4; // TODO: type is string ok?
// string clipboardAny = 4; Client already knows blockIds
message Error {
Code code = 1;
@ -178,9 +260,9 @@ message Rpc {
anytype.model.Range selectedTextRange = 3;
repeated string selectedBlocks = 4;
string clipboardText = 5;
string clipboardHtml = 6;
string clipboardAny = 7;
string textSlot = 5;
string htmlSlot = 6;
string anySlot = 7;
}
message Response {
@ -272,7 +354,6 @@ message Rpc {
}
}
}
message Restrictions {
message Request {
string contextId = 1;
@ -322,8 +403,7 @@ message Rpc {
}
message Text {
message Editable {
message TText {
message Request {
string contextId = 1;
string blockId = 2;
@ -348,6 +428,54 @@ message Rpc {
}
}
message Color {
message Request {
string contextId = 1;
string blockId = 2;
string color = 3;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
message BackgroundColor {
message Request {
string contextId = 1;
string blockId = 2;
string color = 3;
}
message Response {
Error error = 1;
message Error {
Code code = 1;
string description = 2;
enum Code {
NULL = 0;
UNKNOWN_ERROR = 1;
BAD_INPUT = 2;
// ...
}
}
}
}
message Style {
message Request {
string contextId = 1;
@ -660,14 +788,14 @@ message Rpc {
* Create a Smart/Internal block. Request can contain a block with a content, or it can be an empty block with a specific block.content.
* **Example scenario**
* 1A. Create Page on a dashboard
* 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:after, block: emtpy block with page content and id = "")
* 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:bottom, block: emtpy block with page content and id = "")
* 2. Front -> MW: Rpc.Block.Close.Request(block: dashboard.id)
* 3. Front <- MW: Rpc.Block.Close.Response(err)
* 4. Front <- MW: Rpc.Block.Create.Response(page.id)
* 5. Front <- MW: Rpc.Block.Open.Response(err)
* 6. Front <- MW: Event.Block.Show(page)
* 1B. Create Page on a Page
* 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:after, block: emtpy block with page content and id = "")
* 1. Front -> MW: Rpc.Block.Create.Request(blockId:dashboard.id, position:bottom, block: emtpy block with page content and id = "")
* 2. Front <- MW: Rpc.Block.Create.Response(newPage.id)
* 3. Front <- MW: Event.Block.Show(newPage)
*/
@ -677,7 +805,6 @@ message Rpc {
string targetId = 2; // id of the closest block
anytype.model.Block block = 3;
anytype.model.Block.Position position = 4;
string parentId = 5; // id of the parent block
}
message Response {
@ -704,12 +831,8 @@ message Rpc {
message Unlink {
message Request {
string contextId = 1; // id of the context block
repeated Target targets = 2; // targets to remove
repeated string blockIds = 2; // targets to remove
message Target {
string blockId = 1; // id of the block to remove
string parentId = 2; // id of the parent block
}
}
message Response {
@ -926,6 +1049,7 @@ message Rpc {
FAILED_TO_RUN_NODE = 103;
FAILED_TO_FIND_ACCOUNT_INFO = 104;
LOCAL_REPO_NOT_EXISTS_AND_MNEMONIC_NOT_SET = 105;
FAILED_TO_STOP_SEARCHER_NODE = 106;
}
}
}
@ -1060,6 +1184,7 @@ message Rpc {
NOT_FOUND = 101;
TIMEOUT = 102;
NODE_NOT_STARTED = 103;
}
}
}
@ -1087,6 +1212,7 @@ message Rpc {
NOT_FOUND = 101;
TIMEOUT = 102;
NODE_NOT_STARTED = 103;
}
}
}

View file

@ -29,15 +29,13 @@ message Event {
Block.Set.Text blockSetText = 10;
Block.Set.File blockSetFile = 11;
Block.Set.Image blockSetImage = 12;
Block.Set.Video blockSetVideo = 13;
Block.Set.Icon blockSetIcon = 14;
Block.Set.Icon blockSetIcon = 12;
Block.Show blockShow = 15;
User.Block.Join userBlockJoin = 16;
User.Block.Left userBlockLeft = 17;
User.Block.SelectRange userBlockSelectRange = 18;
User.Block.TextRange userBlockTextRange = 19;
Block.Show blockShow = 13;
User.Block.Join userBlockJoin = 14;
User.Block.Left userBlockLeft = 15;
User.Block.SelectRange userBlockSelectRange = 16;
User.Block.TextRange userBlockTextRange = 17;
Ping ping = 100;
}
@ -48,7 +46,7 @@ message Event {
* Message, that will be sent to the front on each account found after an AccountRecoverRequest
*/
message Show {
int64 index = 1; // Number of an account in an all found accounts list
int32 index = 1; // Number of an account in an all found accounts list
anytype.model.Account account = 2; // An Account, that has been found for the mnemonic
}
}
@ -125,12 +123,14 @@ message Event {
message Text {
string id = 1;
Editable text = 2;
TText text = 2;
Style style = 3;
Marks marks = 4;
Checked checked = 5;
Color color = 6;
BackgroundColor backgroundColor = 7;
message Editable {
message TText {
string value = 1;
}
@ -145,79 +145,37 @@ message Event {
message Checked {
bool value = 1;
}
message Color {
string value = 1;
}
message BackgroundColor {
string value = 1;
}
}
message File {
string id = 1;
Name name = 2;
Type type = 2;
State state = 3;
LocalFilePath localFilePath = 4;
Icon icon = 5;
PreviewLocalFilePath previewLocalFilePath = 5;
message Name {
string value = 1;
}
message Width {
int32 value = 1;
}
message State {
anytype.model.Block.Content.File.State value = 1;
}
message LocalFilePath {
string value = 1;
}
message Icon {
string value = 1;
}
}
message Image {
string id = 1;
Name name = 2;
Width width = 3;
State state = 4;
LocalFilePath localFilePath = 5;
PreviewLocalFilePath previewLocalFilePath = 6;
message Name {
string value = 1;
}
message Width {
int32 value = 1;
}
message State {
anytype.model.Block.Content.Image.State value = 1;
}
message LocalFilePath {
string value = 1;
}
message PreviewLocalFilePath {
string value = 1;
}
}
message Video {
string id = 1;
Name name = 2;
Width width = 3;
State state = 4;
LocalFilePath localFilePath = 5;
PreviewLocalFilePath previewLocalFilePath = 6;
message Name {
string value = 1;
}
message Width {
int32 value = 1;
}
message State {
anytype.model.Block.Content.Video.State value = 1;
message Type {
anytype.model.Block.Content.File.Type value = 1;
}
message LocalFilePath {

View file

@ -17,14 +17,12 @@ message Block {
Content.Dataview dataview = 13;
Content.Text text = 14;
Content.Video video = 15;
Content.Image image = 16;
Content.File file = 17;
Content.Layout layout = 18;
Content.Div div = 19;
Content.Bookmark bookmark = 20;
Content.Icon icon = 21;
Content.Link link = 22;
Content.File file = 15;
Content.Layout layout = 16;
Content.Div div = 17;
Content.Bookmark bookmark = 18;
Content.Icon icon = 19;
Content.Link link = 20;
}
@ -37,8 +35,12 @@ message Block {
}
enum Position {
Before = 0;
After = 1;
None = 0;
Top = 1;
Bottom = 2;
Left = 3;
Right = 4;
Inner = 5;
}
message Content {
@ -109,6 +111,8 @@ message Block {
Style style = 2;
Marks marks = 3; // list of marks to apply to the text
bool checked = 4;
string color = 5;
string backgroundColor = 6;
message Marks {
repeated Mark marks = 1;
@ -147,55 +151,20 @@ message Block {
}
}
message Video {
string localFilePath = 1;
string name = 2;
string icon = 3;
int32 width = 4;
State state = 5;
enum State {
Empty = 0; // There is no video and preview, it's an empty block, that waits videos.
Uploading = 1; // There is stil no video/preview, but video already uploading
PreviewDownloaded = 2; // Video exists, preview downloaded, but video  not.
Downloading = 3; // Video exists, preview downloaded, but video downloading
Done = 4; // Video and preview downloaded
}
}
message Image {
message File {
string localFilePath = 1;
string previewFilePath = 2;
State state = 3;
Type type = 4;
string name = 5;
int32 size = 6;
int32 addedAt = 7;
int32 width = 8;
int32 widthToHeight = 9;
enum State {
Empty = 0; // There is no image and preview, it's an empty block, that waits image.
Uploading = 1; // There is stil no image/preview, but image already uploading
PreviewDownloaded = 2; // Image exists, preview downloaded, but image  not.
Downloading = 3; // Image exists, preview downloaded, but image downloading
Done = 4; // Image and preview downloaded
}
int64 size = 5;
int64 addedAt = 6;
enum Type {
Png = 0;
Jpg = 1;
// ...
File = 0;
Image = 1;
Video = 2;
}
}
message File {
string localFilePath = 1; // Path to the file on a local machine
string name = 2;
string icon = 3;
State state = 4;
enum State {
Empty = 0; // There is no file and preview, it's an empty block, that waits files.