Skip to content

Commit

Permalink
Added status and type to Membership. (#151)
Browse files Browse the repository at this point in the history
* Refactor. Use non-deprecated Memberships and ChannelMembers methods.

* Increased timeout for JS test to passed.
In new version of PubNub core js sdk verbose logging has been added that slows down test execution.

* Refactor. Use non-deprecated Memberships and ChannelMembers method.

* PubNub kotlin 0.10.0 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
marcin-cebo and pubnub-release-bot authored Jan 7, 2025
1 parent 1ba266d commit 38a7729
Show file tree
Hide file tree
Showing 20 changed files with 296 additions and 155 deletions.
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.4
version: 0.10.0
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.4
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-chat/0.9.4/
package-name: pubnub-chat-0.10.0
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-chat/0.10.0/
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: 2025-01-07
version: 0.10.0
changes:
- type: feature
text: "Added status and type to Membership."
- date: 2024-12-20
version: 0.9.4
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.4/PubNubChat.xcframework.zip",
checksum: "b2971bcc09a9e0107c4bcbf3795fd53ab80608f4dc3dbb7c67ee668009e4b1fe"
url: "https://github.com/pubnub/kmp-chat/releases/download/kotlin-0.10.0/PubNubChat.xcframework.zip",
checksum: "bc2c024e9b83a67d90e078778e140c0858651f96d0909d9a14143d36fa5efdf3"
)
]
)
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.4</version>
<version>0.10.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PubNubBaseKotlinMultiplatformPlugin : Plugin<Project> {
testTask {
it.environment("MOCHA_OPTIONS", "--exit")
it.useMocha {
timeout = "20s"
timeout = "30s"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
POM_PACKAGING=jar
VERSION_NAME=0.9.6
VERSION_NAME=0.10.0

POM_NAME=PubNub Chat SDK
POM_DESCRIPTION=This SDK offers a set of handy methods to create your own feature-rich chat or add a chat to your existing application.
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ktlint = "12.1.0"
dokka = "1.9.20"
kotlinx_serialization = "1.7.3"
kotlinx_coroutines = "1.9.0"
pubnub = "10.3.2"
pubnub_swift = "8.2.2"
pubnub = "10.3.3"
pubnub_swift = "8.2.3"

[libraries]
pubnub-kotlin-api = { module = "com.pubnub:pubnub-kotlin-api", version.ref = "pubnub" }
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.2.8:
version "8.2.8"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.2.8.tgz#68d3b84d07e128b29f74c6c46495f0c5bedd1a3f"
integrity sha512-OREW+YDWWocOaz16jbrrybD0AyqEFuskCGi+EMgOb9FUJkuYPnInjlMSAUBBrlx7lMTARMQxx3Sk0EIvbB3hig==
pubnub@8.4.1:
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"
Expand Down
2 changes: 2 additions & 0 deletions pubnub-chat-api/api/pubnub-chat-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public abstract interface class com/pubnub/chat/Membership {
public abstract fun getCustom ()Ljava/util/Map;
public abstract fun getETag ()Ljava/lang/String;
public abstract fun getLastReadMessageTimetoken ()Ljava/lang/Long;
public abstract fun getStatus ()Ljava/lang/String;
public abstract fun getType ()Ljava/lang/String;
public abstract fun getUnreadMessagesCount ()Lcom/pubnub/kmp/PNFuture;
public abstract fun getUpdated ()Ljava/lang/String;
public abstract fun getUser ()Lcom/pubnub/chat/User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ interface Membership {
*/
val eTag: String?

/**
* Status of a Membership
*/
val status: String?

/**
* Type of a Membership
*/
val type: String?

/**
* Timetoken of the last message a user read on a given channel.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.pubnub.api.models.consumer.objects.PNSortKey
import com.pubnub.api.models.consumer.objects.channel.PNChannelMetadataResult
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.member.PNMemberArrayResult
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.MembershipInclude
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembershipArrayResult
import com.pubnub.api.models.consumer.objects.uuid.PNUUIDMetadataArrayResult
Expand Down Expand Up @@ -63,6 +63,7 @@ import com.pubnub.chat.internal.error.PubNubErrorMessage.FAILED_TO_FORWARD_MESSA
import com.pubnub.chat.internal.error.PubNubErrorMessage.FAILED_TO_RETRIEVE_WHO_IS_PRESENT_DATA
import com.pubnub.chat.internal.error.PubNubErrorMessage.FAILED_TO_SOFT_DELETE_CHANNEL
import com.pubnub.chat.internal.error.PubNubErrorMessage.ID_IS_REQUIRED
import com.pubnub.chat.internal.error.PubNubErrorMessage.MODERATION_CAN_BE_SET_ONLY_BY_CLIENT_HAVING_SECRET_KEY
import com.pubnub.chat.internal.error.PubNubErrorMessage.ONLY_ONE_LEVEL_OF_THREAD_NESTING_IS_ALLOWED
import com.pubnub.chat.internal.error.PubNubErrorMessage.STORE_USER_ACTIVITY_INTERVAL_SHOULD_BE_AT_LEAST_1_MIN
import com.pubnub.chat.internal.error.PubNubErrorMessage.THERE_IS_NO_ACTION_TIMETOKEN_CORRESPONDING_TO_THE_THREAD
Expand Down Expand Up @@ -556,10 +557,16 @@ class ChatImpl(
val hostMembershipFuture = pubNub.setMemberships(
listOf(PNChannelMembership.Partial(channel.id, membershipCustom)),
filter = "channel.id == '${channel.id}'",
includeCustom = true,
includeChannelDetails = PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM,
includeCount = true,
includeType = true,
include = MembershipInclude(
includeCustom = true,
includeStatus = false,
includeType = false,
includeTotalCount = true,
includeChannel = true,
includeChannelCustom = true,
includeChannelType = true,
includeChannelStatus = false
),
)
awaitAll(
hostMembershipFuture,
Expand Down Expand Up @@ -602,10 +609,16 @@ class ChatImpl(
val hostMembershipFuture = pubNub.setMemberships(
listOf(PNChannelMembership.Partial(channel.id, membershipCustom)),
filter = "channel.id == '${channel.id}'",
includeCustom = true,
includeChannelDetails = PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM,
includeCount = true,
includeType = true,
include = MembershipInclude(
includeCustom = true,
includeStatus = false,
includeType = false,
includeTotalCount = true,
includeChannel = true,
includeChannelCustom = true,
includeChannelType = true,
includeChannelStatus = false
),
)
awaitAll(
hostMembershipFuture,
Expand Down Expand Up @@ -699,6 +712,9 @@ class ChatImpl(
override fun setRestrictions(
restriction: Restriction
): PNFuture<Unit> {
if (this.pubNub.configuration.secretKey.isEmpty()) {
return log.logErrorAndReturnException(MODERATION_CAN_BE_SET_ONLY_BY_CLIENT_HAVING_SECRET_KEY).asFuture()
}
val channel: String = INTERNAL_MODERATION_PREFIX + restriction.channelId
val userId = restriction.userId
return createChannel(channel).catch { exception ->
Expand Down Expand Up @@ -730,7 +746,7 @@ class ChatImpl(
)
)
val uuids = listOf(PNMember.Partial(uuidId = userId, custom = custom, null))
pubNub.setChannelMembers(channel = channel, uuids = uuids)
pubNub.setChannelMembers(channel = channel, users = uuids)
.alsoAsync { _ ->
emitEvent(
channelId = INTERNAL_USER_MODERATION_CHANNEL_PREFIX + userId,
Expand Down Expand Up @@ -876,11 +892,17 @@ class ChatImpl(
pubNub.setMemberships(
channels = channelMembershipInputs,
filter = filterExpression,
uuid = currentUser.id,
includeCount = true,
includeCustom = true,
includeChannelDetails = PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM,
includeType = true
userId = currentUser.id,
include = MembershipInclude(
includeCustom = true,
includeStatus = false,
includeType = false,
includeTotalCount = true,
includeChannel = true,
includeChannelCustom = true,
includeChannelType = true,
includeChannelStatus = false
),
).alsoAsync { _: PNChannelMembershipArrayResult ->
val emitEventFutures: List<PNFuture<PNPublishResult>> =
relevantChannelIds.map { channelId: String ->
Expand Down Expand Up @@ -1162,7 +1184,11 @@ class ChatImpl(
customMetadataToSet[PINNED_MESSAGE_TIMETOKEN] = message.timetoken.toString()
customMetadataToSet[PINNED_MESSAGE_CHANNEL_ID] = message.channelId
}
return pubNub.setChannelMetadata(channel.id, includeCustom = true, custom = createCustomObject(customMetadataToSet))
return pubNub.setChannelMetadata(
channel = channel.id,
includeCustom = true,
custom = createCustomObject(customMetadataToSet)
)
}

internal fun getThreadId(channelId: String, messageTimetoken: Long): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.pubnub.chat.internal

import co.touchlab.kermit.Logger
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.MembershipInclude
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership
import com.pubnub.api.models.consumer.pubsub.objects.PNDeleteMembershipEventMessage
import com.pubnub.api.models.consumer.pubsub.objects.PNSetMembershipEvent
Expand Down Expand Up @@ -35,6 +35,8 @@ data class MembershipImpl(
override val custom: Map<String, Any?>?,
override val updated: String?,
override val eTag: String?,
override val status: String?,
override val type: String?,
) : Membership {
override val lastReadMessageTimetoken: Long?
get() {
Expand All @@ -51,12 +53,18 @@ data class MembershipImpl(
log.pnError(NO_SUCH_MEMBERSHIP_EXISTS)
}
chat.pubNub.setMemberships(
uuid = user.id,
userId = user.id,
channels = listOf(PNChannelMembership.Partial(channel.id, custom)),
includeCustom = true,
includeCount = true,
includeType = true,
includeChannelDetails = PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM,
include = MembershipInclude(
includeCustom = true,
includeStatus = true,
includeType = true,
includeTotalCount = true,
includeChannel = true,
includeChannelCustom = true,
includeChannelType = true,
includeChannelStatus = true
),
filter = filterThisChannel()
).then { pnChannelMembershipArrayResult ->
fromMembershipDTO(chat, pnChannelMembershipArrayResult.data.first(), user)
Expand Down Expand Up @@ -108,14 +116,34 @@ data class MembershipImpl(
chat,
channel,
user,
update.custom?.value ?: custom,
update.custom.let { newCustom ->
if (newCustom != null) {
newCustom.value
} else {
custom
}
},
update.updated,
update.eTag
update.eTag,
update.status.let { newStatus ->
if (newStatus != null) {
newStatus.value
} else {
status
}
},
update.type.let { newType ->
if (newType != null) {
newType.value
} else {
type
}
}
)
}

private fun exists(): PNFuture<Boolean> =
chat.pubNub.getMemberships(uuid = user.id, filter = filterThisChannel()).then {
chat.pubNub.getMemberships(userId = user.id, filter = filterThisChannel()).then {
it.data.isNotEmpty()
}

Expand Down Expand Up @@ -147,11 +175,13 @@ data class MembershipImpl(
previousMembership?.let { it + message.data }
?: MembershipImpl(
chat,
user = membership.user,
channel = membership.channel,
user = membership.user,
custom = message.data.custom?.value,
updated = message.data.updated,
eTag = message.data.eTag
eTag = message.data.eTag,
status = message.data.status?.value,
type = message.data.type?.value,
)
}
is PNDeleteMembershipEventMessage -> null
Expand Down Expand Up @@ -184,7 +214,9 @@ data class MembershipImpl(
user,
channelMembership.custom?.value,
channelMembership.updated,
channelMembership.eTag
channelMembership.eTag,
channelMembership.status?.value,
channelMembership.type?.value,
)

internal fun fromChannelMemberDTO(chat: ChatInternal, userMembership: PNMember, channel: Channel) =
Expand All @@ -195,6 +227,8 @@ data class MembershipImpl(
userMembership.custom?.value,
userMembership.updated,
userMembership.eTag,
userMembership.status?.value,
userMembership.type?.value,
)
}
}
Loading

0 comments on commit 38a7729

Please sign in to comment.