Skip to content

Commit

Permalink
Fixed bug rel. to setRestriction
Browse files Browse the repository at this point in the history
When "Enforce referential integrity for memberships" then when setting restriction(channelMembers) we need to make sure that both channel and user exist in AppContext.
  • Loading branch information
marcin-cebo committed Feb 20, 2025
1 parent 2c46f05 commit 9d55cc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
16 changes: 0 additions & 16 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,22 +659,6 @@ 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==

[email protected]:
version "8.4.1"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.4.1.tgz#5f6f19e84d3187dc8aee0a458bd6b05e90d43e6a"
integrity sha512-mPlwVoHJDWPasZx52UfSMiPX5TATm5A+ficSogyqDqTQ4w5EQnwxH+PJdsWc0mPnlT051jM1vIISMeM0fQ30CQ==
dependencies:
agentkeepalive "^3.5.2"
buffer "^6.0.3"
cbor-js "^0.1.0"
cbor-sync "^1.0.4"
form-data "^4.0.0"
lil-uuid "^0.1.1"
node-fetch "^2.7.0"
proxy-agent "^6.3.0"
react-native-url-polyfill "^2.0.0"
text-encoding "^0.7.0"

[email protected]:
version "8.6.0"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.6.0.tgz#75524e7ed3653090652d160ce83ac089362a0379"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ class ChatImpl(
}
val channel: String = INTERNAL_MODERATION_PREFIX + restriction.channelId
val userId = restriction.userId
// if "Enforce referential integrity for memberships" is enabled we need to make sure that channel exists in AppContext
return createChannel(channel, type = ChannelType.PUBNUB_PRIVATE).catch { exception ->
if (exception.message == CHANNEL_ID_ALREADY_EXIST) {
Result.success(Unit)
Expand Down Expand Up @@ -753,8 +754,16 @@ class ChatImpl(
)
)
val uuids = listOf(PNMember.Partial(uuidId = userId, custom = custom, null))
pubNub.setChannelMembers(channel = channel, users = uuids)
.alsoAsync { _ ->

// if "Enforce referential integrity for memberships" is enabled we need to make sure that user exists in AppContext
createUser(id = userId).catch { exception ->
if (exception.message == USER_ID_ALREADY_EXIST) {
Result.success(Unit)
} else {
Result.failure(exception)
}
}.thenAsync {
pubNub.setChannelMembers(channel = channel, users = uuids).alsoAsync { _ ->
emitEvent(
channelId = INTERNAL_USER_MODERATION_CHANNEL_PREFIX + userId,
payload = EventContent.Moderation(
Expand All @@ -768,6 +777,7 @@ class ChatImpl(
),
)
}
}
}
moderationEvent.then { }
}
Expand Down

0 comments on commit 9d55cc9

Please sign in to comment.