Show dates in edit history modal

This commit is contained in:
Josh Perez 2023-06-26 18:45:56 -04:00 committed by GitHub
parent 9c6fb29edb
commit 8507afd0e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 35 deletions

View file

@ -13,6 +13,8 @@ import { Modal } from './Modal';
import { WidthBreakpoint } from './_util'; import { WidthBreakpoint } from './_util';
import { shouldNeverBeCalled } from '../util/shouldNeverBeCalled'; import { shouldNeverBeCalled } from '../util/shouldNeverBeCalled';
import { useTheme } from '../hooks/useTheme'; import { useTheme } from '../hooks/useTheme';
import { isSameDay } from '../util/timestamp';
import { TimelineDateHeader } from './conversation/TimelineDateHeader';
export type PropsType = { export type PropsType = {
closeEditHistoryModal: () => unknown; closeEditHistoryModal: () => unknown;
@ -55,7 +57,7 @@ const MESSAGE_DEFAULT_PROPS = {
scrollToQuotedMessage: shouldNeverBeCalled, scrollToQuotedMessage: shouldNeverBeCalled,
shouldCollapseAbove: false, shouldCollapseAbove: false,
shouldCollapseBelow: false, shouldCollapseBelow: false,
shouldHideMetadata: true, shouldHideMetadata: false,
showContactModal: shouldNeverBeCalled, showContactModal: shouldNeverBeCalled,
showConversation: noop, showConversation: noop,
showEditHistoryModal: shouldNeverBeCalled, showEditHistoryModal: shouldNeverBeCalled,
@ -144,10 +146,27 @@ export function EditHistoryMessagesModal({
{i18n('icu:EditHistoryMessagesModal__title')} {i18n('icu:EditHistoryMessagesModal__title')}
</h3> </h3>
{pastEdits.map(messageAttributes => { {pastEdits.map((messageAttributes, index) => {
const syntheticId = `${messageAttributes.id}.${messageAttributes.timestamp}`; const syntheticId = `${messageAttributes.id}.${messageAttributes.timestamp}`;
const previousItem = pastEdits[index - 1];
const shouldShowDateHeader = Boolean(
!previousItem ||
// This comparison avoids strange header behavior for out-of-order messages.
(messageAttributes.timestamp > previousItem.timestamp &&
!isSameDay(previousItem.timestamp, messageAttributes.timestamp))
);
const dateHeaderElement = shouldShowDateHeader ? (
<TimelineDateHeader
i18n={i18n}
timestamp={messageAttributes.timestamp}
/>
) : null;
return ( return (
<React.Fragment key={messageAttributes.timestamp}>
{dateHeaderElement}
<Message <Message
{...MESSAGE_DEFAULT_PROPS} {...MESSAGE_DEFAULT_PROPS}
{...messageAttributes} {...messageAttributes}
@ -157,7 +176,6 @@ export function EditHistoryMessagesModal({
getPreferredBadge={getPreferredBadge} getPreferredBadge={getPreferredBadge}
i18n={i18n} i18n={i18n}
isSpoilerExpanded={revealedSpoilersById[syntheticId] || {}} isSpoilerExpanded={revealedSpoilersById[syntheticId] || {}}
key={messageAttributes.timestamp}
kickOffAttachmentDownload={kickOffAttachmentDownload} kickOffAttachmentDownload={kickOffAttachmentDownload}
messageExpanded={(messageId, displayLimit) => { messageExpanded={(messageId, displayLimit) => {
const update = { const update = {
@ -177,6 +195,7 @@ export function EditHistoryMessagesModal({
}} }}
theme={theme} theme={theme}
/> />
</React.Fragment>
); );
})} })}
</div> </div>

View file

@ -142,14 +142,14 @@ export function MessageMetadata({
} else { } else {
timestampNode = ( timestampNode = (
<MessageTimestamp <MessageTimestamp
i18n={i18n}
timestamp={timestamp}
direction={metadataDirection}
deletedForEveryone={deletedForEveryone} deletedForEveryone={deletedForEveryone}
direction={metadataDirection}
i18n={i18n}
module="module-message__metadata__date"
timestamp={timestamp}
withImageNoCaption={withImageNoCaption} withImageNoCaption={withImageNoCaption}
withSticker={isSticker} withSticker={isSticker}
withTapToViewExpired={isTapToViewExpired} withTapToViewExpired={isTapToViewExpired}
module="module-message__metadata__date"
/> />
); );
} }

View file

@ -39,7 +39,7 @@ export function SmartEditHistoryMessagesModal(): JSX.Element {
return messagesAttributes.map(messageAttributes => ({ return messagesAttributes.map(messageAttributes => ({
...messagePropsSelector(messageAttributes as MessageAttributesType), ...messagePropsSelector(messageAttributes as MessageAttributesType),
// Make sure the messages don't get an "edited" badge // Make sure the messages don't get an "edited" badge
editHistory: undefined, isEditedMessage: false,
// Do not show the same reactions in the message history UI // Do not show the same reactions in the message history UI
reactions: undefined, reactions: undefined,
})); }));