Skip to content

Commit

Permalink
PAM test
Browse files Browse the repository at this point in the history
  • Loading branch information
wkal-pubnub committed Jan 15, 2025
1 parent 3e5fc27 commit 5b4de39
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ class MutedUsersManagerImpl(val pubNub: PubNub, val userId: String, val syncEnab
}

fun loadMutedUsers(): PNFuture<Unit> {
return pubNub.getUUIDMetadata(
userMuteChannelId,
includeCustom = true
).nullOn404().then {
muteSetAtomic.value = customToMutedUsersSet(it?.data?.custom)
return if (syncEnabled) {
pubNub.getUUIDMetadata(
userMuteChannelId,
includeCustom = true
).nullOn404().then {
muteSetAtomic.value = customToMutedUsersSet(it?.data?.custom)
}
} else {
Unit.asFuture()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.pubnub.integration

import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant
import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant
import com.pubnub.api.models.consumer.pubsub.PNEvent
import com.pubnub.chat.Event
import com.pubnub.chat.Message
import com.pubnub.chat.config.ChatConfiguration
import com.pubnub.chat.internal.ChatImpl
import com.pubnub.chat.internal.PREFIX_PUBNUB_PRIVATE
import com.pubnub.chat.internal.SUFFIX_MUTE_1
import com.pubnub.chat.internal.mutelist.MutedUsersManagerImpl
import com.pubnub.chat.listenForEvents
import com.pubnub.chat.mutelist.MutedUsersManager
import com.pubnub.chat.types.EventContent
import com.pubnub.chat.types.GetEventsHistoryResult
import com.pubnub.internal.PLATFORM
import com.pubnub.test.await
import com.pubnub.test.randomString
import com.pubnub.test.test
Expand Down Expand Up @@ -72,6 +77,49 @@ class MutedUsersIntegrationTest : BaseChatIntegrationTest() {
}
}

@Test
fun sync_updates_between_clients_on_init() = runTest {
val mutedUsers1 = getMutedUsers(true)
mutedUsers1.muteUser(someUser02.id).await()
val chat2 = ChatImpl(ChatConfiguration(syncMutedUsers = true), pubnub).initialize().await()
assertContains(chat2.mutedUsersManager.mutedUsers, someUser02.id)
}

@Test
fun sync_updates_between_clients_on_init_pam() = runTest {
if (PLATFORM == "iOS") {
return@runTest
}

val clientUserId = pubnubPamClient.configuration.userId.value

val serverChat = ChatImpl(ChatConfiguration(), pubnubPamServer).initialize().await()
val token = serverChat.pubNub.grantToken(
ttl = 1,
channels = listOf(
ChannelGrant.name(get = true, name = "anyChannelForNow"),
ChannelGrant.name(
name = "PN_PRV.$clientUserId.mute1",
read = true,
)
),
uuids = listOf(
UUIDGrant.id(id = clientUserId, get = true, update = true),
UUIDGrant.id(
id = "PN_PRV.$clientUserId.mute1",
update = true,
delete = true,
get = true,
)
) // this is important
).await().token

pubnubPamClient.setToken(token)

ChatImpl(ChatConfiguration(syncMutedUsers = true), pubnubPamClient).initialize().await()
// no exception
}

@Test
fun connect_filters_muted_users() = runTest {
val channel = chat.createChannel(randomString()).await()
Expand Down

0 comments on commit 5b4de39

Please sign in to comment.