Skip to content

Commit 64de427

Browse files
authored
[CLNP-6715]Added markAsUnread (#1347)
[feat]: Added markAsUnread. // PR description (Optional) ChatSDK에 markAsUnread 기능이 추가 됨에 따라, Uikit에서도 해당 기능이 사용할 수 있게 반영 되었습니다. [UX Figma](https://www.figma.com/design/SVbXU00FhjztekD8AiVukK/WIP_UIKit_React?node-id=3054-2&p=f&t=P874pCcveyOShiUJ-0) [Uikit Spec](https://sendbird.atlassian.net/wiki/spaces/SDK/pages/3191373873/MarkAsUnread) Fixes [CLNP-6715](https://sendbird.atlassian.net/browse/CLNP-6715) // Changelogs (Recommended) ### Changelogs ### Checklist Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If unsure, ask the members. This is a reminder of what we look for before merging your code. - [x] **All tests pass locally with my changes** - [ ] **I have added tests that prove my fix is effective or that my feature works** - [ ] **Public components / utils / props are appropriately exported** - [ ] I have added necessary documentation (if appropriate) ## External Contributions This project is not yet set up to accept pull requests from external contributors. If you have a pull request that you believe should be accepted, please contact the Developer Relations team <developer-advocates@sendbird.com> with details and we'll evaluate if we can set up a [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement) to allow for the contribution. [CLNP-6715]: https://sendbird.atlassian.net/browse/CLNP-6715?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 0c5fa0f commit 64de427

File tree

45 files changed

+958
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+958
-85
lines changed

src/lib/Sendbird/context/SendbirdProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ const SendbirdContextManager = ({
210210
suggestedRepliesDirection: configs.groupChannel.channel.suggestedRepliesDirection,
211211
enableMarkdownForUserMessage: configs.groupChannel.channel.enableMarkdownForUserMessage,
212212
enableFormTypeMessage: configs.groupChannel.channel.enableFormTypeMessage,
213+
enableMarkAsUnread: configs.groupChannel.channel.enableMarkAsUnread,
213214
enableReactionsSupergroup: sdkInitialized && configsWithAppAttr(sdk).groupChannel.channel.enableReactionsSupergroup as never,
214215
},
215216
groupChannelList: {

src/lib/Sendbird/context/initialState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const config: SendbirdStateConfig = {
6969
suggestedRepliesDirection: 'vertical',
7070
enableMarkdownForUserMessage: false,
7171
enableFormTypeMessage: false,
72+
enableMarkAsUnread: false,
7273
enableReactionsSupergroup: undefined as never, // @deprecated
7374
},
7475
groupChannelList: {

src/lib/Sendbird/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export interface SendbirdStateConfig {
280280
suggestedRepliesDirection: SBUConfig['groupChannel']['channel']['suggestedRepliesDirection'];
281281
enableMarkdownForUserMessage: SBUConfig['groupChannel']['channel']['enableMarkdownForUserMessage'];
282282
enableFormTypeMessage: SBUConfig['groupChannel']['channel']['enableFormTypeMessage'];
283+
enableMarkAsUnread: SBUConfig['groupChannel']['channel']['enableMarkAsUnread'];
283284
/**
284285
* @deprecated Currently, this feature is turned off by default. If you wish to use this feature, contact us: {@link https://dashboard.sendbird.com/settings/contact_us?category=feedback_and_feature_requests&product=UIKit}
285286
*/

src/lib/utils/__tests__/uikitConfigMapper.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('uikitConfigMapper', () => {
3838
expect(result).toHaveProperty('groupChannel.enableTypingIndicator');
3939
expect(result).toHaveProperty('groupChannel.threadReplySelectType');
4040
expect(result).toHaveProperty('groupChannel.input.enableDocument');
41+
expect(result).toHaveProperty('groupChannel.enableMarkAsUnread');
4142

4243
expect(result).toHaveProperty('openChannel.enableOgtag');
4344
expect(result).toHaveProperty('openChannel.input.enableDocument');
@@ -50,6 +51,7 @@ describe('uikitConfigMapper', () => {
5051
const uikitOptions = {
5152
groupChannel: {
5253
enableMention: false,
54+
enableMarkAsUnread: true,
5355
},
5456
groupChannelSettings: {
5557
enableMessageSearch: false,
@@ -58,6 +60,7 @@ describe('uikitConfigMapper', () => {
5860
const result = uikitConfigMapper({ legacyConfig, uikitOptions });
5961

6062
expect(result.groupChannel?.enableMention).toBe(false);
63+
expect(result.groupChannel?.enableMarkAsUnread).toBe(true);
6164
expect(result.groupChannelSettings?.enableMessageSearch).toBe(false);
6265
});
6366
it('should return true <-> false flipped result for disableUserProfile when its converted into enableUsingDefaultUserProfile', () => {
@@ -74,4 +77,14 @@ describe('uikitConfigMapper', () => {
7477
.common?.enableUsingDefaultUserProfile,
7578
).toBe(false);
7679
});
80+
it('should correctly handle enableMarkAsUnread from uikitOptions', () => {
81+
const uikitOptions = {
82+
groupChannel: {
83+
enableMarkAsUnread: true,
84+
},
85+
} as UIKitOptions;
86+
const result = uikitConfigMapper({ legacyConfig: mockLegacyConfig, uikitOptions });
87+
88+
expect(result.groupChannel?.enableMarkAsUnread).toBe(true);
89+
});
7790
});

src/lib/utils/uikitConfigMapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function uikitConfigMapper({
4141
suggestedRepliesDirection: uikitOptions.groupChannel?.suggestedRepliesDirection,
4242
enableMarkdownForUserMessage: uikitOptions.groupChannel?.enableMarkdownForUserMessage,
4343
enableFormTypeMessage: uikitOptions.groupChannel?.enableFormTypeMessage,
44+
enableMarkAsUnread: uikitOptions.groupChannel?.enableMarkAsUnread,
4445
},
4546
groupChannelList: {
4647
enableTypingIndicator: uikitOptions.groupChannelList?.enableTypingIndicator ?? isTypingIndicatorEnabledOnChannelList,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import NewMessageCount from '../../../GroupChannel/components/NewMessageCountFloatingButton';
2+
3+
export default NewMessageCount;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import UnreadCountFloatingButton from '../../../GroupChannel/components/UnreadCountFloatingButton';
2+
3+
export default UnreadCountFloatingButton;

src/modules/Channel/context/ChannelProvider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {
55
useRef,
66
useMemo,
77
} from 'react';
8+
import { UIKitConfigProvider, useUIKitConfig } from '@sendbird/uikit-tools';
89

910
import type { GroupChannel, Member } from '@sendbird/chat/groupChannel';
1011
import type {
@@ -52,6 +53,7 @@ import { PublishingModuleType } from '../../internalInterfaces';
5253
import { ChannelActionTypes } from './dux/actionTypes';
5354
import useSendbird from '../../../lib/Sendbird/context/hooks/useSendbird';
5455
import { useLocalization } from '../../../lib/LocalizationContext';
56+
import { uikitConfigStorage } from '../../../lib/utils/uikitConfigStorage';
5557

5658
export { ThreadReplySelectType } from './const'; // export for external usage
5759

@@ -215,6 +217,7 @@ const ChannelProvider = (props: ChannelContextProps) => {
215217
const sdk = globalStore?.stores?.sdkStore?.sdk;
216218
const sdkInit = globalStore?.stores?.sdkStore?.initialized;
217219
const globalConfigs = globalStore?.config;
220+
const { configs: uikitConfig } = useUIKitConfig();
218221

219222
const [initialTimeStamp, setInitialTimeStamp] = useState(startingPoint);
220223
useEffect(() => {
@@ -441,6 +444,19 @@ const ChannelProvider = (props: ChannelContextProps) => {
441444
});
442445

443446
return (
447+
<UIKitConfigProvider
448+
storage={uikitConfigStorage}
449+
localConfigs={{
450+
...uikitConfig,
451+
groupChannel: {
452+
...uikitConfig.groupChannel,
453+
channel: {
454+
...uikitConfig.groupChannel.channel,
455+
enableMarkAsUnread: false,
456+
},
457+
},
458+
}
459+
}>
444460
<ChannelContext.Provider value={{
445461
// props
446462
channelUrl,
@@ -519,6 +535,7 @@ const ChannelProvider = (props: ChannelContextProps) => {
519535
{children}
520536
</UserProfileProvider>
521537
</ChannelContext.Provider>
538+
</UIKitConfigProvider>
522539
);
523540
};
524541

src/modules/Channel/context/dux/actionTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const ON_MESSAGE_DELETED_BY_REQ_ID = 'ON_MESSAGE_DELETED_BY_REQ_ID';
2727
export const SET_CURRENT_CHANNEL = 'SET_CURRENT_CHANNEL';
2828
export const SET_CHANNEL_INVALID = 'SET_CHANNEL_INVALID';
2929
export const MARK_AS_READ = 'MARK_AS_READ';
30+
export const MARK_AS_UNREAD = 'MARK_AS_UNREAD';
3031
export const ON_REACTION_UPDATED = 'ON_REACTION_UPDATED';
3132
export const SET_EMOJI_CONTAINER = 'SET_EMOJI_CONTAINER';
3233
export const MESSAGE_LIST_PARAMS_CHANGED = 'MESSAGE_LIST_PARAMS_CHANGED';
@@ -77,6 +78,11 @@ type CHANNEL_PAYLOAD_TYPES = {
7778
[RESEND_MESSAGE_START]: SendableMessageType;
7879
[MARK_AS_READ]: {
7980
channel: null | GroupChannel;
81+
userIds?: null |string[];
82+
};
83+
[MARK_AS_UNREAD]: {
84+
channel: null | GroupChannel;
85+
userIds?: null |string[];
8086
};
8187
[ON_MESSAGE_DELETED]: MessageId;
8288
[ON_MESSAGE_DELETED_BY_REQ_ID]: RequestId;

src/modules/Channel/context/hooks/useHandleChannelEvents.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ function useHandleChannelEvents({
107107
});
108108
}
109109
},
110+
onUserMarkedRead: (channel, userIds) => {
111+
logger.info('Channel | useHandleChannelEvents: onUserMarkedAsRead', channel, userIds);
112+
if (compareIds(channel?.url, channelUrl)) {
113+
messagesDispatcher({
114+
type: messageActions.MARK_AS_READ,
115+
payload: {
116+
channel,
117+
userIds,
118+
},
119+
});
120+
}
121+
},
122+
onUserMarkedUnread: (channel, userIds) => {
123+
logger.info('Channel | useHandleChannelEvents: onUserMarkedUnread', channel, userIds);
124+
// TODO:: MADOKA 이 부분에 대해서 명확하게 확인해야 함.
125+
if (compareIds(channel?.url, channelUrl)) {
126+
messagesDispatcher({
127+
type: messageActions.MARK_AS_UNREAD,
128+
payload: {
129+
channel,
130+
userIds,
131+
},
132+
});
133+
}
134+
},
110135
// before(onDeliveryReceiptUpdated)
111136
onUndeliveredMemberStatusUpdated: (channel) => {
112137
if (compareIds(channel?.url, channelUrl)) {

0 commit comments

Comments
 (0)