Use "text" to refer to message text.

This commit is contained in:
akwizgran
2018-10-10 10:40:23 +01:00
parent a030f92275
commit 79d5612645
145 changed files with 750 additions and 764 deletions

View File

@@ -4,8 +4,8 @@ import io.javalin.BadRequestResponse
import io.javalin.Context
import org.briarproject.bramble.api.identity.IdentityManager
import org.briarproject.bramble.api.system.Clock
import org.briarproject.bramble.util.StringUtils
import org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH
import org.briarproject.bramble.util.StringUtils.utf8IsTooLong
import org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH
import org.briarproject.briar.api.blog.BlogManager
import org.briarproject.briar.api.blog.BlogPostFactory
import org.briarproject.briar.headless.getFromJson
@@ -29,15 +29,15 @@ constructor(
.flatMap { blog -> blogManager.getPostHeaders(blog.id) }
.asSequence()
.sortedBy { it.timeReceived }
.map { header -> header.output(blogManager.getPostBody(header.id)) }
.map { header -> header.output(blogManager.getPostText(header.id)) }
.toList()
return ctx.json(posts)
}
override fun createPost(ctx: Context): Context {
val text = ctx.getFromJson("text")
if (StringUtils.utf8IsTooLong(text, MAX_BLOG_POST_BODY_LENGTH))
throw BadRequestResponse("Too long blog post text")
if (utf8IsTooLong(text, MAX_BLOG_POST_TEXT_LENGTH))
throw BadRequestResponse("Blog post text is too long")
val author = identityManager.localAuthor
val blog = blogManager.getPersonalBlog(author)

View File

@@ -5,8 +5,8 @@ import org.briarproject.briar.api.blog.BlogPostHeader
import org.briarproject.briar.api.blog.MessageType
import org.briarproject.briar.headless.json.JsonDict
internal fun BlogPostHeader.output(body: String) = JsonDict(
"text" to body,
internal fun BlogPostHeader.output(text: String) = JsonDict(
"text" to text,
"author" to author.output(),
"authorStatus" to authorStatus.output(),
"type" to type.output(),

View File

@@ -9,5 +9,5 @@ internal class OutputEvent(val name: String, val data: Any) {
val type = "event"
}
internal fun PrivateMessageReceivedEvent<*>.output(body: String) =
messageHeader.output(contactId, body)
internal fun PrivateMessageReceivedEvent<*>.output(text: String) =
messageHeader.output(contactId, text)

View File

@@ -2,7 +2,7 @@ package org.briarproject.briar.headless.forums
import io.javalin.BadRequestResponse
import io.javalin.Context
import org.briarproject.bramble.util.StringUtils
import org.briarproject.bramble.util.StringUtils.utf8IsTooLong
import org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH
import org.briarproject.briar.api.forum.ForumManager
import org.briarproject.briar.headless.getFromJson
@@ -22,7 +22,7 @@ constructor(private val forumManager: ForumManager) : ForumController {
override fun create(ctx: Context): Context {
val name = ctx.getFromJson("name")
if (StringUtils.utf8IsTooLong(name, MAX_FORUM_NAME_LENGTH))
if (utf8IsTooLong(name, MAX_FORUM_NAME_LENGTH))
throw BadRequestResponse("Forum name is too long")
return ctx.json(forumManager.addForum(name).output())
}

View File

@@ -19,7 +19,7 @@ import org.briarproject.briar.api.forum.ForumInvitationResponse
import org.briarproject.briar.api.introduction.IntroductionRequest
import org.briarproject.briar.api.introduction.IntroductionResponse
import org.briarproject.briar.api.messaging.*
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse
@@ -61,8 +61,8 @@ constructor(
val contact = getContact(ctx)
val message = ctx.getFromJson("text")
if (utf8IsTooLong(message, MAX_PRIVATE_MESSAGE_BODY_LENGTH))
throw BadRequestResponse("Message text too large")
if (utf8IsTooLong(message, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
throw BadRequestResponse("Message text is too long")
val group = messagingManager.getContactGroup(contact)
val now = clock.currentTimeMillis()
@@ -75,8 +75,8 @@ constructor(
override fun eventOccurred(e: Event) {
when (e) {
is PrivateMessageReceivedEvent<*> -> dbExecutor.execute {
val body = messagingManager.getMessageBody(e.messageHeader.id)
webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, e.output(body))
val text = messagingManager.getMessageText(e.messageHeader.id)
webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, e.output(text))
}
}
}
@@ -103,7 +103,7 @@ private class JsonVisitor(
) : PrivateMessageVisitor<JsonDict> {
override fun visitPrivateMessageHeader(h: PrivateMessageHeader) =
h.output(contactId, messagingManager.getMessageBody(h.id))
h.output(contactId, messagingManager.getMessageText(h.id))
override fun visitBlogInvitationRequest(r: BlogInvitationRequest) = r.output(contactId)

View File

@@ -17,16 +17,16 @@ internal fun PrivateMessageHeader.output(contactId: ContactId) = JsonDict(
"groupId" to groupId.bytes
)
internal fun PrivateMessageHeader.output(contactId: ContactId, body: String?): JsonDict {
internal fun PrivateMessageHeader.output(contactId: ContactId, text: String?): JsonDict {
val dict = output(contactId)
dict["text"] = body
dict["text"] = text
return dict
}
/**
* Use only for outgoing messages that were just sent
*/
internal fun PrivateMessage.output(contactId: ContactId, body: String) = JsonDict(
internal fun PrivateMessage.output(contactId: ContactId, text: String) = JsonDict(
"type" to "PrivateMessage",
"contactId" to contactId.int,
"timestamp" to message.timestamp,
@@ -36,5 +36,5 @@ internal fun PrivateMessage.output(contactId: ContactId, body: String) = JsonDic
"local" to true,
"id" to message.id.bytes,
"groupId" to message.groupId.bytes,
"text" to body
"text" to text
)

View File

@@ -11,7 +11,7 @@ import org.briarproject.briar.api.sharing.InvitationRequest
import org.briarproject.briar.headless.json.JsonDict
internal fun PrivateRequest<*>.output(contactId: ContactId): JsonDict {
val dict = (this as PrivateMessageHeader).output(contactId, message)
val dict = (this as PrivateMessageHeader).output(contactId, text)
dict.putAll(
"sessionId" to sessionId.bytes,
"name" to name,

View File

@@ -35,7 +35,7 @@ abstract class ControllerTest {
protected val localAuthor: LocalAuthor = getLocalAuthor()
protected val contact = Contact(ContactId(1), author, localAuthor.id, true, true)
protected val message: Message = getMessage(group.id)
protected val body: String = getRandomString(5)
protected val text: String = getRandomString(5)
protected val timestamp = 42L
protected fun assertJsonEquals(json: String, obj: Any) {

View File

@@ -11,7 +11,7 @@ import org.briarproject.bramble.api.sync.MessageId
import org.briarproject.bramble.identity.output
import org.briarproject.bramble.util.StringUtils.getRandomString
import org.briarproject.briar.api.blog.*
import org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH
import org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH
import org.briarproject.briar.api.blog.MessageType.POST
import org.briarproject.briar.headless.ControllerTest
import org.junit.jupiter.api.Assertions.assertThrows
@@ -38,7 +38,7 @@ internal class BlogControllerTest : ControllerTest() {
fun testCreate() {
val post = BlogPost(message, null, localAuthor)
every { ctx.body() } returns """{"text": "$body"}"""
every { ctx.body() } returns """{"text": "$text"}"""
every { identityManager.localAuthor } returns localAuthor
every { blogManager.getPersonalBlog(localAuthor) } returns blog
every { clock.currentTimeMillis() } returns message.timestamp
@@ -48,12 +48,12 @@ internal class BlogControllerTest : ControllerTest() {
message.timestamp,
parentId,
localAuthor,
body
text
)
} returns post
every { blogManager.addLocalPost(post) } just Runs
every { blogManager.getPostHeader(post.message.groupId, post.message.id) } returns header
every { ctx.json(header.output(body)) } returns ctx
every { ctx.json(header.output(text)) } returns ctx
controller.createPost(ctx)
}
@@ -74,7 +74,7 @@ internal class BlogControllerTest : ControllerTest() {
@Test
fun testCreateTooLongText() {
every { ctx.body() } returns """{"text": "${getRandomString(MAX_BLOG_POST_BODY_LENGTH + 1)}"}"""
every { ctx.body() } returns """{"text": "${getRandomString(MAX_BLOG_POST_TEXT_LENGTH + 1)}"}"""
assertThrows(BadRequestResponse::class.java) { controller.createPost(ctx) }
}
@@ -83,8 +83,8 @@ internal class BlogControllerTest : ControllerTest() {
fun testList() {
every { blogManager.blogs } returns listOf(blog)
every { blogManager.getPostHeaders(group.id) } returns listOf(header)
every { blogManager.getPostBody(message.id) } returns body
every { ctx.json(listOf(header.output(body))) } returns ctx
every { blogManager.getPostText(message.id) } returns text
every { ctx.json(listOf(header.output(text))) } returns ctx
controller.listPosts(ctx)
}
@@ -102,7 +102,7 @@ internal class BlogControllerTest : ControllerTest() {
fun testOutputBlogPost() {
val json = """
{
"text": "$body",
"text": "$text",
"author": ${toJson(author.output())},
"authorStatus": "ourselves",
"type": "post",
@@ -114,7 +114,7 @@ internal class BlogControllerTest : ControllerTest() {
"timestampReceived": $timestamp
}
"""
assertJsonEquals(json, header.output(body))
assertJsonEquals(json, header.output(text))
}
}

View File

@@ -23,7 +23,7 @@ internal class WebSocketControllerTest : ControllerTest() {
private val header =
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true)
private val event = PrivateMessageReceivedEvent(header, contact.id)
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
@Test
fun testSendEvent() {
@@ -32,7 +32,7 @@ internal class WebSocketControllerTest : ControllerTest() {
every { session1.send(capture(slot)) } just Runs
controller.sessions.add(session1)
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
assertJsonEquals(slot.captured, outputEvent)
}
@@ -55,7 +55,7 @@ internal class WebSocketControllerTest : ControllerTest() {
controller.sessions.add(session1)
controller.sessions.add(session2)
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
verify { session2.send(slot.captured) }
}
@@ -66,7 +66,7 @@ internal class WebSocketControllerTest : ControllerTest() {
{
"type": "event",
"name": "PrivateMessageReceivedEvent",
"data": ${toJson(header.output(contact.id, body))}
"data": ${toJson(header.output(contact.id, text))}
}
"""
assertJsonEquals(json, outputEvent)

View File

@@ -13,7 +13,7 @@ import org.briarproject.bramble.util.StringUtils.getRandomString
import org.briarproject.briar.api.client.SessionId
import org.briarproject.briar.api.introduction.IntroductionRequest
import org.briarproject.briar.api.messaging.*
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import org.briarproject.briar.headless.ControllerTest
import org.briarproject.briar.headless.event.WebSocketController
@@ -50,8 +50,8 @@ internal class MessagingControllerImplTest : ControllerTest() {
fun list() {
expectGetContact()
every { conversationManager.getMessageHeaders(contact.id) } returns listOf(header)
every { messagingManager.getMessageBody(message.id) } returns body
every { ctx.json(listOf(header.output(contact.id, body))) } returns ctx
every { messagingManager.getMessageText(message.id) } returns text
every { ctx.json(listOf(header.output(contact.id, text))) } returns ctx
controller.list(ctx)
}
@@ -59,7 +59,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
@Test
fun listIntroductionRequest() {
val request = IntroductionRequest(
message.id, group.id, timestamp, true, true, false, true, sessionId, author, body,
message.id, group.id, timestamp, true, true, false, true, sessionId, author, text,
false, false
)
@@ -95,14 +95,14 @@ internal class MessagingControllerImplTest : ControllerTest() {
val slot = CapturingSlot<JsonDict>()
expectGetContact()
every { ctx.body() } returns """{"text": "$body"}"""
every { ctx.body() } returns """{"text": "$text"}"""
every { messagingManager.getContactGroup(contact) } returns group
every { clock.currentTimeMillis() } returns timestamp
every {
privateMessageFactory.createPrivateMessage(
group.id,
timestamp,
body
text
)
} returns privateMessage
every { messagingManager.addLocalMessage(privateMessage) } just runs
@@ -110,7 +110,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
controller.write(ctx)
assertEquals(privateMessage.output(contact.id, body), slot.captured)
assertEquals(privateMessage.output(contact.id, text), slot.captured)
}
@Test
@@ -124,7 +124,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
}
@Test
fun writeNonexistentBody() {
fun writeNonexistentText() {
expectGetContact()
every { ctx.body() } returns """{"foo": "bar"}"""
@@ -132,7 +132,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
}
@Test
fun writeEmptyBody() {
fun writeEmptyText() {
expectGetContact()
every { ctx.body() } returns """{"text": ""}"""
@@ -140,9 +140,9 @@ internal class MessagingControllerImplTest : ControllerTest() {
}
@Test
fun writeTooLongBody() {
fun writeTooLongText() {
expectGetContact()
every { ctx.body() } returns """{"text": "${getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1)}"}"""
every { ctx.body() } returns """{"text": "${getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH + 1)}"}"""
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
}
@@ -151,8 +151,8 @@ internal class MessagingControllerImplTest : ControllerTest() {
fun privateMessageEvent() {
val event = PrivateMessageReceivedEvent(header, contact.id)
every { messagingManager.getMessageBody(message.id) } returns body
every { webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body)) } just runs
every { messagingManager.getMessageText(message.id) } returns text
every { webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text)) } just runs
controller.eventOccurred(event)
}
@@ -161,7 +161,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
fun testOutputPrivateMessageHeader() {
val json = """
{
"text": "$body",
"text": "$text",
"type": "PrivateMessage",
"timestamp": $timestamp,
"groupId": ${toJson(header.groupId.bytes)},
@@ -173,14 +173,14 @@ internal class MessagingControllerImplTest : ControllerTest() {
"id": ${toJson(header.id.bytes)}
}
"""
assertJsonEquals(json, header.output(contact.id, body))
assertJsonEquals(json, header.output(contact.id, text))
}
@Test
fun testOutputPrivateMessage() {
val json = """
{
"text": "$body",
"text": "$text",
"type": "PrivateMessage",
"timestamp": ${message.timestamp},
"groupId": ${toJson(message.groupId.bytes)},
@@ -192,11 +192,11 @@ internal class MessagingControllerImplTest : ControllerTest() {
"id": ${toJson(message.id.bytes)}
}
"""
assertJsonEquals(json, privateMessage.output(contact.id, body))
assertJsonEquals(json, privateMessage.output(contact.id, text))
}
@Test
fun testIntroductionRequestWithEmptyBody() {
fun testIntroductionRequestWithNullText() {
val request = IntroductionRequest(
message.id, group.id, timestamp, true, true, false, true, sessionId, author, null,
false, false