mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Use short type labels in JSON API instead of long Java-like namespaces
This commit is contained in:
@@ -89,7 +89,7 @@ It returns a JSON array of private messages:
|
|||||||
"seen": true,
|
"seen": true,
|
||||||
"sent": true,
|
"sent": true,
|
||||||
"timestamp": 1537376633850,
|
"timestamp": 1537376633850,
|
||||||
"type": "org.briarproject.briar.api.messaging.PrivateMessageHeader"
|
"type": "PrivateMessage"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -172,9 +172,9 @@ it will send a JSON object to connected websocket clients:
|
|||||||
"seen": false,
|
"seen": false,
|
||||||
"sent": false,
|
"sent": false,
|
||||||
"timestamp": 1537389146088,
|
"timestamp": 1537389146088,
|
||||||
"type": "org.briarproject.briar.api.messaging.PrivateMessageHeader"
|
"type": "PrivateMessage"
|
||||||
},
|
},
|
||||||
"name": "org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent",
|
"name": "PrivateMessageReceivedEvent",
|
||||||
"type": "event"
|
"type": "event"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ import javax.annotation.concurrent.Immutable
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
internal const val EVENT_PRIVATE_MESSAGE =
|
internal const val EVENT_PRIVATE_MESSAGE = "PrivateMessageReceivedEvent"
|
||||||
"org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent"
|
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -121,4 +120,4 @@ private class JsonVisitor(
|
|||||||
override fun visitIntroductionRequest(r: IntroductionRequest) = r.output(contactId)
|
override fun visitIntroductionRequest(r: IntroductionRequest) = r.output(contactId)
|
||||||
|
|
||||||
override fun visitIntroductionResponse(r: IntroductionResponse) = r.output(contactId)
|
override fun visitIntroductionResponse(r: IntroductionResponse) = r.output(contactId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.briarproject.briar.api.messaging.PrivateMessageHeader
|
|||||||
import org.briarproject.briar.headless.json.JsonDict
|
import org.briarproject.briar.headless.json.JsonDict
|
||||||
|
|
||||||
internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?) = JsonDict(
|
internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?) = JsonDict(
|
||||||
"type" to "org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
"type" to "PrivateMessage",
|
||||||
"contactId" to contactId.int,
|
"contactId" to contactId.int,
|
||||||
"timestamp" to timestamp,
|
"timestamp" to timestamp,
|
||||||
"read" to isRead,
|
"read" to isRead,
|
||||||
@@ -19,7 +19,7 @@ internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?) =
|
|||||||
)
|
)
|
||||||
|
|
||||||
internal fun PrivateMessage.output(contactId: ContactId, body: String) = JsonDict(
|
internal fun PrivateMessage.output(contactId: ContactId, body: String) = JsonDict(
|
||||||
"type" to "org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
"type" to "PrivateMessage",
|
||||||
"contactId" to contactId.int,
|
"contactId" to contactId.int,
|
||||||
"timestamp" to message.timestamp,
|
"timestamp" to message.timestamp,
|
||||||
"read" to true,
|
"read" to true,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ internal fun PrivateRequest<*>.output(contactId: ContactId): JsonDict {
|
|||||||
internal fun IntroductionRequest.output(contactId: ContactId): JsonDict {
|
internal fun IntroductionRequest.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as PrivateRequest<*>).output(contactId)
|
val dict = (this as PrivateRequest<*>).output(contactId)
|
||||||
dict.putAll(
|
dict.putAll(
|
||||||
"type" to "org.briarproject.briar.api.introduction.IntroductionRequest",
|
"type" to "IntroductionRequest",
|
||||||
"alreadyContact" to isContact
|
"alreadyContact" to isContact
|
||||||
)
|
)
|
||||||
return dict
|
return dict
|
||||||
@@ -37,18 +37,18 @@ internal fun InvitationRequest<*>.output(contactId: ContactId): JsonDict {
|
|||||||
|
|
||||||
internal fun BlogInvitationRequest.output(contactId: ContactId): JsonDict {
|
internal fun BlogInvitationRequest.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as InvitationRequest<*>).output(contactId)
|
val dict = (this as InvitationRequest<*>).output(contactId)
|
||||||
dict["type"] = "org.briarproject.briar.api.blog.BlogInvitationRequest"
|
dict["type"] = "BlogInvitationRequest"
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ForumInvitationRequest.output(contactId: ContactId): JsonDict {
|
internal fun ForumInvitationRequest.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as InvitationRequest<*>).output(contactId)
|
val dict = (this as InvitationRequest<*>).output(contactId)
|
||||||
dict["type"] = "org.briarproject.briar.api.forum.ForumInvitationRequest"
|
dict["type"] = "ForumInvitationRequest"
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun GroupInvitationRequest.output(contactId: ContactId): JsonDict {
|
internal fun GroupInvitationRequest.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as InvitationRequest<*>).output(contactId)
|
val dict = (this as InvitationRequest<*>).output(contactId)
|
||||||
dict["type"] = "org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest"
|
dict["type"] = "GroupInvitationRequest"
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ internal fun PrivateResponse.output(contactId: ContactId): JsonDict {
|
|||||||
internal fun IntroductionResponse.output(contactId: ContactId): JsonDict {
|
internal fun IntroductionResponse.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as PrivateResponse).output(contactId)
|
val dict = (this as PrivateResponse).output(contactId)
|
||||||
dict.putAll(
|
dict.putAll(
|
||||||
"type" to "org.briarproject.briar.api.introduction.IntroductionResponse",
|
"type" to "IntroductionResponse",
|
||||||
"introducedAuthor" to introducedAuthor.output(),
|
"introducedAuthor" to introducedAuthor.output(),
|
||||||
"introducer" to isIntroducer
|
"introducer" to isIntroducer
|
||||||
)
|
)
|
||||||
@@ -38,18 +38,18 @@ internal fun InvitationResponse.output(contactId: ContactId): JsonDict {
|
|||||||
|
|
||||||
internal fun BlogInvitationResponse.output(contactId: ContactId): JsonDict {
|
internal fun BlogInvitationResponse.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as InvitationResponse).output(contactId)
|
val dict = (this as InvitationResponse).output(contactId)
|
||||||
dict["type"] = "org.briarproject.briar.api.blog.BlogInvitationResponse"
|
dict["type"] = "BlogInvitationResponse"
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ForumInvitationResponse.output(contactId: ContactId): JsonDict {
|
internal fun ForumInvitationResponse.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as InvitationResponse).output(contactId)
|
val dict = (this as InvitationResponse).output(contactId)
|
||||||
dict["type"] = "org.briarproject.briar.api.blog.BlogInvitationResponse"
|
dict["type"] = "BlogInvitationResponse"
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun GroupInvitationResponse.output(contactId: ContactId): JsonDict {
|
internal fun GroupInvitationResponse.output(contactId: ContactId): JsonDict {
|
||||||
val dict = (this as InvitationResponse).output(contactId)
|
val dict = (this as InvitationResponse).output(contactId)
|
||||||
dict["type"] = "org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse"
|
dict["type"] = "GroupInvitationResponse"
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
|||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
"type": "event",
|
"type": "event",
|
||||||
"name": "org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent",
|
"name": "PrivateMessageReceivedEvent",
|
||||||
"data": ${toJson(header.output(contact.id, body))}
|
"data": ${toJson(header.output(contact.id, body))}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -115,10 +115,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
|||||||
assertEquals(contact.id.int, output["contactId"])
|
assertEquals(contact.id.int, output["contactId"])
|
||||||
assertEquals(body, output["body"])
|
assertEquals(body, output["body"])
|
||||||
assertEquals(message.id.bytes, output["id"])
|
assertEquals(message.id.bytes, output["id"])
|
||||||
assertEquals(
|
assertEquals("PrivateMessage", output["type"])
|
||||||
"org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
|
||||||
output["type"]
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -170,7 +167,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
|||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
"body": "$body",
|
"body": "$body",
|
||||||
"type": "org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
"type": "PrivateMessage",
|
||||||
"timestamp": $timestamp,
|
"timestamp": $timestamp,
|
||||||
"groupId": ${toJson(header.groupId.bytes)},
|
"groupId": ${toJson(header.groupId.bytes)},
|
||||||
"contactId": ${contact.id.int},
|
"contactId": ${contact.id.int},
|
||||||
@@ -193,7 +190,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
|||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
"body": null,
|
"body": null,
|
||||||
"type": "org.briarproject.briar.api.introduction.IntroductionRequest",
|
"type": "IntroductionRequest",
|
||||||
"timestamp": $timestamp,
|
"timestamp": $timestamp,
|
||||||
"groupId": ${toJson(request.groupId.bytes)},
|
"groupId": ${toJson(request.groupId.bytes)},
|
||||||
"contactId": ${contact.id.int},
|
"contactId": ${contact.id.int},
|
||||||
|
|||||||
Reference in New Issue
Block a user