diff --git a/app/src/androidTest/java/com/futo/polycentric/core/ProcessHandleTests.kt b/app/src/androidTest/java/com/futo/polycentric/core/ProcessHandleTests.kt index 8b60157937304547b0ec370a426c751254b89ac4..714f843fd8f84edb07a5aa4cfddba1a54f11752f 100644 --- a/app/src/androidTest/java/com/futo/polycentric/core/ProcessHandleTests.kt +++ b/app/src/androidTest/java/com/futo/polycentric/core/ProcessHandleTests.kt @@ -10,10 +10,8 @@ import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith import userpackage.Protocol -import userpackage.Protocol.QueryReferencesResponseItem import java.io.ByteArrayOutputStream - @RunWith(AndroidJUnit4::class) class ProcessHandleTests { @Test @@ -232,16 +230,19 @@ class ProcessHandleTests { babbage.fullyBackfillServers() turing.fullyBackfillServers() - val queryReferences = ApiMethods.getQueryReferences(SERVER, subject, ContentType.POST.value, null, - arrayListOf(Protocol.CountLWWElementReferences.newBuilder() + val queryReferences = ApiMethods.getQueryReferences(SERVER, subject, null, + Protocol.QueryReferencesRequestEvents.newBuilder() + .setFromType(ContentType.POST.value) + .build(), + arrayListOf(Protocol.QueryReferencesRequestCountLWWElementReferences.newBuilder() .setFromType(ContentType.OPINION.value) .setValue(ByteString.copyFrom(Opinion.like.data)) .build(), - Protocol.CountLWWElementReferences.newBuilder() + Protocol.QueryReferencesRequestCountLWWElementReferences.newBuilder() .setFromType(ContentType.OPINION.value) .setValue(ByteString.copyFrom(Opinion.dislike.data)) .build()), - arrayListOf(Protocol.CountReferences.newBuilder() + arrayListOf(Protocol.QueryReferencesRequestCountReferences.newBuilder() .setFromType(ContentType.POST.value) .build()) ) @@ -249,7 +250,7 @@ class ProcessHandleTests { assertEquals(rootPosts.count(), queryReferences.itemsCount) val pointerToString = { pointer: Pointer -> pointer.toProto().toByteArray().toBase64() } - val pointerToItem: HashMap<String, QueryReferencesResponseItem> = hashMapOf() + val pointerToItem: HashMap<String, Protocol.QueryReferencesResponseEventItem> = hashMapOf() for (item in queryReferences.itemsList) { assertTrue(item.hasEvent()) diff --git a/app/src/main/java/com/futo/polycentric/core/ApiMethods.kt b/app/src/main/java/com/futo/polycentric/core/ApiMethods.kt index 30b5aa4b8e45e5f67ce85febc542649a8e9b2fea..d56b13e3ff58b8f2a1342a4bb1c27a4e5db8e944 100644 --- a/app/src/main/java/com/futo/polycentric/core/ApiMethods.kt +++ b/app/src/main/java/com/futo/polycentric/core/ApiMethods.kt @@ -99,9 +99,13 @@ class ApiMethods { return Protocol.Events.parseFrom(result.get()) } - fun getQueryReferences(server: String, reference: Protocol.Reference, fromType: Long? = null, cursor: ByteArray? = null, countLwwElementReferences: List<Protocol.CountLWWElementReferences>? = null, countReferences: List<Protocol.CountReferences>? = null): Protocol.QueryReferencesResponse { + fun getQueryReferences(server: String, reference: Protocol.Reference, cursor: ByteArray? = null, + requestEvents: Protocol.QueryReferencesRequestEvents? = null, + countLwwElementReferences: List<Protocol.QueryReferencesRequestCountLWWElementReferences>? = null, + countReferences: List<Protocol.QueryReferencesRequestCountReferences>? = null): Protocol.QueryReferencesResponse + { val builder = Protocol.QueryReferencesRequest.newBuilder().setReference(reference) - if (fromType != null) builder.fromType = fromType + if (requestEvents != null) builder.requestEvents = requestEvents if (cursor != null) builder.cursor = ByteString.copyFrom(cursor) if (countLwwElementReferences != null) builder.addAllCountLwwElementReferences(countLwwElementReferences) if (countReferences != null) builder.addAllCountReferences(countReferences) diff --git a/app/src/main/proto/com/futo/polycentric/protos/protocol.proto b/app/src/main/proto/com/futo/polycentric/protos/protocol.proto index f6a28dacd767a6c22ee3888ffe532c52551aed55..c8edbb8e0f644e2bf6318d9eb4ddfb4f7ac0a4f4 100644 --- a/app/src/main/proto/com/futo/polycentric/protos/protocol.proto +++ b/app/src/main/proto/com/futo/polycentric/protos/protocol.proto @@ -195,34 +195,45 @@ message RepeatedUInt64 { repeated uint64 numbers = 1; } -message CountLWWElementReferences { +// start /query_references API + +message QueryReferencesRequest { + Reference reference = 1; + optional bytes cursor = 2; + optional QueryReferencesRequestEvents request_events = 3; + repeated QueryReferencesRequestCountLWWElementReferences count_lww_element_references = 4; + repeated QueryReferencesRequestCountReferences count_references = 5; +} + +message QueryReferencesRequestEvents { + optional uint64 from_type = 1; + repeated QueryReferencesRequestCountLWWElementReferences count_lww_element_references = 2; + repeated QueryReferencesRequestCountReferences count_references = 3; +} + +message QueryReferencesRequestCountLWWElementReferences { bytes value = 1; optional uint64 from_type = 2; } -message CountReferences { +message QueryReferencesRequestCountReferences { optional uint64 from_type = 1; } -message QueryReferencesRequest { - Reference reference = 1; - optional bytes cursor = 2; - optional uint64 from_type = 3; - repeated CountLWWElementReferences count_lww_element_references = 4; - repeated CountReferences count_references = 5; -} - -message QueryReferencesResponseItem { +message QueryReferencesResponseEventItem { SignedEvent event = 1; repeated uint64 counts = 2; } message QueryReferencesResponse { - repeated QueryReferencesResponseItem items = 1; - repeated SignedEvent related_events = 2; - optional bytes cursor = 3; + repeated QueryReferencesResponseEventItem items = 1; + repeated SignedEvent related_events = 2; + optional bytes cursor = 3; + repeated uint64 counts = 4; } +// end /query_references API + message URLInfo { // url_type 1 = URLInfoSystemLink // url_type 2 = URLInfoEventLink