Turn output classes into Kotlin data classes

parent 138e520e
......@@ -4,11 +4,14 @@ import org.briarproject.bramble.api.identity.Author
import javax.annotation.concurrent.Immutable
@Immutable
@Suppress("unused")
class OutputAuthor(author: Author) {
val id: ByteArray = author.id.bytes
val name: String = author.name
val publicKey: ByteArray = author.publicKey
data class OutputAuthor(
val id: ByteArray,
val name: String,
val publicKey: ByteArray
) {
constructor(author: Author) : this(
id = author.id.bytes,
name = author.name,
publicKey = author.publicKey
)
}
......@@ -6,17 +6,28 @@ import org.briarproject.briar.headless.output
import javax.annotation.concurrent.Immutable
@Immutable
@Suppress("unused")
internal class OutputBlogPost(header: BlogPostHeader, val body: String) {
val author: OutputAuthor = OutputAuthor(header.author)
val authorStatus: String = header.authorStatus.output()
val type = header.type.output()
val id: ByteArray = header.id.bytes
val parentId = header.parentId?.bytes
val read = header.isRead
val rssFeed = header.isRssFeed
val timestamp = header.timestamp
val timestampReceived = header.timeReceived
internal data class OutputBlogPost(
val body: String,
val author: OutputAuthor,
val authorStatus: String,
val type: String,
val id: ByteArray,
val parentId: ByteArray?,
val read: Boolean,
val rssFeed: Boolean,
val timestamp: Long,
val timestampReceived: Long
) {
internal constructor(header: BlogPostHeader, body: String) : this(
body = body,
author = OutputAuthor(header.author),
authorStatus = header.authorStatus.output(),
type = header.type.output(),
id = header.id.bytes,
parentId = header.parentId?.bytes,
read = header.isRead,
rssFeed = header.isRssFeed,
timestamp = header.timestamp,
timestampReceived = header.timeReceived
)
}
package org.briarproject.briar.headless.contact
import org.briarproject.bramble.api.contact.Contact
import org.briarproject.bramble.identity.OutputAuthor
import org.briarproject.briar.headless.output
import javax.annotation.concurrent.Immutable
@Immutable
@Suppress("unused")
internal class OutputContact(c: Contact) {
val id = c.id.int
val author = c.author.output()
val verified = c.isVerified
internal data class OutputContact(
val id: Int,
val author: OutputAuthor,
val verified: Boolean
) {
internal constructor(c: Contact) : this(
id = c.id.int,
author = c.author.output(),
verified = c.isVerified
)
}
......@@ -4,10 +4,12 @@ import org.briarproject.briar.api.forum.Forum
import javax.annotation.concurrent.Immutable
@Immutable
@Suppress("unused")
internal class OutputForum(forum: Forum) {
val name: String = forum.name
val id: ByteArray = forum.id.bytes
internal class OutputForum(
val name: String,
val id: ByteArray
) {
constructor(forum: Forum) : this(
name = forum.name,
id = forum.id.bytes
)
}
......@@ -6,43 +6,41 @@ import org.briarproject.briar.api.messaging.PrivateMessageHeader
import javax.annotation.concurrent.Immutable
@Immutable
@Suppress("unused", "MemberVisibilityCanBePrivate")
internal class OutputPrivateMessage {
val body: String
val timestamp: Long
val read: Boolean
val seen: Boolean
val sent: Boolean
val local: Boolean
val id: ByteArray
val groupId: ByteArray
internal data class OutputPrivateMessage(
val body: String,
val timestamp: Long,
val read: Boolean,
val seen: Boolean,
val sent: Boolean,
val local: Boolean,
val id: ByteArray,
val groupId: ByteArray,
val contactId: Int
internal constructor(header: PrivateMessageHeader, contactId: ContactId, body: String) {
this.body = body
this.timestamp = header.timestamp
this.read = header.isRead
this.seen = header.isSeen
this.sent = header.isSent
this.local = header.isLocal
this.id = header.id.bytes
this.groupId = header.groupId.bytes
this.contactId = contactId.int
}
) {
internal constructor(header: PrivateMessageHeader, contactId: ContactId, body: String) : this(
body = body,
timestamp = header.timestamp,
read = header.isRead,
seen = header.isSeen,
sent = header.isSent,
local = header.isLocal,
id = header.id.bytes,
groupId = header.groupId.bytes,
contactId = contactId.int
)
/**
* Only meant for own [PrivateMessage]s directly after creation.
*/
internal constructor(m: PrivateMessage, contactId: ContactId, body: String) {
this.body = body
this.timestamp = m.message.timestamp
this.read = true
this.seen = true
this.sent = false
this.local = true
this.id = m.message.id.bytes
this.groupId = m.message.groupId.bytes
this.contactId = contactId.int
}
internal constructor(m: PrivateMessage, contactId: ContactId, body: String) : this(
body = body,
timestamp = m.message.timestamp,
read = true,
seen = true,
sent = true,
local = true,
id = m.message.id.bytes,
groupId = m.message.groupId.bytes,
contactId = contactId.int
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment