Skip to content

Commit

Permalink
feat: support options for ogtag in channel
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed May 16, 2023
1 parent abac6b2 commit d80b8a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import type { SendbirdUserMessage } from '@sendbird/uikit-utils';

import { useSendbirdChat } from '../../../hooks/useContext';
import type { MessageRendererInterface } from '../index';
import BaseUserMessage from './BaseUserMessage';
import OpenGraphUserMessage from './OpenGraphUserMessage';
Expand All @@ -15,7 +16,8 @@ export type UserMessageProps = MessageRendererInterface<
>;

const UserMessage = (props: UserMessageProps) => {
if (props.message.ogMetaData) {
const { features } = useSendbirdChat();
if (props.message.ogMetaData && features.groupChannelOGTagEnabled) {
return <OpenGraphUserMessage {...props} ogMetaData={props.message.ogMetaData} />;
}
return <BaseUserMessage {...props} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@sendbird/uikit-utils';

import type { OpenChannelProps } from '../../domain/openChannel/types';
import { useLocalization, usePlatformService } from '../../hooks/useContext';
import { useLocalization, usePlatformService, useSendbirdChat } from '../../hooks/useContext';
import SBUUtils from '../../libs/SBUUtils';
import OpenChannelMessageDateSeparator from './OpenChannelMessageDateSeparator';

Expand All @@ -26,6 +26,7 @@ const OpenChannelMessageRenderer: OpenChannelProps['Fragment']['renderMessage']
prevMessage,
nextMessage,
}) => {
const { features } = useSendbirdChat();
const { STRINGS } = useLocalization();
const { mediaService } = usePlatformService();
const { groupWithPrev } = calcMessageGrouping(Boolean(enableMessageGrouping), message, prevMessage, nextMessage);
Expand Down Expand Up @@ -55,7 +56,11 @@ const OpenChannelMessageRenderer: OpenChannelProps['Fragment']['renderMessage']
return <OpenChannelMessage.User message={message as SendbirdUserMessage} {...messageProps} />;
}
case 'user.opengraph': {
return <OpenChannelMessage.OpenGraphUser message={message as SendbirdUserMessage} {...messageProps} />;
if (features.openChannelOGTagEnabled) {
return <OpenChannelMessage.OpenGraphUser message={message as SendbirdUserMessage} {...messageProps} />;
} else {
return <OpenChannelMessage.User message={message as SendbirdUserMessage} {...messageProps} />;
}
}
case 'file':
case 'file.audio': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const SendbirdUIKit = Object.freeze({
USER_MENTION: false,
IMAGE_COMPRESSION: true,
MESSAGE_SEARCH: false,
GROUP_CHANNEL_OG_TAG: true,
OPEN_CHANNEL_OG_TAG: true,
},
});

Expand Down Expand Up @@ -208,6 +210,8 @@ const SendbirdUIKitContainer = ({
enableUserMention={chatOptions?.enableUserMention ?? SendbirdUIKit.DEFAULT.USER_MENTION}
enableImageCompression={chatOptions?.enableImageCompression ?? SendbirdUIKit.DEFAULT.IMAGE_COMPRESSION}
enableMessageSearch={chatOptions?.enableMessageSearch ?? SendbirdUIKit.DEFAULT.MESSAGE_SEARCH}
enableGroupChannelOGTag={chatOptions?.enableGroupChannelOGTag ?? SendbirdUIKit.DEFAULT.GROUP_CHANNEL_OG_TAG}
enableOpenChannelOGTag={chatOptions?.enableOpenChannelOGTag ?? SendbirdUIKit.DEFAULT.OPEN_CHANNEL_OG_TAG}
>
<LocalizationProvider stringSet={defaultStringSet}>
<PlatformServiceProvider
Expand Down
8 changes: 8 additions & 0 deletions packages/uikit-react-native/src/contexts/SendbirdChatCtx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface UIKitFeaturesInSendbirdChatContext {
enableUserMention: boolean;
enableImageCompression: boolean;
enableMessageSearch: boolean;
enableGroupChannelOGTag: boolean;
enableOpenChannelOGTag: boolean;
}

interface Props extends UIKitFeaturesInSendbirdChatContext, React.PropsWithChildren {
Expand Down Expand Up @@ -54,6 +56,8 @@ export type SendbirdChatContextType = {
userMentionEnabled: boolean;
imageCompressionEnabled: boolean;
messageSearchEnabled: boolean;
groupChannelOGTagEnabled: boolean;
openChannelOGTagEnabled: boolean;

// Sendbird application features
deliveryReceiptEnabled: boolean;
Expand All @@ -77,6 +81,8 @@ export const SendbirdChatProvider = ({
enableUserMention,
enableImageCompression,
enableMessageSearch,
enableGroupChannelOGTag,
enableOpenChannelOGTag,
}: Props) => {
const [currentUser, _setCurrentUser] = useState<SendbirdUser>();
const forceUpdate = useForceUpdate();
Expand Down Expand Up @@ -153,6 +159,8 @@ export const SendbirdChatProvider = ({
userMentionEnabled: enableUserMention,
imageCompressionEnabled: enableImageCompression,
messageSearchEnabled: enableMessageSearch,
groupChannelOGTagEnabled: enableGroupChannelOGTag,
openChannelOGTagEnabled: enableOpenChannelOGTag,
},
};

Expand Down

0 comments on commit d80b8a0

Please sign in to comment.