Skip to content

Commit

Permalink
Merge pull request #55 from sendbird/fix/profile-invisible
Browse files Browse the repository at this point in the history
fix: make profile img invisible only when consecutive msg senders are same
  • Loading branch information
AhyoungRyu authored Sep 11, 2023
2 parents 636f8a5 + 7fab34b commit 4a93c29
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ export function groupMessagesByShortSpanTime(
messages: EveryMessage[]
): EveryMessage[] {
// Create an object to group messages based on their creation time
const groupedMessagesByCreatedAt = messages.reduce((groups, message) => {
const { createdAt } = message;
const groupedMessagesByCreatedAt = messages.reduce((groups, message, idx) => {
const { createdAt, sender, messageType } = message;
// Get the key of the previous group
const prevKey = Object.keys(groups)[Object.keys(groups).length - 1];

// Check if the time difference between the current message and the previous one is within 3 minutes
if (prevKey && message.createdAt - Number(prevKey) <= TIME_SPAN) {
if (
prevKey &&
createdAt - Number(prevKey) <= TIME_SPAN &&
messageType !== 'admin' &&
sender?.userId === messages[idx - 1]?.sender.userId
) {
// Add the message to the existing group
return {
...groups,
Expand Down

0 comments on commit 4a93c29

Please sign in to comment.