Skip to content

Commit d225569

Browse files
sravan-sSravan S
andauthored
fix: rate limit markAsDelivered (#144)
Co-authored-by: Sravan S <sravan@sendbird.com>
1 parent 16fcc50 commit d225569

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/smart-components/ChannelList/components/ChannelListUI/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import useSendbirdStateContext from '../../../../hooks/useSendbirdStateContext';
1515
import EditUserProfile from '../../../EditUserProfile';
1616
import PlaceHolder, { PlaceHolderTypes } from '../../../../ui/PlaceHolder';
1717

18+
const DELIVERY_RECIPT = 'delivery_receipt';
19+
1820
interface RenderChannelPreviewProps {
1921
channel: SendBird.GroupChannel;
2022
onLeaveChannel(
@@ -124,9 +126,18 @@ const ChannelListUI: React.FC<ChannelListUIProps> = (props: ChannelListUIProps)
124126
type: channelListActions.FETCH_CHANNELS_SUCCESS,
125127
payload: channelList,
126128
});
127-
if (channelList && typeof channelList.forEach === 'function') {
129+
const canSetMarkAsDelivered = sdk?.appInfo?.premiumFeatureList
130+
?.find((feature) => (feature === DELIVERY_RECIPT));
131+
132+
if (canSetMarkAsDelivered) {
128133
logger.info('ChannelList: Marking all channels as read');
129-
channelList.forEach((c) => { sdk.markAsDelivered(c.url) });
134+
// eslint-disable-next-line no-unused-expressions
135+
channelList?.forEach((c, idx) => {
136+
// Plan-based rate limits - minimum limit is 5 requests per second
137+
setTimeout(() => {
138+
sdk?.markAsDelivered(c?.url);
139+
}, 300 * idx);
140+
});
130141
}
131142
});
132143
}

src/smart-components/ChannelList/utils.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as channelActions from './dux/actionTypes';
22
import * as topics from '../../lib/pubSub/topics';
33

4+
const DELIVERY_RECIPT = 'delivery_receipt';
5+
46
const createEventHandler = ({
57
sdk,
68
sdkChannelHandlerId,
@@ -217,9 +219,19 @@ function setupChannelList({
217219
type: channelActions.INIT_CHANNELS_SUCCESS,
218220
payload: sortedChannelList,
219221
});
220-
if (channelList && typeof channelList.forEach === 'function') {
221-
logger.info('ChannelList - mark all channels as delivered');
222-
channelList.forEach((c) => c.markAsDelivered());
222+
const canSetMarkAsDelivered = sdk?.appInfo?.premiumFeatureList
223+
?.find((feature) => (feature === DELIVERY_RECIPT));
224+
225+
if (canSetMarkAsDelivered) {
226+
logger.info('ChannelList: Marking all channels as read');
227+
// eslint-disable-next-line no-unused-expressions
228+
channelList?.forEach((c, idx) => {
229+
// Plan-based rate limits - minimum limit is 5 requests per second
230+
setTimeout(() => {
231+
// eslint-disable-next-line no-unused-expressions
232+
sdk?.markAsDelivered(c?.url);
233+
}, 300 * idx);
234+
});
223235
}
224236
});
225237
} else {

0 commit comments

Comments
 (0)