mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +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,
|
||||
"sent": true,
|
||||
"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,
|
||||
"sent": false,
|
||||
"timestamp": 1537389146088,
|
||||
"type": "org.briarproject.briar.api.messaging.PrivateMessageHeader"
|
||||
"type": "PrivateMessage"
|
||||
},
|
||||
"name": "org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent",
|
||||
"name": "PrivateMessageReceivedEvent",
|
||||
"type": "event"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -31,8 +31,7 @@ import javax.annotation.concurrent.Immutable
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
internal const val EVENT_PRIVATE_MESSAGE =
|
||||
"org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent"
|
||||
internal const val EVENT_PRIVATE_MESSAGE = "PrivateMessageReceivedEvent"
|
||||
|
||||
@Immutable
|
||||
@Singleton
|
||||
@@ -121,4 +120,4 @@ private class JsonVisitor(
|
||||
override fun visitIntroductionRequest(r: IntroductionRequest) = 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
|
||||
|
||||
internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?) = JsonDict(
|
||||
"type" to "org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
||||
"type" to "PrivateMessage",
|
||||
"contactId" to contactId.int,
|
||||
"timestamp" to timestamp,
|
||||
"read" to isRead,
|
||||
@@ -19,7 +19,7 @@ internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?) =
|
||||
)
|
||||
|
||||
internal fun PrivateMessage.output(contactId: ContactId, body: String) = JsonDict(
|
||||
"type" to "org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
||||
"type" to "PrivateMessage",
|
||||
"contactId" to contactId.int,
|
||||
"timestamp" to message.timestamp,
|
||||
"read" to true,
|
||||
|
||||
@@ -23,7 +23,7 @@ internal fun PrivateRequest<*>.output(contactId: ContactId): JsonDict {
|
||||
internal fun IntroductionRequest.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as PrivateRequest<*>).output(contactId)
|
||||
dict.putAll(
|
||||
"type" to "org.briarproject.briar.api.introduction.IntroductionRequest",
|
||||
"type" to "IntroductionRequest",
|
||||
"alreadyContact" to isContact
|
||||
)
|
||||
return dict
|
||||
@@ -37,18 +37,18 @@ internal fun InvitationRequest<*>.output(contactId: ContactId): JsonDict {
|
||||
|
||||
internal fun BlogInvitationRequest.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as InvitationRequest<*>).output(contactId)
|
||||
dict["type"] = "org.briarproject.briar.api.blog.BlogInvitationRequest"
|
||||
dict["type"] = "BlogInvitationRequest"
|
||||
return dict
|
||||
}
|
||||
|
||||
internal fun ForumInvitationRequest.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as InvitationRequest<*>).output(contactId)
|
||||
dict["type"] = "org.briarproject.briar.api.forum.ForumInvitationRequest"
|
||||
dict["type"] = "ForumInvitationRequest"
|
||||
return dict
|
||||
}
|
||||
|
||||
internal fun GroupInvitationRequest.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as InvitationRequest<*>).output(contactId)
|
||||
dict["type"] = "org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest"
|
||||
dict["type"] = "GroupInvitationRequest"
|
||||
return dict
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ internal fun PrivateResponse.output(contactId: ContactId): JsonDict {
|
||||
internal fun IntroductionResponse.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as PrivateResponse).output(contactId)
|
||||
dict.putAll(
|
||||
"type" to "org.briarproject.briar.api.introduction.IntroductionResponse",
|
||||
"type" to "IntroductionResponse",
|
||||
"introducedAuthor" to introducedAuthor.output(),
|
||||
"introducer" to isIntroducer
|
||||
)
|
||||
@@ -38,18 +38,18 @@ internal fun InvitationResponse.output(contactId: ContactId): JsonDict {
|
||||
|
||||
internal fun BlogInvitationResponse.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as InvitationResponse).output(contactId)
|
||||
dict["type"] = "org.briarproject.briar.api.blog.BlogInvitationResponse"
|
||||
dict["type"] = "BlogInvitationResponse"
|
||||
return dict
|
||||
}
|
||||
|
||||
internal fun ForumInvitationResponse.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as InvitationResponse).output(contactId)
|
||||
dict["type"] = "org.briarproject.briar.api.blog.BlogInvitationResponse"
|
||||
dict["type"] = "BlogInvitationResponse"
|
||||
return dict
|
||||
}
|
||||
|
||||
internal fun GroupInvitationResponse.output(contactId: ContactId): JsonDict {
|
||||
val dict = (this as InvitationResponse).output(contactId)
|
||||
dict["type"] = "org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse"
|
||||
dict["type"] = "GroupInvitationResponse"
|
||||
return dict
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
||||
val json = """
|
||||
{
|
||||
"type": "event",
|
||||
"name": "org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent",
|
||||
"name": "PrivateMessageReceivedEvent",
|
||||
"data": ${toJson(header.output(contact.id, body))}
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -115,10 +115,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
assertEquals(contact.id.int, output["contactId"])
|
||||
assertEquals(body, output["body"])
|
||||
assertEquals(message.id.bytes, output["id"])
|
||||
assertEquals(
|
||||
"org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
||||
output["type"]
|
||||
)
|
||||
assertEquals("PrivateMessage", output["type"])
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,7 +167,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
val json = """
|
||||
{
|
||||
"body": "$body",
|
||||
"type": "org.briarproject.briar.api.messaging.PrivateMessageHeader",
|
||||
"type": "PrivateMessage",
|
||||
"timestamp": $timestamp,
|
||||
"groupId": ${toJson(header.groupId.bytes)},
|
||||
"contactId": ${contact.id.int},
|
||||
@@ -193,7 +190,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
val json = """
|
||||
{
|
||||
"body": null,
|
||||
"type": "org.briarproject.briar.api.introduction.IntroductionRequest",
|
||||
"type": "IntroductionRequest",
|
||||
"timestamp": $timestamp,
|
||||
"groupId": ${toJson(request.groupId.bytes)},
|
||||
"contactId": ${contact.id.int},
|
||||
|
||||
Reference in New Issue
Block a user