Add new method to fetch unread message counts for user's channels#185
Add new method to fetch unread message counts for user's channels#185jguz-pubnub merged 8 commits intomasterfrom
Conversation
| channel = membershipMatchingChannel.channel, | ||
| membership = membershipMatchingChannel, | ||
| count = messageCount | ||
| count = messageCount, |
There was a problem hiding this comment.
What about adding test.
We could add test similar to can_getUnreadMessageCounts_global
but with limit = 1 to test paging
e.g.
chat.getUnreadMessagesCounts(limit = 1).await()
Maybe there are better way to test paging?
My understanding is that we would like to support situation that there are more than 100 channels that user is member of.
@Test
fun can_getUnreadMessageCounts_withPagination() = runTest {
val channelId01 = channel01.id
val channelId02 = channel02.id
// join two channels
channel01.join { }.await()
channel02.join { }.await()
// send message
channel01.sendText("message01In$channelId01").await()
channel02.sendText("message01In$channelId02").await()
delayForHistory()
// read message count with limit=1 to get pagination
val unreadMessagesCounts: List<GetUnreadMessagesCounts> = chat.getUnreadMessagesCounts(limit = 1).await()
// Verify we got one result due to limit
assertEquals(1, unreadMessagesCounts.size)
// Verify first count is correct
val firstCount: GetUnreadMessagesCounts = unreadMessagesCounts.first()
assertEquals(1, firstCount.count)
assertEquals(channelId01, firstCount.channel.id)
// Verify we have next page but no prev page
assertNotNull(firstCount.next, "Should have next page")
assertNull(firstCount.prev, "Should not have prev page")
// Get next page
val nextPageCounts: List<GetUnreadMessagesCounts> = chat.getUnreadMessagesCounts(limit = 1, page = firstCount.next).await()
// Verify next page results
assertEquals(1, nextPageCounts.size)
val nextPageCount = nextPageCounts.first()
assertEquals(1, nextPageCount.count)
assertEquals(channelId02, nextPageCount.channel.id)
// remove messages
chat.pubNub.deleteMessages(listOf(channelId01, channelId02))
}
| createJsObject<GetUnreadMessagesCountsJs> { | ||
| this.channel = unreadMessagesCount.channel.asJs(this@ChatJs) | ||
| this.membership = unreadMessagesCount.membership.asJs(this@ChatJs) | ||
| this.page = MetadataPage(unreadMessagesCount.next, unreadMessagesCount.prev) |
There was a problem hiding this comment.
Maybe we could add test for paging in JS.
There is already test for getUnreadMessagesCounts called : test("Should get the number of unread messages on channels"
located:
kmp-chat/js-chat/tests/channel.test.ts
| }.asPromise() | ||
| } | ||
|
|
||
| private fun GetUnreadMessagesCounts.toJs() = |
There was a problem hiding this comment.
I am wondering why this method was not present before. Why it is needed now?
There was a problem hiding this comment.
This is because the newly introduced UnreadMessagesCounts class stores an array of GetUnreadMessagesCounts.These stored items must be serialized into the type expected by the JS
| } | ||
|
|
||
| override fun fetchUnreadMessagesCounts( | ||
| limit: Int?, |
There was a problem hiding this comment.
What about adding tests ?
06a8d16 to
4457a75
Compare
| } | ||
|
|
||
| fun fetchUnreadMessagesCounts(params: PubNub.GetMembershipsParametersv2?): Promise<FetchUnreadMessagesCountsJs> { | ||
| fun fetchUnreadMessagesCounts(params: PubNub.GetMembershipsParametersv2?): Promise<FetchUnreadMessagesCountsResponseJs> { |
There was a problem hiding this comment.
Do we have doc changes for this ?
4908d62 to
1cee446
Compare
|
@pubnub-release-bot release kotlin as 0.13.0 |
f1b110e to
6534c2c
Compare
|
🚀 Release successfully completed 🚀 |
feat: Add new API method returning paginated unread message counts