Skip to content

Commit

Permalink
Fixed getUnreadMessagesCounts function
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo committed Dec 10, 2024
1 parent 20a796a commit 9c1d33f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,11 @@ class ChatImpl(
return@thenAsync emptyList<GetUnreadMessagesCounts>().asFuture()
}
val channels = memberships.map { membership -> membership.channel.id }
val channelsTimetoken =
memberships.map { membership -> membership.lastReadMessageTimetoken ?: 0 }

// we need to increased returned lastReadMessageTimetoken by 1 because for odds numbers larger than 9007199254740991 server store them one bigger
val channelsTimetoken: List<Long> =
memberships.map { membership -> (membership.lastReadMessageTimetoken?.plus(1))?: 0 }

pubNub.messageCounts(channels = channels, channelsTimetoken = channelsTimetoken)
.then { pnMessageCountResult ->
val unreadMessageCounts =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ abstract class BaseChannel<C : Channel, M : Message>(
log.pnError(READ_RECEIPTS_ARE_NOT_SUPPORTED_IN_PUBLIC_CHATS)
}
val timetokensPerUser = mutableMapOf<String, Long>()
val future = getMembers().then { members -> // todo what about paging? maybe not needed in non-public chats...
// in group chats it work till 100 members
val future = getMembers().then { members ->
members.members.forEach { m ->
val lastTimetoken = m.custom?.get(METADATA_LAST_READ_MESSAGE_TIMETOKEN)?.tryLong()
if (lastTimetoken != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ class ChatIntegrationTest : BaseChatIntegrationTest() {
chat.pubNub.deleteMessages(listOf(channelId01)).await()
}

@Ignore // fails from time to time
@Test
fun can_getUnreadMessageCounts_global() = runTest {
val channelId01 = channel01.id
Expand Down Expand Up @@ -359,7 +358,7 @@ class ChatIntegrationTest : BaseChatIntegrationTest() {
}?.count
?: 0
assertEquals(0, unreadMessagesCountsForChannel01)
assertEquals(0, unreadMessagesCountsForChannel02) // todo when run in set sometimes fails :/
assertEquals(0, unreadMessagesCountsForChannel02)

// remove messages
chat.pubNub.deleteMessages(listOf(channelId01, channelId02))
Expand Down

0 comments on commit 9c1d33f

Please sign in to comment.