Skip to content
Snippets Groups Projects
Commit 043700c7 authored by Nico's avatar Nico
Browse files

[WIP] Expose unread messages count in API's contacts list

WIP because it seems that the unread counter is never set to 0.

Fixes #1746
parent 4e5f2e31
No related branches found
No related tags found
No related merge requests found
Pipeline #4857 failed
......@@ -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) }
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment