Skip to content

Commit

Permalink
feat(group behavior): modify message grouping behavior AP-107
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick committed Dec 2, 2021
1 parent 518a474 commit a175eb2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions utilities/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ export function groupMessages(
? dayjs(currentMessage.at).isSame(prevMessage.at, 'day')
: false

let isSameGroup
if (!prevMessage) {
isSameGroup = false
} else {
const currentAt = dayjs(currentMessage.at)
const prevAt = dayjs(prevMessage.at)
if (!dayjs().isSame(currentAt, 'day')) {
isSameGroup = currentAt.isSame(prevAt, 'day')
} else {
const prevAt = dayjs(prevMessage.at)
isSameGroup = currentAt.diff(prevAt, 'minutes') < 15 ? true : false
}
}

// Eventually place a divider if the day changes
if (!isSameDay) {
groupedMessages.push({
Expand All @@ -82,7 +96,7 @@ export function groupMessages(
groupedMessages.length === 0 ||
groupOrDivider?.type === 'divider' ||
!isSameSender ||
(prevMessage && !isSameDay)
(prevMessage && !isSameGroup)

if (isNewGroup) {
groupedMessages.push({
Expand Down Expand Up @@ -187,8 +201,8 @@ export function getUsernameFromState(
const username = isMe
? accountDetails.name
: state.friends.all.find(
(friend) => friend.textilePubkey === textilePublicKey
)?.name || 'unknown'
(friend) => friend.textilePubkey === textilePublicKey
)?.name || 'unknown'

return username
}
Expand Down

0 comments on commit a175eb2

Please sign in to comment.