Skip to content

Commit

Permalink
Updated PubNub Js sdk containing membership type.
Browse files Browse the repository at this point in the history
In KMP js implemented new Memberships and ChannelMembers methods containing possibility to specify membership type and all optional data returned by API using include parameters.
  • Loading branch information
marcin-cebo committed Dec 19, 2024
1 parent 31d5360 commit 3e3b6c3
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ktlint = "12.1.0"
dokka = "1.9.20"
kotlinx_datetime = "0.6.1"
kotlinx_coroutines = "1.9.0"
pubnub_js = "8.3.1"
pubnub_js = "8.4.0"
pubnub_swift = "8.2.2"

[libraries]
Expand Down
8 changes: 4 additions & 4 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,10 @@ proxy-from-env@^1.1.0:
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pubnub@8.3.1:
version "8.3.1"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.3.1.tgz#48b6c2468452427c9d1aa9a51e78781d25eec660"
integrity sha512-+aFp84Jsqpmu9utci8uQhABTMoh1Uk8UafGS1QANSkceXX3HDRTQnpTw8itH0UchzCS9pSfUATTl+Ay3jvM5EA==
pubnub@8.4.0:
version "8.4.0"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.4.0.tgz#8a5fdd3af9783abb1de44ea4145107e296c8394d"
integrity sha512-HvkFhn4XcfR1wdJv4paX94I0TT4UBHW/vIuYnS+6XuoSx0AunJMCk5wbKnSesmdbzYUZa8Ag3H1mJQZKuyRy8Q==
dependencies:
agentkeepalive "^3.5.2"
buffer "^6.0.3"
Expand Down
30 changes: 15 additions & 15 deletions pubnub-kotlin/pubnub-kotlin-api/config/ktlint/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@
<error line="1034" column="15" source="standard:class-naming" />
<error line="1040" column="15" source="standard:class-naming" />
<error line="1160" column="13" source="standard:property-naming" />
<error line="1166" column="13" source="standard:property-naming" />
<error line="1168" column="13" source="standard:property-naming" />
<error line="1228" column="39" source="standard:comment-wrapping" />
<error line="1313" column="15" source="standard:class-naming" />
<error line="1341" column="42" source="standard:comment-wrapping" />
<error line="1391" column="37" source="standard:comment-wrapping" />
<error line="1412" column="13" source="standard:property-naming" />
<error line="1413" column="13" source="standard:property-naming" />
<error line="1170" column="13" source="standard:property-naming" />
<error line="1233" column="39" source="standard:comment-wrapping" />
<error line="1318" column="15" source="standard:class-naming" />
<error line="1346" column="42" source="standard:comment-wrapping" />
<error line="1396" column="37" source="standard:comment-wrapping" />
<error line="1417" column="13" source="standard:property-naming" />
<error line="1418" column="13" source="standard:property-naming" />
<error line="1437" column="9" source="standard:property-naming" />
<error line="1438" column="9" source="standard:property-naming" />
<error line="1439" column="9" source="standard:property-naming" />
<error line="1440" column="9" source="standard:property-naming" />
<error line="1441" column="9" source="standard:property-naming" />
<error line="1422" column="13" source="standard:property-naming" />
<error line="1423" column="13" source="standard:property-naming" />
<error line="1442" column="9" source="standard:property-naming" />
<error line="1443" column="9" source="standard:property-naming" />
<error line="1444" column="9" source="standard:property-naming" />
Expand All @@ -43,11 +38,11 @@
<error line="1447" column="9" source="standard:property-naming" />
<error line="1448" column="9" source="standard:property-naming" />
<error line="1449" column="9" source="standard:property-naming" />
<error line="1450" column="9" source="standard:property-naming" />
<error line="1451" column="9" source="standard:property-naming" />
<error line="1452" column="9" source="standard:property-naming" />
<error line="1453" column="9" source="standard:property-naming" />
<error line="1454" column="9" source="standard:property-naming" />
<error line="1455" column="9" source="standard:property-naming" />
<error line="1456" column="9" source="standard:property-naming" />
<error line="1457" column="9" source="standard:property-naming" />
<error line="1458" column="9" source="standard:property-naming" />
<error line="1459" column="9" source="standard:property-naming" />
<error line="1460" column="9" source="standard:property-naming" />
Expand Down Expand Up @@ -79,5 +74,10 @@
<error line="1486" column="9" source="standard:property-naming" />
<error line="1487" column="9" source="standard:property-naming" />
<error line="1488" column="9" source="standard:property-naming" />
<error line="1489" column="9" source="standard:property-naming" />
<error line="1490" column="9" source="standard:property-naming" />
<error line="1491" column="9" source="standard:property-naming" />
<error line="1492" column="9" source="standard:property-naming" />
<error line="1493" column="9" source="standard:property-naming" />
</file>
</baseline>
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub {
)
}

// deprecated
override fun getChannelMembers(
channel: String,
limit: Int?,
Expand Down Expand Up @@ -837,6 +838,7 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub {
)
}

// deprecated
override fun removeChannelMembers(
channel: String,
uuids: List<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GetChannelMembersImpl(
private val includeFields: MemberInclude
) : GetChannelMembers {
override fun async(callback: Consumer<Result<PNMemberArrayResult>>) {
// todo use new method with include
pubnub.getChannelMembersWithChannel(
channel = channelId,
limit = limit?.let { NSNumber(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RemoveChannelMembersImpl(
private val includeFields: MemberInclude
) : ManageChannelMembers {
override fun async(callback: Consumer<Result<PNMemberArrayResult>>) {
// todo use new method with include
pubnub.removeChannelMembersWithChannel(
channel = channel,
users = userIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SetChannelMembersImpl(
private val includeFields: MemberInclude
) : ManageChannelMembers {
override fun async(callback: Consumer<Result<PNMemberArrayResult>>) {
// todo use new method with include
pubnub.setChannelMembersWithChannel(
channel = channelId,
users = users.map { KMPUserMetadata(id = it.uuid, custom = KMPAnyJSON(it.custom?.value), status = it.status) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GetMembershipsImpl(
private val includeFields: MembershipInclude
) : GetMemberships {
override fun async(callback: Consumer<Result<PNChannelMembershipArrayResult>>) {
// todo use new method with include
pubnub.getMembershipsWithUserId(
userId = userId,
limit = limit?.let { NSNumber(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AddMembershipsImpl(
private val includeFields: MembershipInclude
) : ManageMemberships {
override fun async(callback: Consumer<Result<PNChannelMembershipArrayResult>>) {
// todo use new method with include
pubnub.setMembershipsWithChannels(
channels = channels.map { KMPChannelMetadata(it.channel, KMPAnyJSON(it.custom?.value), it.status) },
userId = userId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pubnub.test.integration

import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.member.MemberInclude
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel
import com.pubnub.kmp.PLATFORM
Expand All @@ -26,7 +27,7 @@ class MembersTest : BaseIntegrationTest() {
private val type = randomString()

@Test
fun can_set_members() = runTest {
fun can_set_members_deprecated() = runTest {
// when
val result = pubnub.setChannelMembers(
channel,
Expand All @@ -41,7 +42,50 @@ class MembersTest : BaseIntegrationTest() {
}

@Test
fun can_set_members_with_status() = runTest(timeout = 10.seconds) {
fun can_set_members() = runTest {
// when
val result = pubnub.setChannelMembers(
channel,
listOf(PNMember.Partial(pubnub.configuration.userId.value, custom, status, type)),
include = MemberInclude(includeCustom = includeCustom, includeUser = true, includeUserCustom = true, includeStatus = true, includeType = true),
).await()

// then
val pnChannelDetails = result.data.single { it.uuid.id == pubnub.configuration.userId.value }
assertEquals(customData, pnChannelDetails.custom?.value)
assertEquals(status, pnChannelDetails.status?.value)
assertEquals(type, pnChannelDetails.type?.value)
}

@Test
fun can_get_members() = runTest {
// when
pubnub.setChannelMembers(
channel,
listOf(PNMember.Partial(pubnub.configuration.userId.value, custom, status, type)),
include = MemberInclude(
includeCustom = includeCustom,
includeUser = true,
includeUserCustom = true,
includeStatus = true,
includeType = true
),
).await()

val result = pubnub.getChannelMembers(
channel,
include = MemberInclude(includeCustom = includeCustom, includeStatus = true, includeType = true)
).await()

// then
val pnChannelDetails = result.data.single { it.uuid.id == pubnub.configuration.userId.value }
assertEquals(customData, pnChannelDetails.custom?.value)
assertEquals(status, pnChannelDetails.status?.value)
assertEquals(type, pnChannelDetails.type?.value)
}

@Test
fun can_set_members_with_status_deprecated() = runTest(timeout = 10.seconds) {
if (PLATFORM == "JS") {
// TODO JS doesn't have membership status
return@runTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pubnub.test.integration

import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.membership.MembershipInclude
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership
import com.pubnub.api.models.consumer.pubsub.objects.PNDeleteMembershipEventMessage
Expand All @@ -19,16 +20,16 @@ import kotlin.test.assertFalse

class MembershipsTest : BaseIntegrationTest() {
private val channel = "myChannel" + randomString()
private val name = randomString()
private val description = randomString()
private val status = randomString()
private val customData = mapOf("aa" to randomString())
private val custom = createCustomObject(customData)
private val includeCustom = true
private val includeChannel = true
private val includeChannelCustom = true
private val type = randomString()

@Test
fun can_set_memberships() = runTest {
fun can_set_memberships_deprecated() = runTest {
// when
val result = pubnub.setMemberships(
listOf(PNChannelMembership.Partial(channel, custom, status)),
Expand All @@ -43,7 +44,29 @@ class MembershipsTest : BaseIntegrationTest() {
}

@Test
fun can_set_and_get_memberships_for_other_uuid() = runTest {
fun can_set_memberships() = runTest {
// when
val result = pubnub.setMemberships(
listOf(PNChannelMembership.Partial(channel, custom, status, type)),
include = MembershipInclude(
includeCustom = includeCustom,
includeChannel = includeChannel,
includeChannelCustom = includeChannelCustom,
includeStatus = true,
includeType = true
),
).await()

// then
val pnChannelDetails = result.data.single { it.channel.id == channel }
assertEquals(channel, pnChannelDetails.channel.id)
assertEquals(customData, pnChannelDetails.custom?.value)
assertEquals(status, pnChannelDetails.status?.value)
assertEquals(type, pnChannelDetails.type?.value)
}

@Test
fun can_set_and_get_memberships_for_other_uuid_deprecated() = runTest {
// when
val userId = "some-user-" + randomString()
pubnub.setMemberships(
Expand All @@ -53,7 +76,8 @@ class MembershipsTest : BaseIntegrationTest() {
includeChannelDetails = PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM,
).await()

val result = pubnub.getMemberships(uuid = userId, filter = "channel.id == '$channel'", includeCustom = true).await()
val result =
pubnub.getMemberships(uuid = userId, filter = "channel.id == '$channel'", includeCustom = true).await()

// then
val pnChannelDetails = result.data.single { it.channel.id == channel }
Expand All @@ -62,7 +86,40 @@ class MembershipsTest : BaseIntegrationTest() {
}

@Test
fun can_receive_set_membership_event() = runTest {
fun can_set_and_get_memberships_for_other_uuid() = runTest {
// when
val userId = "some-user-" + randomString()
pubnub.setMemberships(
channels = listOf(PNChannelMembership.Partial(channel, custom, status, type)),
userId = userId,
include = MembershipInclude(
includeCustom = includeCustom,
includeChannel = includeChannel,
includeChannelCustom = includeChannelCustom
),
).await()

val result =
pubnub.getMemberships(
userId = userId,
filter = "channel.id == '$channel'",
include = MembershipInclude(
includeCustom = includeCustom,
includeStatus = true,
includeType = true
),
).await()

// then
val pnChannelDetails = result.data.single { it.channel.id == channel }
assertEquals(channel, pnChannelDetails.channel.id)
assertEquals(customData, pnChannelDetails.custom?.value)
assertEquals(status, pnChannelDetails.status?.value)
assertEquals(type, pnChannelDetails.type?.value)
}

@Test
fun can_receive_set_membership_event_deprecated() = runTest {
pubnub.test(backgroundScope) {
// given
pubnub.awaitSubscribe(listOf(channel))
Expand All @@ -84,6 +141,32 @@ class MembershipsTest : BaseIntegrationTest() {
}
}

@Test
fun can_receive_set_membership_event() = runTest {
pubnub.test(backgroundScope) {
// given
pubnub.awaitSubscribe(listOf(channel))

// when
pubnub.setMemberships(
listOf(PNChannelMembership.Partial(channel, custom, status)),
include = MembershipInclude(
includeCustom = includeCustom,
includeChannel = includeChannel,
includeChannelCustom = includeChannelCustom
),
).await()

// then
val result = nextEvent<PNObjectEventResult>()
val message = result.extractedMessage
message as PNSetMembershipEventMessage
assertEquals(channel, message.data.channel)
assertEquals(pubnub.configuration.userId.value, message.data.uuid)
assertEquals(customData, message.data.custom?.value)
}
}

@Test
fun can_delete_membership() = runTest {
if (PLATFORM == "JS" || PLATFORM == "iOS") { // todo enable for JS/iOS once is implemented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ open external class PubNub(config: Any /* UUID | UserId */) {

interface ChannelMembershipObject : v2ObjectDataOmitId {
var channel: ChannelMetadataObject

var status: String?
var type: String?
}

interface IncludeOptions {
Expand All @@ -1163,6 +1163,8 @@ open external class PubNub(config: Any /* UUID | UserId */) {

var statusField: Boolean?

var typeField: Boolean?

var UUIDStatusField: Boolean?

var UUIDTypeField: Boolean?
Expand Down Expand Up @@ -1191,6 +1193,8 @@ open external class PubNub(config: Any /* UUID | UserId */) {

var statusField: Boolean?

var typeField: Boolean?

var channelStatusField: Boolean?

var channelTypeField: Boolean?
Expand Down Expand Up @@ -1220,6 +1224,7 @@ open external class PubNub(config: Any /* UUID | UserId */) {
var id: String
var custom: CustomObject?
var status: String?
var type: String?
}

interface SetMembershipsParameters : ChannelMembersParameters {
Expand Down
Loading

0 comments on commit 3e3b6c3

Please sign in to comment.