2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-09-27 21:23:52 +00:00
|
|
|
import { last } from 'lodash';
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo } from 'react';
|
2023-09-18 21:17:26 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
2023-09-27 21:23:52 +00:00
|
|
|
import { TypingBubble } from '../../components/conversation/TypingBubble';
|
2023-09-18 21:17:26 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
2021-11-15 20:01:58 +00:00
|
|
|
import { getIntl, getTheme } from '../selectors/user';
|
2024-02-27 16:01:25 +00:00
|
|
|
import { useTimelineItem } from '../selectors/timeline';
|
2023-09-27 21:23:52 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
getConversationMessagesSelector,
|
|
|
|
} from '../selectors/conversations';
|
2021-11-15 20:01:58 +00:00
|
|
|
import { getPreferredBadgeSelector } from '../selectors/badges';
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
type ExternalProps = {
|
2023-09-18 21:17:26 +00:00
|
|
|
conversationId: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartTypingBubble = memo(function SmartTypingBubble({
|
2023-09-27 21:23:52 +00:00
|
|
|
conversationId,
|
|
|
|
}: ExternalProps): JSX.Element {
|
2023-09-18 21:17:26 +00:00
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
const getConversation = useSelector(getConversationSelector);
|
|
|
|
const conversation = getConversation(conversationId);
|
2019-05-31 22:42:01 +00:00
|
|
|
if (!conversation) {
|
2023-09-18 21:17:26 +00:00
|
|
|
throw new Error(`Did not find conversation ${conversationId} in state!`);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 21:23:52 +00:00
|
|
|
const typingContactIdTimestamps =
|
|
|
|
conversation.typingContactIdTimestamps ?? {};
|
|
|
|
const conversationMessages = useSelector(getConversationMessagesSelector)(
|
|
|
|
conversationId
|
2023-09-18 21:17:26 +00:00
|
|
|
);
|
2023-09-27 21:23:52 +00:00
|
|
|
const lastMessageId = last(conversationMessages.items);
|
2024-02-27 16:01:25 +00:00
|
|
|
const lastItem = useTimelineItem(lastMessageId, conversationId);
|
2023-09-27 21:23:52 +00:00
|
|
|
let lastItemAuthorId: string | undefined;
|
|
|
|
let lastItemTimestamp: number | undefined;
|
|
|
|
if (lastItem?.data) {
|
|
|
|
if ('author' in lastItem.data) {
|
|
|
|
lastItemAuthorId = lastItem.data.author?.id;
|
|
|
|
}
|
2023-11-04 00:55:12 +00:00
|
|
|
if ('receivedAtMS' in lastItem.data) {
|
|
|
|
lastItemTimestamp = lastItem.data.receivedAtMS;
|
2023-09-27 21:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 21:17:26 +00:00
|
|
|
|
|
|
|
const { showContactModal } = useGlobalModalActions();
|
2023-09-27 21:23:52 +00:00
|
|
|
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
|
2023-09-18 21:17:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TypingBubble
|
|
|
|
conversationId={conversationId}
|
|
|
|
conversationType={conversation.type}
|
2023-09-27 21:23:52 +00:00
|
|
|
typingContactIdTimestamps={typingContactIdTimestamps}
|
|
|
|
lastItemAuthorId={lastItemAuthorId}
|
|
|
|
lastItemTimestamp={lastItemTimestamp}
|
2023-09-18 21:17:26 +00:00
|
|
|
i18n={i18n}
|
|
|
|
theme={theme}
|
2023-09-27 21:23:52 +00:00
|
|
|
getConversation={getConversation}
|
|
|
|
getPreferredBadge={getPreferredBadge}
|
|
|
|
showContactModal={showContactModal}
|
2023-09-18 21:17:26 +00:00
|
|
|
/>
|
|
|
|
);
|
2024-03-13 20:44:13 +00:00
|
|
|
});
|