From df2dcb3031f47a0909a65a14867f5ec47213ce2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Kalici=C5=84ski?= Date: Fri, 20 Dec 2024 11:09:57 +0100 Subject: [PATCH 1/3] Fix setRestrictions with referential integrity enabled fix: Make setRestrictions work with `Enforce referential integrity for memberships` enabled on keyset --- .github/workflows/release/versions.json | 7 ++ .../com/pubnub/chat/internal/ChatImpl.kt | 83 ++++++++++--------- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/.github/workflows/release/versions.json b/.github/workflows/release/versions.json index baa8396f..6c136ebf 100644 --- a/.github/workflows/release/versions.json +++ b/.github/workflows/release/versions.json @@ -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,}(v?(\\d+\\.?){2,}([a-zA-Z0-9-]+(\\.?\\d+)?)?)<\\/version>$", diff --git a/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/ChatImpl.kt b/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/ChatImpl.kt index 04ea75c6..15c3cf38 100644 --- a/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/ChatImpl.kt +++ b/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/ChatImpl.kt @@ -701,46 +701,53 @@ class ChatImpl( ): PNFuture { val channel: String = INTERNAL_MODERATION_PREFIX + restriction.channelId val userId = restriction.userId - - val moderationEvent: PNFuture = - 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 = + 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): PNFuture { From c10ce725db710ee5932300f25ca98ff51e33b73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Kalici=C5=84ski?= Date: Fri, 20 Dec 2024 13:41:10 +0100 Subject: [PATCH 2/3] Fix tests --- .../src/commonTest/kotlin/com/pubnub/kmp/ChatTest.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/kmp/ChatTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/kmp/ChatTest.kt index 3e56e13a..eb116eb1 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/kmp/ChatTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/kmp/ChatTest.kt @@ -1346,6 +1346,12 @@ class ChatTest : BaseTest() { mute = mute, reason = "paid" ) + every { getChannelMetadataEndpoint.async(any()) } calls { (callback1: Consumer>) -> + 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), @@ -1405,6 +1411,12 @@ class ChatTest : BaseTest() { mute = mute, reason = reason ) + every { getChannelMetadataEndpoint.async(any()) } calls { (callback1: Consumer>) -> + 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), From 33bcb12d0d140c63289f23b24d9d1a1c5a379c27 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:23:35 +0100 Subject: [PATCH 3/3] PubNub kotlin 0.9.4 release. --- .pubnub.yml | 11 ++++++++--- Package.swift | 4 ++-- README.md | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index aa130820..106bc70d 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,5 @@ name: kmp-chat -version: 0.9.3 +version: 0.9.4 schema: 1 scm: github.com/pubnub/kmp-chat sdks: @@ -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: @@ -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: diff --git a/Package.swift b/Package.swift index 2b15ca5b..8c8bbebf 100644 --- a/Package.swift +++ b/Package.swift @@ -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" ) ] ) diff --git a/README.md b/README.md index be2d85ac..4c2f04eb 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your com.pubnub pubnub-chat - 0.9.3 + 0.9.4 ```