Skip to content

Commit

Permalink
Add Space, User and Membership events
Browse files Browse the repository at this point in the history
New methods has been added:

* addSpaceEventsListener
* addUserEventsListener
* addMembershipEventsListener

Each of them returns DisposableListener. To stop receiving callbacks
to the passed lambda  PubNub#removeListner method can be used or directly on
the returned instance DisposableListener#dispose.
  • Loading branch information
kleewho authored Jun 14, 2022
1 parent 7c439b5 commit c514d0a
Show file tree
Hide file tree
Showing 26 changed files with 796 additions and 97 deletions.
21 changes: 15 additions & 6 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kotlin
version: 7.1.0
version: 7.2.0
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-7.1.0-all.jar
- build/libs/pubnub-kotlin-7.2.0-all.jar
sdks:
-
type: library
Expand All @@ -23,8 +23,8 @@ sdks:
-
distribution-type: library
distribution-repository: GitHub
package-name: pubnub-kotlin-7.1.0
location: https://github.com/pubnub/kotlin/releases/download/v7.1.0/pubnub-kotlin-7.1.0-all.jar
package-name: pubnub-kotlin-7.2.0
location: https://github.com/pubnub/kotlin/releases/download/v7.2.0/pubnub-kotlin-7.2.0-all.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -135,8 +135,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-kotlin-7.1.0
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/7.1.0/pubnub-kotlin-7.1.0.jar
package-name: pubnub-kotlin-7.2.0
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/7.2.0/pubnub-kotlin-7.2.0.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -233,6 +233,15 @@ sdks:
license-url: https://github.com/stleary/JSON-java/blob/20210307/LICENSE
is-required: Required
changelog:
- date: 2022-06-14
version: v7.2.0
changes:
- type: feature
text: "PNChannelMetadata and PNUUIDMetadata has status and type now."
- type: feature
text: "PNChannelMembership and PNMember has status now."
- type: bug
text: "It's possible to sort memberships and members by nested fields."
- date: 2022-05-23
version: v7.1.0
changes:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v7.2.0
June 14 2022

#### Added
- PNChannelMetadata and PNUUIDMetadata has status and type now.
- PNChannelMembership and PNMember has status now.

#### Fixed
- It's possible to sort memberships and members by nested fields.

## v7.1.0
May 23 2022

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-gson</artifactId>
<version>7.1.0</version>
<version>7.2.0</version>
</dependency>
```

* for Gradle, add the following dependency in your `gradle.build`:
```groovy
implementation 'com.pubnub:pubnub-kotlin:7.1.0'
implementation 'com.pubnub:pubnub-kotlin:7.2.0'
```

2. Configure your keys:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ org.gradle.unsafe.configuration-cache=false

GROUP=com.pubnub
POM_ARTIFACT_ID=pubnub-kotlin
VERSION_NAME=7.1.0
VERSION_NAME=7.2.0
POM_PACKAGING=jar

POM_NAME=PubNub Android Chat Components
Expand Down
1 change: 1 addition & 0 deletions pubnub-memberships/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.8.2"
testImplementation "io.mockk:mockk:1.11.0"
testImplementation "org.aeonbits.owner:owner:1.0.12"
testImplementation "org.slf4j:slf4j-simple:1.7.36"
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package com.pubnub.entities

import com.pubnub.api.PNConfiguration
import com.pubnub.api.PubNub
import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.callbacks.SubscribeCallback
import com.pubnub.api.enums.PNStatusCategory
import com.pubnub.api.models.consumer.PNStatus
import com.pubnub.api.models.consumer.objects.ResultSortKey
import com.pubnub.entities.models.consumer.membership.Membership
import com.pubnub.entities.models.consumer.membership.MembershipModified
import com.pubnub.entities.models.consumer.membership.MembershipsResult
import com.pubnub.entities.models.consumer.membership.SpaceDetailsLevel
import com.pubnub.entities.models.consumer.membership.SpaceMembershipResultKey
Expand All @@ -19,6 +22,9 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.fail
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

class MembershipIntegTest {
private lateinit var pubnub: PubNub
Expand Down Expand Up @@ -53,8 +59,6 @@ class MembershipIntegTest {
IntegTestConf.origin?.let {
origin = it
}
secure = false
logVerbosity = PNLogVerbosity.BODY
}
pubnub = PubNub(config)

Expand Down Expand Up @@ -335,6 +339,79 @@ class MembershipIntegTest {
assertEquals(USER_NAME, membershipsResultSortUserNameDesc?.data?.elementAt(1)?.user?.name)
}

@Test
internal fun can_receiveMembershipEventsForUser() {
val allUpdatesDone = CountDownLatch(2)
val lastUpdate = mapOf("this" to "that")
val created = CountDownLatch(1)
val user = User(id = USER_ID)
val space = Space(id = SPACE_ID)
var membership = Membership(
user = user,
space = space,
custom = mapOf(),
status = null
)
val connected = CountDownLatch(1)
pubnub.addListener(object : SubscribeCallback() {
override fun status(pubnub: PubNub, pnStatus: PNStatus) {
if (pnStatus.category == PNStatusCategory.PNConnectedCategory) {
connected.countDown()
}
}
})

pubnub.addMembershipEventsListener {

if (it is MembershipModified) {
if (it.data.custom != lastUpdate) {
created.countDown()
}
membership = membership.copy(
user = it.data.user,
space = it.data.space,
custom = it.data.custom,
status = it.data.status
)
}
allUpdatesDone.countDown()
}
pubnub.subscribe(channels = listOf(USER_ID.value))
if (!connected.await(5, TimeUnit.SECONDS)) {
fail("Didn't connect")
}

pubnub.addMemberships(
spaceId = SPACE_ID,
partialMembershipsWithUser = listOf(Membership.Partial(userId = USER_ID))
).sync()

if (!created.await(5, TimeUnit.SECONDS)) {
fail("Didn't receive created event")
}
pubnub.updateMemberships(
spaceId = SPACE_ID,
partialMembershipsWithUser = listOf(
Membership.Partial(
userId = USER_ID,
custom = lastUpdate
)
)
).sync()
if (!allUpdatesDone.await(5, TimeUnit.SECONDS)) {
fail("Didn't receive enough events")
}
assertEquals(
Membership(
user = user,
space = space,
custom = lastUpdate,
status = null
),
membership
)
}

@AfterEach
internal fun tearDown() {
removeEntities()
Expand Down
Loading

0 comments on commit c514d0a

Please sign in to comment.