Memberships
When a user joins a channel, an association called a Membership is stored between the User and the Channel. Application users can immediately see which channels they belong to, join or leave channels to create these memberships, and access information about other users and channels.
State Shape
The data about Memberships is stored from the perspective of Users and Channels in a normalized structure. The following example shows the shape of Memberships in the store:
{
"byId": {
"user_53bbe00387004010a8b9ad5f36bdd4a7": [
{
"id": "channel_ac4e67b98b34b44c4a39466e93e",
"custom": {
"admin": true
}
}
]
}
}
Reducers
The PubNub Redux framework provides reducers your app can implement that respond to various actions that update the store. To track the state of a set of objects in the store, combine the reducers you want into the rootReducer
for your app.
createMembershipReducer
createMembershipReducer
instantiates a reducer in the store that responds to actions dispatched to update the state of a user's memberships, and all channel memberships, in the store.
createMembershipReducer();
Listeners
The PubNub Redux framework includes listeners that monitor PubNub events from the server and dispatch corresponding actions. All listeners are automatically invoked if your app registers the combined PubNub listener. You can register only specific listeners, or implement your own combine listeners function.
createMembershipListener
createMembershipListener
registers a listener in the store that monitors Membership events.
A sample implementation of a single listener:
pubnub.addListener(createMembershipListener(store.dispatch));
Commands
The PubNub Redux framework provides commands that your app can dispatch to the store to be managed by the Thunk middleware. Commands interact with the PubNub API and dispatch basic actions which are then processed by reducers to update the state in the store.
fetchMemberships
Get the specified user's channel memberships.
fetchMemberships( request, [meta] );
fetchMemberships Arguments
Parameter | Type | Required | Description |
---|---|---|---|
request | FetchMembershipRequest | Yes | Memberships request parameter object. |
[meta] | object | Optional | Standard meta options object. |
fetchMemberships FetchMembershipRequest Properties
Property | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Yes | The ID of the user whose memberships you wish to retrieve. | |
limit | number | Optional | 100 | Maximum number of results to return per page |
filter | string | Optional | n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | string | Optional | n/a | Key-value pair of a property to sort by, and a sort direction. Available options are updated , channel.id , channel.name , and channel.updated .Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).For example: {channel.name: 'asc'} |
page | object | Optional | n/a | To get the next set of results, specify next. To get the previous set of results, specify prev. If you specify both, prev is ignored. { next: "next-page-id" ,prev: "prev-page-id" } |
include | object | Optional | { customFields: false, channelFields: false, customChannelFields: false, totalCount : false } | Specifies whether to include custom fields in the response, and whether to include a total result count. |
fetchMemberships Sample Usage
dispatch(fetchMemberships({
uuid: 'user_53bbe00387004010a8b9ad5f36bdd4a7',
limit: '2'
}));
setMemberships
Set memberships of user to a list of channels.
setMemberships( request, [meta] );
setMemberships Arguments
Parameter | Type | Required | Description |
---|---|---|---|
request | MembershipRequest | Yes | Membership request parameter object. |
[meta] | object | Optional | Standard meta options object. |
setMemberships MembershipRequest Properties
Property | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Yes | The ID of the user. | |
channels | Array of object s | Yes | Array of objects indicating the channels(s) to be joined, along with optional custom data.[ { id: "channel-id-1" custom: { ... } }, { id: "channel-id-2" custom: { ... } }, ] | |
limit | number | Optional | 100 | Maximum number of results to return per page |
filter | string | Optional | n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | string | Optional | n/a | Key-value pair of a property to sort by, and a sort direction. Available options are updated , channel.id , channel.name , and channel.updated .Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).For example: {channel.name: 'asc'} |
page | object | Optional | n/a | To get the next set of results, specify next. To get the previous set of results, specify prev. If you specify both, prev is ignored. { next: "next-page-id" ,prev: "prev-page-id" } |
include | object | Optional | { customFields: false, channelFields: false, customChannelFields: false, totalCount : false } | Specifies whether to include custom fields in the response, and whether to include a total result count. |
setMemberships Sample Usage
dispatch(setMemberships({
uuid: 'user_53bbe00387004010a8b9ad5f36bdd4a7',
channels: [ { id: 'channel_ac4e67b98b34b44c4a39466e93e' } ]
}));
removeMemberships
Remove a user from a list of channels.
removeMemberships( request, [meta] );
removeMemberships Arguments
Parameter | Type | Required | Description |
---|---|---|---|
request | MembershipRequest | Yes | Membership request parameter object. |
[meta] | object | Optional | Standard meta options object. |
removeMemberships MembershipRequest Properties
Property | Type | Required | Default | Description |
---|---|---|---|---|
uuid | string | Yes | The ID of the user. | |
channels | Array of strings s | Yes | Array of channels(s) to leave.["channel-id-1","channel-id-2"] | |
limit | number | Optional | 100 | Maximum number of results to return per page |
filter | string | Optional | n/a | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. |
sort | string | Optional | n/a | Key-value pair of a property to sort by, and a sort direction. Available options are updated , channel.id , channel.name , and channel.updated .Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).For example: {channel.name: 'asc'} |
page | object | Optional | n/a | To get the next set of results, specify next. To get the previous set of results, specify prev. If you specify both, prev is ignored. { next: "next-page-id" ,prev: "prev-page-id" } |
include | object | Optional | { customFields: false, channelFields: false, customChannelFields: false, totalCount : false } | Specifies whether to include custom fields in the response, and whether to include a total result count. |
removeMemberships Sample Usage
dispatch(removeMemberships({
uuid: 'user_53bbe00387004010a8b9ad5f36bdd4a7',
channels: [ 'channel_ac4e67b98b34b44c4a39466e93e' ]
}));