Skip to content

Commit

Permalink
fix: Fix bug where timestamp is not grouped when welcome message given (
Browse files Browse the repository at this point in the history
#252)

### Changelog
- Fixed a bug where timestamp is not grouped when should be if welcome
messages are injected

### Ticket
- https://sendbird.atlassian.net/browse/AC-2500
  • Loading branch information
liamcho authored May 29, 2024
1 parent 84ee0ed commit 696125e
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/components/CustomChannelComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
} from '../utils';
import {
getBotWelcomeMessages,
getSenderUserIdFromMessage,
groupMessagesByShortSpanTime,
isSentBy,
isStaticReplyVisible as getStaticMessageVisibility,
Expand Down Expand Up @@ -228,6 +229,16 @@ export function CustomChannelComponent() {
botWelcomeMessages[botWelcomeMessages.length - 1];
const lastWelcomeMessageCreatedAt = lastBotWelcomeMessage?.createdAt;
const isWelcomeMessagesGiven = welcomeMessages && welcomeMessages.length > 0;
const firstUserMessage = allMessages.find(
(message) => getSenderUserIdFromMessage(message) !== botId
);
/**
* Injected welcome messages should have timestamp set to either:
* 1. last real welcome message createdAt.
* 2. first message of the channel. This is because welcome message should have timestamp <= of first message.
*/
const welcomeMessageTimeStamp =
lastWelcomeMessageCreatedAt ?? firstMessageCreatedAt;

return (
<Root height={'100%'} isStaticReplyVisible={isStaticReplyVisible}>
Expand Down Expand Up @@ -260,9 +271,7 @@ export function CustomChannelComponent() {
showSuggestedReplies={
lastMessage?.messageId === lastBotWelcomeMessage?.messageId
}
timestamp={
lastWelcomeMessageCreatedAt ?? firstMessageCreatedAt
}
timestamp={welcomeMessageTimeStamp}
/>
)
: undefined
Expand All @@ -289,10 +298,18 @@ export function CustomChannelComponent() {
);

let hasSeparator = props.hasSeparator;
const prevMessageTimestamp =
lastWelcomeMessageCreatedAt ?? firstMessageCreatedAt;
if (isWelcomeMessagesGiven && prevMessageTimestamp) {
hasSeparator = !isSameDay(message.createdAt, prevMessageTimestamp);
/**
* For first user message, if welcome message is given and timestamps are different
*/
if (
isWelcomeMessagesGiven &&
welcomeMessageTimeStamp &&
message.messageId === firstUserMessage?.messageId
) {
hasSeparator = !isSameDay(
message.createdAt,
welcomeMessageTimeStamp
);
}

return (
Expand Down

0 comments on commit 696125e

Please sign in to comment.