mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
@@ -69,7 +69,8 @@ Returns a JSON array of contacts:
|
||||
"handshakePublicKey": "XnYRd7a7E4CTqgAvh4hCxh/YZ0EPscxknB9ZcEOpSzY=",
|
||||
"verified": true,
|
||||
"lastChatActivity": 1557838312175,
|
||||
"connected": false
|
||||
"connected": false,
|
||||
"unreadCount": 7
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -77,7 +77,8 @@ constructor(
|
||||
val contacts = contactManager.contacts.map { contact ->
|
||||
val latestMsgTime = conversationManager.getGroupCount(contact.id).latestMsgTime
|
||||
val connected = connectionRegistry.isConnected(contact.id)
|
||||
contact.output(latestMsgTime, connected)
|
||||
val unreadCount = conversationManager.getGroupCount(contact.id).unreadCount
|
||||
contact.output(latestMsgTime, connected, unreadCount)
|
||||
}
|
||||
return ctx.json(contacts)
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent
|
||||
import org.briarproject.bramble.identity.output
|
||||
import org.briarproject.briar.headless.json.JsonDict
|
||||
|
||||
internal fun Contact.output(latestMsgTime: Long, connected: Boolean) = JsonDict(
|
||||
internal fun Contact.output(latestMsgTime: Long, connected: Boolean, unreadCount: Int) = JsonDict(
|
||||
"contactId" to id.int,
|
||||
"author" to author.output(),
|
||||
"verified" to isVerified,
|
||||
"lastChatActivity" to latestMsgTime,
|
||||
"connected" to connected
|
||||
"connected" to connected,
|
||||
"unreadCount" to unreadCount
|
||||
).apply {
|
||||
alias?.let { put("alias", it) }
|
||||
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
||||
|
||||
@@ -46,6 +46,7 @@ abstract class ControllerTest {
|
||||
protected val message: Message = getMessage(group.id)
|
||||
protected val text: String = getRandomString(5)
|
||||
protected val timestamp = 42L
|
||||
protected val unreadCount = 42
|
||||
|
||||
protected fun assertJsonEquals(json: String, obj: Any) {
|
||||
assertEquals(json, outputCtx.json(obj).resultString(), STRICT)
|
||||
|
||||
@@ -58,7 +58,8 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
every { contactManager.contacts } returns listOf(contact)
|
||||
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
||||
every { connectionRegistry.isConnected(contact.id) } returns connected
|
||||
every { ctx.json(listOf(contact.output(timestamp, connected))) } returns ctx
|
||||
every { conversationManager.getGroupCount(contact.id).unreadCount } returns unreadCount
|
||||
every { ctx.json(listOf(contact.output(timestamp, connected, unreadCount))) } returns ctx
|
||||
controller.list(ctx)
|
||||
}
|
||||
|
||||
@@ -313,10 +314,11 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
||||
"verified": ${contact.isVerified},
|
||||
"lastChatActivity": $timestamp,
|
||||
"connected": $connected
|
||||
"connected": $connected,
|
||||
"unreadCount": $unreadCount
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, contact.output(timestamp, connected))
|
||||
assertJsonEquals(json, contact.output(timestamp, connected, unreadCount))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user