mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
@@ -67,7 +67,8 @@ Returns a JSON array of contacts:
|
|||||||
"contactId": 1,
|
"contactId": 1,
|
||||||
"alias" : "A local nickname",
|
"alias" : "A local nickname",
|
||||||
"handshakePublicKey": "XnYRd7a7E4CTqgAvh4hCxh/YZ0EPscxknB9ZcEOpSzY=",
|
"handshakePublicKey": "XnYRd7a7E4CTqgAvh4hCxh/YZ0EPscxknB9ZcEOpSzY=",
|
||||||
"verified": true
|
"verified": true,
|
||||||
|
"lastChatActivity": 1557838312175
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.briarproject.bramble.api.event.Event
|
|||||||
import org.briarproject.bramble.api.event.EventListener
|
import org.briarproject.bramble.api.event.EventListener
|
||||||
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
||||||
import org.briarproject.bramble.util.StringUtils.toUtf8
|
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.event.WebSocketController
|
||||||
import org.briarproject.briar.headless.getContactIdFromPathParam
|
import org.briarproject.briar.headless.getContactIdFromPathParam
|
||||||
import org.briarproject.briar.headless.getFromJson
|
import org.briarproject.briar.headless.getFromJson
|
||||||
@@ -38,6 +39,7 @@ internal class ContactControllerImpl
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val contactManager: ContactManager,
|
private val contactManager: ContactManager,
|
||||||
|
private val conversationManager: ConversationManager,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val webSocket: WebSocketController
|
private val webSocket: WebSocketController
|
||||||
) : ContactController, EventListener {
|
) : ContactController, EventListener {
|
||||||
@@ -61,7 +63,7 @@ constructor(
|
|||||||
|
|
||||||
override fun list(ctx: Context): Context {
|
override fun list(ctx: Context): Context {
|
||||||
val contacts = contactManager.contacts.map { contact ->
|
val contacts = contactManager.contacts.map { contact ->
|
||||||
contact.output()
|
contact.output(conversationManager)
|
||||||
}
|
}
|
||||||
return ctx.json(contacts)
|
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.Contact
|
||||||
import org.briarproject.bramble.api.contact.event.ContactAddedEvent
|
import org.briarproject.bramble.api.contact.event.ContactAddedEvent
|
||||||
import org.briarproject.bramble.identity.output
|
import org.briarproject.bramble.identity.output
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager
|
||||||
import org.briarproject.briar.headless.json.JsonDict
|
import org.briarproject.briar.headless.json.JsonDict
|
||||||
|
|
||||||
internal fun Contact.output() = JsonDict(
|
internal fun Contact.output(conversationManager: ConversationManager) = JsonDict(
|
||||||
"contactId" to id.int,
|
"contactId" to id.int,
|
||||||
"author" to author.output(),
|
"author" to author.output(),
|
||||||
"verified" to isVerified
|
"verified" to isVerified,
|
||||||
|
"lastChatActivity" to this.getLastChatActivity(conversationManager)
|
||||||
).apply {
|
).apply {
|
||||||
alias?.let { put("alias", it) }
|
alias?.let { put("alias", it) }
|
||||||
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun Contact.getLastChatActivity(conversationManager: ConversationManager) =
|
||||||
|
conversationManager.getGroupCount(this.id).latestMsgTime
|
||||||
|
|
||||||
internal fun ContactAddedEvent.output() = JsonDict(
|
internal fun ContactAddedEvent.output() = JsonDict(
|
||||||
"contactId" to contactId.int,
|
"contactId" to contactId.int,
|
||||||
"verified" to isVerified
|
"verified" to isVerified
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.sync.Message
|
|||||||
import org.briarproject.bramble.api.system.Clock
|
import org.briarproject.bramble.api.system.Clock
|
||||||
import org.briarproject.bramble.test.TestUtils.*
|
import org.briarproject.bramble.test.TestUtils.*
|
||||||
import org.briarproject.bramble.util.StringUtils.getRandomString
|
import org.briarproject.bramble.util.StringUtils.getRandomString
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager
|
||||||
import org.briarproject.briar.headless.event.WebSocketController
|
import org.briarproject.briar.headless.event.WebSocketController
|
||||||
import org.skyscreamer.jsonassert.JSONAssert.assertEquals
|
import org.skyscreamer.jsonassert.JSONAssert.assertEquals
|
||||||
import org.skyscreamer.jsonassert.JSONCompareMode.STRICT
|
import org.skyscreamer.jsonassert.JSONCompareMode.STRICT
|
||||||
@@ -23,6 +24,7 @@ import javax.servlet.http.HttpServletResponse
|
|||||||
abstract class ControllerTest {
|
abstract class ControllerTest {
|
||||||
|
|
||||||
protected val contactManager = mockk<ContactManager>()
|
protected val contactManager = mockk<ContactManager>()
|
||||||
|
protected val conversationManager = mockk<ConversationManager>()
|
||||||
protected val identityManager = mockk<IdentityManager>()
|
protected val identityManager = mockk<IdentityManager>()
|
||||||
protected val clock = mockk<Clock>()
|
protected val clock = mockk<Clock>()
|
||||||
protected val ctx = mockk<Context>()
|
protected val ctx = mockk<Context>()
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
private val pendingContact = getPendingContact()
|
private val pendingContact = getPendingContact()
|
||||||
|
|
||||||
private val controller =
|
private val controller =
|
||||||
ContactControllerImpl(contactManager, objectMapper, webSocketController)
|
ContactControllerImpl(contactManager, conversationManager, objectMapper, webSocketController)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEmptyContactList() {
|
fun testEmptyContactList() {
|
||||||
@@ -47,7 +47,8 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun testList() {
|
fun testList() {
|
||||||
every { contactManager.contacts } returns listOf(contact)
|
every { contactManager.contacts } returns listOf(contact)
|
||||||
every { ctx.json(listOf(contact.output())) } returns ctx
|
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
||||||
|
every { ctx.json(listOf(contact.output(conversationManager))) } returns ctx
|
||||||
controller.list(ctx)
|
controller.list(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,6 +265,7 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOutputContact() {
|
fun testOutputContact() {
|
||||||
|
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
||||||
assertNotNull(contact.handshakePublicKey)
|
assertNotNull(contact.handshakePublicKey)
|
||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
@@ -271,10 +273,11 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
"author": ${toJson(author.output())},
|
"author": ${toJson(author.output())},
|
||||||
"alias" : "${contact.alias}",
|
"alias" : "${contact.alias}",
|
||||||
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
||||||
"verified": ${contact.isVerified}
|
"verified": ${contact.isVerified},
|
||||||
|
"lastChatActivity": ${timestamp}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
assertJsonEquals(json, contact.output())
|
assertJsonEquals(json, contact.output(conversationManager))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import org.junit.jupiter.api.Test
|
|||||||
internal class MessagingControllerImplTest : ControllerTest() {
|
internal class MessagingControllerImplTest : ControllerTest() {
|
||||||
|
|
||||||
private val messagingManager = mockk<MessagingManager>()
|
private val messagingManager = mockk<MessagingManager>()
|
||||||
private val conversationManager = mockk<ConversationManager>()
|
|
||||||
private val privateMessageFactory = mockk<PrivateMessageFactory>()
|
private val privateMessageFactory = mockk<PrivateMessageFactory>()
|
||||||
private val dbExecutor = ImmediateExecutor()
|
private val dbExecutor = ImmediateExecutor()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user