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