Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
briar
briar
Commits
6f547187
Verified
Commit
6f547187
authored
Oct 03, 2018
by
Torsten Grote
Browse files
Use short type labels in JSON API instead of long Java-like namespaces
parent
ea749f21
Changes
7
Hide whitespace changes
Inline
Side-by-side
briar-headless/README.md
View file @
6f547187
...
...
@@ -89,7 +89,7 @@ It returns a JSON array of private messages:
"seen"
:
true
,
"sent"
:
true
,
"timestamp"
:
1537376633850
,
"type"
:
"
org.briarproject.briar.api.messaging.
PrivateMessage
Header
"
"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.
PrivateMessage
Header
"
"type"
:
"PrivateMessage"
},
"name"
:
"
org.briarproject.briar.api.messaging.event.
PrivateMessageReceivedEvent"
,
"name"
:
"PrivateMessageReceivedEvent"
,
"type"
:
"event"
}
```
...
...
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/MessagingControllerImpl.kt
View file @
6f547187
...
...
@@ -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
)
}
\ No newline at end of file
}
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateMessage.kt
View file @
6f547187
...
...
@@ -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.
PrivateMessage
Header
"
,
"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.
PrivateMessage
Header
"
,
"type"
to
"PrivateMessage"
,
"contactId"
to
contactId
.
int
,
"timestamp"
to
message
.
timestamp
,
"read"
to
true
,
...
...
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateRequest.kt
View file @
6f547187
...
...
@@ -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
}
briar-headless/src/main/java/org/briarproject/briar/headless/messaging/OutputPrivateResponse.kt
View file @
6f547187
...
...
@@ -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
}
briar-headless/src/test/java/org/briarproject/briar/headless/event/WebSocketControllerTest.kt
View file @
6f547187
...
...
@@ -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))}
}
"""
...
...
briar-headless/src/test/java/org/briarproject/briar/headless/messaging/MessagingControllerImplTest.kt
View file @
6f547187
...
...
@@ -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.
PrivateMessage
Header
",
"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},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment