Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setRestrictions with referential integrity enabled #152

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"clearedSuffix": false
}
],
"../gradle.properties": [
{
"pattern": "^VERSION_NAME=(v?(\\d+\\.?){2,}([a-zA-Z0-9-]+(\\.?\\d+)?)?)$",
"clearedPrefix": true,
"clearedSuffix": false
}
],
"README.md": [
{
"pattern": "^\\s{2,}<version>(v?(\\d+\\.?){2,}([a-zA-Z0-9-]+(\\.?\\d+)?)?)<\\/version>$",
Expand Down
11 changes: 8 additions & 3 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: kmp-chat
version: 0.9.3
version: 0.9.4
schema: 1
scm: github.com/pubnub/kmp-chat
sdks:
Expand All @@ -21,8 +21,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-chat-0.9.3
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-chat/0.9.3/
package-name: pubnub-chat-0.9.4
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-chat/0.9.4/
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -77,6 +77,11 @@ sdks:
license-url: https://github.com/pubnub/kotlin/blob/master/LICENSE
is-required: Required
changelog:
- date: 2024-12-20
version: 0.9.4
changes:
- type: bug
text: "Make setRestrictions work with `Enforce referential integrity for memberships` enabled on keyset."
- date: 2024-12-16
version: 0.9.3
changes:
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "PubNubChatRemoteBinaryPackage",
url: "https://github.com/pubnub/kmp-chat/releases/download/kotlin-0.9.3/PubNubChat.xcframework.zip",
checksum: "dccc53b725a2c5f75936a8b85ae4dab7bd5060ede5b6e19ce80c7ecc35090578"
url: "https://github.com/pubnub/kmp-chat/releases/download/kotlin-0.9.4/PubNubChat.xcframework.zip",
checksum: "b2971bcc09a9e0107c4bcbf3795fd53ab80608f4dc3dbb7c67ee668009e4b1fe"
)
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-chat</artifactId>
<version>0.9.3</version>
<version>0.9.4</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,46 +701,53 @@ class ChatImpl(
): PNFuture<Unit> {
val channel: String = INTERNAL_MODERATION_PREFIX + restriction.channelId
val userId = restriction.userId

val moderationEvent: PNFuture<PNMemberArrayResult> =
if (!restriction.ban && !restriction.mute) {
pubNub.removeChannelMembers(channel = channel, uuids = listOf(userId))
.alsoAsync { _ ->
emitEvent(
channelId = INTERNAL_USER_MODERATION_CHANNEL_PREFIX + userId,
payload = EventContent.Moderation(
channelId = channel,
restriction = RestrictionType.LIFT,
reason = restriction.reason
),
)
}
return createChannel(channel).catch { exception ->
if (exception.message == CHANNEL_ID_ALREADY_EXIST) {
Result.success(Unit)
} else {
val custom = createCustomObject(
mapOf(
RESTRICTION_BAN to restriction.ban,
RESTRICTION_MUTE to restriction.mute,
RESTRICTION_REASON to restriction.reason
)
)
val uuids = listOf(PNMember.Partial(uuidId = userId, custom = custom, null))
pubNub.setChannelMembers(channel = channel, uuids = uuids)
.alsoAsync { _ ->
emitEvent(
channelId = INTERNAL_USER_MODERATION_CHANNEL_PREFIX + userId,
payload = EventContent.Moderation(
channelId = channel,
restriction = if (restriction.ban) {
RestrictionType.BAN
} else {
RestrictionType.MUTE
},
reason = restriction.reason
),
)
}
Result.failure(exception)
}
return moderationEvent.then { }
}.thenAsync {
val moderationEvent: PNFuture<PNMemberArrayResult> =
if (!restriction.ban && !restriction.mute) {
pubNub.removeChannelMembers(channel = channel, uuids = listOf(userId))
.alsoAsync { _ ->
emitEvent(
channelId = INTERNAL_USER_MODERATION_CHANNEL_PREFIX + userId,
payload = EventContent.Moderation(
channelId = channel,
restriction = RestrictionType.LIFT,
reason = restriction.reason
),
)
}
} else {
val custom = createCustomObject(
mapOf(
RESTRICTION_BAN to restriction.ban,
RESTRICTION_MUTE to restriction.mute,
RESTRICTION_REASON to restriction.reason
)
)
val uuids = listOf(PNMember.Partial(uuidId = userId, custom = custom, null))
pubNub.setChannelMembers(channel = channel, uuids = uuids)
.alsoAsync { _ ->
emitEvent(
channelId = INTERNAL_USER_MODERATION_CHANNEL_PREFIX + userId,
payload = EventContent.Moderation(
channelId = channel,
restriction = if (restriction.ban) {
RestrictionType.BAN
} else {
RestrictionType.MUTE
},
reason = restriction.reason
),
)
}
}
moderationEvent.then { }
}
}

override fun registerPushChannels(channels: List<String>): PNFuture<PNPushAddChannelResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,12 @@ class ChatTest : BaseTest() {
mute = mute,
reason = "paid"
)
every { getChannelMetadataEndpoint.async(any()) } calls { (callback1: Consumer<Result<PNChannelMetadataResult>>) ->
callback1.accept(Result.success(getPNChannelMetadataResult("PUBNUB_INTERNAL_MODERATION_myChannelId")))
}
every {
pubnub.getChannelMetadata(channel = "PUBNUB_INTERNAL_MODERATION_myChannelId", includeCustom = true)
} returns getChannelMetadataEndpoint
every {
pubnub.removeChannelMembers(
capture(channelIdSlot),
Expand Down Expand Up @@ -1405,6 +1411,12 @@ class ChatTest : BaseTest() {
mute = mute,
reason = reason
)
every { getChannelMetadataEndpoint.async(any()) } calls { (callback1: Consumer<Result<PNChannelMetadataResult>>) ->
callback1.accept(Result.success(getPNChannelMetadataResult("PUBNUB_INTERNAL_MODERATION_myChannelId")))
}
every {
pubnub.getChannelMetadata(channel = "PUBNUB_INTERNAL_MODERATION_myChannelId", includeCustom = true)
} returns getChannelMetadataEndpoint
every {
pubnub.setChannelMembers(
channel = capture(channelIdSlot),
Expand Down
Loading