2022-01-26 23:05:26 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-05-28 16:15:17 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { CSSProperties } from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import type { ConversationColorType } from '../types/Colors';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
2022-01-26 23:05:26 +00:00
|
|
|
import { formatTime } from '../util/timestamp';
|
2021-05-28 16:15:17 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
backgroundStyle?: CSSProperties;
|
|
|
|
color?: ConversationColorType;
|
|
|
|
i18n: LocalizerType;
|
|
|
|
includeAnotherBubble?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
const A_FEW_DAYS_AGO = 60 * 60 * 24 * 5 * 1000;
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
function SampleMessage({
|
2021-05-28 16:15:17 +00:00
|
|
|
color = 'ultramarine',
|
|
|
|
direction,
|
|
|
|
i18n,
|
|
|
|
text,
|
2022-03-03 20:23:10 +00:00
|
|
|
timestampDeltaFromNow,
|
2021-05-28 16:15:17 +00:00
|
|
|
status,
|
|
|
|
style,
|
|
|
|
}: {
|
|
|
|
color?: ConversationColorType;
|
|
|
|
direction: 'incoming' | 'outgoing';
|
|
|
|
i18n: LocalizerType;
|
|
|
|
text: string;
|
2022-03-03 20:23:10 +00:00
|
|
|
timestampDeltaFromNow: number;
|
2021-05-28 16:15:17 +00:00
|
|
|
status: 'delivered' | 'read' | 'sent';
|
|
|
|
style?: CSSProperties;
|
2022-11-18 00:45:19 +00:00
|
|
|
}): JSX.Element {
|
|
|
|
return (
|
|
|
|
<div className={`module-message module-message--${direction}`}>
|
|
|
|
<div className="module-message__container-outer">
|
2021-05-28 16:15:17 +00:00
|
|
|
<div
|
2022-11-18 00:45:19 +00:00
|
|
|
className={`module-message__container module-message__container--${direction} module-message__container--${direction}-${color}`}
|
|
|
|
style={style}
|
2021-05-28 16:15:17 +00:00
|
|
|
>
|
2022-11-18 00:45:19 +00:00
|
|
|
<div
|
|
|
|
dir="auto"
|
|
|
|
className={`module-message__text module-message__text--${direction}`}
|
2021-05-28 16:15:17 +00:00
|
|
|
>
|
2022-11-18 00:45:19 +00:00
|
|
|
<span>{text}</span>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className={`module-message__metadata module-message__metadata--${direction}`}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
className={`module-message__metadata__date module-message__metadata__date--${direction}`}
|
|
|
|
>
|
|
|
|
{formatTime(i18n, Date.now() - timestampDeltaFromNow, Date.now())}
|
|
|
|
</span>
|
|
|
|
{direction === 'outgoing' && (
|
|
|
|
<div
|
|
|
|
className={`module-message__metadata__status-icon module-message__metadata__status-icon--${status}`}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-05-28 16:15:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-18 00:45:19 +00:00
|
|
|
);
|
|
|
|
}
|
2021-05-28 16:15:17 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function SampleMessageBubbles({
|
2021-05-28 16:15:17 +00:00
|
|
|
backgroundStyle = {},
|
|
|
|
color,
|
|
|
|
i18n,
|
|
|
|
includeAnotherBubble = false,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2021-05-28 16:15:17 +00:00
|
|
|
const firstBubbleStyle = includeAnotherBubble ? backgroundStyle : undefined;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<SampleMessage
|
|
|
|
color={color}
|
|
|
|
direction={includeAnotherBubble ? 'outgoing' : 'incoming'}
|
|
|
|
i18n={i18n}
|
|
|
|
text={i18n('ChatColorPicker__sampleBubble1')}
|
2022-03-03 20:23:10 +00:00
|
|
|
timestampDeltaFromNow={A_FEW_DAYS_AGO}
|
2021-05-28 16:15:17 +00:00
|
|
|
status="read"
|
|
|
|
style={firstBubbleStyle}
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
{includeAnotherBubble ? (
|
|
|
|
<>
|
|
|
|
<br style={{ clear: 'both' }} />
|
|
|
|
<br />
|
|
|
|
<SampleMessage
|
|
|
|
direction="incoming"
|
|
|
|
i18n={i18n}
|
|
|
|
text={i18n('ChatColorPicker__sampleBubble2')}
|
2022-03-03 20:23:10 +00:00
|
|
|
timestampDeltaFromNow={A_FEW_DAYS_AGO / 2}
|
2021-05-28 16:15:17 +00:00
|
|
|
status="read"
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
<SampleMessage
|
|
|
|
color={color}
|
|
|
|
direction="outgoing"
|
|
|
|
i18n={i18n}
|
|
|
|
text={i18n('ChatColorPicker__sampleBubble3')}
|
2022-03-03 20:23:10 +00:00
|
|
|
timestampDeltaFromNow={0}
|
2021-05-28 16:15:17 +00:00
|
|
|
status="delivered"
|
|
|
|
style={backgroundStyle}
|
|
|
|
/>
|
|
|
|
<br style={{ clear: 'both' }} />
|
|
|
|
</>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|