Skip to content

Commit afa1c3d

Browse files
committed
feat: added visibility of users who reacted in SuperGroupChannel
1 parent 7cf3f47 commit afa1c3d

File tree

8 files changed

+21
-33
lines changed

8 files changed

+21
-33
lines changed

packages/uikit-react-native/src/components/ChannelMessageList/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,7 @@ const useCreateMessagePressActions = <T extends SendbirdGroupChannel | SendbirdO
390390
const configs = sbOptions.uikitWithAppInfo.groupChannel.channel;
391391
const bottomSheetItem: BottomSheetItem = {
392392
sheetItems,
393-
HeaderComponent: shouldRenderReaction(
394-
channel,
395-
channel.isGroupChannel() && (channel.isSuper ? configs.enableReactionsSupergroup : configs.enableReactions),
396-
)
393+
HeaderComponent: shouldRenderReaction(channel, channel.isGroupChannel() && configs.enableReactions)
397394
? ({ onClose }) => <ReactionAddons.BottomSheet message={message} channel={channel} onClose={onClose} />
398395
: undefined,
399396
};

packages/uikit-react-native/src/components/ChannelThreadMessageList/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,7 @@ const useCreateMessagePressActions = <T extends SendbirdGroupChannel | SendbirdO
342342
const configs = sbOptions.uikitWithAppInfo.groupChannel.channel;
343343
const bottomSheetItem: BottomSheetItem = {
344344
sheetItems,
345-
HeaderComponent: shouldRenderReaction(
346-
channel,
347-
channel.isGroupChannel() && (channel.isSuper ? configs.enableReactionsSupergroup : configs.enableReactions),
348-
)
345+
HeaderComponent: shouldRenderReaction(channel, channel.isGroupChannel() && configs.enableReactions)
349346
? ({ onClose }) => <ReactionAddons.BottomSheet message={message} channel={channel} onClose={onClose} />
350347
: undefined,
351348
};

packages/uikit-react-native/src/components/GroupChannelMessageRenderer/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ const GroupChannelMessageRenderer: GroupChannelProps['Fragment']['renderMessage'
6767

6868
const reactionChildren = useIIFE(() => {
6969
const configs = sbOptions.uikitWithAppInfo.groupChannel.channel;
70-
if (
71-
shouldRenderReaction(channel, channel.isSuper ? configs.enableReactionsSupergroup : configs.enableReactions) &&
72-
message.reactions &&
73-
message.reactions.length > 0
74-
) {
70+
if (shouldRenderReaction(channel, configs.enableReactions) && message.reactions && message.reactions.length > 0) {
7571
return <ReactionAddons.Message channel={channel} message={message} />;
7672
}
7773
return null;

packages/uikit-react-native/src/components/ReactionAddons/MessageReactionAddon.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ import { useForceUpdate, useGroupChannelHandler } from '@sendbird/uikit-tools';
77
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdReaction } from '@sendbird/uikit-utils';
88
import { getReactionCount } from '@sendbird/uikit-utils';
99

10-
import { DEFAULT_LONG_PRESS_DELAY, UNKNOWN_USER_ID } from '../../constants';
10+
import { DEFAULT_LONG_PRESS_DELAY } from '../../constants';
1111
import { useReaction, useSendbirdChat } from '../../hooks/useContext';
1212
import ReactionRoundedButton from './ReactionRoundedButton';
1313

1414
const NUM_COL = 4;
1515
const REACTION_MORE_KEY = 'reaction-more-button';
1616
export type ReactionAddonType = 'default' | 'thread_parent_message';
1717

18-
const getUserReacted = (reaction: SendbirdReaction, userId = UNKNOWN_USER_ID) => {
19-
return reaction.userIds.indexOf(userId) > -1;
20-
};
21-
2218
const createOnPressReaction = (
2319
reaction: SendbirdReaction,
2420
channel: SendbirdBaseChannel,
@@ -41,7 +37,6 @@ const createReactionButtons = (
4137
emojiLimit: number,
4238
onOpenReactionList: () => void,
4339
onOpenReactionUserList: (focusIndex: number) => void,
44-
currentUserId?: string,
4540
reactionAddonType?: ReactionAddonType,
4641
) => {
4742
const reactions = message.reactions ?? [];
@@ -51,15 +46,15 @@ const createReactionButtons = (
5146
return (
5247
<Pressable
5348
key={reaction.key}
54-
onPress={createOnPressReaction(reaction, channel, message, getUserReacted(reaction, currentUserId))}
49+
onPress={createOnPressReaction(reaction, channel, message, reaction.hasCurrentUserReacted)}
5550
onLongPress={() => onOpenReactionUserList(index)}
5651
delayLongPress={DEFAULT_LONG_PRESS_DELAY}
5752
>
5853
{({ pressed }) => (
5954
<ReactionRoundedButton
6055
url={getEmoji(reaction.key).url}
6156
count={getReactionCount(reaction)}
62-
reacted={pressed || getUserReacted(reaction, currentUserId)}
57+
reacted={pressed || reaction.hasCurrentUserReacted}
6358
style={
6459
reactionAddonType === 'default'
6560
? [isNotLastOfRow && styles.marginRight, isNotLastOfCol && styles.marginBottom]
@@ -91,7 +86,7 @@ const MessageReactionAddon = ({
9186
reactionAddonType?: ReactionAddonType;
9287
}) => {
9388
const { colors } = useUIKitTheme();
94-
const { sdk, emojiManager, currentUser } = useSendbirdChat();
89+
const { sdk, emojiManager } = useSendbirdChat();
9590
const { openReactionList, openReactionUserList } = useReaction();
9691
const forceUpdate = useForceUpdate();
9792

@@ -113,7 +108,6 @@ const MessageReactionAddon = ({
113108
emojiManager.allEmoji.length,
114109
() => openReactionList({ channel, message }),
115110
(focusIndex) => openReactionUserList({ channel, message, focusIndex }),
116-
currentUser?.userId,
117111
reactionAddonType,
118112
);
119113

packages/uikit-react-native/src/components/ReactionBottomSheets/ReactionUserListBottomSheet.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ReactionUserListBottomSheet = ({
2626
}: ReactionBottomSheetProps) => {
2727
const { width } = useWindowDimensions();
2828
const { bottom, left, right } = useSafeAreaInsets();
29-
const { colors } = useUIKitTheme();
29+
const { colors, select, palette } = useUIKitTheme();
3030

3131
const [tabIndex, setTabIndex] = useState(0);
3232
const scrollRef = useRef<ScrollView>();
@@ -123,9 +123,11 @@ const ReactionUserListBottomSheet = ({
123123
};
124124

125125
const renderPage = () => {
126+
const userCountDifference = (focusedReaction?.count || 0) - (focusedReaction?.sampledUserIds.length || 0);
127+
126128
return (
127129
<>
128-
{focusedReaction?.userIds.map((userId) => {
130+
{focusedReaction?.sampledUserIds.map((userId) => {
129131
if (channel?.isGroupChannel()) {
130132
const user = channel.members.find((x) => x.userId === userId);
131133
return (
@@ -148,6 +150,13 @@ const ReactionUserListBottomSheet = ({
148150
}
149151
return null;
150152
})}
153+
{userCountDifference > 0 && (
154+
<View style={styles.pageItem}>
155+
<Text body3 color={select({ dark: palette.onBackgroundDark02, light: palette.onBackgroundLight02 })}>
156+
And {userCountDifference} others
157+
</Text>
158+
</View>
159+
)}
151160
</>
152161
);
153162
};

packages/uikit-react-native/src/contexts/ReactionCtx.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ export const ReactionProvider = ({ children, onPressUserProfile }: Props) => {
4646

4747
const openReactionUserList: ReactionContextType['openReactionUserList'] = useCallback(
4848
({ channel, message, focusIndex = 0 }) => {
49-
// NOTE: We don't support reaction user list for supergroup channel
50-
if (channel.isGroupChannel() && channel.isSuper) return;
5149

5250
setState({ channel, message });
5351
setReactionUserListFocusIndex(focusIndex);

packages/uikit-react-native/src/domain/groupChannelThread/component/GroupChannelThreadParentMessageInfo.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const GroupChannelThreadParentMessageInfo = (props: GroupChannelThreadProps['Par
9494

9595
const renderReactionAddons = () => {
9696
const configs = sbOptions.uikitWithAppInfo.groupChannel.channel;
97-
if (shouldRenderReaction(channel, channel.isSuper ? configs.enableReactionsSupergroup : configs.enableReactions)) {
97+
if (shouldRenderReaction(channel, configs.enableReactions)) {
9898
return (
9999
<View style={styles.reactionButtonContainer}>
100100
<ReactionAddons.Message
@@ -302,10 +302,7 @@ const useCreateMessagePressActions = ({
302302
const configs = sbOptions.uikitWithAppInfo.groupChannel.channel;
303303
const bottomSheetItem: BottomSheetItem = {
304304
sheetItems,
305-
HeaderComponent: shouldRenderReaction(
306-
channel,
307-
channel.isGroupChannel() && (channel.isSuper ? configs.enableReactionsSupergroup : configs.enableReactions),
308-
)
305+
HeaderComponent: shouldRenderReaction(channel, channel.isGroupChannel() && configs.enableReactions)
309306
? ({ onClose }) => <ReactionAddons.BottomSheet message={message} channel={channel} onClose={onClose} />
310307
: undefined,
311308
};

packages/uikit-utils/src/sendbird/message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabl
159159
}
160160

161161
export function getReactionCount(reaction: SendbirdReaction) {
162-
return reaction.userIds.length;
162+
return reaction.count;
163163
}
164164

165165
export type MessageType =

0 commit comments

Comments
 (0)