Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 7c23c22

Browse files
fix(lib): fix custom metadata not being returned properly (#110)
* fix(lib): fix custom metadata not being returned properly * fix(lib): fix types * PubNub SDK v0.22.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 89f696d commit 7c23c22

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

.pubnub.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
22
name: pubnub-react-chat-components
3-
version: v0.21.0
3+
version: v0.22.0
44
scm: github.com/pubnub/react-chat-components
55
schema: 1
66
files:
77
- lib/dist/index.js
88
- lib/dist/index.es.js
99
changelog:
10+
- date: 2023-03-28
11+
version: v0.22.0
12+
changes:
13+
- type: feature
14+
text: "UseUserMemberships hook and useChannelMembers - make sure that both channel and user custom metadata fields are present in the hooks' responses."
1015
- date: 2023-03-27
1116
version: v0.21.0
1217
changes:

packages/common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/common-chat-components",
3-
"version": "0.21.0",
3+
"version": "0.22.0",
44
"main": "src/index.ts",
55
"license": "MIT",
66
"scripts": {

packages/common/src/hooks/use-channel-members.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { useState, useEffect, useMemo } from "react";
22
import { GetChannelMembersParameters } from "pubnub";
33
import { usePubNub } from "pubnub-react";
44
import { merge, cloneDeep } from "lodash";
5-
import { UserEntity } from "../types";
5+
import { UserEntityWithMembership } from "../types";
66

7-
type HookReturnValue = [UserEntity[], () => void, () => void, number, Error];
7+
type HookReturnValue = [UserEntityWithMembership[], () => void, () => void, number, Error];
88

99
export const useChannelMembers = (options: GetChannelMembersParameters): HookReturnValue => {
1010
const jsonOptions = JSON.stringify(options);
1111

1212
const pubnub = usePubNub();
13-
const [members, setMembers] = useState<UserEntity[]>([]);
13+
const [members, setMembers] = useState<UserEntityWithMembership[]>([]);
1414
const [totalCount, setTotalCount] = useState(0);
1515
const [page, setPage] = useState("");
1616
const [error, setError] = useState<Error>();
@@ -49,11 +49,22 @@ export const useChannelMembers = (options: GetChannelMembersParameters): HookRet
4949
try {
5050
if (totalCount && members.length >= totalCount) return;
5151
const response = await pubnub.objects.getChannelMembers(paginatedOptions);
52+
5253
if (ignoreRequest) return;
5354
setDoFetch(false);
5455
setMembers((members) => [
5556
...members,
56-
...(response.data.map((m) => m.uuid) as UserEntity[]),
57+
...(response.data.map((m) => {
58+
const returnObject = {
59+
...m.uuid,
60+
} as UserEntityWithMembership;
61+
62+
if (m.custom) {
63+
returnObject.membership = m.custom;
64+
}
65+
66+
return returnObject;
67+
}) as UserEntityWithMembership[]),
5768
]);
5869
setTotalCount(response.totalCount);
5970
setPage(response.next);

packages/common/src/hooks/use-user-memberships.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { useState, useEffect, useMemo } from "react";
22
import { GetMembershipsParametersv2 } from "pubnub";
33
import { usePubNub } from "pubnub-react";
44
import { merge, cloneDeep } from "lodash";
5-
import { ChannelEntity } from "../types";
5+
import { ChannelEntityWithMembership } from "../types";
66

7-
type HookReturnValue = [ChannelEntity[], () => void, () => void, number, Error];
7+
type HookReturnValue = [ChannelEntityWithMembership[], () => void, () => void, number, Error];
88

99
export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): HookReturnValue => {
1010
const jsonOptions = JSON.stringify(options);
1111

1212
const pubnub = usePubNub();
13-
const [channels, setChannels] = useState<ChannelEntity[]>([]);
13+
const [channels, setChannels] = useState<ChannelEntityWithMembership[]>([]);
1414
const [totalCount, setTotalCount] = useState(0);
1515
const [page, setPage] = useState("");
1616
const [error, setError] = useState<Error>();
@@ -49,20 +49,22 @@ export const useUserMemberships = (options: GetMembershipsParametersv2 = {}): Ho
4949
try {
5050
if (totalCount && channels.length >= totalCount) return;
5151
const response = await pubnub.objects.getMemberships(paginatedOptions);
52+
5253
if (ignoreRequest) return;
5354
setDoFetch(false);
5455
setChannels((channels) => [
5556
...channels,
5657
...(response.data.map((m) => {
58+
const returnObject = {
59+
...m.channel,
60+
} as ChannelEntityWithMembership;
61+
5762
if (m.custom) {
58-
return {
59-
...m.channel,
60-
custom: m.custom,
61-
};
63+
returnObject.membership = m.custom;
6264
}
6365

64-
return m.channel;
65-
}) as ChannelEntity[]),
66+
return returnObject;
67+
}) as ChannelEntityWithMembership[]),
6668
]);
6769
setTotalCount(response.totalCount);
6870
setPage(response.next);

packages/common/src/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export type ChannelEntity = ChannelMetadataObject<ObjectCustom>;
1111

1212
export type UserEntity = UUIDMetadataObject<ObjectCustom>;
1313

14+
export type ChannelEntityWithMembership = ChannelEntity & {
15+
membership?: ObjectCustom;
16+
};
17+
18+
export type UserEntityWithMembership = UserEntity & {
19+
membership?: ObjectCustom;
20+
};
21+
1422
export interface MessageEnvelope {
1523
channel?: string;
1624
message: MessagePayload | FilePayload;

packages/react-native/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-native-chat-components",
3-
"version": "0.21.0",
3+
"version": "0.22.0",
44
"description": "PubNub Chat Components is a development kit of React Native components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/commonjs/index",

packages/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-chat-components",
3-
"version": "0.21.0",
3+
"version": "0.22.0",
44
"description": "PubNub Chat Components is a development kit of React components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/index.js",

0 commit comments

Comments
 (0)