Expose unread messages count in API's contacts list

Fixes #1746
This commit is contained in:
Nico Alt
2020-09-25 12:40:43 +02:00
parent 4e5f2e31df
commit ccbe6d4bb8
5 changed files with 13 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -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) }