Skip to content

Commit

Permalink
fix(CLNP-983): display a message unavailable text if the message is n…
Browse files Browse the repository at this point in the history
…ot accessible
  • Loading branch information
bang9 committed Nov 3, 2023
1 parent e9d545c commit e38512a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@sendbird/uikit-react-native-foundation';
import {
SendbirdFileMessage,
SendbirdGroupChannel,
SendbirdMessage,
SendbirdUserMessage,
getFileIconFromMessageType,
Expand All @@ -26,12 +27,13 @@ import { useLocalization, usePlatformService, useSendbirdChat } from '../../hook

type Props = {
variant: 'outgoing' | 'incoming';
channel: SendbirdGroupChannel;
message: SendbirdUserMessage | SendbirdFileMessage;
childMessage: SendbirdUserMessage | SendbirdFileMessage;
onPress?: (message: SendbirdMessage) => void;
};

const GroupChannelMessageParentMessage = ({ variant, message, childMessage, onPress }: Props) => {
const GroupChannelMessageParentMessage = ({ variant, channel, message, childMessage, onPress }: Props) => {
const { currentUser } = useSendbirdChat();
const groupChannelPubSub = useContext(GroupChannelContexts.PubSub);
const { select, colors, palette } = useUIKitTheme();
Expand Down Expand Up @@ -98,6 +100,10 @@ const GroupChannelMessageParentMessage = ({ variant, message, childMessage, onPr
};

const parentMessageComponent = useIIFE(() => {
if (channel.messageOffsetTimestamp > parentMessage.createdAt) {
return renderMessageWithText(STRINGS.LABELS.MESSAGE_UNAVAILABLE);
}

switch (type) {
case 'user':
case 'user.opengraph': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ const GroupChannelMessageRenderer: GroupChannelProps['Fragment']['renderMessage'
) : null,
parentMessage: shouldRenderParentMessage(message) ? (
<GroupChannelMessageParentMessage
channel={channel}
message={message.parentMessage}
variant={variant}
childMessage={message}
message={message.parentMessage}
onPress={onPressParentMessage}
/>
) : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export interface StringSet {
parentMessage: SendbirdUserMessage | SendbirdFileMessage,
currentUserId?: string,
) => string;
MESSAGE_UNAVAILABLE: string;

USER_BAR_ME_POSTFIX: string;
USER_BAR_OPERATOR: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export const createBaseStringSet = ({ dateLocale, overrides }: StringSetCreateOp
const receiverNickname = parent.sender.nickname || USER_NO_NAME;
return `${reply.sender.userId !== currentUserId ? senderNickname : 'You'} replied to ${receiverNickname}`;
},
MESSAGE_UNAVAILABLE: 'Message unavailable',

USER_BAR_ME_POSTFIX: ' (You)',
USER_BAR_OPERATOR: 'Operator',
Expand Down
4 changes: 2 additions & 2 deletions sample/src/screens/uikit/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const SettingsScreen = () => {

if (!photo) return;

await updateCurrentUserInfo(sdk.currentUser.nickname, photo);
await updateCurrentUserInfo(sdk.currentUser?.nickname, photo);
},
},
{
Expand All @@ -106,7 +106,7 @@ const SettingsScreen = () => {
});
if (!files || !files[0]) return;

await updateCurrentUserInfo(sdk.currentUser.nickname, files[0]);
await updateCurrentUserInfo(sdk.currentUser?.nickname, files[0]);
},
},
],
Expand Down

0 comments on commit e38512a

Please sign in to comment.