From 0cacb99ee175cca7546154d70448c4ff5b48a169 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 30 Apr 2024 23:13:19 +0100 Subject: [PATCH 1/2] separate msg groups by age --- .../Messages/Conversation/MessageItem.tsx | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/screens/Messages/Conversation/MessageItem.tsx b/src/screens/Messages/Conversation/MessageItem.tsx index 688c4244a5..5b6ddfba4e 100644 --- a/src/screens/Messages/Conversation/MessageItem.tsx +++ b/src/screens/Messages/Conversation/MessageItem.tsx @@ -1,4 +1,4 @@ -import React, {useCallback} from 'react' +import React, {useCallback, useMemo} from 'react' import {StyleProp, TextStyle, View} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -25,7 +25,26 @@ export function MessageItem({ TempDmChatDefs.isMessageView(next) && next.sender?.did === getAgent().session?.did - const isLastInGroup = !next || isFromSelf ? !isNextFromSelf : isNextFromSelf + const isLastInGroup = useMemo(() => { + const followedByOther = + !next || isFromSelf ? !isNextFromSelf : isNextFromSelf + + if (followedByOther) { + return true + } + + if (TempDmChatDefs.isMessageView(next)) { + const thisDate = new Date(item.sentAt) + const nextDate = new Date(next.sentAt) + + const diff = nextDate.getTime() - thisDate.getTime() + + // 10 minutes + return diff > 10 * 60 * 1000 + } + + return true + }, [item, next, isFromSelf, isNextFromSelf]) return ( From d2568349645419cf3c421112c609f34230ff9370 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 30 Apr 2024 23:16:16 +0100 Subject: [PATCH 2/2] clean up logic and add comments --- src/screens/Messages/Conversation/MessageItem.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/screens/Messages/Conversation/MessageItem.tsx b/src/screens/Messages/Conversation/MessageItem.tsx index 5b6ddfba4e..72f74c29bf 100644 --- a/src/screens/Messages/Conversation/MessageItem.tsx +++ b/src/screens/Messages/Conversation/MessageItem.tsx @@ -26,13 +26,12 @@ export function MessageItem({ next.sender?.did === getAgent().session?.did const isLastInGroup = useMemo(() => { - const followedByOther = - !next || isFromSelf ? !isNextFromSelf : isNextFromSelf - - if (followedByOther) { + // if the next message is from a different sender, then it's the last in the group + if (isFromSelf ? !isNextFromSelf : isNextFromSelf) { return true } + // or, if there's a 10 minute gap between this message and the next if (TempDmChatDefs.isMessageView(next)) { const thisDate = new Date(item.sentAt) const nextDate = new Date(next.sentAt)