diff --git a/.pubnub.yml b/.pubnub.yml index 05b8dd226..d8120da65 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -123,7 +123,7 @@ changelog: version: v10.2.0 changes: - type: feature - text: "Publish, signal, share file, subscribe, and history." + text: "Added custom messageType for publish, signal, file, subscribe and history." - date: 2024-11-06 version: v10.1.0 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 026bf0e01..6df6e4439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ December 03 2024 November 18 2024 #### Added -- Publish, signal, share file, subscribe, and history. +- Added customMessageType to publish, signal, file, subscribe and history. ## v10.1.0 November 06 2024 diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/PubNub.kt b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/PubNub.kt index 7f14c4bae..a44fe6da6 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/PubNub.kt +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/PubNub.kt @@ -32,13 +32,20 @@ import com.pubnub.api.java.endpoints.objects_api.channel.GetChannelMetadata import com.pubnub.api.java.endpoints.objects_api.channel.RemoveChannelMetadata import com.pubnub.api.java.endpoints.objects_api.channel.SetChannelMetadata import com.pubnub.api.java.endpoints.objects_api.members.GetChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.GetChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.members.ManageChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.ManageChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.memberships.GetMemberships import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMemberships +import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMembershipsBuilder import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMemberships +import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMembershipsBuilder import com.pubnub.api.java.endpoints.objects_api.memberships.SetMemberships +import com.pubnub.api.java.endpoints.objects_api.memberships.SetMembershipsBuilder import com.pubnub.api.java.endpoints.objects_api.uuid.GetAllUUIDMetadata import com.pubnub.api.java.endpoints.objects_api.uuid.GetUUIDMetadata import com.pubnub.api.java.endpoints.objects_api.uuid.RemoveUUIDMetadata @@ -53,6 +60,8 @@ import com.pubnub.api.java.endpoints.push.AddChannelsToPush import com.pubnub.api.java.endpoints.push.ListPushProvisions import com.pubnub.api.java.endpoints.push.RemoveAllPushChannelsForDevice import com.pubnub.api.java.endpoints.push.RemoveChannelsFromPush +import com.pubnub.api.java.models.consumer.objects_api.member.PNUser +import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership import com.pubnub.api.java.v2.PNConfiguration import com.pubnub.api.java.v2.callbacks.EventEmitter import com.pubnub.api.java.v2.callbacks.StatusEmitter @@ -468,39 +477,106 @@ interface PubNub : EventEmitter, StatusEmitter { /** * Set channel memberships for a UUID. */ - fun setMemberships(): SetMemberships.Builder + @Deprecated( + message = "Use setMemberships(Collection) instead.", + replaceWith = ReplaceWith("setMemberships(channelMemberships)") + ) + fun setMemberships(): SetMemberships.Builder // add deprecation + + /** + * Set channel memberships for a User. + */ + fun setMemberships(channelMemberships: Collection): SetMembershipsBuilder /** * Remove channel memberships for a UUID. */ + @Deprecated( + message = "Use removeMemberships(Collection) instead.", + replaceWith = ReplaceWith("removeMemberships(channelMemberships)") + ) fun removeMemberships(): RemoveMemberships.Builder /** - * Add and remove channel memberships for a UUID. + * Remove channel memberships for a UUID. + */ + fun removeMemberships(channelMemberships: Collection): RemoveMembershipsBuilder + + /** + * Add and/or remove channel memberships for a UUID. */ + @Deprecated( + message = "Use manageMemberships(Collection, Collection) instead.", + replaceWith = ReplaceWith("manageMemberships(channelMembershipsToAdd, channelMembershipsToRemove)") + ) fun manageMemberships(): ManageMemberships.Builder + /** + * Add and/or remove channel memberships for a UUID. + */ + fun manageMemberships( + channelsToSet: Collection, + channelsToDelete: Collection + ): ManageMembershipsBuilder + /** * The method returns a list of members in a channel. The list will include user metadata for members * that have additional metadata stored in the database. */ + @Deprecated( + message = "Use getChannelMembers(String) instead.", + replaceWith = ReplaceWith("getChannelMembers(channelId)") + ) fun getChannelMembers(): GetChannelMembers.Builder + /** + * The method returns a list of members in a channel. The list will include user metadata for members + * that have additional metadata stored in the database. + */ + fun getChannelMembers(channelId: String): GetChannelMembersBuilder + /** * This method sets members in a channel. */ + @Deprecated( + message = "Use setChannelMembers(String, Collection) instead.", + replaceWith = ReplaceWith("setChannelMembers(channelId, channelMembers)") + ) fun setChannelMembers(): SetChannelMembers.Builder + /** + * This method sets members in a channel. + */ + fun setChannelMembers(channelId: String, channelMembers: Collection): SetChannelMembersBuilder + /** * Remove members from a Channel. */ + @Deprecated( + message = "Use removeChannelMembers(String, Collection) instead.", + replaceWith = ReplaceWith("removeChannelMembers(channelId, channelMembers)") + ) fun removeChannelMembers(): RemoveChannelMembers.Builder + /** + * Remove members from a Channel. + */ + fun removeChannelMembers(channelId: String, channelMembers: Collection): RemoveChannelMembersBuilder + /** * Set or remove members in a channel. */ + @Deprecated( + message = "Use manageChannelMembers(String, Collection, Collection) instead.", + replaceWith = ReplaceWith("manageChannelMembers(channelId, channelMembersToSet, channelMembersToRemove)") + ) fun manageChannelMembers(): ManageChannelMembers.Builder + /** + * Set or remove members in a channel. + */ + fun manageChannelMembers(channelId: String, set: Collection, remove: Collection): ManageChannelMembersBuilder + /** * Add an action on a published message. Returns the added action in the response. */ diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembers.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembers.java index d1709cdd0..5e9777cba 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembers.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembers.java @@ -6,6 +6,7 @@ import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; import com.pubnub.api.java.models.consumer.objects_api.member.PNGetChannelMembersResult; +@Deprecated public interface GetChannelMembers extends Endpoint { GetChannelMembers limit(Integer limit); @@ -21,6 +22,7 @@ public interface GetChannelMembers extends Endpoint { GetChannelMembers includeUUID(Include.PNUUIDDetailsLevel includeUUID); + @Deprecated interface Builder extends BuilderSteps.ChannelStep { @Override GetChannelMembers channel(String channel); diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembersBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembersBuilder.java new file mode 100644 index 000000000..5a55c6ad1 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/GetChannelMembersBuilder.java @@ -0,0 +1,14 @@ +package com.pubnub.api.java.endpoints.objects_api.members; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; +import com.pubnub.api.java.models.consumer.objects_api.member.PNGetChannelMembersResult; + +public interface GetChannelMembersBuilder extends Endpoint { + GetChannelMembersBuilder limit(Integer limit); + GetChannelMembersBuilder page(com.pubnub.api.models.consumer.objects.PNPage page); + GetChannelMembersBuilder filter(String filter); + GetChannelMembersBuilder sort(java.util.Collection sort); + GetChannelMembersBuilder include(MemberInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembers.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembers.java index d1ba01434..b23af4323 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembers.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembers.java @@ -9,6 +9,7 @@ import java.util.Collection; +@Deprecated public interface ManageChannelMembers extends Endpoint { ManageChannelMembers limit(Integer limit); @@ -24,6 +25,7 @@ public interface ManageChannelMembers extends Endpoint> { @Override ObjectsBuilderSteps.RemoveOrSetStep channel(String channel); diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembersBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembersBuilder.java new file mode 100644 index 000000000..210fd9eca --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/ManageChannelMembersBuilder.java @@ -0,0 +1,16 @@ +package com.pubnub.api.java.endpoints.objects_api.members; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; +import com.pubnub.api.java.models.consumer.objects_api.member.PNManageChannelMembersResult; + +import java.util.Collection; + +public interface ManageChannelMembersBuilder extends Endpoint { + ManageChannelMembersBuilder limit(Integer limit); + ManageChannelMembersBuilder page(com.pubnub.api.models.consumer.objects.PNPage page); + ManageChannelMembersBuilder filter(String filter); + ManageChannelMembersBuilder sort(Collection sort); + ManageChannelMembersBuilder include(MemberInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembers.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembers.java index a8b7e6eb9..028661de2 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembers.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembers.java @@ -9,6 +9,7 @@ import java.util.Collection; +@Deprecated public interface RemoveChannelMembers extends Endpoint { RemoveChannelMembers limit(Integer limit); @@ -25,6 +26,7 @@ public interface RemoveChannelMembers extends Endpoint> { @Override ObjectsBuilderSteps.UUIDsStep channel(String channel); diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembersBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembersBuilder.java new file mode 100644 index 000000000..fd7367918 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/RemoveChannelMembersBuilder.java @@ -0,0 +1,16 @@ +package com.pubnub.api.java.endpoints.objects_api.members; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; +import com.pubnub.api.java.models.consumer.objects_api.member.PNRemoveChannelMembersResult; + +import java.util.Collection; + +public interface RemoveChannelMembersBuilder extends Endpoint { + RemoveChannelMembersBuilder limit(Integer limit); + RemoveChannelMembersBuilder page(com.pubnub.api.models.consumer.objects.PNPage page); + RemoveChannelMembersBuilder filter(String filter); + RemoveChannelMembersBuilder sort(Collection sort); + RemoveChannelMembersBuilder include(MemberInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembers.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembers.java index 0d6d8457a..78f6c76ac 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembers.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembers.java @@ -9,6 +9,7 @@ import java.util.Collection; +@Deprecated public interface SetChannelMembers extends Endpoint { SetChannelMembers limit(Integer limit); @@ -25,6 +26,7 @@ public interface SetChannelMembers extends Endpoint { SetChannelMembers includeUUID(Include.PNUUIDDetailsLevel includeUUID); + @Deprecated interface Builder extends BuilderSteps.ChannelStep> { @Override ObjectsBuilderSteps.UUIDsStep channel(String channel); diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembersBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembersBuilder.java new file mode 100644 index 000000000..606086366 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/members/SetChannelMembersBuilder.java @@ -0,0 +1,16 @@ +package com.pubnub.api.java.endpoints.objects_api.members; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; +import com.pubnub.api.java.models.consumer.objects_api.member.PNSetChannelMembersResult; + +import java.util.Collection; + +public interface SetChannelMembersBuilder extends Endpoint { + SetChannelMembers limit(Integer limit); + SetChannelMembers page(com.pubnub.api.models.consumer.objects.PNPage page); + SetChannelMembers filter(String filter); + SetChannelMembers sort(Collection sort); + SetChannelMembers include(MemberInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/GetMemberships.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/GetMemberships.java index b6c705794..a1cf34c07 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/GetMemberships.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/GetMemberships.java @@ -3,9 +3,24 @@ import com.pubnub.api.java.endpoints.Endpoint; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; import com.pubnub.api.java.models.consumer.objects_api.membership.PNGetMembershipsResult; public interface GetMemberships extends Endpoint { + /** + * Set the user ID for fetching memberships. + * + * @param userId the user ID + * @return the current instance of {@code GetMemberships} + */ + GetMemberships userId(String userId); + + /** + * @deprecated Use {@link #userId(String)} instead. + * @param uuid the user ID (previously referred to as UUID) + * @return the current instance of {@code GetMemberships} + */ + @Deprecated() GetMemberships uuid(String uuid); GetMemberships limit(Integer limit); @@ -16,9 +31,29 @@ public interface GetMemberships extends Endpoint { GetMemberships sort(java.util.Collection sort); + /** + * @deprecated Use {@link #include(MembershipInclude)} instead. + * @param includeTotalCount specifies in totalCount should be included in response + * @return the current instance of {@code GetMemberships} + */ + @Deprecated() GetMemberships includeTotalCount(boolean includeTotalCount); + /** + * @deprecated Use {@link #include(MembershipInclude)} instead. + * @param includeCustom specifies in Custom data should be included in response + * @return the current instance of {@code GetMemberships} + */ + @Deprecated() GetMemberships includeCustom(boolean includeCustom); + /** + * @deprecated Use {@link #include(MembershipInclude)} instead. + * @param includeChannel specifies in ChannelMetadata should be included in response + * @return the current instance of {@code GetMemberships} + */ + @Deprecated() GetMemberships includeChannel(Include.PNChannelDetailsLevel includeChannel); + + GetMemberships include(MembershipInclude include); } diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMemberships.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMemberships.java index 7c934331e..d852dff1f 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMemberships.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMemberships.java @@ -9,6 +9,7 @@ import java.util.Collection; +@Deprecated public interface ManageMemberships extends Endpoint { ManageMemberships set(Collection set); @@ -31,6 +32,7 @@ public interface ManageMemberships extends Endpoint { ManageMemberships includeChannel(Include.PNChannelDetailsLevel includeChannel); + @Deprecated interface Builder extends ObjectsBuilderSteps.RemoveOrSetStep { @Override RemoveStep set(Collection channelsToSet); diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMembershipsBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMembershipsBuilder.java new file mode 100644 index 000000000..b2e985de9 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/ManageMembershipsBuilder.java @@ -0,0 +1,17 @@ +package com.pubnub.api.java.endpoints.objects_api.memberships; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; +import com.pubnub.api.java.models.consumer.objects_api.membership.PNManageMembershipResult; + +import java.util.Collection; + +public interface ManageMembershipsBuilder extends Endpoint { + ManageMembershipsBuilder userId(String userId); + ManageMembershipsBuilder limit(Integer limit); + ManageMembershipsBuilder page(com.pubnub.api.models.consumer.objects.PNPage page); + ManageMembershipsBuilder filter(String filter); + ManageMembershipsBuilder sort(Collection sort); + ManageMembershipsBuilder include(MembershipInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMemberships.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMemberships.java index a87341614..328f41a39 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMemberships.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMemberships.java @@ -10,6 +10,7 @@ import java.util.Collection; +@Deprecated public interface RemoveMemberships extends Endpoint { RemoveMemberships uuid(String uuid); @@ -28,6 +29,7 @@ public interface RemoveMemberships extends Endpoint { RemoveMemberships includeChannel(Include.PNChannelDetailsLevel includeChannel); + @Deprecated interface Builder extends ObjectsBuilderSteps.ChannelMembershipsStep { @Override RemoveMemberships channelMemberships(@NotNull Collection channelMemberships); diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMembershipsBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMembershipsBuilder.java new file mode 100644 index 000000000..c9af88a22 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/RemoveMembershipsBuilder.java @@ -0,0 +1,17 @@ +package com.pubnub.api.java.endpoints.objects_api.memberships; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; +import com.pubnub.api.java.models.consumer.objects_api.membership.PNRemoveMembershipResult; + +import java.util.Collection; + +public interface RemoveMembershipsBuilder extends Endpoint { + RemoveMembershipsBuilder userId(String userId); + RemoveMembershipsBuilder limit(Integer limit); + RemoveMembershipsBuilder page(com.pubnub.api.models.consumer.objects.PNPage page); + RemoveMembershipsBuilder filter(String filter); + RemoveMembershipsBuilder sort(Collection sort); + RemoveMembershipsBuilder include(MembershipInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMemberships.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMemberships.java index a5b9c4442..3fc4db5da 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMemberships.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMemberships.java @@ -9,6 +9,7 @@ import java.util.Collection; +@Deprecated public interface SetMemberships extends Endpoint { SetMemberships uuid(String uuid); @@ -26,6 +27,7 @@ public interface SetMemberships extends Endpoint { SetMemberships includeChannel(Include.PNChannelDetailsLevel includeChannel); + @Deprecated interface Builder { SetMemberships channelMemberships(@NotNull Collection channelMemberships); } diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMembershipsBuilder.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMembershipsBuilder.java new file mode 100644 index 000000000..4bd4859f5 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/memberships/SetMembershipsBuilder.java @@ -0,0 +1,17 @@ +package com.pubnub.api.java.endpoints.objects_api.memberships; + +import com.pubnub.api.java.endpoints.Endpoint; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; +import com.pubnub.api.java.models.consumer.objects_api.membership.PNSetMembershipResult; + +import java.util.Collection; + +public interface SetMembershipsBuilder extends Endpoint { + SetMembershipsBuilder userId(String userId); + SetMembershipsBuilder limit(Integer limit); + SetMembershipsBuilder page(com.pubnub.api.models.consumer.objects.PNPage page); + SetMembershipsBuilder filter(String filter); + SetMembershipsBuilder sort(Collection sort); + SetMembershipsBuilder include(MembershipInclude include); +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/utils/PNSortKey.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/utils/PNSortKey.java index 28d751013..e1058afc2 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/utils/PNSortKey.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/objects_api/utils/PNSortKey.java @@ -19,7 +19,11 @@ public enum Dir { } public enum Key { - ID("id"), NAME("name"), UPDATED("updated"); + ID("id"), + NAME("name"), + UPDATED("updated"), + STATUS("status"), + TYPE("type"); @Getter(AccessLevel.PACKAGE) private final String fieldName; diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/MemberInclude.kt b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/MemberInclude.kt new file mode 100644 index 000000000..d7617f6ff --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/MemberInclude.kt @@ -0,0 +1,72 @@ +package com.pubnub.api.java.models.consumer.objects_api.member + +interface MemberInclude : com.pubnub.api.models.consumer.objects.member.MemberInclude { + companion object { + @JvmStatic + fun builder() = Builder() + } + + class Builder internal constructor() { + var includeCustom: Boolean = false + var includeStatus: Boolean = false + var includeType: Boolean = false + var includeTotalCount: Boolean = false + var includeUser: Boolean = false + var includeUserCustom: Boolean = false + var includeUserType: Boolean = false + var includeUserStatus: Boolean = false + + fun includeCustom(includeCustom: Boolean): Builder { + this.includeCustom = includeCustom + return this + } + + fun includeStatus(includeStatus: Boolean): Builder { + this.includeStatus = includeStatus + return this + } + + fun includeType(includeType: Boolean): Builder { + this.includeType = includeType + return this + } + + fun includeTotalCount(includeTotalCount: Boolean): Builder { + this.includeTotalCount = includeTotalCount + return this + } + + fun includeUser(includeUser: Boolean): Builder { + this.includeUser = includeUser + return this + } + + fun includeUserCustom(includeUserCustom: Boolean): Builder { + this.includeUserCustom = includeUserCustom + return this + } + + fun includeUserType(includeUserType: Boolean): Builder { + this.includeUserType = includeUserType + return this + } + + fun includeUserStatus(includeUserStatus: Boolean): Builder { + this.includeUserStatus = includeUserStatus + return this + } + + fun build(): MemberInclude { + return object : MemberInclude { + override val includeCustom: Boolean = this@Builder.includeCustom + override val includeUserStatus: Boolean = this@Builder.includeUserStatus + override val includeUserType: Boolean = this@Builder.includeUserType + override val includeTotalCount: Boolean = this@Builder.includeTotalCount + override val includeUser: Boolean = this@Builder.includeUser + override val includeUserCustom: Boolean = this@Builder.includeUserCustom + override val includeStatus: Boolean = this@Builder.includeStatus + override val includeType: Boolean = this@Builder.includeType + } + } + } +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembers.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembers.java index 3b4d9590b..c848f5a38 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembers.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembers.java @@ -18,7 +18,7 @@ @EqualsAndHashCode @ToString @RequiredArgsConstructor -public class PNMembers { +public class PNMembers { // todo why this is plural? Shouldn't be PNMember? private PNUUIDMetadata uuid; protected PatchValue<@Nullable Map> custom; @@ -26,4 +26,5 @@ public class PNMembers { protected String updated; protected String eTag; protected PatchValue<@Nullable String> status; + protected PatchValue<@Nullable String> type; } diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUUID.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUUID.java index e13bbf7ac..dd1613ee7 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUUID.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUUID.java @@ -56,4 +56,4 @@ private UUIDWithCustom(UUIDId uuid, Object custom, String status) { this.custom = custom; } } -} \ No newline at end of file +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUser.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUser.java new file mode 100644 index 000000000..68b9ac277 --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNUser.java @@ -0,0 +1,68 @@ +package com.pubnub.api.java.models.consumer.objects_api.member; + +public class PNUser { + private final String userId; + private String status; + private String type; + private Object custom; + + public static Builder builder(String userId) { + return new PNUser.Builder(userId); + } + + private PNUser(Builder builder) { + this.userId = builder.userId; + this.custom = builder.custom; + this.status = builder.status; + this.type = builder.type; + } + + public static class Builder { + private final String userId; + private Object custom; + private String status; + private String type; + + public Builder(String userId) { + if (userId == null || userId.isEmpty()) { + throw new IllegalArgumentException("userId cannot be null or empty"); + } + this.userId = userId; + } + + public PNUser.Builder custom(Object custom) { + this.custom = custom; + return this; + } + + public PNUser.Builder status(String status) { + this.status = status; + return this; + } + + public PNUser.Builder type(String type) { + this.type = type; + return this; + } + + public PNUser build() { + return new PNUser(this); + } + } + + public String getUserId() { + return userId; + } + + public String getStatus() { + return status; + } + + public String getType() { + return type; + } + + public Object getCustom() { + return custom; + } +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/MembershipInclude.kt b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/MembershipInclude.kt new file mode 100644 index 000000000..e4df62ced --- /dev/null +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/MembershipInclude.kt @@ -0,0 +1,72 @@ +package com.pubnub.api.java.models.consumer.objects_api.membership + +interface MembershipInclude : com.pubnub.api.models.consumer.objects.membership.MembershipInclude { + companion object { + @JvmStatic + fun builder() = Builder() + } + + class Builder internal constructor() { + var includeCustom: Boolean = false + var includeStatus: Boolean = false + var includeType: Boolean = false + var includeTotalCount: Boolean = false + var includeChannel: Boolean = false + var includeChannelCustom: Boolean = false + var includeChannelType: Boolean = false + var includeChannelStatus: Boolean = false + + fun includeCustom(includeCustom: Boolean): Builder { + this.includeCustom = includeCustom + return this + } + + fun includeStatus(includeStatus: Boolean): Builder { + this.includeStatus = includeStatus + return this + } + + fun includeType(includeType: Boolean): Builder { + this.includeType = includeType + return this + } + + fun includeTotalCount(includeTotalCount: Boolean): Builder { + this.includeTotalCount = includeTotalCount + return this + } + + fun includeChannel(includeChannel: Boolean): Builder { + this.includeChannel = includeChannel + return this + } + + fun includeChannelCustom(includeChannelCustom: Boolean): Builder { + this.includeChannelCustom = includeChannelCustom + return this + } + + fun includeChannelType(includeChannelType: Boolean): Builder { + this.includeChannelType = includeChannelType + return this + } + + fun includeChannelStatus(includeChannelStatus: Boolean): Builder { + this.includeChannelStatus = includeChannelStatus + return this + } + + fun build(): MembershipInclude { + return object : MembershipInclude { + override val includeCustom: Boolean = this@Builder.includeCustom + override val includeTotalCount: Boolean = this@Builder.includeTotalCount + override val includeChannel: Boolean = this@Builder.includeChannel + override val includeChannelCustom: Boolean = this@Builder.includeChannelCustom + override val includeChannelType: Boolean = this@Builder.includeChannelType + override val includeChannelStatus: Boolean = this@Builder.includeChannelStatus + override val includeStatus: Boolean = this@Builder.includeStatus + override val includeType: Boolean = this@Builder.includeType + } + } + } +} diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNChannelMembership.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNChannelMembership.java index 14c52ae7d..f7fa16f58 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNChannelMembership.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNChannelMembership.java @@ -6,43 +6,100 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; -import java.util.HashMap; -import java.util.Map; - @RequiredArgsConstructor -public abstract class PNChannelMembership { +@EqualsAndHashCode +public class PNChannelMembership { + @Getter + private final ChannelId channel; + @Getter + private Object custom; + @Getter + private String status; + @Getter + private String type; + + public static Builder builder(String channelId) { + return new Builder(channelId); + } + + private PNChannelMembership(Builder builder) { + this.channel = new ChannelId(builder.channelId); + this.custom = builder.custom; + this.status = builder.status; + this.type = builder.type; + } + + + public static class Builder { + private final String channelId; + private Object custom; + private String status; + private String type; + + public Builder(String channelId) { + if (channelId == null || channelId.isEmpty()) { + throw new IllegalArgumentException("channelId cannot be null or empty"); + } + this.channelId = channelId; + } + + public Builder custom(Object custom) { + this.custom = custom; + return this; + } + + public Builder status(String status) { + this.status = status; + return this; + } + + public Builder type(String type) { + this.type = type; + return this; + } + + public PNChannelMembership build() { + return new PNChannelMembership(this); + } + } + @AllArgsConstructor @EqualsAndHashCode @Getter public static class ChannelId { - private String id; + private final String id; } - @Getter - private final ChannelId channel; - + // Factory method for creating a membership with only a channel ID. public static PNChannelMembership channel(final String channelId) { return new JustChannel(new ChannelId(channelId)); } - public static PNChannelMembership channelWithCustom(final String channelId, final Map custom) { - return new ChannelWithCustom(new ChannelId(channelId), new HashMap<>(custom)); + // Factory method for creating a membership with a channel ID and custom data. + public static PNChannelMembership channelWithCustom(final String channelId, final Object custom) { + return new ChannelWithCustom(new ChannelId(channelId), custom); } + /** + * Represents a membership with only a channel ID. + */ @Getter @EqualsAndHashCode(callSuper = true) public static class JustChannel extends PNChannelMembership { - JustChannel(@NonNull final ChannelId channelId) { + public JustChannel(@NonNull final ChannelId channelId) { super(channelId); } } + /** + * Represents a membership with a channel ID and custom data. + */ @Getter @EqualsAndHashCode(callSuper = true) public static class ChannelWithCustom extends PNChannelMembership { private final Object custom; - ChannelWithCustom(@NonNull final ChannelId channelId, @NonNull Object custom) { + public ChannelWithCustom(@NonNull final ChannelId channelId, @NonNull Object custom) { super(channelId); this.custom = custom; } diff --git a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembership.java b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembership.java index 9caabfea1..48b57cbec 100644 --- a/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembership.java +++ b/pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembership.java @@ -23,4 +23,5 @@ public PNMembership(@NotNull PNChannelMetadata channel) { private String updated; private String eTag; private PatchValue<@Nullable String> status; + private PatchValue<@Nullable String> type; } diff --git a/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/SubscribeIntegrationTests.java b/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/SubscribeIntegrationTests.java index ea01a4c72..5b0d9ba79 100644 --- a/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/SubscribeIntegrationTests.java +++ b/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/SubscribeIntegrationTests.java @@ -6,7 +6,9 @@ import com.pubnub.api.integration.util.RandomGenerator; import com.pubnub.api.java.PubNub; import com.pubnub.api.java.callbacks.SubscribeCallback; +import com.pubnub.api.java.models.consumer.objects_api.member.PNUser; import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership; +import com.pubnub.api.java.models.consumer.objects_api.membership.PNMembershipResult; import com.pubnub.api.java.v2.callbacks.handlers.OnMessageHandler; import com.pubnub.api.java.v2.entities.Channel; import com.pubnub.api.java.v2.entities.ChannelMetadata; @@ -26,15 +28,21 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import static com.pubnub.api.integration.util.Utils.random; import static com.pubnub.api.integration.util.Utils.randomChannel; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class SubscribeIntegrationTests extends BaseIntegrationTest { @@ -276,9 +284,83 @@ public void testAssignBehaviourForUuidMetadataUsingUserMetadataObject() throws P assertEquals(1, numberOfUuidMetadataEvents.get()); } + @Test + public void testListeningToSetChannelMembersAndRemoveChannelMembersEventsWithStatusAndType() throws PubNubException, InterruptedException { + CountDownLatch countDownLatch = new CountDownLatch(2); + List capturedPNMembershipResult = new ArrayList<>(); + String status = "Status" + random(); + String type = "Type" + random(); + + Channel chan01 = pubNub.channel(randomChannel()); + Subscription subscription = chan01.subscription(SubscriptionOptions.receivePresenceEvents()); + subscription.setOnMembership(pnMembershipResult -> { + countDownLatch.countDown(); + capturedPNMembershipResult.add(pnMembershipResult); + }); + + subscription.subscribe(); + Thread.sleep(2000); + + List channelMembers = Arrays.asList(PNUser.builder(pubNub.getConfiguration().getUserId().getValue()).status(status).type(type).build()); + List channelMembersIds = channelMembers.stream().map(pnUser -> pnUser.getUserId()).collect(Collectors.toList()); + pubNub.setChannelMembers(chan01.getName(), channelMembers).sync(); + pubNub.removeChannelMembers(chan01.getName(), channelMembersIds).sync(); + + countDownLatch.await(5, TimeUnit.SECONDS); + + PNMembershipResult setChannelMembersEventMessage = capturedPNMembershipResult.get(0); + PNMembershipResult removeChannelMembersEventMessage = capturedPNMembershipResult.get(1); + assertEquals(chan01.getName(), setChannelMembersEventMessage.getData().getChannel().getId()); + assertEquals(chan01.getName(), setChannelMembersEventMessage.getChannel()); + assertEquals(status, setChannelMembersEventMessage.getData().getStatus().getValue()); + assertEquals(type, setChannelMembersEventMessage.getData().getType().getValue()); + + assertEquals(chan01.getName(), removeChannelMembersEventMessage.getData().getChannel().getId()); + assertEquals(chan01.getName(), removeChannelMembersEventMessage.getChannel()); + assertNull(removeChannelMembersEventMessage.getData().getStatus()); + assertNull(removeChannelMembersEventMessage.getData().getType()); + } + + @Test + public void testListeningToSetMembershipAndRemoveMembershipEventsWithStatusAndType() throws PubNubException, InterruptedException { + CountDownLatch countDownLatch = new CountDownLatch(2); + List capturedPNMembershipResult = new ArrayList<>(); + String status = "Status" + random(); + String type = "Type" + random(); + + Channel chan01 = pubNub.channel(randomChannel()); + Subscription subscription = chan01.subscription(SubscriptionOptions.receivePresenceEvents()); + subscription.setOnMembership(pnMembershipResult -> { + countDownLatch.countDown(); + capturedPNMembershipResult.add(pnMembershipResult); + }); + + subscription.subscribe(); + Thread.sleep(2000); + + pubNub.setMemberships(Collections.singletonList(PNChannelMembership.builder(chan01.getName()).status(status).type(type).build())).sync(); + pubNub.removeMemberships(Arrays.asList(chan01.getName())).sync(); + + countDownLatch.await(5, TimeUnit.SECONDS); + + PNMembershipResult setMembershipEventMessage = capturedPNMembershipResult.get(0); + PNMembershipResult removeMembershipEventMessage = capturedPNMembershipResult.get(1); + assertEquals(chan01.getName(), setMembershipEventMessage.getData().getChannel().getId()); + assertEquals(chan01.getName(), setMembershipEventMessage.getChannel()); + assertEquals(status, setMembershipEventMessage.getData().getStatus().getValue()); + assertEquals(type, setMembershipEventMessage.getData().getType().getValue()); + + assertEquals(chan01.getName(), removeMembershipEventMessage.getData().getChannel().getId()); + assertEquals(chan01.getName(), removeMembershipEventMessage.getChannel()); + assertNull(removeMembershipEventMessage.getData().getStatus()); + assertNull(removeMembershipEventMessage.getData().getType()); + } + @Test public void testAssigningEventBehaviourToSubscription() throws InterruptedException, PubNubException, IOException { String expectedMessage = random(); + String status = "active"; + String type = "admin"; String fileContent = "This is content"; ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)); final JsonObject expectedStatePayload = generatePayload(); @@ -295,7 +377,6 @@ public void testAssigningEventBehaviourToSubscription() throws InterruptedExcept Subscription subscription = chan01.subscription(SubscriptionOptions.receivePresenceEvents()); OnMessageHandler onMessageHandler = pnMessageResult -> { numberOfReceivedMessage.incrementAndGet(); - System.out.println("-=pnMessageResult: " + pnMessageResult.getMessage()); }; subscription.setOnMessage(pnMessageResult -> System.out.println("Received message: " + pnMessageResult.getMessage())); @@ -303,7 +384,6 @@ public void testAssigningEventBehaviourToSubscription() throws InterruptedExcept subscription.setOnMessage(onMessageHandler); subscription.setOnPresence(pnPresenceEventResult -> { numberOfReceivedPresentEvent.incrementAndGet(); - System.out.println("-=pnPresenceEventResult: " + pnPresenceEventResult.getEvent()); }); subscription.setOnSignal(pnSignalResult -> numberOfReceivedSignal.incrementAndGet()); @@ -319,7 +399,7 @@ public void testAssigningEventBehaviourToSubscription() throws InterruptedExcept PNMessageAction pnMessageAction = new PNMessageAction().setType("reaction").setValue(RandomGenerator.emoji()).setMessageTimetoken(pnPublishResult01.getTimetoken()); pubNub.addMessageAction().messageAction(pnMessageAction).channel(chan01.getName()).sync(); pubNub.setChannelMetadata().channel(chan01.getName()).name("Channel name").description("-=desc").status("active").type("Chat").sync(); - pubNub.setMemberships().channelMemberships(Collections.singletonList(PNChannelMembership.channel(chan01.getName()))).sync(); + pubNub.setMemberships().channelMemberships(Collections.singletonList(PNChannelMembership.builder(chan01.getName()).status(status).type(type).build())).sync(); pubNub.sendFile().channel(chan01.getName()).fileName(random()).inputStream(inputStream).message("message").sync(); Thread.sleep(1000); @@ -348,7 +428,7 @@ public void testAssigningEventBehaviourToSubscription() throws InterruptedExcept pubNub.setChannelMetadata().channel(chan01.getName()).name("Channel name").description("desc").status("active").type("Chat").sync(); pubNub.setMemberships().channelMemberships(Collections.singletonList(PNChannelMembership.channel(chan01.getName()))).uuid("differentUUID").sync(); pubNub.sendFile().channel(chan01.getName()).fileName(random()).inputStream(inputStream).message("message").sync(); - Thread.sleep(1000); + Thread.sleep(4000); // number of events received should remain 1 assertEquals(1, numberOfReceivedMessage.get()); diff --git a/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/members/ChannelMembersIT.java b/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/members/ChannelMembersIT.java index 9d4e8a6dd..677d602f4 100644 --- a/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/members/ChannelMembersIT.java +++ b/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/members/ChannelMembersIT.java @@ -2,12 +2,15 @@ import com.pubnub.api.PubNubException; import com.pubnub.api.integration.objects.ObjectsApiBaseIT; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; import com.pubnub.api.java.models.consumer.objects_api.member.PNGetChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNManageChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNMembers; import com.pubnub.api.java.models.consumer.objects_api.member.PNRemoveChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNSetChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID; +import com.pubnub.api.java.models.consumer.objects_api.member.PNUser; import com.pubnub.api.java.models.consumer.objects_api.uuid.PNUUIDMetadata; import com.pubnub.api.utils.PatchValue; import org.apache.http.HttpStatus; @@ -28,6 +31,7 @@ import java.util.UUID; import java.util.stream.Collectors; +import static com.pubnub.api.integration.util.Utils.random; import static com.pubnub.api.java.endpoints.objects_api.utils.Include.PNUUIDDetailsLevel.UUID_WITH_CUSTOM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; @@ -39,11 +43,15 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class ChannelMembersIT extends ObjectsApiBaseIT { private static final Logger LOG = LoggerFactory.getLogger(ChannelMembersIT.class); private static final String STATUS_01 = "myStatus01"; + private static final String TYPE_01 = "myType01" + random(); + private static final String TYPE_02 = "myType02" + random(); private static final String STATUS_02 = "myStatus02"; private final List createdMembersList = new ArrayList<>(); @@ -55,6 +63,48 @@ public class ChannelMembersIT extends ObjectsApiBaseIT { @Test public void addChannelMembersHappyPath() throws PubNubException { + //given + Map customMembershipObject = customChannelMembershipObject(); + final Collection channelMembers = Arrays.asList( + PNUser.builder(TEST_UUID1).status(STATUS_01).type(TYPE_01).build(), + PNUser.builder(TEST_UUID2).custom(customMembershipObject).status(STATUS_02).type(TYPE_02).build()); + + //when + final PNSetChannelMembersResult setChannelMembersResult = pubNubUnderTest.setChannelMembers(testChannelId, channelMembers) + .include(MemberInclude.builder() + .includeCustom(true) + .includeStatus(true) + .includeType(true) + .includeTotalCount(true) + .includeUser(true) + .includeUserCustom(true) + .includeUserStatus(true) + .includeUserType(true) + .build()) + .sort(Arrays.asList(PNSortKey.asc(PNSortKey.Key.STATUS))) + .sync(); + + //then + assertEquals(STATUS_01, setChannelMembersResult.getData().get(0).getStatus().getValue()); + assertEquals(STATUS_02, setChannelMembersResult.getData().get(1).getStatus().getValue()); + + assertNotNull(setChannelMembersResult); + assertEquals(HttpStatus.SC_OK, setChannelMembersResult.getStatus()); + createdMembersList.add(setChannelMembersResult); + + PNMembers pnMember01 = getChannelMemberByUserId(setChannelMembersResult, TEST_UUID1); + assertEquals(STATUS_01, pnMember01.getStatus().getValue()); + assertEquals(TYPE_01, pnMember01.getType().getValue()); + PNMembers pnMember02 = getChannelMemberByUserId(setChannelMembersResult, TEST_UUID2); + assertEquals(STATUS_02, pnMember02.getStatus().getValue()); + assertEquals(TYPE_02, pnMember02.getType().getValue()); + assertTrue(pnMember02.getCustom().getValue().containsKey("members_param1")); + assertTrue(pnMember02.getCustom().getValue().containsKey("members_param2")); + + } + + @Test + public void addChannelMembersHappyPathDeprecated() throws PubNubException { //given Map customMembershipObject = customChannelMembershipObject(); final Collection channelMembers = Arrays.asList( @@ -109,6 +159,54 @@ public void addChannelMembersHappyPath() throws PubNubException { @Test public void getChannelMembersHappyPath() throws PubNubException { + //given + final Collection channelMembers = Arrays.asList( + PNUser.builder(TEST_UUID1).status(STATUS_01).type(TYPE_01).build(), + PNUser.builder(TEST_UUID2).custom(customChannelMembershipObject()).status(STATUS_02).type(TYPE_02).build()); + + final PNSetChannelMembersResult setChannelMembersResult = pubNubUnderTest + .setChannelMembers(testChannelId, channelMembers) + .include(MemberInclude.builder() + .includeTotalCount(true) + .includeCustom(true) + .includeUser(true) + .includeUserCustom(true) + .build()) + .sync(); + createdMembersList.add(setChannelMembersResult); + + //when + final PNGetChannelMembersResult getMembersResult = pubNubUnderTest + .getChannelMembers(testChannelId) + .include(MemberInclude.builder() + .includeTotalCount(true) + .includeStatus(true) + .includeType(true) + .includeCustom(true) + .includeUser(true) + .includeUserCustom(true) + .build()) + .sort(Arrays.asList(PNSortKey.desc(PNSortKey.Key.STATUS))) + .sync(); + + + //then + assertEquals(TYPE_01, getMembersResult.getData().get(1).getType().getValue()); + assertEquals(TYPE_02, getMembersResult.getData().get(0).getType().getValue()); + assertNotNull(getMembersResult); + assertEquals(HttpStatus.SC_OK, getMembersResult.getStatus()); + PNMembers pnMember01 = getChannelMemberByUserId(getMembersResult, TEST_UUID1); + assertEquals(STATUS_01, pnMember01.getStatus().getValue()); + assertEquals(TYPE_01, pnMember01.getType().getValue()); + PNMembers pnMember02 = getChannelMemberByUserId(getMembersResult, TEST_UUID2); + assertEquals(STATUS_02, pnMember02.getStatus().getValue()); + assertEquals(TYPE_02, pnMember02.getType().getValue()); + assertTrue(pnMember02.getCustom().getValue().containsKey("members_param1")); + assertTrue(pnMember02.getCustom().getValue().containsKey("members_param2")); + } + + @Test + public void getChannelMembersHappyPathDeprecated() throws PubNubException { //given final Collection channelMembers = Arrays.asList( PNUUID.uuid(TEST_UUID1), @@ -167,9 +265,68 @@ public void getChannelMembersHappyPath() throws PubNubException { assertThat(actualStatusList, containsInAnyOrder(STATUS_02)); } - @Test public void removeChannelMembersHappyPath() throws PubNubException { + //given + final Collection channelMembers = Arrays.asList( + PNUser.builder(TEST_UUID1).status(STATUS_01).type(TYPE_01).build(), + PNUser.builder(TEST_UUID2).custom(customChannelMembershipObject()).status(STATUS_02).type(TYPE_02).build()); + + final PNSetChannelMembersResult setChannelMembersResult = pubNubUnderTest + .setChannelMembers(testChannelId, channelMembers) + .include(MemberInclude.builder() + .includeTotalCount(true) + .includeCustom(true) + .includeUser(true) + .includeUserCustom(true) + .build()) + .sync(); + createdMembersList.add(setChannelMembersResult); + + //when + final PNRemoveChannelMembersResult removeMembersResult = pubNubUnderTest + .removeChannelMembers(testChannelId, Collections.singletonList(TEST_UUID2)) + .include(MemberInclude.builder() + .includeTotalCount(true) + .includeStatus(true) + .includeType(true) + .includeCustom(true) + .includeUser(true) + .includeUserCustom(true) + .build()) + .sync(); + + //then + final List returnedUUIDs = new ArrayList<>(); + for (final PNMembers pnMembers : removeMembersResult.getData()) { + final PNUUIDMetadata uuid = pnMembers.getUuid(); + final String id = uuid.getId(); + returnedUUIDs.add(id); + } + + assertNotNull(removeMembersResult); + assertEquals(HttpStatus.SC_OK, removeMembersResult.getStatus()); + assertThat(returnedUUIDs, not(hasItem(TEST_UUID2))); + + final PNGetChannelMembersResult getMembersResult = pubNubUnderTest + .getChannelMembers(testChannelId) + .include(MemberInclude.builder() + .includeTotalCount(true) + .includeStatus(true) + .includeType(true) + .includeCustom(true) + .includeUser(true) + .includeUserCustom(true) + .build()) + .sync(); + + List userIdsOfRemainingMembers = getMembersResult.getData().stream().map(pnMember -> pnMember.getUuid().getId()).collect(Collectors.toList()); + assertTrue(userIdsOfRemainingMembers.contains(TEST_UUID1)); + assertFalse(userIdsOfRemainingMembers.contains(TEST_UUID2)); + } + + @Test + public void removeChannelMembersHappyPathDeprecated() throws PubNubException { //given final Collection channelMembers = Arrays.asList( PNUUID.uuid(TEST_UUID1, STATUS_01), @@ -209,6 +366,63 @@ public void removeChannelMembersHappyPath() throws PubNubException { @Test public void manageChannelMembersHappyPath() throws PubNubException { + //given + final List channelMembersIdsToRemove = Collections.singletonList(TEST_UUID1); + final List channelMembersToRemove = Collections.singletonList( + PNUser.builder(TEST_UUID1) + .custom(customChannelMembershipObject()) + .status(STATUS_01) + .type(TYPE_01) + .build() + ); + + final PNSetChannelMembersResult setChannelMembersResult = pubNubUnderTest + .setChannelMembers(testChannelId, channelMembersToRemove) + .sync(); + createdMembersList.add(setChannelMembersResult); + + final List channelMembersToSet = Collections.singletonList( + PNUser.builder(TEST_UUID2).custom(customChannelMembershipObject()).status(STATUS_02).type(TYPE_01).build()); + + //when + final PNManageChannelMembersResult manageChannelMembersResult = pubNubUnderTest + .manageChannelMembers(testChannelId, channelMembersToSet, channelMembersIdsToRemove) + .include(MemberInclude.builder() + .includeCustom(true) + .includeStatus(true) + .includeType(true) + .includeTotalCount(true) + .includeUser(true) + .includeUserCustom(true) + .includeUserStatus(true) + .includeUserType(true) + .build()) + .sync(); + createdMembersList.add(new PNSetChannelMembersResult(manageChannelMembersResult)); + + + + //then + assertEquals(HttpStatus.SC_OK, manageChannelMembersResult.getStatus()); + assertEquals(1, manageChannelMembersResult.getData().size()); + PNMembers pnMembers = manageChannelMembersResult.getData().get(0); + assertEquals(TEST_UUID2, pnMembers.getUuid().getId()); + assertEquals(STATUS_02, pnMembers.getStatus().getValue()); + assertEquals(TYPE_01, pnMembers.getType().getValue()); + + + assertThat(manageChannelMembersResult, allOf( + notNullValue(), + hasProperty("status", is(HttpStatus.SC_OK)), + hasProperty("data", allOf( + hasItem(hasProperty("uuid", + hasProperty("id", is(channelMembersToSet.get(0).getUserId())))), + not(hasItem(hasProperty("uuid", + hasProperty("id", is(channelMembersToRemove.get(0).getUserId()))))))))); + } + + @Test + public void manageChannelMembersHappyPathDeprecated() throws PubNubException { //given final List channelMembersToRemove = Collections.singletonList( PNUUID.uuidWithCustom(TEST_UUID1, customChannelMembershipObject(), STATUS_01)); @@ -272,4 +486,12 @@ private Map customChannelMembershipObject() { customMap.putIfAbsent("members_param2", "val2"); return customMap; } + + private PNMembers getChannelMemberByUserId(PNSetChannelMembersResult setChannelMembersResult, String userId) { + return setChannelMembersResult.getData().stream().filter(member -> userId.equals(member.getUuid().getId())).collect(Collectors.toList()).get(0); + } + + private PNMembers getChannelMemberByUserId(PNGetChannelMembersResult setChannelMembersResult, String userId) { + return setChannelMembersResult.getData().stream().filter(member -> userId.equals(member.getUuid().getId())).collect(Collectors.toList()).get(0); + } } diff --git a/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/memberships/MembershipIT.java b/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/memberships/MembershipIT.java index 984b118e3..2b1772640 100644 --- a/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/memberships/MembershipIT.java +++ b/pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/objects/memberships/MembershipIT.java @@ -2,6 +2,8 @@ import com.pubnub.api.PubNubException; import com.pubnub.api.integration.objects.ObjectsApiBaseIT; +import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership; import com.pubnub.api.java.models.consumer.objects_api.membership.PNGetMembershipsResult; import com.pubnub.api.java.models.consumer.objects_api.membership.PNManageMembershipResult; @@ -22,7 +24,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; +import static com.pubnub.api.integration.util.Utils.random; import static com.pubnub.api.java.endpoints.objects_api.utils.Include.PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; @@ -31,19 +35,99 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class MembershipIT extends ObjectsApiBaseIT { private static final Logger LOG = LoggerFactory.getLogger(MembershipIT.class); private static final String STATUS = "status"; private static final String CHANNEL = "channel"; - public final String testChannelId1 = UUID.randomUUID().toString(); - public final String testChannelId2 = UUID.randomUUID().toString(); + private final String testChannelId1 = UUID.randomUUID().toString(); + private final String testChannelId2 = UUID.randomUUID().toString(); + + private final String membership01ChannelId = random(); + private final String membership01Status = "active"; + private final String membership01Type = "admin"; + private final String membership02ChannelId = random(); + private final String membership02Status = "inactive"; + private final String membership02Type = "member"; + private final String membership03ChannelId = random(); + private final String membership04ChannelId = random(); + private final String membership05ChannelId = random(); + private final String membership06ChannelId = random(); + private final String userId = random().toString(); private final List createdMembershipsList = new ArrayList<>(); @Test - public void setMembershipsHappyPath() throws PubNubException { + public void setMembershipsHappyPath() throws PubNubException { + final List channelMemberships = buildChannelMemberships( + membership01ChannelId, + membership01Status, + membership01Type, + membership02ChannelId, + membership02Status, + membership02Type, + membership03ChannelId, + membership04ChannelId, + membership05ChannelId, + membership06ChannelId + ); + + PNSetMembershipResult setMembershipResult = pubNubUnderTest + .setMemberships(channelMemberships) + .userId(userId).limit(10) + .include(MembershipInclude.builder() + .includeCustom(true) + .includeStatus(true) + .includeType(true) + .includeTotalCount(true) + .includeChannel(true) + .includeChannelCustom(true) + .includeChannelType(true) + .includeChannelStatus(true) + .build()) + .sort(Arrays.asList(PNSortKey.asc(PNSortKey.Key.STATUS))) + .sync(); + + assertEquals(membership01Status, setMembershipResult.getData().get(0).getStatus().getValue()); + assertEquals(membership02Status, setMembershipResult.getData().get(1).getStatus().getValue()); + + createdMembershipsList.add(setMembershipResult); + + PNMembership pnMembership01 = getMembershipByChannelId(setMembershipResult, membership01ChannelId); + assertEquals(membership01Status, pnMembership01.getStatus().getValue()); + assertEquals(membership01Type, pnMembership01.getType().getValue()); + + PNMembership pnMembership02 = getMembershipByChannelId(setMembershipResult, membership02ChannelId); + assertEquals(membership02Status, pnMembership02.getStatus().getValue()); + assertEquals(membership02Type, pnMembership02.getType().getValue()); + assertNotNull(pnMembership02.getCustom().getValue()); + + PNMembership pnMembership03 = getMembershipByChannelId(setMembershipResult, membership03ChannelId); + assertNull(pnMembership03.getStatus().getValue()); + assertNull(pnMembership03.getType().getValue()); + + PNMembership pnMembership04 = getMembershipByChannelId(setMembershipResult, membership04ChannelId); + assertNull(pnMembership04.getStatus().getValue()); + assertNull(pnMembership04.getType().getValue()); + assertNotNull(pnMembership04.getCustom().getValue()); + + PNMembership pnMembership05 = getMembershipByChannelId(setMembershipResult, membership05ChannelId); + assertNull(pnMembership05.getStatus().getValue()); + assertNull(pnMembership05.getType().getValue()); + assertNull(pnMembership05.getCustom().getValue()); + + PNMembership pnMembership06 = getMembershipByChannelId(setMembershipResult, membership06ChannelId); + assertNull(pnMembership06.getStatus().getValue()); + assertNull(pnMembership06.getType().getValue()); + assertNotNull(pnMembership06.getCustom().getValue()); + } + + @Test + public void setMembershipsHappyPath_deprecated() throws PubNubException { //given final List channelMemberships = Arrays.asList( PNChannelMembership.channel(testChannelId1), @@ -81,6 +165,90 @@ public void setMembershipsHappyPath() throws PubNubException { @Test public void getMembershipsHappyPath() throws PubNubException { + final List channelMemberships = buildChannelMemberships( + membership01ChannelId, + membership01Status, + membership01Type, + membership02ChannelId, + membership02Status, + membership02Type, + membership03ChannelId, + membership04ChannelId, + membership05ChannelId, + membership06ChannelId + ); + + PNSetMembershipResult setMembershipResult = pubNubUnderTest + .setMemberships(channelMemberships) + .userId(userId).limit(10) + .sync(); + + createdMembershipsList.add(setMembershipResult); + + //when + final PNGetMembershipsResult getMembershipsResult = pubNubUnderTest.getMemberships() + .userId(userId) + .limit(10) + .include(MembershipInclude.builder() + .includeCustom(true) + .includeStatus(true) + .includeType(true) + .includeTotalCount(true) + .includeChannel(true) + .includeChannelCustom(true) + .includeChannelType(true) + .includeChannelStatus(true) + .build()) + .sort(Arrays.asList(PNSortKey.asc(PNSortKey.Key.TYPE))) + .sync(); + + assertEquals(membership01Type, getMembershipsResult.getData().get(0).getType().getValue()); + assertEquals(membership02Type, getMembershipsResult.getData().get(1).getType().getValue()); + + PNMembership pnMembership01 = getMembershipByChannelId(getMembershipsResult, membership01ChannelId); + assertEquals(membership01Status, pnMembership01.getStatus().getValue()); + assertEquals(membership01Type, pnMembership01.getType().getValue()); + + PNMembership pnMembership02 = getMembershipByChannelId(getMembershipsResult, membership02ChannelId); + assertEquals(membership02Status, pnMembership02.getStatus().getValue()); + assertEquals(membership02Type, pnMembership02.getType().getValue()); + assertNotNull(pnMembership02.getCustom().getValue()); + + PNMembership pnMembership03 = getMembershipByChannelId(getMembershipsResult, membership03ChannelId); + assertNull(pnMembership03.getStatus().getValue()); + assertNull(pnMembership03.getType().getValue()); + + PNMembership pnMembership04 = getMembershipByChannelId(getMembershipsResult, membership04ChannelId); + assertNull(pnMembership04.getStatus().getValue()); + assertNull(pnMembership04.getType().getValue()); + assertNotNull(pnMembership04.getCustom().getValue()); + + PNMembership pnMembership05 = getMembershipByChannelId(getMembershipsResult, membership05ChannelId); + assertNull(pnMembership05.getStatus().getValue()); + assertNull(pnMembership05.getType().getValue()); + assertNull(pnMembership05.getCustom().getValue()); + + PNMembership pnMembership06 = getMembershipByChannelId(getMembershipsResult, membership06ChannelId); + assertEquals(membership06ChannelId, pnMembership06.getChannel().getId()); + assertNull(pnMembership06.getStatus().getValue()); + assertNull(pnMembership06.getType().getValue()); + assertNotNull(pnMembership06.getCustom().getValue()); + } + + private PNMembership getMembershipByChannelId(PNGetMembershipsResult getMembershipsResult, String membershipId) { + return getMembershipsResult.getData().stream().filter(membership -> membershipId.equals(membership.getChannel().getId())).collect(Collectors.toList()).get(0); + } + + private PNMembership getMembershipByChannelId(PNSetMembershipResult setMembershipResult, String membershipId) { + return setMembershipResult.getData().stream().filter(membership -> membershipId.equals(membership.getChannel().getId())).collect(Collectors.toList()).get(0); + } + + private PNMembership getMembershipByChannelId(PNRemoveMembershipResult removeMembershipsResult, String membershipId) { + return removeMembershipsResult.getData().stream().filter(membership -> membershipId.equals(membership.getChannel().getId())).collect(Collectors.toList()).get(0); + } + + @Test + public void getMembershipsHappyPathDeprecated() throws PubNubException { //given final List channelMemberships = Arrays.asList( PNChannelMembership.channel(testChannelId1), @@ -115,6 +283,50 @@ public void getMembershipsHappyPath() throws PubNubException { @Test public void removeMembershipsHappyPath() throws PubNubException { + //given + final List channelMemberships = buildChannelMemberships( + membership01ChannelId, + membership01Status, + membership01Type, + membership02ChannelId, + membership02Status, + membership02Type, + membership03ChannelId, + membership04ChannelId, + membership05ChannelId, + membership06ChannelId + ); + + final PNSetMembershipResult setMembershipResult = pubNubUnderTest.setMemberships(channelMemberships) + .include(MembershipInclude.builder() + .includeTotalCount(true) + .includeCustom(true) + .includeChannel(true) + .includeChannelCustom(true) + .build()) + .sync(); + createdMembershipsList.add(setMembershipResult); + + //when + List channelMembershipsToRemove = Collections.singletonList(testChannelId2); + final PNRemoveMembershipResult removeMembershipResult = pubNubUnderTest.removeMemberships(channelMembershipsToRemove) + .include(MembershipInclude.builder() + .includeTotalCount(true) + .includeCustom(true) + .includeChannel(true) + .includeType(true) + .includeStatus(true) + .build()) + .sync(); + + //then + PNMembership pnMembership01 = getMembershipByChannelId(removeMembershipResult, membership01ChannelId); + assertEquals(membership01Status, pnMembership01.getStatus().getValue()); + assertEquals(membership01Type, pnMembership01.getType().getValue()); + } + + @Test + public void removeMembershipsHappyPathDeprecated() throws PubNubException { //given final List channelMemberships = Arrays.asList(PNChannelMembership.channel(testChannelId1), PNChannelMembership.channelWithCustom(testChannelId2, customChannelMembershipObject())); @@ -150,6 +362,47 @@ public void removeMembershipsHappyPath() throws PubNubException { @Test public void manageMembershipsHappyPath() throws PubNubException { + //given + final List channelIdsToRemove = Collections.singletonList(testChannelId1); + final List channelMembershipsToRemove = Collections.singletonList( + PNChannelMembership.channelWithCustom(testChannelId1, customChannelMembershipObject())); + + final PNSetMembershipResult setMembershipResult = pubNubUnderTest.setMemberships(channelMembershipsToRemove).sync(); + createdMembershipsList.add(setMembershipResult); + + final List channelMembershipsToSet = Collections.singletonList( + PNChannelMembership.builder(testChannelId2) + .custom(customChannelMembershipObject()) + .status(membership02Status) + .type(membership02Type) + .build()); + + //when + final PNManageMembershipResult manageMembershipResult = pubNubUnderTest.manageMemberships(channelMembershipsToSet, channelIdsToRemove) + .userId(pubNubUnderTest.getConfiguration().getUserId().getValue()) + .include(MembershipInclude.builder() + .includeTotalCount(true) + .includeCustom(true) + .includeChannel(true) + .includeChannelCustom(true) + .includeStatus(true) + .includeType(true) + .build()) + .sync(); + + createdMembershipsList.add(new PNSetMembershipResult(manageMembershipResult)); + + //then + assertEquals(HttpStatus.SC_OK, manageMembershipResult.getStatus()); + assertEquals(1, manageMembershipResult.getData().size()); + PNMembership pnMembership = manageMembershipResult.getData().get(0); + assertEquals(testChannelId2, pnMembership.getChannel().getId()); + assertEquals(membership02Status, pnMembership.getStatus().getValue()); + assertEquals(membership02Type, pnMembership.getType().getValue()); + } + + @Test + public void manageMembershipsHappyPathDeprecated() throws PubNubException { //given final List channelMembershipsToRemove = Collections.singletonList( PNChannelMembership.channelWithCustom(testChannelId1, customChannelMembershipObject())); @@ -191,16 +444,13 @@ public void manageMembershipsHappyPath() throws PubNubException { public void cleanUp() { for (final PNSetMembershipResult createdMembership : createdMembershipsList) { try { - final List channelMemberships = new ArrayList<>(); + final List channelIds = new ArrayList<>(); for (final PNMembership it : createdMembership.getData()) { final String id = it.getChannel().getId(); - final PNChannelMembership pnChannelMembership = PNChannelMembership.channel(id); - channelMemberships.add(pnChannelMembership); + channelIds.add(id); } - pubNubUnderTest.removeMemberships() - .channelMemberships(channelMemberships) - .sync(); + pubNubUnderTest.removeMemberships(channelIds).sync(); } catch (Exception e) { LOG.warn("Could not cleanup {}", createdMembership, e); @@ -214,4 +464,22 @@ private static Map customChannelMembershipObject() { customMap.putIfAbsent("membership_param2", "val2"); return customMap; } + + private List buildChannelMemberships(String membership01ChannelId, String membership01Status, String membership01Type, String membership02ChannelId, String membership02Status, String membership02Type, String membership03ChannelId, String membership04ChannelId, String membership05ChannelId, String membership06ChannelId) { + return Arrays.asList( + PNChannelMembership.builder(membership01ChannelId) + .status(membership01Status) + .type(membership01Type) + .build(), + PNChannelMembership.builder(membership02ChannelId) + .custom(customChannelMembershipObject()) + .status(membership02Status) + .type(membership02Type) + .build(), + PNChannelMembership.channel(membership03ChannelId), // this old usage + PNChannelMembership.channelWithCustom(membership04ChannelId, customChannelMembershipObject()), // this old usage + new PNChannelMembership.JustChannel(new PNChannelMembership.ChannelId(membership05ChannelId)), // this old usage + new PNChannelMembership.ChannelWithCustom(new PNChannelMembership.ChannelId(membership06ChannelId), customChannelMembershipObject()) // this is deprecated usage + ); + } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembersConverter.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembersConverter.java index e2b659fd6..cdfecfbcd 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembersConverter.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/member/PNMembersConverter.java @@ -19,7 +19,8 @@ static PNMembers from(@Nullable PNMember member) { .setCustom(member.getCustom()) .setUpdated(member.getUpdated()) .setETag(member.getETag()) - .setStatus(member.getStatus()); + .setStatus(member.getStatus()) + .setType(member.getType()); } static List from(Collection members) { diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembershipConverter.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembershipConverter.java index 9f2d985d0..d7d82085d 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembershipConverter.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/api/java/models/consumer/objects_api/membership/PNMembershipConverter.java @@ -31,6 +31,7 @@ static PNMembership from(@Nullable PNChannelMembership data) { newData.setUpdated(data.getUpdated()); newData.setETag(data.getETag()); newData.setStatus(data.getStatus()); + newData.setType(data.getType()); return newData; } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/PubNubForJavaImpl.kt b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/PubNubForJavaImpl.kt index 1dbd6e9d2..db298dbb0 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/PubNubForJavaImpl.kt +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/PubNubForJavaImpl.kt @@ -32,13 +32,20 @@ import com.pubnub.api.java.endpoints.objects_api.channel.GetChannelMetadata import com.pubnub.api.java.endpoints.objects_api.channel.RemoveChannelMetadata import com.pubnub.api.java.endpoints.objects_api.channel.SetChannelMetadata import com.pubnub.api.java.endpoints.objects_api.members.GetChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.GetChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.members.ManageChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.ManageChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembers +import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembersBuilder import com.pubnub.api.java.endpoints.objects_api.memberships.GetMemberships import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMemberships +import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMembershipsBuilder import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMemberships +import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMembershipsBuilder import com.pubnub.api.java.endpoints.objects_api.memberships.SetMemberships +import com.pubnub.api.java.endpoints.objects_api.memberships.SetMembershipsBuilder import com.pubnub.api.java.endpoints.objects_api.uuid.GetAllUUIDMetadata import com.pubnub.api.java.endpoints.objects_api.uuid.GetUUIDMetadata import com.pubnub.api.java.endpoints.objects_api.uuid.RemoveUUIDMetadata @@ -53,6 +60,8 @@ import com.pubnub.api.java.endpoints.push.AddChannelsToPush import com.pubnub.api.java.endpoints.push.ListPushProvisions import com.pubnub.api.java.endpoints.push.RemoveAllPushChannelsForDevice import com.pubnub.api.java.endpoints.push.RemoveChannelsFromPush +import com.pubnub.api.java.models.consumer.objects_api.member.PNUser +import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership import com.pubnub.api.java.v2.PNConfiguration import com.pubnub.api.java.v2.callbacks.EventListener import com.pubnub.api.java.v2.callbacks.StatusListener @@ -277,33 +286,71 @@ open class PubNubForJavaImpl(configuration: PNConfiguration) : } override fun setMemberships(): SetMemberships.Builder { - return SetMembershipsImpl.Builder(this) + return SetMembershipsImpl.BuilderDeprecated(this) + } + + override fun setMemberships(channelMemberships: Collection): SetMembershipsBuilder { + return SetMembershipsImpl(channelMemberships, this) } override fun removeMemberships(): RemoveMemberships.Builder { return RemoveMembershipsImpl.Builder(this) } + override fun removeMemberships(channelMemberships: Collection): RemoveMembershipsBuilder { + return RemoveMembershipsImpl(channelMemberships, this) + } + override fun manageMemberships(): ManageMemberships.Builder { return ManageMembershipsImpl.Builder(this) } + override fun manageMemberships( + channelsToSet: Collection, + channelsToDelete: Collection + ): ManageMembershipsBuilder { + return ManageMembershipsImpl(channelsToSet, channelsToDelete, this) + } + override fun getChannelMembers(): GetChannelMembers.Builder { return GetChannelMembersImpl.Builder(this) } + override fun getChannelMembers(channelId: String): GetChannelMembersBuilder { + return GetChannelMembersImpl(channelId, this) + } + override fun setChannelMembers(): SetChannelMembers.Builder { return SetChannelMembersImpl.Builder(this) } + override fun setChannelMembers(channelId: String, channelMembers: Collection): SetChannelMembersBuilder { + return SetChannelMembersImpl(channelId, channelMembers, this) + } + override fun removeChannelMembers(): RemoveChannelMembers.Builder { return RemoveChannelMembersImpl.Builder(this) } + override fun removeChannelMembers( + channelId: String, + channelMembers: Collection + ): RemoveChannelMembersBuilder { + return RemoveChannelMembersImpl(this, channelId, channelMembers) + } + override fun manageChannelMembers(): ManageChannelMembers.Builder { return ManageChannelMembersImpl.Builder(this) } + override fun manageChannelMembers( + channelId: String, + set: Collection, + remove: Collection + ): ManageChannelMembersBuilder { + return ManageChannelMembersImpl(this, channelId, set, remove) + } + // End Objects API // Start Message Actions API override fun addMessageAction(): AddMessageAction { diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/channel/GetAllChannelsMetadataImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/channel/GetAllChannelsMetadataImpl.java index cb6174a46..a01230f39 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/channel/GetAllChannelsMetadataImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/channel/GetAllChannelsMetadataImpl.java @@ -70,6 +70,12 @@ public static Collection implements GetChannelMembers { +public class GetChannelMembersImpl extends DelegatingEndpoint implements GetChannelMembers, GetChannelMembersBuilder { private final String channel; private Integer limit = null; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private Include.PNUUIDDetailsLevel includeUUID; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNUUIDDetailsLevel includeUUID; // deprecated + private MemberInclude include; public GetChannelMembersImpl(String channel, final PubNub pubnubInstance) { super(pubnubInstance); @@ -52,10 +57,7 @@ protected Endpoint createRemoteAction() { page, filter, SetChannelMembersImpl.toInternal(sort), - includeTotalCount, - includeCustom, - SetChannelMembersImpl.toInternal(includeUUID), - includeType + getMemberInclude(include, includeUUID, includeTotalCount, includeCustom, includeType) ); } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/ManageChannelMembersImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/ManageChannelMembersImpl.java index 5c53b9ad2..83934c095 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/ManageChannelMembersImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/ManageChannelMembersImpl.java @@ -5,12 +5,15 @@ import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction; import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction; import com.pubnub.api.java.endpoints.objects_api.members.ManageChannelMembers; +import com.pubnub.api.java.endpoints.objects_api.members.ManageChannelMembersBuilder; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.ObjectsBuilderSteps; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; import com.pubnub.api.java.models.consumer.objects_api.member.PNManageChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNManageChannelMembersResultConverter; import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID; +import com.pubnub.api.java.models.consumer.objects_api.member.PNUser; import com.pubnub.api.models.consumer.objects.PNPage; import com.pubnub.api.models.consumer.objects.member.MemberInput; import com.pubnub.api.models.consumer.objects.member.PNMember; @@ -25,22 +28,28 @@ import java.util.Collections; import java.util.List; +import static com.pubnub.internal.java.endpoints.objects_api.members.SetChannelMembersImpl.getMemberInclude; + @Setter @Accessors(chain = true, fluent = true) -public class ManageChannelMembersImpl extends DelegatingEndpoint implements ManageChannelMembers { +public class ManageChannelMembersImpl extends DelegatingEndpoint implements ManageChannelMembers, ManageChannelMembersBuilder { + private final String channel; private Integer limit = null; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private final String channel; - private Include.PNUUIDDetailsLevel includeUUID; - private final Collection uuidsToSet; - private final Collection uuidsToRemove; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNUUIDDetailsLevel includeUUID; // deprecated + private Collection uuidsToSet; // deprecated + private Collection uuidsToRemove; // deprecated + private Collection usersToSet; + private List usersIdsToRemove; + private MemberInclude include; + @Deprecated public ManageChannelMembersImpl(String channel, Collection uuidsToSet, Collection uuidsToRemove, final PubNub pubnubInstance) { super(pubnubInstance); this.channel = channel; @@ -48,6 +57,13 @@ public ManageChannelMembersImpl(String channel, Collection uuidsToSet, C this.uuidsToRemove = uuidsToRemove; } + public ManageChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection usersToSet, Collection usersIdsToRemove) { + super(pubnubInstance); + this.channel = channel; + this.usersToSet = usersToSet; + this.usersIdsToRemove = new ArrayList<>(usersIdsToRemove); + } + @NotNull @Override protected ExtendedRemoteAction mapResult(@NotNull ExtendedRemoteAction action) { @@ -57,17 +73,16 @@ protected ExtendedRemoteAction mapResult(@NotNull @Override @NotNull protected Endpoint createRemoteAction() { - List toRemove = new ArrayList(uuidsToRemove.size()); - for (PNUUID pnuuid : uuidsToRemove) { - toRemove.add(pnuuid.getUuid().getId()); - } - List toSet = new ArrayList(uuidsToSet.size()); - for (PNUUID pnuuid : uuidsToSet) { - toSet.add(new PNMember.Partial( - pnuuid.getUuid().getId(), - (pnuuid instanceof PNUUID.UUIDWithCustom) ? ((PNUUID.UUIDWithCustom) pnuuid).getCustom() : null, - pnuuid.getStatus() - )); + List toSet; + List toRemove; + + // new API use + if (usersToSet != null || usersIdsToRemove != null) { + toSet = createMemberInputFromUserToSet(); + toRemove = usersIdsToRemove; + } else { // old API used + toSet = createMemberInputFromUUIDToSet(); + toRemove = createUserIdsFromUUIDToRemove(); } return pubnub.manageChannelMembers( @@ -78,10 +93,7 @@ protected Endpoint createRemoteAction() { page, filter, SetChannelMembersImpl.toInternal(sort), - includeTotalCount, - includeCustom, - SetChannelMembersImpl.toInternal(includeUUID), - includeType + getMemberInclude(include, includeUUID, includeTotalCount, includeCustom, includeType) ); } @@ -127,4 +139,46 @@ public ManageChannelMembers set(final Collection uuidsToSet) { }; } } + + private List createMemberInputFromUserToSet() { + if (usersToSet == null) { + return Collections.emptyList(); + } + List memberInputs = new ArrayList<>(); + for (PNUser user : usersToSet) { + memberInputs.add(new PNMember.Partial( + user.getUserId(), + user.getCustom(), // despite IDE error this works ¯\_(ツ)_/¯ + user.getStatus(), + user.getType() + )); + } + return memberInputs; + } + private List createMemberInputFromUUIDToSet() { + if (uuidsToSet == null) { + return Collections.emptyList(); + } + List memberInputs = new ArrayList<>(); + for (PNUUID uuid : uuidsToSet) { + memberInputs.add(new PNMember.Partial( + uuid.getUuid().getId(), + (uuid instanceof PNUUID.UUIDWithCustom) ? ((PNUUID.UUIDWithCustom) uuid).getCustom() : null, // despite IDE error this works ¯\_(ツ)_/¯ + uuid.getStatus(), + null + )); + } + return memberInputs; + } + + private List createUserIdsFromUUIDToRemove() { + if (uuidsToRemove == null) { + return Collections.emptyList(); + } + List toRemove = new ArrayList<>(); + for (PNUUID uuid : uuidsToRemove) { + toRemove.add(uuid.getUuid().getId()); + } + return toRemove; + } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/RemoveChannelMembersImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/RemoveChannelMembersImpl.java index 63631c550..c16351e5f 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/RemoveChannelMembersImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/RemoveChannelMembersImpl.java @@ -5,9 +5,11 @@ import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction; import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction; import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembers; +import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembersBuilder; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.ObjectsBuilderSteps; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; import com.pubnub.api.java.models.consumer.objects_api.member.PNRemoveChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNRemoveChannelMembersResultConverter; import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID; @@ -23,30 +25,40 @@ import java.util.Collections; import java.util.List; +import static com.pubnub.internal.java.endpoints.objects_api.members.SetChannelMembersImpl.getMemberInclude; + @Setter @Accessors(chain = true, fluent = true) -public class RemoveChannelMembersImpl extends DelegatingEndpoint implements RemoveChannelMembers { +public class RemoveChannelMembersImpl extends DelegatingEndpoint implements RemoveChannelMembers, RemoveChannelMembersBuilder { private Integer limit = null; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated private final String channel; - private final List uuids; - private Include.PNUUIDDetailsLevel includeUUID; + private final List userIds; + private Include.PNUUIDDetailsLevel includeUUID; // deprecated + private MemberInclude include; - public RemoveChannelMembersImpl(String channel, Collection uuids, final PubNub pubnubInstance) { + @Deprecated + private RemoveChannelMembersImpl(String channel, Collection uuids, final PubNub pubnubInstance) { super(pubnubInstance); this.channel = channel; - this.uuids = new ArrayList<>(uuids.size()); + this.userIds = new ArrayList<>(uuids.size()); for (PNUUID uuid : uuids) { - this.uuids.add(uuid.getUuid().getId()); + this.userIds.add(uuid.getUuid().getId()); } } + public RemoveChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection userIds) { + super(pubnubInstance); + this.channel = channel; + this.userIds = new ArrayList<>(userIds); + } + @NotNull @Override protected ExtendedRemoteAction mapResult(@NotNull ExtendedRemoteAction action) { @@ -58,15 +70,12 @@ protected ExtendedRemoteAction mapResult(@NotNull protected Endpoint createRemoteAction() { return pubnub.removeChannelMembers( channel, - uuids, + userIds, limit, page, filter, SetChannelMembersImpl.toInternal(sort), - includeTotalCount, - includeCustom, - SetChannelMembersImpl.toInternal(includeUUID), - includeType + getMemberInclude(include, includeUUID, includeTotalCount, includeCustom, includeType) ); } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/SetChannelMembersImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/SetChannelMembersImpl.java index 8ffcef1dc..8d7dc7019 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/SetChannelMembersImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/members/SetChannelMembersImpl.java @@ -5,12 +5,15 @@ import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction; import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction; import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembers; +import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembersBuilder; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.ObjectsBuilderSteps; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.member.MemberInclude; import com.pubnub.api.java.models.consumer.objects_api.member.PNSetChannelMembersResult; import com.pubnub.api.java.models.consumer.objects_api.member.PNSetChannelMembersResultConverter; import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID; +import com.pubnub.api.java.models.consumer.objects_api.member.PNUser; import com.pubnub.api.models.consumer.objects.PNMemberKey; import com.pubnub.api.models.consumer.objects.PNPage; import com.pubnub.api.models.consumer.objects.member.MemberInput; @@ -30,39 +33,53 @@ @Setter @Accessors(chain = true, fluent = true) -public class SetChannelMembersImpl extends DelegatingEndpoint implements SetChannelMembers { +public class SetChannelMembersImpl extends DelegatingEndpoint implements SetChannelMembers, SetChannelMembersBuilder { private Integer limit = null; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private Include.PNUUIDDetailsLevel includeUUID; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNUUIDDetailsLevel includeUUID; // deprecated private final String channel; - private final Collection uuids; + private Collection uuids; // deprecated + private Collection users; + private MemberInclude include; - public SetChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection uuids) { + @Deprecated + private SetChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection uuids) { super(pubnubInstance); this.channel = channel; this.uuids = uuids; } + public SetChannelMembersImpl(String channel, Collection users, final PubNub pubnubInstance) { + super(pubnubInstance); + this.channel = channel; + this.users = users; + } + @NotNull @Override protected ExtendedRemoteAction mapResult(@NotNull ExtendedRemoteAction action) { - return new MappingRemoteAction<>(action, PNSetChannelMembersResultConverter::from); + MappingRemoteAction pnMemberArrayResultPNSetChannelMembersResultMappingRemoteAction = new MappingRemoteAction<>(action, PNSetChannelMembersResultConverter::from); + return pnMemberArrayResultPNSetChannelMembersResultMappingRemoteAction; } @Override @NotNull protected Endpoint createRemoteAction() { - List memberInputs = new ArrayList<>(uuids.size()); - for (PNUUID uuid : uuids) { - memberInputs.add(new PNMember.Partial(uuid.getUuid().getId(), (uuid instanceof PNUUID.UUIDWithCustom) ? ((PNUUID.UUIDWithCustom) uuid).getCustom() : null, uuid.getStatus())); - } - return pubnub.setChannelMembers(channel, memberInputs, limit, page, filter, toInternal(sort), includeTotalCount, includeCustom, toInternal(includeUUID), includeType); + return pubnub.setChannelMembers( + channel, + createMemberInputs(), + limit, + page, + filter, + toInternal(sort), + getMemberInclude(include, includeUUID, includeTotalCount, includeCustom, includeType) + ); } static Collection> toInternal(Collection sort) { @@ -79,6 +96,12 @@ static Collection uuids) { }; } } + + + private List createMemberInputs() { + List memberInputs = new ArrayList<>(); + if (users != null) { + for (PNUser user: users) { + memberInputs.add(new PNMember.Partial( + user.getUserId(), + user.getCustom(), // despite IDE error this works ¯\_(ツ)_/¯ + user.getStatus(), + user.getType() + )); + } + } else if (uuids != null) { + for (PNUUID uuid : uuids) { + memberInputs.add(new PNMember.Partial( + uuid.getUuid().getId(), + (uuid instanceof PNUUID.UUIDWithCustom) ? ((PNUUID.UUIDWithCustom) uuid).getCustom() : null, + uuid.getStatus(), + null + )); + } + } + return memberInputs; + } + + static MemberInclude getMemberInclude( + MemberInclude include, + Include.PNUUIDDetailsLevel includeUser, + boolean includeTotalCount, + boolean includeCustom, + boolean includeType + ) { + if (include != null) { + return include; + } else { + // if deprecated setChannelMembership API use + MemberInclude.Builder builderWithCommonParams = MemberInclude.builder() + .includeTotalCount(includeTotalCount) + .includeCustom(includeCustom) + .includeUserType(includeType); + if (includeUser == Include.PNUUIDDetailsLevel.UUID) { + return builderWithCommonParams + .includeStatus(true) + .includeUser(true) + .build(); + } else if (includeUser == Include.PNUUIDDetailsLevel.UUID_WITH_CUSTOM) { + return builderWithCommonParams + .includeStatus(true) + .includeUser(true) + .includeUserCustom(true) + .build(); + } else { + return builderWithCommonParams.build(); + } + } + } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/GetMembershipsImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/GetMembershipsImpl.java index 11e41268a..795d6891f 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/GetMembershipsImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/GetMembershipsImpl.java @@ -7,6 +7,7 @@ import com.pubnub.api.java.endpoints.objects_api.memberships.GetMemberships; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; import com.pubnub.api.java.models.consumer.objects_api.membership.PNGetMembershipsResult; import com.pubnub.api.java.models.consumer.objects_api.membership.PNGetMembershipsResultConverter; import com.pubnub.api.models.consumer.objects.PNPage; @@ -19,19 +20,22 @@ import java.util.Collection; import java.util.Collections; +import static com.pubnub.internal.java.endpoints.objects_api.memberships.SetMembershipsImpl.getMembershipInclude; + @Setter @Accessors(chain = true, fluent = true) public class GetMembershipsImpl extends DelegatingEndpoint implements GetMemberships { - - private String uuid; + private String uuid; // deprecated + private String userId; private Integer limit; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private Include.PNChannelDetailsLevel includeChannel; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNChannelDetailsLevel includeChannel; // deprecated + private MembershipInclude include; public GetMembershipsImpl(PubNub pubnub) { super(pubnub); @@ -46,15 +50,18 @@ protected ExtendedRemoteAction mapResult(@NotNull Extend @Override @NotNull protected Endpoint createRemoteAction() { - return pubnub.getMemberships(uuid, + return pubnub.getMemberships( + getUserId(), limit, page, filter, SetMembershipsImpl.toInternal(sort), - includeTotalCount, - includeCustom, - SetMembershipsImpl.toInternal(includeChannel), - includeType); + getMembershipInclude(include, includeChannel, includeTotalCount, includeCustom, includeType) + ); + } + + private String getUserId() { + return userId != null ? userId : uuid; } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/ManageMembershipsImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/ManageMembershipsImpl.java index 6d2016897..99d23504a 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/ManageMembershipsImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/ManageMembershipsImpl.java @@ -5,8 +5,10 @@ import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction; import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction; import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMemberships; +import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMembershipsBuilder; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership; import com.pubnub.api.java.models.consumer.objects_api.membership.PNManageMembershipResult; import com.pubnub.api.java.models.consumer.objects_api.membership.PNManageMembershipResultConverter; @@ -21,26 +23,32 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static com.pubnub.internal.java.endpoints.objects_api.memberships.SetMembershipsImpl.getMembershipInclude; @Setter @Accessors(chain = true, fluent = true) -public class ManageMembershipsImpl extends DelegatingEndpoint implements ManageMemberships { +public class ManageMembershipsImpl extends DelegatingEndpoint implements ManageMemberships, ManageMembershipsBuilder { private Collection set; private Collection remove; - private String uuid; + private String uuid; // deprecated + private String userId; private Integer limit; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private Include.PNChannelDetailsLevel includeChannel; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNChannelDetailsLevel includeChannel; // deprecated + private MembershipInclude include; - public ManageMembershipsImpl(Collection channelsToSet, Collection channelsToRemove, final PubNub pubnubInstance) { + public ManageMembershipsImpl(Collection channelsToSet, Collection channelsToRemove, final PubNub pubnubInstance) { super(pubnubInstance); set = channelsToSet; - remove = channelsToRemove; + remove = getChannelMembershipsToRemove(channelsToRemove); } @NotNull @@ -56,30 +64,22 @@ protected Endpoint createRemoteAction() { for (PNChannelMembership channel : set) { toSet.add(new com.pubnub.api.models.consumer.objects.membership.PNChannelMembership.Partial( channel.getChannel().getId(), - (channel instanceof PNChannelMembership.ChannelWithCustom) - ? ((PNChannelMembership.ChannelWithCustom) channel).getCustom() - : null, - null + channel.getCustom(), // despite IDE error this works ¯\_(ツ)_/¯ + channel.getStatus(), + channel.getType() )); } - ArrayList toRemove = new ArrayList<>(remove.size()); - for (PNChannelMembership channel : remove) { - toRemove.add(channel.getChannel().getId()); - } + List channelIdsToRemove = remove.stream().map(membership -> membership.getChannel().getId()).collect(Collectors.toList()); - return - pubnub.manageMemberships( + return pubnub.manageMemberships( toSet, - toRemove, - uuid, + channelIdsToRemove, + getUserId(), limit, page, filter, SetMembershipsImpl.toInternal(sort), - includeTotalCount, - includeCustom, - SetMembershipsImpl.toInternal(includeChannel), - includeType + getMembershipInclude(include, includeChannel, includeTotalCount, includeCustom, includeType) ); } @@ -95,8 +95,9 @@ public RemoveStep set(final Collection

() { @Override public ManageMemberships remove(final Collection channelsToRemove) { + List channelIdsToRemove = channelsToRemove.stream().map(membership -> membership.getChannel().getId()).collect(Collectors.toList()); return new ManageMembershipsImpl(channelsToSet, - channelsToRemove, + channelIdsToRemove, pubnubInstance); } }; @@ -104,14 +105,27 @@ public ManageMemberships remove(final Collection channelsTo @Override public SetStep remove(final Collection channelsToRemove) { + List channelIdsToRemove = channelsToRemove.stream().map(membership -> membership.getChannel().getId()).collect(Collectors.toList()); return new SetStep() { @Override public ManageMemberships set(final Collection channelsToSet) { return new ManageMembershipsImpl(channelsToSet, - channelsToRemove, + channelIdsToRemove, pubnubInstance); } }; } } + + private String getUserId() { + return userId != null ? userId : uuid; + } + + private Collection getChannelMembershipsToRemove(Collection channelsToRemove) { + Collection channelMembershipsToRemove = new ArrayList<>(); + for (String channelIdToRemove : channelsToRemove) { + channelMembershipsToRemove.add(PNChannelMembership.channel(channelIdToRemove)); + } + return channelMembershipsToRemove; + } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/RemoveMembershipsImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/RemoveMembershipsImpl.java index 4df7439c2..96555d65e 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/RemoveMembershipsImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/RemoveMembershipsImpl.java @@ -5,8 +5,10 @@ import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction; import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction; import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMemberships; +import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMembershipsBuilder; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership; import com.pubnub.api.java.models.consumer.objects_api.membership.PNRemoveMembershipResult; import com.pubnub.api.java.models.consumer.objects_api.membership.PNRemoveMembershipResultConverter; @@ -17,27 +19,32 @@ import lombok.experimental.Accessors; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static com.pubnub.internal.java.endpoints.objects_api.memberships.SetMembershipsImpl.getMembershipInclude; @Setter @Accessors(chain = true, fluent = true) -public class RemoveMembershipsImpl extends DelegatingEndpoint implements RemoveMemberships { - private final Collection channelMemberships; - private String uuid; +public class RemoveMembershipsImpl extends DelegatingEndpoint implements RemoveMemberships, RemoveMembershipsBuilder { + private List channelIds; + private String uuid; // deprecated + private String userId; private Integer limit; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private Include.PNChannelDetailsLevel includeChannel; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNChannelDetailsLevel includeChannel; // deprecated + private MembershipInclude include; - public RemoveMembershipsImpl(@NotNull Collection channelMemberships, final PubNub pubnubInstance) { + public RemoveMembershipsImpl(@NotNull Collection channelIds, final PubNub pubnubInstance) { super(pubnubInstance); - this.channelMemberships = channelMemberships; + this.channelIds = (List) channelIds; } @NotNull @@ -49,21 +56,15 @@ protected ExtendedRemoteAction mapResult(@NotNull Exte @Override @NotNull protected Endpoint createRemoteAction() { - ArrayList channelList = new ArrayList<>(channelMemberships.size()); - for (PNChannelMembership channel : channelMemberships) { - channelList.add(channel.getChannel().getId()); - } + return pubnub.removeMemberships( - channelList, - uuid, + channelIds, + getUserId(), limit, page, filter, SetMembershipsImpl.toInternal(sort), - includeTotalCount, - includeCustom, - SetMembershipsImpl.toInternal(includeChannel), - includeType + getMembershipInclude(include, includeChannel, includeTotalCount, includeCustom, includeType) ); } @@ -76,7 +77,13 @@ public Builder(PubNub pubnubInstance) { @Override public RemoveMemberships channelMemberships(@NotNull final Collection channelMemberships) { - return new RemoveMembershipsImpl(channelMemberships, pubnubInstance); + List channelIds = channelMemberships.stream().map(pnChannelMembership -> + pnChannelMembership.getChannel().getId()).collect(Collectors.toList()); + return new RemoveMembershipsImpl(channelIds, pubnubInstance); } } + + private String getUserId() { + return userId != null ? userId : uuid; + } } diff --git a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/SetMembershipsImpl.java b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/SetMembershipsImpl.java index 9c7299206..41d2af962 100644 --- a/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/SetMembershipsImpl.java +++ b/pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/endpoints/objects_api/memberships/SetMembershipsImpl.java @@ -5,8 +5,10 @@ import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction; import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction; import com.pubnub.api.java.endpoints.objects_api.memberships.SetMemberships; +import com.pubnub.api.java.endpoints.objects_api.memberships.SetMembershipsBuilder; import com.pubnub.api.java.endpoints.objects_api.utils.Include; import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey; +import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude; import com.pubnub.api.java.models.consumer.objects_api.membership.PNChannelMembership; import com.pubnub.api.java.models.consumer.objects_api.membership.PNSetMembershipResult; import com.pubnub.api.java.models.consumer.objects_api.membership.PNSetMembershipResultConverter; @@ -28,17 +30,19 @@ @Setter @Accessors(chain = true, fluent = true) -public class SetMembershipsImpl extends DelegatingEndpoint implements SetMemberships { +public class SetMembershipsImpl extends DelegatingEndpoint implements SetMemberships, SetMembershipsBuilder { private final Collection channels; - private String uuid; + private String uuid; // deprecated + private String userId; private Integer limit; private PNPage page; private String filter; private Collection sort = Collections.emptyList(); - private boolean includeTotalCount; - private boolean includeCustom; - private boolean includeType; - private Include.PNChannelDetailsLevel includeChannel; + private boolean includeTotalCount; // deprecated + private boolean includeCustom; // deprecated + private boolean includeType; // deprecated + private Include.PNChannelDetailsLevel includeChannel; // deprecated + private MembershipInclude include; public SetMembershipsImpl(@NotNull Collection channelMemberships, final PubNub pubnubInstance) { super(pubnubInstance); @@ -52,23 +56,19 @@ protected Endpoint createRemoteAction() { for (PNChannelMembership channel : channels) { channelList.add(new Partial( channel.getChannel().getId(), - (channel instanceof PNChannelMembership.ChannelWithCustom) - ? ((PNChannelMembership.ChannelWithCustom) channel).getCustom() - : null, - null + channel.getCustom(), // despite IDE error this works ¯\_(ツ)_/¯ + channel.getStatus(), + channel.getType() )); } return pubnub.setMemberships( channelList, - uuid, + getUserId(), limit, page, filter, toInternal(sort), - includeTotalCount, - includeCustom, - toInternal(includeChannel), - includeType + getMembershipInclude(include, includeChannel, includeTotalCount, includeCustom, includeType) ); } @@ -78,10 +78,10 @@ protected ExtendedRemoteAction mapResult(@NotNull Extende return new MappingRemoteAction<>(action, PNSetMembershipResultConverter::from); } - public static class Builder implements SetMemberships.Builder { + public static class BuilderDeprecated implements SetMemberships.Builder { private final PubNub pubnubInstance; - public Builder(PubNub pubnubInstance) { + public BuilderDeprecated(PubNub pubnubInstance) { this.pubnubInstance = pubnubInstance; } @@ -119,6 +119,12 @@ static Collection + + + + + + @@ -13,18 +19,17 @@ - - - - - - - - + + + + + + + - + - + @@ -37,7 +42,7 @@ - + @@ -73,5 +78,6 @@ + diff --git a/pubnub-kotlin/pubnub-kotlin-api/pubnub_kotlin_api.podspec b/pubnub-kotlin/pubnub-kotlin-api/pubnub_kotlin_api.podspec index 2513ff46b..a1ef508ad 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/pubnub_kotlin_api.podspec +++ b/pubnub-kotlin/pubnub-kotlin-api/pubnub_kotlin_api.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'pubnub_kotlin_api' - spec.version = '10.2.0' + spec.version = '10.2.1' spec.homepage = '' spec.source = { :http=> ''} spec.authors = '' diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/api/PubNubImpl.kt b/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/api/PubNubImpl.kt index 33990ead4..dd57776b4 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/api/PubNubImpl.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/api/PubNubImpl.kt @@ -118,9 +118,11 @@ import com.pubnub.api.models.consumer.objects.PNMemberKey import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey +import com.pubnub.api.models.consumer.objects.member.MemberInclude import com.pubnub.api.models.consumer.objects.member.MemberInput import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel import com.pubnub.api.v2.PNConfiguration import com.pubnub.api.v2.callbacks.EventListener @@ -590,6 +592,7 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + // deprecated override fun getMemberships( uuid: String?, limit: Int?, @@ -615,6 +618,18 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + override fun getMemberships( + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): GetMemberships { + TODO("Not yet implemented") + } + + // deprecated override fun setMemberships( channels: List, uuid: String?, @@ -642,6 +657,19 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + override fun setMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships { + TODO("Not yet implemented") + } + + // deprecated override fun removeMemberships( channels: List, uuid: String?, @@ -669,6 +697,18 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + override fun removeMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude, + ): ManageMemberships { + TODO("Not yet implemented") + } + override fun getChannelMembers( channel: String, limit: Int?, @@ -694,6 +734,18 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + override fun getChannelMembers( + channel: String, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): GetChannelMembers { + TODO("Not yet implemented") + } + + // deprecated override fun setChannelMembers( channel: String, uuids: List, @@ -721,6 +773,18 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + override fun setChannelMembers( + channel: String, + users: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers { + TODO("Not yet implemented") + } + override fun removeChannelMembers( channel: String, uuids: List, @@ -748,6 +812,18 @@ class PubNubImpl(private val pubNubObjC: KMPPubNub) : PubNub { ) } + override fun removeChannelMembers( + channel: String, + userIds: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers { + TODO("Not yet implemented") + } + override fun listFiles(channel: String, limit: Int?, next: PNPage.PNNext?): ListFiles { return ListFilesImpl( pubnub = pubNubObjC, diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/converters.kt b/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/converters.kt index c4ac69228..de4bae185 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/converters.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/converters.kt @@ -111,7 +111,8 @@ internal fun createPNMember(from: KMPMembershipMetadata?): PNMember { custom = PatchValue.of(from.custom()?.safeCast()), updated = from.updated().orEmpty(), eTag = from.eTag().orEmpty(), - status = PatchValue.of(from.status()) + status = PatchValue.of(from.status()), + type = PatchValue.of(null) // todo add when available ) } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/factories.ios.kt b/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/factories.ios.kt index d1e9c8243..7b52ad831 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/factories.ios.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/appleMain/kotlin/com/pubnub/kmp/factories.ios.kt @@ -309,7 +309,8 @@ private fun mapAppContextEvent(from: KMPAppContextEventResult?): PNObjectEventMe custom = PatchValue.of(from.metadata().custom()?.safeCast()), eTag = from.metadata().eTag().orEmpty(), updated = from.metadata().updated().orEmpty(), - status = PatchValue.of(from.metadata().status().orEmpty()) + status = PatchValue.of(from.metadata().status().orEmpty()), + type = null // todo add when available ) ) is KMPRemoveMembershipResult -> diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/PubNub.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/PubNub.kt index c00bc671d..b0a8f397d 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/PubNub.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/PubNub.kt @@ -56,9 +56,11 @@ import com.pubnub.api.models.consumer.objects.PNMemberKey import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey +import com.pubnub.api.models.consumer.objects.member.MemberInclude import com.pubnub.api.models.consumer.objects.member.MemberInput import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel import com.pubnub.api.v2.PNConfiguration import com.pubnub.api.v2.callbacks.EventListener @@ -298,6 +300,7 @@ expect interface PubNub { fun removeUUIDMetadata(uuid: String? = null): RemoveUUIDMetadata + // deprecated fun getMemberships( uuid: String? = null, limit: Int? = null, @@ -310,6 +313,16 @@ expect interface PubNub { includeType: Boolean = false, ): GetMemberships + fun getMemberships( + userId: String? = null, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MembershipInclude = MembershipInclude(), + ): GetMemberships + + // deprecated fun setMemberships( channels: List, uuid: String? = null, @@ -323,6 +336,17 @@ expect interface PubNub { includeType: Boolean = false, ): ManageMemberships + fun setMemberships( + channels: List, + userId: String? = null, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MembershipInclude = MembershipInclude(), + ): ManageMemberships + + // deprecated fun removeMemberships( channels: List, uuid: String? = null, @@ -336,6 +360,16 @@ expect interface PubNub { includeType: Boolean = false, ): ManageMemberships + fun removeMemberships( + channels: List, + userId: String? = null, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MembershipInclude = MembershipInclude(), + ): ManageMemberships + // fun manageMemberships( // channelsToSet: List, // channelsToRemove: List, @@ -349,6 +383,7 @@ expect interface PubNub { // includeChannelDetails: PNChannelDetailsLevel? = null, // ): ManageMemberships + // deprecated fun getChannelMembers( channel: String, limit: Int? = null, @@ -361,6 +396,16 @@ expect interface PubNub { includeType: Boolean = false, ): GetChannelMembers + fun getChannelMembers( + channel: String, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MemberInclude = MemberInclude() + ): GetChannelMembers + + // deprecated fun setChannelMembers( channel: String, uuids: List, @@ -374,6 +419,17 @@ expect interface PubNub { includeType: Boolean = false, ): ManageChannelMembers + fun setChannelMembers( + channel: String, + users: List, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MemberInclude = MemberInclude() + ): ManageChannelMembers + + // deprecated fun removeChannelMembers( channel: String, uuids: List, @@ -387,6 +443,16 @@ expect interface PubNub { includeType: Boolean = false, ): ManageChannelMembers + fun removeChannelMembers( + channel: String, + userIds: List, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MemberInclude = MemberInclude() + ): ManageChannelMembers + // fun manageChannelMembers( // channel: String, // uuidsToSet: Collection, diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/PNSortKey.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/PNSortKey.kt index dc78413d4..30c0a4e8d 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/PNSortKey.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/PNSortKey.kt @@ -16,14 +16,22 @@ enum class PNMembershipKey(override val fieldName: String) : SortField { CHANNEL_ID("channel.id"), CHANNEL_NAME("channel.name"), CHANNEL_UPDATED("channel.updated"), + CHANNEL_STATUS("channel.status"), + CHANNEL_TYPE("channel.type"), UPDATED("updated"), + STATUS("status"), + TYPE("type"), } enum class PNMemberKey(override val fieldName: String) : SortField { UUID_ID("uuid.id"), UUID_NAME("uuid.name"), UUID_UPDATED("uuid.updated"), + UUID_STATUS("uuid.status"), + UUID_TYPE("uuid.type"), UPDATED("updated"), + STATUS("status"), + TYPE("type"), } sealed class PNSortKey( diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInclude.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInclude.kt new file mode 100644 index 000000000..75e85be53 --- /dev/null +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInclude.kt @@ -0,0 +1,21 @@ +package com.pubnub.api.models.consumer.objects.member + +fun MemberInclude( + includeCustom: Boolean = false, + includeStatus: Boolean = false, + includeType: Boolean = false, + includeTotalCount: Boolean = false, + includeUser: Boolean = false, + includeUserCustom: Boolean = false, + includeUserType: Boolean = false, + includeUserStatus: Boolean = false, +) = object : MemberInclude { + override val includeCustom: Boolean = includeCustom + override val includeStatus: Boolean = includeStatus + override val includeType: Boolean = includeType + override val includeTotalCount: Boolean = includeTotalCount + override val includeUser: Boolean = includeUser + override val includeUserCustom: Boolean = includeUserCustom + override val includeUserType: Boolean = includeUserType + override val includeUserStatus: Boolean = includeUserStatus +} diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInput.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInput.kt index f0a34ac2b..63b988915 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInput.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInput.kt @@ -3,7 +3,8 @@ package com.pubnub.api.models.consumer.objects.member import com.pubnub.kmp.CustomObject interface MemberInput { - val uuid: String + val uuid: String // todo change to userId? val custom: CustomObject? val status: String? + val type: String? } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/PNMember.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/PNMember.kt index 8ba1650c4..4f818f528 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/PNMember.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/PNMember.kt @@ -5,16 +5,18 @@ import com.pubnub.api.utils.PatchValue import com.pubnub.kmp.CustomObject data class PNMember( - val uuid: PNUUIDMetadata, + val uuid: PNUUIDMetadata, // todo change to userId? val custom: PatchValue?>? = null, val updated: String, val eTag: String, val status: PatchValue?, + val type: PatchValue?, ) { data class Partial( val uuidId: String, override val custom: CustomObject? = null, override val status: String? = null, + override val type: String? = null ) : MemberInput { override val uuid: String = uuidId } @@ -26,7 +28,8 @@ data class PNMember( update.custom ?: custom, update.updated, update.eTag, - update.status ?: status + update.status ?: status, + update.type ?: type ) } } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/ChannelMembershipInput.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/ChannelMembershipInput.kt index d4b26ac96..53f141e7a 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/ChannelMembershipInput.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/ChannelMembershipInput.kt @@ -6,4 +6,5 @@ interface ChannelMembershipInput { val channel: String val custom: CustomObject? val status: String? + val type: String? } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipInclude.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipInclude.kt new file mode 100644 index 000000000..ead05909e --- /dev/null +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipInclude.kt @@ -0,0 +1,21 @@ +package com.pubnub.api.models.consumer.objects.membership + +fun MembershipInclude( + includeCustom: Boolean = false, + includeStatus: Boolean = false, + includeType: Boolean = false, + includeTotalCount: Boolean = false, + includeChannel: Boolean = false, + includeChannelCustom: Boolean = false, + includeChannelType: Boolean = false, + includeChannelStatus: Boolean = false, +) = object : MembershipInclude { + override val includeCustom: Boolean = includeCustom + override val includeStatus: Boolean = includeStatus + override val includeType: Boolean = includeType + override val includeTotalCount: Boolean = includeTotalCount + override val includeChannel: Boolean = includeChannel + override val includeChannelCustom: Boolean = includeChannelCustom + override val includeChannelType: Boolean = includeChannelType + override val includeChannelStatus: Boolean = includeChannelStatus +} diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembership.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembership.kt index c51aec9c5..511499c00 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembership.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembership.kt @@ -11,11 +11,13 @@ data class PNChannelMembership( val updated: String, val eTag: String, val status: PatchValue? = null, + val type: PatchValue? = null, ) { data class Partial( val channelId: String, override val custom: CustomObject? = null, override val status: String? = null, + override val type: String? = null ) : ChannelMembershipInput { override val channel: String = channelId } @@ -27,7 +29,8 @@ data class PNChannelMembership( update.custom ?: custom, update.updated, update.eTag, - update.status ?: status + update.status ?: status, + update.type ?: type ) } @@ -40,7 +43,8 @@ data class PNChannelMembership( update.custom ?: custom, update.updated, update.eTag, - update.status ?: status + update.status ?: status, + update.type ?: type ) } } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/pubsub/objects/PNObjectEventResult.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/pubsub/objects/PNObjectEventResult.kt index 94b46dcb2..b20227ae3 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/pubsub/objects/PNObjectEventResult.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/pubsub/objects/PNObjectEventResult.kt @@ -73,9 +73,10 @@ data class PNSetMembershipEvent( val eTag: String, val updated: String, val status: PatchValue?, + val type: PatchValue?, ) data class PNDeleteMembershipEvent( val channelId: String, - val uuid: String, + val uuid: String, // todo change to userId? ) diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipIncludeTest.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipIncludeTest.kt new file mode 100644 index 000000000..960168f91 --- /dev/null +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipIncludeTest.kt @@ -0,0 +1,44 @@ +package com.pubnub.api.models.consumer.objects.membership + +import kotlin.test.Test +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class MembershipIncludeTest { + @Test + fun canCreateMembershipIncludeWithAllParameters() { + val membershipInclude = MembershipInclude( + includeCustom = true, + includeStatus = true, + includeType = true, + includeTotalCount = true, + includeChannel = true, + includeChannelCustom = true, + includeChannelType = true, + includeChannelStatus = true + ) + + assertTrue(membershipInclude.includeCustom) + assertTrue(membershipInclude.includeStatus) + assertTrue(membershipInclude.includeType) + assertTrue(membershipInclude.includeTotalCount) + assertTrue(membershipInclude.includeChannel) + assertTrue(membershipInclude.includeChannelCustom) + assertTrue(membershipInclude.includeChannelType) + assertTrue(membershipInclude.includeChannelStatus) + } + + @Test + fun canCreateMembershipIncludeDefault() { + val membershipInclude = MembershipInclude() + + assertFalse(membershipInclude.includeCustom) + assertFalse(membershipInclude.includeStatus) + assertFalse(membershipInclude.includeType) + assertFalse(membershipInclude.includeTotalCount) + assertFalse(membershipInclude.includeChannel) + assertFalse(membershipInclude.includeChannelCustom) + assertFalse(membershipInclude.includeChannelType) + assertFalse(membershipInclude.includeChannelStatus) + } +} diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembershipTest.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembershipTest.kt index e29593098..0d24fb018 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembershipTest.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/api/models/consumer/objects/membership/PNChannelMembershipTest.kt @@ -24,12 +24,14 @@ class PNChannelMembershipTest { custom = null, updated = randomString(), eTag = randomString(), - status = PatchValue.of(randomString()) + status = PatchValue.of(randomString()), + type = PatchValue.of(randomString()) ) val expectedMembership = originalMembership.copy( updated = updateMembership.updated, eTag = updateMembership.eTag, - status = updateMembership.status + status = updateMembership.status, + type = updateMembership.type ) val actualMembership = originalMembership + updateMembership diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembersTest.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembersTest.kt index d63bad55c..33925797f 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembersTest.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembersTest.kt @@ -61,6 +61,9 @@ class MembersTest : BaseIntegrationTest() { @Test fun can_delete_members() = runTest { + if (PLATFORM == "JS" || PLATFORM == "iOS") { // todo enable for JS/iOS once is implemented + return@runTest + } // given pubnub.setChannelMembers( channel, diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembershipsTest.kt b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembershipsTest.kt index a87c331ba..1798d0c09 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembershipsTest.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/commonTest/kotlin/com/pubnub/test/integration/MembershipsTest.kt @@ -6,6 +6,7 @@ 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.PNObjectEventResult import com.pubnub.api.models.consumer.pubsub.objects.PNSetMembershipEventMessage +import com.pubnub.kmp.PLATFORM import com.pubnub.kmp.createCustomObject import com.pubnub.test.BaseIntegrationTest import com.pubnub.test.await @@ -85,6 +86,9 @@ class MembershipsTest : BaseIntegrationTest() { @Test fun can_delete_membership() = runTest { + if (PLATFORM == "JS" || PLATFORM == "iOS") { // todo enable for JS/iOS once is implemented + return@runTest + } // given pubnub.setMemberships( listOf(PNChannelMembership.Partial(channel, custom, status)) @@ -107,6 +111,9 @@ class MembershipsTest : BaseIntegrationTest() { @Test fun can_receive_delete_membership_event() = runTest { + if (PLATFORM == "JS" || PLATFORM == "iOS") { // todo enable for JS/iOS once is implemented + return@runTest + } pubnub.test(backgroundScope) { // given pubnub.setMemberships( diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/Pubnub.d.kt b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/Pubnub.d.kt index ca1772c48..46b57c54c 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/Pubnub.d.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/Pubnub.d.kt @@ -1139,6 +1139,7 @@ open external class PubNub(config: Any /* UUID | UserId */) { interface UUIDMembershipObject : v2ObjectDataOmitId { var uuid: UUIDMetadataObject // UUIDMetadataObject & HasStatus | HasId var status: String? + var type: String? } interface ChannelMembershipObject : v2ObjectDataOmitId { diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt index f06494c3f..27780c179 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt @@ -107,9 +107,11 @@ import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey import com.pubnub.api.models.consumer.objects.SortField +import com.pubnub.api.models.consumer.objects.member.MemberInclude import com.pubnub.api.models.consumer.objects.member.MemberInput import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel import com.pubnub.api.utils.PatchValue import com.pubnub.api.v2.PNConfiguration @@ -667,6 +669,7 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + // deprecated override fun getMemberships( uuid: String?, limit: Int?, @@ -701,6 +704,18 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + override fun getMemberships( + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): GetMemberships { + TODO("Not yet implemented") + } + + // deprecated override fun setMemberships( channels: List, uuid: String?, @@ -744,6 +759,19 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + override fun setMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships { + TODO("Not yet implemented") + } + + // deprecated override fun removeMemberships( channels: List, uuid: String?, @@ -781,6 +809,18 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + override fun removeMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships { + TODO("Not yet implemented") + } + // TODO doesn't exist in JS // override fun manageMemberships( // channelsToSet: List, @@ -797,6 +837,7 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { // TODO("Not yet implemented") // } + // deprecated override fun getChannelMembers( channel: String, limit: Int?, @@ -834,6 +875,18 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + override fun getChannelMembers( + channel: String, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): GetChannelMembers { + TODO("Not yet implemented") + } + + // deprecated override fun setChannelMembers( channel: String, uuids: List, @@ -880,6 +933,18 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + override fun setChannelMembers( + channel: String, + users: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers { + TODO("Not yet implemented") + } + override fun removeChannelMembers( channel: String, uuids: List, @@ -920,6 +985,18 @@ class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { ) } + override fun removeChannelMembers( + channel: String, + userIds: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers { + TODO("Not yet implemented") + } + // override fun manageChannelMembers( // channel: String, // uuidsToSet: Collection, diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/converters.js.kt b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/converters.js.kt index af55057e8..05604f30c 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/converters.js.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/converters.js.kt @@ -75,7 +75,8 @@ internal fun PubNub.UUIDMembershipObject.toPNMember() = PNMember( patchValueOf(custom.letIfDefined { it?.toMap() }), updated, eTag, - patchValueOf(status), + status = patchValueOf(status), + type = patchValueOf(type), ) internal fun ManageChannelMembersResponse.toPNMemberArrayResult() = PNMemberArrayResult( diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/factories.js.kt b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/factories.js.kt index 044d5f723..4b9e5b919 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/factories.js.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/kmp/factories.js.kt @@ -174,7 +174,8 @@ actual fun createEventListener( PatchValue.of(it.custom?.toMap()), it.eTag, it.updated, - PatchValue.of(it.asDynamic().status) // todo missing + PatchValue.of(it.asDynamic().status), // todo missing + null // todo add type when available ) ) } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/jvmMain/kotlin/com/pubnub/api/PubNub.kt b/pubnub-kotlin/pubnub-kotlin-api/src/jvmMain/kotlin/com/pubnub/api/PubNub.kt index 09514e4d3..f714f7e7a 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/jvmMain/kotlin/com/pubnub/api/PubNub.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/jvmMain/kotlin/com/pubnub/api/PubNub.kt @@ -61,9 +61,11 @@ import com.pubnub.api.models.consumer.objects.PNMemberKey import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey +import com.pubnub.api.models.consumer.objects.member.MemberInclude import com.pubnub.api.models.consumer.objects.member.MemberInput import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel import com.pubnub.api.v2.PNConfiguration import com.pubnub.api.v2.callbacks.EventEmitter @@ -1246,6 +1248,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeChannelDetails Include custom fields for channels metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new getMemberships(userId, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "getMemberships(userId, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.membership.MembershipInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeChannel = true, includeChannelCustom = true, includeType = includeType))" + ) + ) actual fun getMemberships( uuid: String?, limit: Int?, @@ -1258,6 +1267,33 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean, ): GetMemberships + /** + * The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions. + * + * @param userId Unique user identifier. If not supplied then current user’s id is used. + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.membership.MembershipInclude] to easily create the desired configuration. + */ + actual fun getMemberships( + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): GetMemberships + /** * @see [PubNub.setMemberships] */ @@ -1305,6 +1341,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeChannelDetails Include custom fields for channels metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new setMemberships(channels, userId, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "setMemberships(channels, userId, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.membership.MembershipInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeChannel = true, includeChannelCustom = true, includeType = includeType))" + ) + ) actual fun setMemberships( channels: List, uuid: String?, @@ -1318,6 +1361,36 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean, ): ManageMemberships + /** + * Set channel memberships for a UUID. + * + * @param channels List of channels to add to membership. List can contain strings (channel-name only) + * or objects (which can include custom data). @see [PNChannelWithCustom] + * @param uuid Unique user identifier. If not supplied then current user’s uuid is used. + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.membership.MembershipInclude] to easily create the desired configuration. + */ + actual fun setMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude, + ): ManageMemberships + /** * Remove channel memberships for a UUID. * @@ -1339,6 +1412,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeChannelDetails Include custom fields for channels metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new removeMemberships(channels, userId, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "removeMemberships(channels, userId, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.membership.MembershipInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeChannel = true, includeChannelCustom = true, includeType = includeType))" + ) + ) actual fun removeMemberships( channels: List, uuid: String?, @@ -1352,6 +1432,35 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean, ): ManageMemberships + /** + * Remove channel memberships for a UUID. + * + * @param channels Channels to remove from membership. + * @param uuid Unique user identifier. If not supplied then current user’s uuid is used. + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.membership.MembershipInclude] to easily create the desired configuration. + */ + actual fun removeMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships + /** * Add and remove channel memberships for a UUID. * @@ -1374,6 +1483,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeChannelDetails Include custom fields for channels metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new manageMemberships(channels, userId, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "manageMemberships(channels, userId, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.membership.MembershipInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeChannel = true, includeChannelCustom = true, includeChannelType = includeType))" + ) + ) fun manageMemberships( channelsToSet: List, channelsToRemove: List, @@ -1388,6 +1504,37 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean = false, ): ManageMemberships + /** + * Add and remove channel memberships for a UUID. + * + * @param channelsToSet Collection of channels to add to membership. @see [com.pubnub.api.models.consumer.objects.membership.PNChannelMembership.Partial] + * @param channelsToRemove Channels to remove from membership. + * @param uuid Unique user identifier. If not supplied then current user’s uuid is used. + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.membership.MembershipInclude] to easily create the desired configuration. + */ + fun manageMemberships( + channelsToSet: List, + channelsToRemove: List, + userId: String? = null, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MembershipInclude = MembershipInclude() + ): ManageMemberships + /** * @see [PubNub.getChannelMembers] */ @@ -1433,6 +1580,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeUUIDDetails Include custom fields for UUIDs metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new getChannelMembers(channel, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "getChannelMembers(channel, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.member.MemberInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeUser = true, includeUserCustom = true, includeUserType = includeUUIDType)" + ) + ) actual fun getChannelMembers( channel: String, limit: Int?, @@ -1445,6 +1599,34 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean, ): GetChannelMembers + /** + * The method returns a list of members in a channel. The list will include user metadata for members + * that have additional metadata stored in the database. + * + * @param channel Channel name + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.member.MemberInclude] to easily create the desired configuration. + */ + actual fun getChannelMembers( + channel: String, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): GetChannelMembers + /** * @see [PubNub.setChannelMembers] */ @@ -1492,6 +1674,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeUUIDDetails Include custom fields for UUIDs metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new setChannelMembers(channel, userIds, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "setChannelMembers(channel, userIds, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.member.MemberInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeUser = true, includeUserCustom = true, includeUserType = includeUUIDType)" + ) + ) actual fun setChannelMembers( channel: String, uuids: List, @@ -1505,6 +1694,36 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean, ): ManageChannelMembers + /** + * This method sets members in a channel. + * + * @param channel Channel name + * @param uuids List of members to add to the channel. List can contain strings (uuid only) + * or objects (which can include custom data). @see [PNMember.Partial] + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.member.MemberInclude] to easily create the desired configuration. + */ + actual fun setChannelMembers( + channel: String, + users: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers + /** * @see [PubNub.removeChannelMembers] */ @@ -1551,6 +1770,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeCustom Include respective additional fields in the response. * @param includeUUIDDetails Include custom fields for UUIDs metadata. */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new removeChannelMembers(channel, userIds, limit, page, filter, sort, MembershipInclude(...))", + replaceWith = ReplaceWith( + "removeChannelMembers(channel, userIds, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.member.MemberInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeUser = true, includeUserCustom = true, includeUserType = includeUUIDType)" + ) + ) actual fun removeChannelMembers( channel: String, uuids: List, @@ -1564,6 +1790,35 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeType: Boolean, ): ManageChannelMembers + /** + * Remove members from a Channel. + * + * @param channel Channel name + * @param userIds Members to remove from channel. + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.member.MemberInclude] to easily create the desired configuration. + */ + actual fun removeChannelMembers( + channel: String, + userIds: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers + /** * Set or remove members in a channel. * @@ -1587,6 +1842,13 @@ actual interface PubNub : StatusEmitter, EventEmitter { * @param includeUUIDDetails Include custom fields for UUIDs metadata. * @param includeType Include the type field for UUID metadata */ + @Deprecated( + level = DeprecationLevel.WARNING, + message = "This function is deprecated. Use the new manageChannelMembers(channels, uuidsToSet, uuidsToRemove, limit, page, filter, sort, MemberInclude(...))", + replaceWith = ReplaceWith( + "manageChannelMembers(channels, uuidsToSet, uuidsToRemove, limit, page, filter, sort, com.pubnub.api.models.consumer.objects.member.MemberInclude(includeTotalCount = includeCount, includeCustom = includeCustom, includeUser = true, includeUserCustom = true, includeUserType = includeUUIDType)" + ) + ) fun manageChannelMembers( channel: String, uuidsToSet: Collection, @@ -1601,6 +1863,37 @@ actual interface PubNub : StatusEmitter, EventEmitter { includeUUIDType: Boolean = false, ): ManageChannelMembers + /** + * Set or remove members in a channel. + * + * @param channel Channel name + * @param usersToSet Collection of members to add to the channel. @see [com.pubnub.api.models.consumer.objects.member.PNMember.Partial] + * @param usersToRemove Members to remove from channel. + * @param limit Number of objects to return in the response. + * Default is 100, which is also the maximum value. + * Set limit to 0 (zero) and includeCount to true if you want to retrieve only a result count. + * @param page Use for pagination. + * - [PNNext] : Previously-returned cursor bookmark for fetching the next page. + * - [PNPrev] : Previously-returned cursor bookmark for fetching the previous page. + * Ignored if you also supply the start parameter. + * @param filter Expression used to filter the results. Only objects whose properties satisfy the given + * expression are returned. + * @param sort List of properties to sort by. Available options are id, name, and updated. + * @see [PNAsc], [PNDesc] + * @param include Request specific elements to be available in response. + * Use [com.pubnub.api.models.consumer.objects.member.MemberInclude] to easily create the desired configuration. + */ + fun manageChannelMembers( + channel: String, + usersToSet: Collection, + usersToRemove: Collection, + limit: Int? = null, + page: PNPage? = null, + filter: String? = null, + sort: Collection> = listOf(), + include: MemberInclude = MemberInclude() + ): ManageChannelMembers + /** * Upload file / data to specified Channel. * diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt b/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt index bce6cf199..cbbb85cb9 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/nonJvm/kotlin/com/pubnub/api/PubNub.nonJvm.kt @@ -56,9 +56,11 @@ import com.pubnub.api.models.consumer.objects.PNMemberKey import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey +import com.pubnub.api.models.consumer.objects.member.MemberInclude import com.pubnub.api.models.consumer.objects.member.MemberInput import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel import com.pubnub.api.v2.PNConfiguration import com.pubnub.api.v2.callbacks.EventListener @@ -278,6 +280,7 @@ actual interface PubNub { actual fun removeUUIDMetadata(uuid: String?): RemoveUUIDMetadata + // deprecated actual fun getMemberships( uuid: String?, limit: Int?, @@ -290,6 +293,16 @@ actual interface PubNub { includeType: Boolean ): GetMemberships + actual fun getMemberships( + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude, + ): GetMemberships + + // deprecated actual fun setMemberships( channels: List, uuid: String?, @@ -303,6 +316,17 @@ actual interface PubNub { includeType: Boolean ): ManageMemberships + actual fun setMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude, + ): ManageMemberships + + // deprecated actual fun removeMemberships( channels: List, uuid: String?, @@ -316,6 +340,17 @@ actual interface PubNub { includeType: Boolean ): ManageMemberships + actual fun removeMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships + + // deprecated actual fun getChannelMembers( channel: String, limit: Int?, @@ -328,6 +363,16 @@ actual interface PubNub { includeType: Boolean ): GetChannelMembers + actual fun getChannelMembers( + channel: String, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): GetChannelMembers + + // deprecated actual fun setChannelMembers( channel: String, uuids: List, @@ -341,6 +386,17 @@ actual interface PubNub { includeType: Boolean ): ManageChannelMembers + actual fun setChannelMembers( + channel: String, + users: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers + + // deprecated actual fun removeChannelMembers( channel: String, uuids: List, @@ -354,6 +410,16 @@ actual interface PubNub { includeType: Boolean ): ManageChannelMembers + actual fun removeChannelMembers( + channel: String, + userIds: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers + actual fun listFiles( channel: String, limit: Int?, diff --git a/pubnub-kotlin/pubnub-kotlin-core-api/pubnub_kotlin_core_api.podspec b/pubnub-kotlin/pubnub-kotlin-core-api/pubnub_kotlin_core_api.podspec index 7d233bac1..199675c7f 100644 --- a/pubnub-kotlin/pubnub-kotlin-core-api/pubnub_kotlin_core_api.podspec +++ b/pubnub-kotlin/pubnub-kotlin-core-api/pubnub_kotlin_core_api.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'pubnub_kotlin_core_api' - spec.version = '10.2.0' + spec.version = '10.2.1' spec.homepage = '' spec.source = { :http=> ''} spec.authors = '' diff --git a/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInclude.kt b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInclude.kt new file mode 100644 index 000000000..a6e60be11 --- /dev/null +++ b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/member/MemberInclude.kt @@ -0,0 +1,15 @@ +package com.pubnub.api.models.consumer.objects.member + +interface Include { + val includeCustom: Boolean + val includeStatus: Boolean + val includeType: Boolean + val includeTotalCount: Boolean +} + +interface MemberInclude : Include { + val includeUser: Boolean + val includeUserCustom: Boolean + val includeUserType: Boolean + val includeUserStatus: Boolean +} diff --git a/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipInclude.kt b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipInclude.kt new file mode 100644 index 000000000..a87527f09 --- /dev/null +++ b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/models/consumer/objects/membership/MembershipInclude.kt @@ -0,0 +1,10 @@ +package com.pubnub.api.models.consumer.objects.membership + +import com.pubnub.api.models.consumer.objects.member.Include + +interface MembershipInclude : Include { + val includeChannel: Boolean + val includeChannelCustom: Boolean + val includeChannelType: Boolean + val includeChannelStatus: Boolean +} diff --git a/pubnub-kotlin/pubnub-kotlin-impl/config/ktlint/baseline.xml b/pubnub-kotlin/pubnub-kotlin-impl/config/ktlint/baseline.xml index 22344ac9b..3950feb64 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/config/ktlint/baseline.xml +++ b/pubnub-kotlin/pubnub-kotlin-impl/config/ktlint/baseline.xml @@ -1,15 +1,5 @@ - - - - - - - - - - diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/ObjectsIntegrationTest.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/ObjectsIntegrationTest.kt index 6d3aaf16a..53ec5c7da 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/ObjectsIntegrationTest.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/ObjectsIntegrationTest.kt @@ -3,17 +3,24 @@ package com.pubnub.api.integration import com.pubnub.api.PubNub import com.pubnub.api.callbacks.SubscribeCallback import com.pubnub.api.models.consumer.PNStatus +import com.pubnub.api.models.consumer.objects.PNMemberKey import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey import com.pubnub.api.models.consumer.objects.channel.PNChannelMetadata +import com.pubnub.api.models.consumer.objects.member.MemberInclude 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.member.PNUUIDDetailsLevel +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel 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.PNUUIDMetadata import com.pubnub.api.models.consumer.objects.uuid.PNUUIDMetadataArrayResult +import com.pubnub.api.models.consumer.pubsub.objects.PNDeleteMembershipEventMessage import com.pubnub.api.models.consumer.pubsub.objects.PNObjectEventResult +import com.pubnub.api.models.consumer.pubsub.objects.PNSetMembershipEventMessage import com.pubnub.api.utils.PatchValue import com.pubnub.test.CommonUtils.randomValue import com.pubnub.test.subscribeToBlocking @@ -21,18 +28,24 @@ import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsInAnyOrder import org.hamcrest.Matchers.not import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit class ObjectsIntegrationTest : BaseIntegrationTest() { - private val testUuid = "ThisIsMyId" + randomValue() - private val otherTestUuid = "OtherTestId" + randomValue() - val channel = "ThisIsMyChannel" + randomValue() + private val testUserId01 = "ThisIsMyId01" + randomValue() + private val testUserId02 = "ThisIsMyId02" + randomValue() + val channel = "ThisIsMyChannel01" + randomValue() + val channel02 = "ThisIsMyChannel02" + randomValue() val otherChannel = "OtherChannel" + randomValue() - val status = "Status" + randomValue() - val type = "Type" + randomValue() + val status01 = "Status01" + randomValue() + val status02 = "Status02" + randomValue() + val type01 = "Type01" + randomValue() + val type02 = "Type02" + randomValue() val noUpdated = "" val noEtag = "" @@ -42,8 +55,8 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { pubnub.setChannelMetadata( channel = channel, name = randomValue(15), - status = status, - type = type, + status = status01, + type = type01, ).sync() val getAllResult = pubnub.getAllChannelMetadata(filter = "id == \"$channel\"").sync() @@ -65,40 +78,40 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { val setResult = pubnub.setUUIDMetadata( - uuid = testUuid, + uuid = testUserId01, name = randomValue(15), - status = status, - type = type, + status = status01, + type = type01, ).sync() - assertEquals(status, setResult.data?.status?.value) - assertEquals(type, setResult.data?.type?.value) + assertEquals(status01, setResult.data?.status?.value) + assertEquals(type01, setResult.data?.type?.value) - val getAllResult = pubnub.getAllUUIDMetadata(filter = "id == \"$testUuid\"").sync() - val getSingleResult = pubnub.getUUIDMetadata(uuid = testUuid).sync() - pubnub.removeUUIDMetadata(uuid = testUuid).sync() + val getAllResult = pubnub.getAllUUIDMetadata(filter = "id == \"$testUserId01\"").sync() + val getSingleResult = pubnub.getUUIDMetadata(uuid = testUserId01).sync() + pubnub.removeUUIDMetadata(uuid = testUserId01).sync() - assertTrue(getAllResult.data.any { it.id == testUuid }) + assertTrue(getAllResult.data.any { it.id == testUserId01 }) assertEquals(setResult, getSingleResult) - val getAllAfterRemovalResult = pubnub.getAllUUIDMetadata(filter = "id == \"$testUuid\"").sync() + val getAllAfterRemovalResult = pubnub.getAllUUIDMetadata(filter = "id == \"$testUserId01\"").sync() - assertTrue(getAllAfterRemovalResult.data.none { it.id == testUuid }) + assertTrue(getAllAfterRemovalResult.data.none { it.id == testUserId01 }) } @Test - fun addGetAndRemoveMembership() { + fun addGetAndRemoveMembershipDeprecated() { val channels = listOf(PNChannelMembership.Partial(channelId = channel)) val setResult = pubnub.setMemberships( channels = channels, - uuid = testUuid, + uuid = testUserId01, includeChannelDetails = PNChannelDetailsLevel.CHANNEL, ).sync() val getAllResult = pubnub.getMemberships( - uuid = testUuid, + uuid = testUserId01, sort = listOf(PNSortKey.PNDesc(PNMembershipKey.CHANNEL_ID)), includeChannelDetails = PNChannelDetailsLevel.CHANNEL, ).sync() @@ -107,24 +120,195 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { pubnub.removeMemberships( channels = channels.map { it.channel }, - uuid = testUuid, + uuid = testUserId01, includeChannelDetails = PNChannelDetailsLevel.CHANNEL, ).sync() val getAllAfterRemovalResult = pubnub.getMemberships( - uuid = testUuid, + uuid = testUserId01, includeChannelDetails = PNChannelDetailsLevel.CHANNEL, ).sync() assertTrue(getAllAfterRemovalResult.data.filter { it.channel != null }.none { it.channel!!.id == channel }) } + @Test + fun addGetAndRemoveMembershipWithStatusAndType() { + val customKey = randomValue() + val customValue = randomValue() + val custom = mapOf(customKey to customValue) + val channelMembership01 = PNChannelMembership.Partial(channel, custom = custom, status = status01, type = type01) + val channelMembership02 = PNChannelMembership.Partial(channel02, custom = custom, status = status02, type = type02) + + val channels = listOf(channelMembership01, channelMembership02) + + val setResult: PNChannelMembershipArrayResult = + pubnub.setMemberships( + channels = channels, + userId = testUserId01, + include = MembershipInclude( + includeCustom = true, + includeStatus = true, + includeType = true, + includeChannel = true, + includeChannelCustom = true, + includeChannelType = true, + includeChannelStatus = true, + includeTotalCount = true + ), + sort = listOf(PNSortKey.PNDesc(PNMembershipKey.STATUS)) + ).sync() + + val setMembership01 = setResult.data.first { membership -> membership.status?.value == status01 } + val setMembership02 = setResult.data.first { membership -> membership.status?.value == status02 } + + assertEquals(type01, setMembership01.type?.value) + assertEquals(type02, setMembership02.type?.value) + assertEquals(custom, setMembership02.custom?.value) + assertEquals(status01, (setResult.data as ArrayList)[1].status?.value) + assertEquals(status02, (setResult.data as ArrayList)[0].status?.value) + + val getAllResult: PNChannelMembershipArrayResult = + pubnub.getMemberships( + userId = testUserId01, + include = MembershipInclude(includeType = true, includeStatus = true), + sort = listOf(PNSortKey.PNAsc(PNMembershipKey.CHANNEL_ID)), + ).sync() + + val allPnChannelMemberships = getAllResult.data as ArrayList + assertEquals(channel, allPnChannelMemberships[0].channel.id) + assertEquals(channel02, allPnChannelMemberships[1].channel.id) + val getMembership01 = getAllResult.data.first { membership -> membership.status?.value == status01 } + val getMembership02 = getAllResult.data.first { membership -> membership.status?.value == status02 } + + assertEquals(type01, getMembership01.type?.value) + assertEquals(type02, getMembership02.type?.value) + + // returns remaining memberships + val removeMembershipResult = pubnub.removeMemberships( + channels = listOf(channel), + userId = testUserId01, + include = MembershipInclude( + includeCustom = true, + includeStatus = true, + includeType = true, + includeChannel = true, + includeChannelCustom = true, + includeChannelType = true, + includeChannelStatus = true, + includeTotalCount = true + ), + sort = listOf(PNSortKey.PNAsc(PNMembershipKey.TYPE)) + ).sync() + assertEquals(channel02, removeMembershipResult.data.first().channel.id) + assertEquals(status02, removeMembershipResult.data.first().status?.value) + assertEquals(type02, removeMembershipResult.data.first().type?.value) + + val getAllAfterRemovalResult = + pubnub.getMemberships( + userId = testUserId01, + include = MembershipInclude(includeChannel = true) + ).sync() + + assertTrue(getAllAfterRemovalResult.data.filter { it.channel != null }.none { it.channel!!.id == channel }) + } + + @Test + fun addGetAndRemoveMembershipWithStatusAndType_includeTypeFalse_includeStatusFalse() { + val channel01 = PNChannelMembership.Partial(channelId = channel, status = status01, type = type01) + val channel02 = PNChannelMembership.Partial(channelId = channel02, status = status02, type = type02) + val channels = listOf(channel01, channel02) + + val setResult: PNChannelMembershipArrayResult = + pubnub.setMemberships( + channels = channels, + userId = testUserId01, + ).sync() + + val sortedMembership = sortPNChannelMembershipsByUpdatedValue(setResult.data) + + assertNull(status01, sortedMembership[0].status?.value) + assertNull(status02, sortedMembership[1].status?.value) + assertNull(type01, sortedMembership[0].type?.value) + assertNull(type02, sortedMembership[1].type?.value) + + val getAllResult: PNChannelMembershipArrayResult = + pubnub.getMemberships( + userId = testUserId01, + ).sync() + + val sortedGetAllResult: List = sortPNChannelMembershipsByUpdatedValue(getAllResult.data) + + assertNull(status01, sortedGetAllResult[0].status?.value) + assertNull(status02, sortedGetAllResult[1].status?.value) + assertNull(type01, sortedGetAllResult[0].type?.value) + assertNull(type02, sortedGetAllResult[1].type?.value) + + pubnub.removeMemberships( + channels = channels.map { it.channel }, + userId = testUserId01, + ).sync() + + val getAllAfterRemovalResult = + pubnub.getMemberships( + userId = testUserId01, + include = MembershipInclude(includeChannel = true) + ).sync() + + assertTrue(getAllAfterRemovalResult.data.filter { it.channel != null }.none { it.channel!!.id == channel }) + } + @Test fun addGetAndRemoveMember() { - val uuids = listOf(PNMember.Partial(uuidId = testUuid, custom = null, null)) + val users = listOf( + PNMember.Partial(uuidId = testUserId01, custom = null, status = status01, type = type01), + PNMember.Partial(uuidId = testUserId02, custom = null, status = status02, type = type02), + ) - val setResult = + val setResult: PNMemberArrayResult = + pubnub.setChannelMembers( + channel = channel, + users = users, + include = MemberInclude(includeUser = true, includeStatus = true, includeType = true), + sort = listOf(PNSortKey.PNAsc(PNMemberKey.STATUS)) + ).sync() + val pnMembers = setResult.data as ArrayList + assertEquals(status01, pnMembers[0].status?.value) + assertEquals(status02, pnMembers[1].status?.value) + + val getAllResult = + pubnub.getChannelMembers( + channel = channel, + include = MemberInclude(includeUser = true, includeStatus = true, includeType = true), + sort = listOf(PNSortKey.PNAsc(PNMemberKey.TYPE)) + ).sync() + + val getPnMembers = getAllResult.data as ArrayList + assertEquals(type01, getPnMembers[0].type?.value) + assertEquals(type02, getPnMembers[10].type?.value) + assertEquals(setResult, getAllResult) + + pubnub.removeChannelMembers( + channel = channel, + userIds = users.map { it.uuid }, + include = MemberInclude(includeUser = true, includeStatus = true, includeType = true) + ).sync() + + val getAllAfterRemovalResult = + pubnub.getChannelMembers( + channel = channel, + include = MemberInclude(includeUser = true, includeStatus = true, includeType = true) + ).sync() + + assertTrue(getAllAfterRemovalResult.data.filter { it.uuid != null }.none { it.uuid!!.id == testUserId01 }) + } + + @Test + fun addGetAndRemoveMemberDeprecated() { + val uuids = listOf(PNMember.Partial(uuidId = testUserId01, custom = null, null)) + + val setResult: PNMemberArrayResult = pubnub.setChannelMembers( channel = channel, uuids = uuids, @@ -151,17 +335,79 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { includeUUIDDetails = PNUUIDDetailsLevel.UUID, ).sync() - assertTrue(getAllAfterRemovalResult.data.filter { it.uuid != null }.none { it.uuid!!.id == testUuid }) + assertTrue(getAllAfterRemovalResult.data.filter { it.uuid != null }.none { it.uuid!!.id == testUserId01 }) + } + + @Test + fun testListeningToSetChannelMembersAndRemoveChannelMembersEventsWithStatusAndType() { + val countDownLatch = CountDownLatch(2) + val capturedPNObjectEventResult = mutableListOf() + val uuids = listOf(PNMember.Partial(uuidId = testUserId01, custom = null, status = status01, type = type01)) + pubnub.addListener( + listener = object : SubscribeCallback() { + override fun status(pubnub: PubNub, status: PNStatus) { + } + + override fun objects(pubnub: PubNub, result: PNObjectEventResult) { + capturedPNObjectEventResult.add(result) + countDownLatch.countDown() + } + } + ) + + pubnub.subscribeToBlocking(channel) + + pubnub.setChannelMembers(channel = channel, users = uuids).sync() + pubnub.removeChannelMembers(channel = channel, userIds = listOf(testUserId01)).sync() + + assertTrue(countDownLatch.await(5000, TimeUnit.MILLISECONDS)) + val setChannelMembersEventMessage = capturedPNObjectEventResult[0].extractedMessage as PNSetMembershipEventMessage + val removeChannelMembersEventMessage = capturedPNObjectEventResult[1].extractedMessage as PNDeleteMembershipEventMessage + assertEquals(channel, setChannelMembersEventMessage.data.channel) + assertEquals(status01, setChannelMembersEventMessage.data.status?.value) + assertEquals(type01, setChannelMembersEventMessage.data.type?.value) + assertEquals(channel, removeChannelMembersEventMessage.data.channelId) + assertEquals(testUserId01, removeChannelMembersEventMessage.data.uuid) + } + + @Test + fun testListeningToSetMembershipAndRemoveMembershipEventsWithStatusAndType() { + val countDownLatch = CountDownLatch(2) + val capturedPNObjectEventResult = mutableListOf() + val channels = listOf(PNChannelMembership.Partial(channelId = channel, status = status01, type = type01)) + pubnub.addListener( + listener = object : SubscribeCallback() { + override fun status(pubnub: PubNub, status: PNStatus) { + } + + override fun objects(pubnub: PubNub, result: PNObjectEventResult) { + capturedPNObjectEventResult.add(result) + countDownLatch.countDown() + } + } + ) + + pubnub.subscribeToBlocking(channel) + + pubnub.setMemberships(channels = channels).sync() + pubnub.removeMemberships(channels = channels.map { it.channel }).sync() + + assertTrue(countDownLatch.await(5000, TimeUnit.MILLISECONDS)) + val setMembershipEventMessage = capturedPNObjectEventResult[0].extractedMessage as PNSetMembershipEventMessage + val removeMembershipEventMessage = capturedPNObjectEventResult[1].extractedMessage as PNDeleteMembershipEventMessage + assertEquals(channel, setMembershipEventMessage.data.channel) + assertEquals(status01, setMembershipEventMessage.data.status?.value) + assertEquals(type01, setMembershipEventMessage.data.type?.value) + assertEquals(channel, removeMembershipEventMessage.data.channelId) } @Test fun testListeningToAllObjectsEvents() { - val countDownLatch = CountDownLatch(8) - val uuids = listOf(PNMember.Partial(uuidId = testUuid, custom = null, null)) - val channels = - listOf( - PNChannelMembership.Partial(channelId = channel), - ) + val countDownLatch = CountDownLatch(9) + val status = "active" + val type = "user" + val uuids = listOf(PNMember.Partial(uuidId = testUserId01, custom = null, status = status, type = type)) + val channels = listOf(PNChannelMembership.Partial(channelId = channel, status = status, type = type)) pubnub.addListener( listener = @@ -183,17 +429,15 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { pubnub.subscribeToBlocking(channel) - pubnub.setMemberships( - channels = channels, - ).sync() + pubnub.setMemberships(channels = channels).sync() pubnub.setChannelMembers(channel = channel, uuids = uuids).sync() - pubnub.setChannelMetadata(channel = channel, name = randomValue(15)).sync() - pubnub.setUUIDMetadata(name = randomValue(15)).sync() + pubnub.setChannelMetadata(channel = channel, name = randomValue(15), status = status, type = type).sync() + pubnub.setUUIDMetadata(name = randomValue(15), status = status, type = type).sync() - pubnub.setChannelMetadata(channel = channel, description = "aaa").sync() + pubnub.setChannelMetadata(channel = channel, description = "aaa", status = status, type = type).sync() pubnub.removeChannelMetadata(channel = channel).sync() pubnub.removeUUIDMetadata().sync() - pubnub.removeChannelMembers(channel = channel, uuids = uuids.map { it.uuid }).sync() + pubnub.removeChannelMembers(channel = channel, userIds = uuids.map { it.uuid }).sync() pubnub.removeMemberships(channels = channels.map { it.channel }).sync() assertTrue(countDownLatch.await(5000, TimeUnit.MILLISECONDS)) @@ -202,7 +446,7 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { @Test fun testListeningToAllObjectsEventsV2() { val countDownLatch = CountDownLatch(16) - val uuids = listOf(PNMember.Partial(uuidId = testUuid, custom = null, null)) + val uuids = listOf(PNMember.Partial(uuidId = testUserId01, custom = null, null)) val channels = listOf( PNChannelMembership.Partial(channelId = channel), @@ -248,7 +492,7 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { pubnub.setChannelMetadata(channel = channel, description = "aaa").sync() pubnub.removeChannelMetadata(channel = channel).sync() pubnub.removeUUIDMetadata().sync() - pubnub.removeChannelMembers(channel = channel, uuids = uuids.map { it.uuid }).sync() + pubnub.removeChannelMembers(channel = channel, userIds = uuids.map { it.uuid }).sync() pubnub.removeMemberships(channels = channels.map { it.channel }).sync() assertTrue(countDownLatch.await(5000, TimeUnit.MILLISECONDS)) @@ -286,13 +530,78 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { fun testManageMember() { pubnub.setChannelMembers( channel = channel, - uuids = listOf(PNMember.Partial(uuidId = otherTestUuid, status = status)), + users = listOf(PNMember.Partial(uuidId = testUserId02, status = status01, type = type01)), + include = MemberInclude( + includeStatus = true, + includeType = true, + ) ).sync() pubnub.manageChannelMembers( channel = channel, - uuidsToSet = listOf(PNMember.Partial(uuidId = testUuid, status = status)), - uuidsToRemove = listOf(), + usersToSet = listOf(PNMember.Partial(uuidId = testUserId01, status = status01, type = type01)), + usersToRemove = listOf(), + include = MemberInclude( + includeStatus = true, + includeType = true, + ) + ).sync() + + val getAllResult = + pubnub.getChannelMembers( + channel = channel, + include = MemberInclude( + includeUser = true, + includeType = true, + includeStatus = true + ) + ).sync().data + + val otherTestUuidMatcher = + PNMember( + uuidMetadata(id = testUserId02), + custom = null, + status = PatchValue.of(status01), + eTag = noEtag, + updated = noUpdated, + type = PatchValue.of(type01), + ) + val testUuidMatcher = + PNMember( + uuidMetadata(id = testUserId01), + custom = null, + status = PatchValue.of(status01), + eTag = noEtag, + updated = noUpdated, + type = PatchValue.of(type01), + ) + + assertThat( + getAllResult.map { it.copy(updated = noUpdated, eTag = noEtag) }, + containsInAnyOrder(testUuidMatcher, otherTestUuidMatcher), + ) + + val removeResult = + pubnub.manageChannelMembers( + channel = channel, + usersToSet = listOf(), + usersToRemove = listOf(testUserId01, testUserId02), + ).sync().data + + assertThat(removeResult, not(containsInAnyOrder(testUuidMatcher, otherTestUuidMatcher))) + } + + @Test + fun testManageMemberDeprecated() { + pubnub.setChannelMembers( + channel = channel, + uuids = listOf(PNMember.Partial(uuidId = testUserId02, status = status01)), + ).sync() + + pubnub.manageChannelMembers( + channel = channel, + usersToSet = listOf(PNMember.Partial(uuidId = testUserId01, status = status01)), + usersToRemove = listOf(), ).sync() val getAllResult = @@ -300,19 +609,21 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { val otherTestUuidMatcher = PNMember( - uuidMetadata(id = otherTestUuid), + uuidMetadata(id = testUserId02), custom = null, - status = PatchValue.of(status), + status = PatchValue.of(status01), eTag = noEtag, updated = noUpdated, + type = PatchValue.of(null), ) val testUuidMatcher = PNMember( - uuidMetadata(id = testUuid), + uuidMetadata(id = testUserId01), custom = null, - status = PatchValue.of(status), + status = PatchValue.of(status01), eTag = noEtag, updated = noUpdated, + type = PatchValue.of(null), ) assertThat( @@ -323,8 +634,8 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { val removeResult = pubnub.manageChannelMembers( channel = channel, - uuidsToSet = listOf(), - uuidsToRemove = listOf(testUuid, otherTestUuid), + usersToSet = listOf(), + usersToRemove = listOf(testUserId01, testUserId02), ).sync().data assertThat(removeResult, not(containsInAnyOrder(testUuidMatcher, otherTestUuidMatcher))) @@ -333,24 +644,33 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { @Test fun testManageMembership() { pubnub.setMemberships( - uuid = testUuid, - channels = listOf(PNChannelMembership.Partial(channelId = channel, status = status)), + channels = listOf(PNChannelMembership.Partial(channelId = channel, status = status01)), + userId = testUserId01 ).sync() - pubnub.manageMemberships( - channelsToSet = listOf(PNChannelMembership.Partial(channelId = otherChannel, status = status)), + val manageMembershipsResult = pubnub.manageMemberships( + channelsToSet = listOf(PNChannelMembership.Partial(channelId = otherChannel, status = status01, type = type01)), channelsToRemove = listOf(), - uuid = testUuid, + userId = testUserId01, + include = MembershipInclude(includeStatus = true, includeType = true) ).sync() + val sortedGetAllResult: List = sortPNChannelMembershipsByUpdatedValue(manageMembershipsResult.data) + + assertEquals(status01, sortedGetAllResult[0].status?.value) + assertEquals(status01, sortedGetAllResult[1].status?.value) + assertNull(null, sortedGetAllResult[0].type?.value) + assertEquals(type01, sortedGetAllResult[1].type?.value) + val getAllResult = - pubnub.getMemberships(uuid = testUuid, includeChannelDetails = PNChannelDetailsLevel.CHANNEL).sync().data + pubnub.getMemberships(uuid = testUserId01, includeChannelDetails = PNChannelDetailsLevel.CHANNEL).sync().data val channelMatcher = PNChannelMembership( channelMetadata(id = channel), custom = null, - status = PatchValue.of(status), + status = PatchValue.of(status01), + type = PatchValue.of(null), eTag = noEtag, updated = noUpdated, ) @@ -358,7 +678,8 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { PNChannelMembership( channelMetadata(id = otherChannel), custom = null, - status = PatchValue.of(status), + status = PatchValue.of(status01), + type = PatchValue.of(type01), eTag = noEtag, updated = noUpdated, ) @@ -372,7 +693,7 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { pubnub.manageMemberships( channelsToSet = listOf(), channelsToRemove = listOf(channel, otherChannel), - uuid = testUuid, + userId = testUserId01, ).sync().data assertThat( @@ -423,4 +744,8 @@ class ObjectsIntegrationTest : BaseIntegrationTest() { hasMore = page != null } } + + private fun sortPNChannelMembershipsByUpdatedValue(channelMemberships: Collection): List { + return channelMemberships.sortedWith(compareBy { ZonedDateTime.parse(it.updated, ISO_ZONED_DATE_TIME) }) + } } diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/PresenceEventsIntegrationTests.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/PresenceEventsIntegrationTests.kt index 98aa02191..aef36cc2d 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/PresenceEventsIntegrationTests.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/PresenceEventsIntegrationTests.kt @@ -18,6 +18,7 @@ import org.hamcrest.core.IsEqual import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicInteger @@ -78,25 +79,28 @@ class PresenceEventsIntegrationTests : BaseIntegrationTest() { @Test fun testJoinChannelUsingSubscription() { - val successPresenceEventCont = AtomicInteger() val expectedChannel = randomChannel() val subscription = pubnub.channel(expectedChannel).subscription(SubscriptionOptions.receivePresenceEvents()) + val capturePresenceEvent = mutableListOf() + val countDownLatch = CountDownLatch(1) subscription.onPresence = { pnPresenceEventResult: PNPresenceEventResult -> - assertEquals("join", pnPresenceEventResult.event) - assertEquals(expectedChannel, pnPresenceEventResult.channel) - successPresenceEventCont.incrementAndGet() + capturePresenceEvent.add(pnPresenceEventResult) + countDownLatch.countDown() } subscription.subscribe() - Thread.sleep(2000) - assertEquals(1, successPresenceEventCont.get()) + assertTrue(countDownLatch.await(5000, TimeUnit.MILLISECONDS)) + assertEquals(1, capturePresenceEvent.size) + assertEquals("join", capturePresenceEvent.first().event) + assertEquals(expectedChannel, capturePresenceEvent.first().channel) } @Test fun testJoinChannelUsingSubscriptionSet() { - val successPresenceEventCont = AtomicInteger() + val countDownLatch = CountDownLatch(2) + val capturePresenceEvent = mutableListOf() val expectedChannel01 = randomChannel() val expectedChannel02 = randomChannel() val subscriptionSetOf = @@ -106,15 +110,19 @@ class PresenceEventsIntegrationTests : BaseIntegrationTest() { ) subscriptionSetOf.onPresence = { pnPresenceEventResult: PNPresenceEventResult -> - assertEquals("join", pnPresenceEventResult.event) - assertTrue(pnPresenceEventResult.channel == expectedChannel01 || pnPresenceEventResult.channel == expectedChannel02) - successPresenceEventCont.incrementAndGet() + capturePresenceEvent.add(pnPresenceEventResult) + countDownLatch.countDown() } subscriptionSetOf.subscribe() - Thread.sleep(2000) - assertEquals(2, successPresenceEventCont.get()) + assertTrue(countDownLatch.await(5000, TimeUnit.MILLISECONDS)) + assertEquals(2, capturePresenceEvent.size) + assertEquals("join", capturePresenceEvent.first().event) + assertEquals("join", capturePresenceEvent[1].event) + val subscribedChannels = capturePresenceEvent.map { pnPresenceEvent -> pnPresenceEvent.channel }.toSet() + assertTrue(subscribedChannels.contains(expectedChannel01)) + assertTrue(subscribedChannels.contains(expectedChannel02)) } @Test diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/SubscribeIntegrationTests.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/SubscribeIntegrationTests.kt index 49e86b033..48a3c81be 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/SubscribeIntegrationTests.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/integrationTest/kotlin/com/pubnub/api/integration/SubscribeIntegrationTests.kt @@ -634,7 +634,7 @@ class SubscribeIntegrationTests : BaseIntegrationTest() { }, ) channelMetaSubscription.subscribe() - Thread.sleep(100) + Thread.sleep(200) guestClient.publish(userMetaDataName, randomValue()).sync() success.listen() diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/PubNubImpl.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/PubNubImpl.kt index 7707eae24..c6bc9f1d2 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/PubNubImpl.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/PubNubImpl.kt @@ -67,9 +67,11 @@ import com.pubnub.api.models.consumer.objects.PNMemberKey import com.pubnub.api.models.consumer.objects.PNMembershipKey import com.pubnub.api.models.consumer.objects.PNPage import com.pubnub.api.models.consumer.objects.PNSortKey +import com.pubnub.api.models.consumer.objects.member.MemberInclude import com.pubnub.api.models.consumer.objects.member.MemberInput import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel import com.pubnub.api.models.consumer.objects.membership.ChannelMembershipInput +import com.pubnub.api.models.consumer.objects.membership.MembershipInclude import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel import com.pubnub.api.models.consumer.pubsub.PNMessageResult import com.pubnub.api.models.consumer.pubsub.PNPresenceEventResult @@ -833,6 +835,7 @@ open class PubNubImpl( return RemoveUUIDMetadataEndpoint(pubnub = this, uuid = uuid) } + // deprecated override fun getMemberships( uuid: String?, limit: Int?, @@ -844,26 +847,71 @@ open class PubNubImpl( includeChannelDetails: PNChannelDetailsLevel?, includeType: Boolean, ): GetMemberships { - return GetMembershipsEndpoint( - pubnub = this, - uuid = uuid ?: configuration.userId.value, - collectionQueryParameters = - CollectionQueryParameters( - limit = limit, - page = page, - filter = filter, - sort = sort, - includeCount = includeCount, - ), - includeQueryParam = + val includeQueryParamValue = when (includeChannelDetails) { + PNChannelDetailsLevel.CHANNEL -> { IncludeQueryParam( includeCustom = includeCustom, - includeChannelDetails = includeChannelDetails, + includeChannel = true, includeChannelType = includeType, - ), + ) + } + + PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeChannel = true, + includeChannelCustom = true, + includeChannelType = includeType, + ) + } + + else -> IncludeQueryParam(includeCustom = includeCustom, includeChannelType = includeType) + } + return GetMembershipsEndpoint( + pubnub = this, + uuid = uuid ?: configuration.userId.value, + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = includeCount, + ), + includeQueryParam = includeQueryParamValue + ) + } + + override fun getMemberships( + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): GetMemberships { + return GetMembershipsEndpoint( + pubnub = this, + uuid = userId ?: configuration.userId.value, + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = include.includeTotalCount, + ), + includeQueryParam = IncludeQueryParam( + includeCustom = include.includeCustom, + includeType = include.includeType, + includeStatus = include.includeStatus, + includeChannel = include.includeChannel, + includeChannelCustom = include.includeChannelCustom, + includeChannelStatus = include.includeChannelStatus, + includeChannelType = include.includeChannelType, + ) ) } + // deprecated override fun setMemberships( channels: List, uuid: String?, @@ -889,6 +937,26 @@ open class PubNubImpl( includeType = includeType ) + override fun setMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships = manageMemberships( + channelsToSet = channels, + channelsToRemove = listOf(), + userId = userId, + limit = limit, + page = page, + filter = filter, + sort = sort, + include = include + ) + + // deprecated override fun removeMemberships( channels: List, uuid: String?, @@ -914,6 +982,26 @@ open class PubNubImpl( includeType = includeType, ) + override fun removeMemberships( + channels: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships = manageMemberships( + channelsToSet = listOf(), + channelsToRemove = channels, + userId = userId, + limit = limit, + page = page, + filter = filter, + sort = sort, + include = include + ) + + // deprecated override fun manageMemberships( channelsToSet: List, channelsToRemove: List, @@ -927,25 +1015,73 @@ open class PubNubImpl( includeChannelDetails: PNChannelDetailsLevel?, includeType: Boolean, ): ManageMemberships { + val includeQueryParamValue = when (includeChannelDetails) { + PNChannelDetailsLevel.CHANNEL -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeChannel = true, + includeChannelType = includeType, + ) + } + + PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeChannel = true, + includeChannelCustom = true, + includeChannelType = includeType, + ) + } + + null -> IncludeQueryParam(includeCustom = includeCustom, includeChannelType = includeType) + } return ManageMembershipsEndpoint( pubnub = this, channelsToSet = channelsToSet, channelsToRemove = channelsToRemove, uuid = uuid ?: configuration.userId.value, - collectionQueryParameters = - CollectionQueryParameters( - limit = limit, - page = page, - filter = filter, - sort = sort, - includeCount = includeCount, - ), - includeQueryParam = - IncludeQueryParam( - includeCustom = includeCustom, - includeChannelDetails = includeChannelDetails, - includeChannelType = includeType, - ), + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = includeCount, + ), + includeQueryParam = includeQueryParamValue + ) + } + + override fun manageMemberships( + channelsToSet: List, + channelsToRemove: List, + userId: String?, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MembershipInclude + ): ManageMemberships { + return ManageMembershipsEndpoint( + pubnub = this, + channelsToSet = channelsToSet, + channelsToRemove = channelsToRemove, + uuid = userId ?: configuration.userId.value, + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = include.includeTotalCount, + ), + includeQueryParam = IncludeQueryParam( + includeCustom = include.includeCustom, + includeType = include.includeType, + includeStatus = include.includeStatus, + includeChannel = include.includeChannel, + includeChannelCustom = include.includeChannelCustom, + includeChannelStatus = include.includeChannelStatus, + includeChannelType = include.includeChannelType, + ), ) } @@ -960,23 +1096,67 @@ open class PubNubImpl( includeUUIDDetails: PNUUIDDetailsLevel?, includeType: Boolean, ): GetChannelMembers { + val includeQueryParamValue = when (includeUUIDDetails) { + PNUUIDDetailsLevel.UUID -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeUser = true, + includeUserType = includeType, + ) + } + + PNUUIDDetailsLevel.UUID_WITH_CUSTOM -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeUser = true, + includeUserCustom = true, + includeUserType = includeType, + ) + } + + null -> IncludeQueryParam(includeCustom = includeCustom, includeUserType = includeType) + } return GetChannelMembersEndpoint( pubnub = this, channel = channel, - collectionQueryParameters = - CollectionQueryParameters( - limit = limit, - page = page, - filter = filter, - sort = sort, - includeCount = includeCount, - ), - includeQueryParam = - IncludeQueryParam( - includeCustom = includeCustom, - includeUUIDDetails = includeUUIDDetails, - includeUuidType = includeType, - ), + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = includeCount, + ), + includeQueryParam = includeQueryParamValue + ) + } + + override fun getChannelMembers( + channel: String, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): GetChannelMembers { + return GetChannelMembersEndpoint( + pubnub = this, + channel = channel, + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = include.includeTotalCount, + ), + includeQueryParam = IncludeQueryParam( + includeCustom = include.includeCustom, + includeType = include.includeType, + includeStatus = include.includeStatus, + includeUser = include.includeUser, + includeUserCustom = include.includeUserCustom, + includeUserStatus = include.includeUserStatus, + includeUserType = include.includeUserType + ) ) } @@ -1122,6 +1302,7 @@ open class PubNubImpl( includeUUIDDetails = includeUUIDDetails, ) + // deprecated override fun setChannelMembers( channel: String, uuids: List, @@ -1147,6 +1328,25 @@ open class PubNubImpl( includeUUIDType = includeType ) + override fun setChannelMembers( + channel: String, + users: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers = manageChannelMembers( + channel = channel, + userToSet = users, + userIdsToRemove = listOf(), + limit = limit, + page = page, + filter = filter, + sort = sort, + include = include + ) + @Deprecated( "Use removeChannelMembers instead", replaceWith = @@ -1179,6 +1379,7 @@ open class PubNubImpl( includeUUIDDetails = includeUUIDDetails, ) + // deprecated override fun removeChannelMembers( channel: String, uuids: List, @@ -1204,6 +1405,26 @@ open class PubNubImpl( includeUUIDType = includeType, ) + override fun removeChannelMembers( + channel: String, + userIds: List, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers = manageChannelMembers( + channel = channel, + userToSet = listOf(), + userIdsToRemove = userIds, + limit = limit, + page = page, + filter = filter, + sort = sort, + include = include + ) + + // deprecated override fun manageChannelMembers( channel: String, uuidsToSet: Collection, @@ -1217,25 +1438,71 @@ open class PubNubImpl( includeUUIDDetails: PNUUIDDetailsLevel?, includeUUIDType: Boolean, ): ManageChannelMembers { + val includeQueryParamValue = when (includeUUIDDetails) { + PNUUIDDetailsLevel.UUID -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeUser = true, + includeUserType = includeUUIDType, + ) + } + PNUUIDDetailsLevel.UUID_WITH_CUSTOM -> { + IncludeQueryParam( + includeCustom = includeCustom, + includeUser = true, + includeUserCustom = true, + includeUserType = includeUUIDType, + ) + } + null -> IncludeQueryParam(includeCustom = includeCustom, includeUserType = includeUUIDType) + } return ManageChannelMembersEndpoint( pubnub = this, channel = channel, - uuidsToSet = uuidsToSet, - uuidsToRemove = uuidsToRemove, - collectionQueryParameters = - CollectionQueryParameters( - limit = limit, - page = page, - filter = filter, - sort = sort, - includeCount = includeCount, - ), - includeQueryParam = - IncludeQueryParam( - includeCustom = includeCustom, - includeUUIDDetails = includeUUIDDetails, - includeUuidType = includeUUIDType, - ), + userToSet = uuidsToSet, + userIdsRemove = uuidsToRemove, + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = includeCount, + ), + includeQueryParam = includeQueryParamValue + ) + } + + override fun manageChannelMembers( + channel: String, + userToSet: Collection, + userIdsToRemove: Collection, + limit: Int?, + page: PNPage?, + filter: String?, + sort: Collection>, + include: MemberInclude + ): ManageChannelMembers { + return ManageChannelMembersEndpoint( + pubnub = this, + channel = channel, + userToSet = userToSet, + userIdsRemove = userIdsToRemove, + collectionQueryParameters = CollectionQueryParameters( + limit = limit, + page = page, + filter = filter, + sort = sort, + includeCount = include.includeTotalCount, + ), + includeQueryParam = IncludeQueryParam( + includeCustom = include.includeCustom, + includeType = include.includeType, + includeStatus = include.includeStatus, + includeUser = include.includeUser, + includeUserCustom = include.includeUserCustom, + includeUserStatus = include.includeUserStatus, + includeUserType = include.includeUserType + ) ) } diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParam.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParam.kt index 8be289b8b..b02a2027e 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParam.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParam.kt @@ -1,46 +1,55 @@ package com.pubnub.internal.endpoints.objects.internal -import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel -import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel - data class IncludeQueryParam( + // common private val includeCustom: Boolean = false, - private val includeChannelDetails: PNChannelDetailsLevel? = null, - private val includeUUIDDetails: PNUUIDDetailsLevel? = null, private val includeType: Boolean = true, private val includeStatus: Boolean = true, + // channel(membership) related + private val includeChannel: Boolean = false, + private val includeChannelCustom: Boolean = false, + private val includeChannelStatus: Boolean = false, private val includeChannelType: Boolean = false, - private val includeUuidType: Boolean = false + // user(member) related + private val includeUser: Boolean = false, + private val includeUserCustom: Boolean = false, + private val includeUserStatus: Boolean = false, + private val includeUserType: Boolean = false, ) { + internal companion object { + const val QUERY_PARAM_CUSTOM = "custom" + const val QUERY_PARAM_TYPE = "type" + const val QUERY_PARAM_STATUS = "status" + const val QUERY_PARAM_CHANNEL = "channel" + const val QUERY_PARAM_CHANNEL_CUSTOM = "channel.custom" + const val QUERY_PARAM_CHANNEL_STATUS = "channel.status" + const val QUERY_PARAM_CHANNEL_TYPE = "channel.type" + const val QUERY_PARAM_UUID = "uuid" + const val QUERY_PARAM_UUID_CUSTOM = "uuid.custom" + const val QUERY_PARAM_UUID_STATUS = "uuid.status" + const val QUERY_PARAM_UUID_TYPE = "uuid.type" + const val QUERY_KEY_INCLUDE = "include" + } + internal fun createIncludeQueryParams(): Map { - val includeList = mutableListOf() - if (includeCustom) { - includeList.add("custom") - } - when (includeChannelDetails) { - PNChannelDetailsLevel.CHANNEL -> includeList.add("channel") - PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM -> includeList.add("channel.custom") - null -> {} - } - when (includeUUIDDetails) { - PNUUIDDetailsLevel.UUID -> includeList.add("uuid") - PNUUIDDetailsLevel.UUID_WITH_CUSTOM -> includeList.add("uuid.custom") - null -> {} - } - if (includeType) { - includeList.add("type") - } - if (includeChannelType) { - includeList.add("channel.type") - } - if (includeUuidType) { - includeList.add("uuid.type") - } - if (includeStatus) { - includeList.add("status") - } + val includeMapping: List> = listOf( + includeCustom to QUERY_PARAM_CUSTOM, + includeType to QUERY_PARAM_TYPE, + includeStatus to QUERY_PARAM_STATUS, + includeChannel to QUERY_PARAM_CHANNEL, + includeChannelCustom to QUERY_PARAM_CHANNEL_CUSTOM, + includeChannelStatus to QUERY_PARAM_CHANNEL_STATUS, + includeChannelType to QUERY_PARAM_CHANNEL_TYPE, + includeUser to QUERY_PARAM_UUID, + includeUserCustom to QUERY_PARAM_UUID_CUSTOM, + includeUserStatus to QUERY_PARAM_UUID_STATUS, + includeUserType to QUERY_PARAM_UUID_TYPE + ) + + val includeList = includeMapping.filter { it.first }.map { it.second } + return if (includeList.isNotEmpty()) { - mapOf("include" to includeList.joinToString(",")) + mapOf(QUERY_KEY_INCLUDE to includeList.joinToString(",")) } else { mapOf() } diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/member/ManageChannelMembersEndpoint.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/member/ManageChannelMembersEndpoint.kt index 5dfc1080e..0d26a331b 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/member/ManageChannelMembersEndpoint.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/member/ManageChannelMembersEndpoint.kt @@ -23,8 +23,8 @@ import retrofit2.Response */ class ManageChannelMembersEndpoint( pubnub: PubNubImpl, - private val uuidsToSet: Collection, - private val uuidsToRemove: Collection, + private val userToSet: Collection, + private val userIdsRemove: Collection, private val channel: String, private val collectionQueryParameters: CollectionQueryParameters, private val includeQueryParam: IncludeQueryParam, @@ -39,15 +39,15 @@ class ManageChannelMembersEndpoint( options = params, body = ChangeMemberInput( - delete = uuidsToRemove.map { ServerMemberInput(UUIDId(id = it)) }, - set = - uuidsToSet.map { - ServerMemberInput( - uuid = UUIDId(id = it.uuid), - custom = it.custom, - status = it.status, - ) - }, + delete = userIdsRemove.map { ServerMemberInput(UUIDId(id = it)) }, + set = userToSet.map { + ServerMemberInput( + uuid = UUIDId(id = it.uuid), + custom = it.custom, + status = it.status, + type = it.type, + ) + }, ), ) } diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/membership/ManageMembershipsEndpoint.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/membership/ManageMembershipsEndpoint.kt index f6bea51e8..90cf97a57 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/membership/ManageMembershipsEndpoint.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/endpoints/objects/membership/ManageMembershipsEndpoint.kt @@ -46,6 +46,7 @@ class ManageMembershipsEndpoint internal constructor( channel = ChannelId(id = it.channel), custom = it.custom, status = it.status, + type = it.type ) }, delete = channelsToRemove.map { ServerMembershipInput(channel = ChannelId(id = it)) }, diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/consumer/pubsub/objects/PNObjectEventResult.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/consumer/pubsub/objects/PNObjectEventResult.kt index 38c20817e..0b8b3ad63 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/consumer/pubsub/objects/PNObjectEventResult.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/consumer/pubsub/objects/PNObjectEventResult.kt @@ -93,6 +93,7 @@ data class PNSetMembershipEvent( val eTag: String, val updated: String, val status: PatchValue?, + val type: PatchValue?, ) data class PNDeleteMembershipEvent( @@ -175,6 +176,7 @@ private fun PNSetMembershipEvent.toApi(): com.pubnub.api.models.consumer.pubsub. eTag = this.eTag, updated = this.updated, status = this.status, + type = this.type ) } diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMemberInput.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMemberInput.kt index 16054673d..b70d82fa4 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMemberInput.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMemberInput.kt @@ -4,6 +4,7 @@ internal data class ServerMemberInput( val uuid: UUIDId, val custom: Any? = null, val status: String? = null, + val type: String? = null ) internal data class UUIDId(val id: String) diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMembershipInput.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMembershipInput.kt index f0d6914ab..7c0b4e5f9 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMembershipInput.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/models/server/objects_api/ServerMembershipInput.kt @@ -4,6 +4,7 @@ internal data class ServerMembershipInput( val channel: ChannelId, val custom: Any? = null, val status: String? = null, + val type: String? = null ) internal data class ChannelId( diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/contract/membership/step/WhenSteps.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/contract/membership/step/WhenSteps.kt index 483e5529a..b9710dcdb 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/contract/membership/step/WhenSteps.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/contract/membership/step/WhenSteps.kt @@ -81,7 +81,7 @@ class WhenSteps( fun i_remove_the_membership() { val channels = membershipState.memberships.map { it.channel.id } world.pubnub.removeMemberships( - uuid = membershipState.uuid(), + userId = membershipState.uuid(), channels = channels, ).sync().let { world.responseStatus = it.status @@ -114,7 +114,7 @@ class WhenSteps( world.pubnub.manageMemberships( channelsToSet = channelsToSet, channelsToRemove = channelsToRemove, - uuid = membershipState.uuid(), + userId = membershipState.uuid(), ).sync().let { world.responseStatus = it.status membershipState.returnedMemberships = it.data diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParamTest.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParamTest.kt new file mode 100644 index 000000000..89663673c --- /dev/null +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/endpoints/objects/internal/IncludeQueryParamTest.kt @@ -0,0 +1,63 @@ +package com.pubnub.internal.endpoints.objects.internal + +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_KEY_INCLUDE +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_CHANNEL +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_CHANNEL_CUSTOM +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_CHANNEL_STATUS +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_CHANNEL_TYPE +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_CUSTOM +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_STATUS +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_TYPE +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_UUID +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_UUID_CUSTOM +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_UUID_STATUS +import com.pubnub.internal.endpoints.objects.internal.IncludeQueryParam.Companion.QUERY_PARAM_UUID_TYPE +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +class IncludeQueryParamTest { + private lateinit var objectUnderTest: IncludeQueryParam + + @Test + fun createIncludeQueryParamsShouldReturnParamsThatHasTrue() { + objectUnderTest = IncludeQueryParam( + includeCustom = true, + includeType = true, + includeStatus = true, + includeChannel = true, + includeChannelCustom = true, + includeChannelStatus = true, + includeChannelType = true, + includeUser = true, + includeUserCustom = true, + includeUserStatus = true, + includeUserType = true + ) + + val createIncludeQueryParams = objectUnderTest.createIncludeQueryParams() + + val stringWithQueryParams: String = createIncludeQueryParams[QUERY_KEY_INCLUDE]!! + val set = stringWithQueryParams.split(",").toSet() + + assertTrue(set.contains(QUERY_PARAM_CUSTOM)) + assertTrue(set.contains(QUERY_PARAM_TYPE)) + assertTrue(set.contains(QUERY_PARAM_STATUS)) + assertTrue(set.contains(QUERY_PARAM_CHANNEL)) + assertTrue(set.contains(QUERY_PARAM_CHANNEL_CUSTOM)) + assertTrue(set.contains(QUERY_PARAM_CHANNEL_STATUS)) + assertTrue(set.contains(QUERY_PARAM_CHANNEL_TYPE)) + assertTrue(set.contains(QUERY_PARAM_UUID)) + assertTrue(set.contains(QUERY_PARAM_UUID_CUSTOM)) + assertTrue(set.contains(QUERY_PARAM_UUID_STATUS)) + assertTrue(set.contains(QUERY_PARAM_UUID_TYPE)) + } + + @Test + fun createIncludeQueryParamsShouldNotReturnParamsWhenAllAreFalse() { + objectUnderTest = IncludeQueryParam(includeType = false, includeStatus = false) + + val queryParamsMap = objectUnderTest.createIncludeQueryParams() + + assertTrue(queryParamsMap.isEmpty()) + } +} diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/subscribe/eventengine/effect/EmitMessagesEffectTest.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/subscribe/eventengine/effect/EmitMessagesEffectTest.kt index 9b43d703c..cd3a7655a 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/subscribe/eventengine/effect/EmitMessagesEffectTest.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/test/kotlin/com/pubnub/internal/subscribe/eventengine/effect/EmitMessagesEffectTest.kt @@ -169,6 +169,7 @@ class EmitMessagesEffectTest { "AZO/t53al7m8fw", "2023-05-05T14:26:55.824848794Z", null, + null, ) val pnSetMembershipEventMessage = PNSetMembershipEventMessage("objects", "2.0", "set", objectEventType, pnSetMembershipEvent)