mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Use "text" to refer to message text.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user