mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
@@ -17,6 +17,7 @@ import org.briarproject.bramble.api.event.Event
|
||||
import org.briarproject.bramble.api.event.EventListener
|
||||
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
||||
import org.briarproject.bramble.util.StringUtils.toUtf8
|
||||
import org.briarproject.briar.api.conversation.ConversationManager
|
||||
import org.briarproject.briar.headless.event.WebSocketController
|
||||
import org.briarproject.briar.headless.getContactIdFromPathParam
|
||||
import org.briarproject.briar.headless.getFromJson
|
||||
@@ -38,6 +39,7 @@ internal class ContactControllerImpl
|
||||
@Inject
|
||||
constructor(
|
||||
private val contactManager: ContactManager,
|
||||
private val conversationManager: ConversationManager,
|
||||
private val objectMapper: ObjectMapper,
|
||||
private val webSocket: WebSocketController
|
||||
) : ContactController, EventListener {
|
||||
@@ -61,7 +63,7 @@ constructor(
|
||||
|
||||
override fun list(ctx: Context): Context {
|
||||
val contacts = contactManager.contacts.map { contact ->
|
||||
contact.output()
|
||||
contact.output(conversationManager)
|
||||
}
|
||||
return ctx.json(contacts)
|
||||
}
|
||||
|
||||
@@ -3,17 +3,22 @@ package org.briarproject.briar.headless.contact
|
||||
import org.briarproject.bramble.api.contact.Contact
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedEvent
|
||||
import org.briarproject.bramble.identity.output
|
||||
import org.briarproject.briar.api.conversation.ConversationManager
|
||||
import org.briarproject.briar.headless.json.JsonDict
|
||||
|
||||
internal fun Contact.output() = JsonDict(
|
||||
internal fun Contact.output(conversationManager: ConversationManager) = JsonDict(
|
||||
"contactId" to id.int,
|
||||
"author" to author.output(),
|
||||
"verified" to isVerified
|
||||
"verified" to isVerified,
|
||||
"lastChatActivity" to this.getLastChatActivity(conversationManager)
|
||||
).apply {
|
||||
alias?.let { put("alias", it) }
|
||||
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
||||
}
|
||||
|
||||
internal fun Contact.getLastChatActivity(conversationManager: ConversationManager) =
|
||||
conversationManager.getGroupCount(this.id).latestMsgTime
|
||||
|
||||
internal fun ContactAddedEvent.output() = JsonDict(
|
||||
"contactId" to contactId.int,
|
||||
"verified" to isVerified
|
||||
|
||||
Reference in New Issue
Block a user