@ethora/chat-component-rn 26.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +148 -0
- package/empty-shim.js +15 -0
- package/index.js +13 -0
- package/metro.js +72 -0
- package/package.json +99 -0
- package/src/api.config.ts +34 -0
- package/src/assets/BG.png +0 -0
- package/src/assets/BG.tsx +56 -0
- package/src/assets/File.svg +4 -0
- package/src/assets/ForzaCare.png +0 -0
- package/src/assets/ForzaCare.tsx +27 -0
- package/src/assets/icons.tsx +685 -0
- package/src/assets/images.tsx +41 -0
- package/src/assets/test.xml +243 -0
- package/src/components/AuthForms/Login.tsx +295 -0
- package/src/components/AuthForms/LoginAnonym.tsx +68 -0
- package/src/components/AuthForms/Register.tsx +8 -0
- package/src/components/ContextMenu/ContextMenuComponents.tsx +87 -0
- package/src/components/DropdownMenu/DropdownMenu.tsx +244 -0
- package/src/components/ExampleComponents/CustomMessage.tsx +92 -0
- package/src/components/ExampleComponents/CustomTypingIndicatorExamples.tsx +239 -0
- package/src/components/Header/HeaderRoomList.tsx +104 -0
- package/src/components/InputComponents/AudioInput.tsx +24 -0
- package/src/components/InputComponents/AudioRecorder.tsx +100 -0
- package/src/components/InputComponents/MediaInput.tsx +114 -0
- package/src/components/InputComponents/RecordingIndicator.tsx +77 -0
- package/src/components/InputComponents/Search.tsx +135 -0
- package/src/components/InputComponents/TextInput.tsx +66 -0
- package/src/components/MainComponents/ChatHeader.tsx +163 -0
- package/src/components/MainComponents/ChatRoom.tsx +392 -0
- package/src/components/MainComponents/ChatWrapper.tsx +318 -0
- package/src/components/MainComponents/ChooseChatMessage.tsx +44 -0
- package/src/components/MainComponents/ConnectionBanner.tsx +33 -0
- package/src/components/MainComponents/EditWrapper.tsx +72 -0
- package/src/components/MainComponents/LoginWrapper.tsx +134 -0
- package/src/components/MainComponents/MediaMessage.tsx +55 -0
- package/src/components/MainComponents/MessageContainer.tsx +122 -0
- package/src/components/MainComponents/MessageList.tsx +429 -0
- package/src/components/MainComponents/NoMessagesPlaceholder.tsx +49 -0
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +143 -0
- package/src/components/MainComponents/RNStyled.tsx +34 -0
- package/src/components/MainComponents/ReduxWrapper.tsx +40 -0
- package/src/components/MainComponents/RoomList.tsx +246 -0
- package/src/components/MainComponents/Select.tsx +165 -0
- package/src/components/MainComponents/Switch.tsx +73 -0
- package/src/components/MainComponents/SystemMessage.tsx +42 -0
- package/src/components/Menu/HeaderRoomListMenu.tsx +169 -0
- package/src/components/MenuRoom/MenuRoom.tsx +46 -0
- package/src/components/MessageBubble/Avatar.tsx +84 -0
- package/src/components/MessageBubble/BottomReplyContainer.tsx +117 -0
- package/src/components/MessageBubble/CustomDivider.tsx +10 -0
- package/src/components/MessageBubble/DeletedMessage.tsx +36 -0
- package/src/components/MessageBubble/Message.tsx +400 -0
- package/src/components/MessageBubble/MessageInteractions.tsx +247 -0
- package/src/components/MessageBubble/MessageReaction.tsx +149 -0
- package/src/components/MessageBubble/MessageReply.tsx +50 -0
- package/src/components/MessageBubble/MessageTranslations.tsx +30 -0
- package/src/components/Modals/AddMembersModal/AddMembersModal.tsx +142 -0
- package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +471 -0
- package/src/components/Modals/ChatProfileModal/DeleteChatModal.tsx +91 -0
- package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +298 -0
- package/src/components/Modals/Modal/Modal.tsx +52 -0
- package/src/components/Modals/ModalHeaderComponent.tsx +41 -0
- package/src/components/Modals/ModalSelectMedia/ModalSelectMedia.tsx +285 -0
- package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +103 -0
- package/src/components/Modals/NewChatModal/ModalContent.tsx +151 -0
- package/src/components/Modals/NewChatModal/NewChatModal.tsx +391 -0
- package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +136 -0
- package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +134 -0
- package/src/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.tsx +63 -0
- package/src/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.tsx +115 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/ManageDataModal.tsx +121 -0
- package/src/components/Modals/SettingsModals/ManageDataModal/StyledComponents.ts +0 -0
- package/src/components/Modals/SettingsModals/ProfileShares/ProfileShares.tsx +65 -0
- package/src/components/Modals/SettingsModals/Referrals/Referrals.tsx +90 -0
- package/src/components/Modals/SettingsModals/SharedStyledComponents.ts +74 -0
- package/src/components/Modals/SettingsModals/Visibility/RadioInput.tsx +59 -0
- package/src/components/Modals/SettingsModals/Visibility/StyledComponents.ts +32 -0
- package/src/components/Modals/SettingsModals/Visibility/VisibilityModal.tsx +146 -0
- package/src/components/Modals/UserProfileModal/EditUserModal.tsx +163 -0
- package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +410 -0
- package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +85 -0
- package/src/components/Modals/styledModalComponents.tsx +181 -0
- package/src/components/OperationalModal/OperationalModal.tsx +78 -0
- package/src/components/RoomComponents/ChatRoomItem.tsx +219 -0
- package/src/components/RoomComponents/LastMessageItem.tsx +47 -0
- package/src/components/RoomComponents/styled/LastAudioMessage.tsx +62 -0
- package/src/components/RoomComponents/styled/LastMessageEmoji.tsx +26 -0
- package/src/components/RoomComponents/styled/LastMessageFile.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +54 -0
- package/src/components/RoomComponents/styled/LastMessageVideo.tsx +70 -0
- package/src/components/RoomComponents/styled/LastTextMessage.tsx +65 -0
- package/src/components/RoomComponents/styled/StyledRoomComponents.ts +53 -0
- package/src/components/SortDropDown/index.tsx +76 -0
- package/src/components/Thread/ThreadHeader.tsx +41 -0
- package/src/components/Thread/ThreadWrapper.tsx +270 -0
- package/src/components/Toast/Toast.tsx +128 -0
- package/src/components/Toast/index.ts +13 -0
- package/src/components/UsersList/StyledComponents.ts +30 -0
- package/src/components/UsersList/UsersList.tsx +112 -0
- package/src/components/styled/ActionButton.tsx +40 -0
- package/src/components/styled/AudioMessage.tsx +82 -0
- package/src/components/styled/Button.tsx +107 -0
- package/src/components/styled/ChatWrapperBox.tsx +9 -0
- package/src/components/styled/DateLabel.tsx +77 -0
- package/src/components/styled/Loader.tsx +65 -0
- package/src/components/styled/MediaFilePreview.tsx +42 -0
- package/src/components/styled/MediaModal.tsx +54 -0
- package/src/components/styled/MessageImage.tsx +54 -0
- package/src/components/styled/NewMessageLabel.tsx +50 -0
- package/src/components/styled/RoomListComponents/index.tsx +164 -0
- package/src/components/styled/SendInput.tsx +297 -0
- package/src/components/styled/StyledComponents.ts +320 -0
- package/src/components/styled/StyledInput.tsx +101 -0
- package/src/components/styled/StyledInputComponents/AudioComponents.tsx +1 -0
- package/src/components/styled/StyledInputComponents/Composing.tsx +97 -0
- package/src/components/styled/StyledInputComponents/CustomTypingIndicator.tsx +261 -0
- package/src/components/styled/StyledInputComponents/MediaComponents.tsx +90 -0
- package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +131 -0
- package/src/components/styled/StyledInputComponents/VideoComponents.tsx +49 -0
- package/src/components/styled/TreadLabel.tsx +50 -0
- package/src/components/styled/UnsupportedType.tsx +95 -0
- package/src/components/styled/VideoMessage.tsx +68 -0
- package/src/context/MessageNotificationContext.tsx +335 -0
- package/src/context/PushNotificationProvider.tsx +78 -0
- package/src/context/ToastContext.tsx +63 -0
- package/src/context/toastProvider.tsx +0 -0
- package/src/context/xmppProvider.tsx +364 -0
- package/src/helpers/block_scroll.ts +95 -0
- package/src/helpers/chatAutoEnterer.ts +46 -0
- package/src/helpers/checkUniqueUsers.tsx +31 -0
- package/src/helpers/constants/CHAT_TYPES.ts +6 -0
- package/src/helpers/constants/LANGUAGE_OPTIONS.ts +14 -0
- package/src/helpers/constants/LOCAL_STORAGE.ts +3 -0
- package/src/helpers/constants/MESSAGE_INTERACTIONS.ts +29 -0
- package/src/helpers/constants/MODAL_TYPES.ts +57 -0
- package/src/helpers/constants/PLATFORM_CONSTANTS.ts +3 -0
- package/src/helpers/createMainMessageForThread.ts +23 -0
- package/src/helpers/createMessageFromXml.ts +118 -0
- package/src/helpers/createRoomFromApi.tsx +27 -0
- package/src/helpers/createUserNameFromSetUser.ts +15 -0
- package/src/helpers/dateComparison.ts +12 -0
- package/src/helpers/debounce.ts +10 -0
- package/src/helpers/ensureScopedChatCache.ts +61 -0
- package/src/helpers/extractUniqueMembersFromRooms.ts +45 -0
- package/src/helpers/formatNumberWithCommas.ts +3 -0
- package/src/helpers/getBooleanFromString.ts +7 -0
- package/src/helpers/getDataFromXml.ts +80 -0
- package/src/helpers/getNumberFromString.ts +5 -0
- package/src/helpers/getRoomsWithRetry.ts +45 -0
- package/src/helpers/getTintedColor.ts +28 -0
- package/src/helpers/getUnnamedUsers.ts +39 -0
- package/src/helpers/handleCopyClick.ts +3 -0
- package/src/helpers/handleXmppError.ts +14 -0
- package/src/helpers/hashcolor.ts +34 -0
- package/src/helpers/historyPreloadScheduler.ts +264 -0
- package/src/helpers/initRoomsPresence.ts +32 -0
- package/src/helpers/initXmppRooms.tsx +71 -0
- package/src/helpers/insertMessageWithDelimiter.ts +96 -0
- package/src/helpers/isChatIdPresentInArray.ts +54 -0
- package/src/helpers/localStorageUser.ts +9 -0
- package/src/helpers/markdownParser.tsx +295 -0
- package/src/helpers/nanoToMs.ts +3 -0
- package/src/helpers/parseMessageBody.tsx +516 -0
- package/src/helpers/parseUrls.tsx +42 -0
- package/src/helpers/resolveInitBeforeLoadUser.ts +240 -0
- package/src/helpers/storeConsole.ts +26 -0
- package/src/helpers/transformTranslatations.ts +16 -0
- package/src/helpers/updateMessagesTillLast.tsx +104 -0
- package/src/helpers/updatedChatLastTimestamps.ts +29 -0
- package/src/helpers/validator.ts +20 -0
- package/src/helpers/walletUsername.ts +12 -0
- package/src/hooks/hooks.ts +6 -0
- package/src/hooks/useChatSettingState.tsx +38 -0
- package/src/hooks/useChatWrapperInit.ts +266 -0
- package/src/hooks/useComposing.tsx +59 -0
- package/src/hooks/useCustomTypingIndicator.tsx +193 -0
- package/src/hooks/useEventHandlers.tsx +81 -0
- package/src/hooks/useGetNewArchRoom.tsx +57 -0
- package/src/hooks/useHeapSender.tsx +88 -0
- package/src/hooks/useLocalStorage.tsx +53 -0
- package/src/hooks/useLogout.tsx +31 -0
- package/src/hooks/useMessageHeapState.tsx +11 -0
- package/src/hooks/useMessageLoaderQueue.tsx +90 -0
- package/src/hooks/useMessageQueue.ts +146 -0
- package/src/hooks/usePendingNotification.ts +49 -0
- package/src/hooks/usePrevious.tsx +15 -0
- package/src/hooks/usePushNotifications.ts +106 -0
- package/src/hooks/useQRCodeChatHandler.ts +58 -0
- package/src/hooks/useRoomInitialization.tsx +160 -0
- package/src/hooks/useRoomState.tsx +47 -0
- package/src/hooks/useRoomUrl.tsx +41 -0
- package/src/hooks/useSendMessage.tsx +306 -0
- package/src/hooks/useUnreadMessagesCounter.ts +55 -0
- package/src/hooks/useXmppInitialization.ts +148 -0
- package/src/main.ts +45 -0
- package/src/networking/api-requests/auth.api.ts +140 -0
- package/src/networking/api-requests/push.api.ts +55 -0
- package/src/networking/api-requests/roomMembers.api.ts +20 -0
- package/src/networking/api-requests/rooms.api.ts +142 -0
- package/src/networking/api-requests/user.api.ts +65 -0
- package/src/networking/apiClient.ts +149 -0
- package/src/networking/helpers/refreshChecker.ts +13 -0
- package/src/networking/stanzaHandlers.ts +418 -0
- package/src/networking/xmpp/actionSetTimestampToPrivateStore.xmpp.ts +37 -0
- package/src/networking/xmpp/allRoomPresences.xmpp.ts +10 -0
- package/src/networking/xmpp/createPrivateRoom.xmpp.ts +26 -0
- package/src/networking/xmpp/createRoom.xmpp.ts +35 -0
- package/src/networking/xmpp/createRoomPresence.xmpp.ts +74 -0
- package/src/networking/xmpp/createTimeoutPromise.xmpp.ts +15 -0
- package/src/networking/xmpp/deleteMessage.xmpp.ts +19 -0
- package/src/networking/xmpp/editMessage.xmpp.ts +46 -0
- package/src/networking/xmpp/getChatsPrivateStoreRequest.xmpp.ts +57 -0
- package/src/networking/xmpp/getHistory.xmpp.ts +140 -0
- package/src/networking/xmpp/getLastMessageArchive.xmpp.ts +24 -0
- package/src/networking/xmpp/getRoomInfo.xmpp.ts +15 -0
- package/src/networking/xmpp/getRoomMembers.xmpp.ts +13 -0
- package/src/networking/xmpp/getRooms.xmpp.ts +43 -0
- package/src/networking/xmpp/getRoomsPaged.xmpp.ts +59 -0
- package/src/networking/xmpp/handlePong.xmpp.ts +7 -0
- package/src/networking/xmpp/handleStanzas.xmpp.ts +55 -0
- package/src/networking/xmpp/inviteRoomRequest.xmpp.ts +25 -0
- package/src/networking/xmpp/leaveTheRoom.xmpp.ts +15 -0
- package/src/networking/xmpp/listenerManager.ts +116 -0
- package/src/networking/xmpp/presenceInRoom.xmpp.ts +57 -0
- package/src/networking/xmpp/roomConfig.xmpp.ts +71 -0
- package/src/networking/xmpp/sendMediaMessage.xmpp.ts +97 -0
- package/src/networking/xmpp/sendMessageReaction.xmpp.ts +41 -0
- package/src/networking/xmpp/sendPing.xmpp.ts +21 -0
- package/src/networking/xmpp/sendTextMessage.xmpp.ts +99 -0
- package/src/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.ts +44 -0
- package/src/networking/xmpp/sendTypingRequest.xmpp.ts +26 -0
- package/src/networking/xmpp/setChatsPrivateStoreRequest.xmpp.ts +48 -0
- package/src/networking/xmpp/setMeAsOwner.xmpp.ts +52 -0
- package/src/networking/xmpp/setRoomImage.xmpp.ts +26 -0
- package/src/networking/xmpp/setVCard.xmpp.ts +19 -0
- package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +75 -0
- package/src/networking/xmppClient.ts +603 -0
- package/src/roomStore/Middleware/logoutMiddleware.tsx +24 -0
- package/src/roomStore/Middleware/newMessageMidlleware.tsx +87 -0
- package/src/roomStore/Middleware/reactionsMiddleware.tsx +77 -0
- package/src/roomStore/Middleware/testMiddleware.tsx +20 -0
- package/src/roomStore/Middleware/unreadMidlleware.tsx +58 -0
- package/src/roomStore/chatSettingsSlice.ts +178 -0
- package/src/roomStore/index.ts +68 -0
- package/src/roomStore/persistence.ts +152 -0
- package/src/roomStore/roomHeapSlice.ts +37 -0
- package/src/roomStore/roomsSlice.ts +353 -0
- package/src/services/pushNotifications.ts +170 -0
- package/src/services/pushSubscriptionService.ts +145 -0
- package/src/types/messages.ts +61 -0
- package/src/types/models/action.model.ts +30 -0
- package/src/types/models/config.model.ts +16 -0
- package/src/types/models/customComponents.model.ts +53 -0
- package/src/types/models/language.model.ts +11 -0
- package/src/types/models/media.model.ts +5 -0
- package/src/types/models/message.model.ts +69 -0
- package/src/types/models/modal.model.ts +9 -0
- package/src/types/models/room.model.ts +120 -0
- package/src/types/models/user.model.ts +90 -0
- package/src/types/models/xmpp.model.ts +155 -0
- package/src/types/types.ts +505 -0
- package/src/utils/PriorityQueue.ts +47 -0
- package/src/utils/actionHelpers.ts +40 -0
- package/src/utils/actionLogger.ts +64 -0
- package/src/utils/clientRegistry.ts +80 -0
- package/src/utils/devLogger.ts +197 -0
- package/src/utils/messageNotificationManager.ts +108 -0
- package/src/utils/resendMessage.ts +87 -0
- package/src/utils/toastEmitter.ts +27 -0
- package/src/utils/xmppMemoryMonitor.ts +63 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
// import QRCode from 'react-qr-code';
|
|
3
|
+
import { CloseButton } from '../Modals/styledModalComponents';
|
|
4
|
+
import { Overlay, StyledModal } from '../styled/MediaModal';
|
|
5
|
+
import { StyledInput } from '../styled/StyledInputComponents/StyledInputComponents';
|
|
6
|
+
import Button from '../styled/Button';
|
|
7
|
+
import { Text, View } from 'react-native';
|
|
8
|
+
import { QRCODE_URL } from '../../helpers/constants/PLATFORM_CONSTANTS';
|
|
9
|
+
import Clipboard from '@react-native-clipboard/clipboard';
|
|
10
|
+
|
|
11
|
+
interface OperationalModalProps {
|
|
12
|
+
isVisible: boolean;
|
|
13
|
+
chatJid: string;
|
|
14
|
+
setVisible: React.Dispatch<React.SetStateAction<boolean>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const OperationalModal: React.FC<OperationalModalProps> = ({
|
|
18
|
+
isVisible,
|
|
19
|
+
chatJid,
|
|
20
|
+
setVisible,
|
|
21
|
+
}) => {
|
|
22
|
+
const handleCopyClick = () => {
|
|
23
|
+
Clipboard.setString(`${QRCODE_URL}${chatJid}`);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
isVisible && (
|
|
28
|
+
<Overlay
|
|
29
|
+
style={{
|
|
30
|
+
position: 'absolute',
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<StyledModal
|
|
34
|
+
style={{
|
|
35
|
+
borderRadius: 16,
|
|
36
|
+
width: 'auto',
|
|
37
|
+
height: 'auto',
|
|
38
|
+
paddingHorizontal: 64,
|
|
39
|
+
paddingVertical: 32,
|
|
40
|
+
minWidth: 480,
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<CloseButton onPress={() => setVisible(false)}>
|
|
44
|
+
<Text style={{ fontSize: 24 }}>×</Text>
|
|
45
|
+
</CloseButton>
|
|
46
|
+
<View
|
|
47
|
+
style={{
|
|
48
|
+
display: 'flex',
|
|
49
|
+
flexDirection: 'column',
|
|
50
|
+
gap: 16,
|
|
51
|
+
alignItems: 'center',
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<View style={{ width: '70%', position: 'relative' }} />
|
|
55
|
+
|
|
56
|
+
<View
|
|
57
|
+
style={{
|
|
58
|
+
display: 'flex',
|
|
59
|
+
gap: 8,
|
|
60
|
+
alignItems: 'center',
|
|
61
|
+
minWidth: 400,
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<StyledInput
|
|
65
|
+
value={chatJid}
|
|
66
|
+
editable={true}
|
|
67
|
+
style={{ width: '80%' }}
|
|
68
|
+
/>
|
|
69
|
+
<Button text="Copy" onPress={handleCopyClick} />
|
|
70
|
+
</View>
|
|
71
|
+
</View>
|
|
72
|
+
</StyledModal>
|
|
73
|
+
</Overlay>
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default OperationalModal;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { IConfig, IRoom } from '../../types/types';
|
|
3
|
+
import { ProfileImagePlaceholder } from '../MainComponents/ProfileImagePlaceholder';
|
|
4
|
+
import {
|
|
5
|
+
ChatItem,
|
|
6
|
+
ChatInfo,
|
|
7
|
+
ChatName,
|
|
8
|
+
LastMessage,
|
|
9
|
+
UserCount,
|
|
10
|
+
} from '../styled/RoomListComponents';
|
|
11
|
+
import Composing from '../styled/StyledInputComponents/Composing';
|
|
12
|
+
import { Text, View } from 'react-native';
|
|
13
|
+
import LastMessageItem from './LastMessageItem';
|
|
14
|
+
import { LastRoomMessageText } from './styled/StyledRoomComponents';
|
|
15
|
+
|
|
16
|
+
interface ChatRoomItemProps {
|
|
17
|
+
chat: IRoom;
|
|
18
|
+
index?: number;
|
|
19
|
+
isDriver?: boolean;
|
|
20
|
+
config?: IConfig;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ChatRoomItem: React.FC<ChatRoomItemProps> = ({
|
|
24
|
+
chat,
|
|
25
|
+
index,
|
|
26
|
+
isDriver,
|
|
27
|
+
config,
|
|
28
|
+
}) => {
|
|
29
|
+
const displayName = String(chat?.title || chat?.name || '').trim();
|
|
30
|
+
|
|
31
|
+
const lastMessage = useMemo(() => {
|
|
32
|
+
if (!chat?.messages || chat.messages.length === 0) {return undefined;}
|
|
33
|
+
|
|
34
|
+
for (let i = chat.messages.length - 1; i >= 0; i--) {
|
|
35
|
+
const msg = chat.messages[i];
|
|
36
|
+
if (!msg.deleted && !msg.isDeleted) {
|
|
37
|
+
return msg;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}, [chat?.messages]);
|
|
42
|
+
|
|
43
|
+
// Mirrors web's formatter: tolerates undefined/garbage inputs (returns
|
|
44
|
+
// undefined instead of "NaN:NaN"), and uses HH:MM today / MM/DD this
|
|
45
|
+
// year / YYYY/MM/DD older.
|
|
46
|
+
const formatTimeToHHMM = (
|
|
47
|
+
isoTime?: string | Date | number
|
|
48
|
+
): string | undefined => {
|
|
49
|
+
if (isoTime == null) {return undefined;}
|
|
50
|
+
let date: Date;
|
|
51
|
+
try {
|
|
52
|
+
if (isoTime instanceof Date) {
|
|
53
|
+
date = isoTime;
|
|
54
|
+
} else if (typeof isoTime === 'number') {
|
|
55
|
+
date = new Date(isoTime);
|
|
56
|
+
} else if (typeof isoTime === 'string') {
|
|
57
|
+
const trimmed = isoTime.trim();
|
|
58
|
+
date = /^\d+$/.test(trimmed)
|
|
59
|
+
? new Date(parseInt(trimmed, 10))
|
|
60
|
+
: new Date(trimmed);
|
|
61
|
+
} else {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
if (isNaN(date.getTime())) {return undefined;}
|
|
65
|
+
const now = new Date();
|
|
66
|
+
if (date.getFullYear() !== now.getFullYear()) {
|
|
67
|
+
const year = date.getFullYear();
|
|
68
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
69
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
70
|
+
return `${year}/${month}/${day}`;
|
|
71
|
+
}
|
|
72
|
+
if (date.toDateString() === now.toDateString()) {
|
|
73
|
+
const hours = date.getHours().toString().padStart(2, '0');
|
|
74
|
+
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
75
|
+
return `${hours}:${minutes}`;
|
|
76
|
+
}
|
|
77
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
78
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
79
|
+
return `${month}/${day}`;
|
|
80
|
+
} catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const stamp = formatTimeToHHMM(lastMessage?.date ?? chat?.createdAt);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<ChatItem key={index}>
|
|
89
|
+
<ProfileImagePlaceholder name={displayName} icon={chat?.icon} active={false} />
|
|
90
|
+
<View
|
|
91
|
+
style={{
|
|
92
|
+
flexDirection: 'column',
|
|
93
|
+
justifyContent: 'space-between',
|
|
94
|
+
flex: 2,
|
|
95
|
+
width: '100%',
|
|
96
|
+
paddingVertical: 8,
|
|
97
|
+
paddingRight: 8,
|
|
98
|
+
borderBottomWidth: 1,
|
|
99
|
+
borderBottomColor: '#F0F0F0',
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<View
|
|
103
|
+
style={{
|
|
104
|
+
flexDirection: 'row',
|
|
105
|
+
alignItems: 'center',
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<ChatInfo>
|
|
109
|
+
<ChatName text={displayName} />
|
|
110
|
+
</ChatInfo>
|
|
111
|
+
{stamp ? (
|
|
112
|
+
<UserCount
|
|
113
|
+
style={{
|
|
114
|
+
color: '#8C8C8C',
|
|
115
|
+
fontSize: 12,
|
|
116
|
+
}}
|
|
117
|
+
text={stamp}
|
|
118
|
+
/>
|
|
119
|
+
) : null}
|
|
120
|
+
</View>
|
|
121
|
+
<View
|
|
122
|
+
style={{
|
|
123
|
+
width: '100%',
|
|
124
|
+
flexDirection: 'row',
|
|
125
|
+
justifyContent: 'space-between',
|
|
126
|
+
alignItems: 'flex-start',
|
|
127
|
+
minHeight: 40,
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{/* {chat.composing ? (
|
|
131
|
+
<Composing
|
|
132
|
+
usersTyping={chat.composingList}
|
|
133
|
+
style={{ color: "#141414" }}
|
|
134
|
+
/>
|
|
135
|
+
) : lastMessage?.body ? (
|
|
136
|
+
<View
|
|
137
|
+
style={{
|
|
138
|
+
display: "flex",
|
|
139
|
+
width: "80%",
|
|
140
|
+
flexDirection: "column",
|
|
141
|
+
alignItems: "flex-start",
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<View
|
|
145
|
+
style={{
|
|
146
|
+
height: 20,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
<Text style={{ fontWeight: "600", textAlign: "right" }}>
|
|
150
|
+
{lastMessage.user.name || ""}:
|
|
151
|
+
</Text>
|
|
152
|
+
</View>
|
|
153
|
+
<View
|
|
154
|
+
style={{
|
|
155
|
+
height: 20,
|
|
156
|
+
maxWidth: 200,
|
|
157
|
+
overflow: "hidden",
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
<Text
|
|
161
|
+
numberOfLines={1}
|
|
162
|
+
ellipsizeMode="tail"
|
|
163
|
+
style={{
|
|
164
|
+
textAlign: "right",
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
{lastMessage.body || "Chat created"}
|
|
168
|
+
</Text>
|
|
169
|
+
</View>
|
|
170
|
+
</View>
|
|
171
|
+
) : null} */}
|
|
172
|
+
{chat.composing ? (
|
|
173
|
+
<Composing
|
|
174
|
+
usersTyping={chat.composingList}
|
|
175
|
+
// style={{ color: !isChatActive ? '#141414' : '#fff' }}
|
|
176
|
+
/>
|
|
177
|
+
) : lastMessage?.body ? (
|
|
178
|
+
<LastMessageItem lastMessage={lastMessage} />
|
|
179
|
+
) : chat.messages.length === 0 && chat.historyComplete ? (
|
|
180
|
+
<LastRoomMessageText>Room created</LastRoomMessageText>
|
|
181
|
+
) : undefined}
|
|
182
|
+
{chat.unreadMessages && chat.unreadMessages > 0 ? (
|
|
183
|
+
<View
|
|
184
|
+
style={{
|
|
185
|
+
borderRadius: 8,
|
|
186
|
+
backgroundColor: config?.colors?.primary,
|
|
187
|
+
padding: 2,
|
|
188
|
+
minWidth: 24,
|
|
189
|
+
minHeight: 24,
|
|
190
|
+
display: 'flex',
|
|
191
|
+
justifyContent: 'center',
|
|
192
|
+
alignItems: 'center',
|
|
193
|
+
marginLeft: 'auto',
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<Text
|
|
197
|
+
style={{
|
|
198
|
+
// color: isChatActive ? "#141414" : "#fff",
|
|
199
|
+
color: '#141414',
|
|
200
|
+
fontSize: 14,
|
|
201
|
+
fontWeight: '600',
|
|
202
|
+
}}
|
|
203
|
+
>
|
|
204
|
+
{chat.unreadMessages || ''}
|
|
205
|
+
</Text>
|
|
206
|
+
</View>
|
|
207
|
+
) : null}
|
|
208
|
+
</View>
|
|
209
|
+
{isDriver && (
|
|
210
|
+
<View
|
|
211
|
+
style={{ height: 1, backgroundColor: '#0052CD0D', marginTop: 8 }}
|
|
212
|
+
/>
|
|
213
|
+
)}
|
|
214
|
+
</View>
|
|
215
|
+
</ChatItem>
|
|
216
|
+
);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export default ChatRoomItem;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { LastMessage } from '../../types/types';
|
|
3
|
+
import LastMessageVideo from './styled/LastMessageVideo';
|
|
4
|
+
import LastTextMessage from './styled/LastTextMessage';
|
|
5
|
+
import LastMessagePhoto from './styled/LastMessagePhoto';
|
|
6
|
+
import LastMessageEmoji from './styled/LastMessageEmoji';
|
|
7
|
+
import LastMessageFile from './styled/LastMessageFile';
|
|
8
|
+
import LastAudioMessage from './styled/LastAudioMessage';
|
|
9
|
+
|
|
10
|
+
interface LastMessageItemProps {
|
|
11
|
+
lastMessage: LastMessage;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const LastMessageItem: FC<LastMessageItemProps> = ({ lastMessage }) => {
|
|
15
|
+
const { body, emoji, mimetype } = lastMessage;
|
|
16
|
+
|
|
17
|
+
if (mimetype) {
|
|
18
|
+
if (mimetype.startsWith('image/')) {
|
|
19
|
+
return <LastMessagePhoto {...lastMessage} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (mimetype.startsWith('video/')) {
|
|
23
|
+
return <LastMessageVideo {...lastMessage} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
mimetype.startsWith('audio/') ||
|
|
28
|
+
mimetype.includes('application/octet-stream')
|
|
29
|
+
) {
|
|
30
|
+
return <LastAudioMessage {...lastMessage} />;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return <LastMessageFile {...lastMessage} />;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (emoji) {
|
|
37
|
+
return <LastMessageEmoji {...lastMessage} />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (body) {
|
|
41
|
+
return <LastTextMessage {...lastMessage} />;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default LastMessageItem;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LastRoomMessageContainer,
|
|
4
|
+
LastRoomMessageName,
|
|
5
|
+
LastRoomMessageText,
|
|
6
|
+
ShadeWrapper,
|
|
7
|
+
} from './StyledRoomComponents';
|
|
8
|
+
import { LastMessage } from '../../../types/types';
|
|
9
|
+
import styled from 'styled-components/native';
|
|
10
|
+
import { Text, View } from 'react-native';
|
|
11
|
+
|
|
12
|
+
interface LastMessageEmojiProps extends Pick<LastMessage, 'user' | 'body'> {}
|
|
13
|
+
|
|
14
|
+
const PlayButton = styled.View`
|
|
15
|
+
position: absolute;
|
|
16
|
+
width: 8px;
|
|
17
|
+
height: 9px;
|
|
18
|
+
border-radius: 50%;
|
|
19
|
+
display: flex;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
align-items: center;
|
|
22
|
+
color: white;
|
|
23
|
+
font-size: 10px;
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
z-index: 100;
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const PhotoContainer = styled.View`
|
|
29
|
+
position: relative;
|
|
30
|
+
width: 20px;
|
|
31
|
+
height: 20px;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
border-radius: 8px;
|
|
34
|
+
width: 20px;
|
|
35
|
+
height: 20px;
|
|
36
|
+
object-fit: cover;
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const LastAudioMessage: FC<LastMessageEmojiProps> = ({ user, body }) => {
|
|
41
|
+
return (
|
|
42
|
+
<LastRoomMessageContainer>
|
|
43
|
+
<LastRoomMessageName>{user?.name ?? ''}</LastRoomMessageName>
|
|
44
|
+
<View
|
|
45
|
+
style={{
|
|
46
|
+
display: 'flex',
|
|
47
|
+
flexDirection: 'row',
|
|
48
|
+
gap: '4px',
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<PhotoContainer>
|
|
52
|
+
<ShadeWrapper>
|
|
53
|
+
<PlayButton><Text>▶</Text></PlayButton>
|
|
54
|
+
</ShadeWrapper>
|
|
55
|
+
</PhotoContainer>
|
|
56
|
+
<LastRoomMessageText>audio</LastRoomMessageText>
|
|
57
|
+
</View>
|
|
58
|
+
</LastRoomMessageContainer>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default LastAudioMessage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LastRoomMessageContainer,
|
|
4
|
+
LastRoomMessageName,
|
|
5
|
+
LastRoomMessageText,
|
|
6
|
+
} from './StyledRoomComponents';
|
|
7
|
+
import { LastMessage } from '../../../types/types';
|
|
8
|
+
import emojiData from 'emoji-mart';
|
|
9
|
+
|
|
10
|
+
interface LastMessageEmojiProps extends Pick<LastMessage, 'user' | 'emoji'> {}
|
|
11
|
+
|
|
12
|
+
const LastMessageEmoji: FC<LastMessageEmojiProps> = ({ user, emoji }) => {
|
|
13
|
+
const memoEmoji = (id: string) => {
|
|
14
|
+
const emoji = (emojiData as any).emojis[id];
|
|
15
|
+
return emoji ? emoji.skins[0].native : '';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<LastRoomMessageContainer>
|
|
20
|
+
<LastRoomMessageName>{user?.name || ''}:</LastRoomMessageName>
|
|
21
|
+
<LastRoomMessageText>{emoji ? memoEmoji(emoji) : ''}</LastRoomMessageText>
|
|
22
|
+
</LastRoomMessageContainer>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default LastMessageEmoji;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { FC, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { LastMessage } from '../../../types/types';
|
|
4
|
+
import {
|
|
5
|
+
LastRoomMessageContainer,
|
|
6
|
+
LastRoomMessageName,
|
|
7
|
+
LastRoomMessageText,
|
|
8
|
+
} from './StyledRoomComponents';
|
|
9
|
+
import { FileIcon } from '../../../assets/icons';
|
|
10
|
+
import { Image, View } from 'react-native';
|
|
11
|
+
|
|
12
|
+
interface LastMessageFileProps
|
|
13
|
+
extends Pick<LastMessage, 'user' | 'originalName' | 'locationPreview'> {}
|
|
14
|
+
|
|
15
|
+
const fallbackImage =
|
|
16
|
+
'https://as2.ftcdn.net/v2/jpg/02/51/95/53/1000_F_251955356_FAQH0U1y1TZw3ZcdPGybwUkH90a3VAhb.jpg';
|
|
17
|
+
|
|
18
|
+
const LastMessageFile: FC<LastMessageFileProps> = ({
|
|
19
|
+
user,
|
|
20
|
+
originalName,
|
|
21
|
+
locationPreview,
|
|
22
|
+
}) => {
|
|
23
|
+
const [imgSrc, setImgSrc] = useState(locationPreview);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<LastRoomMessageContainer>
|
|
27
|
+
<LastRoomMessageName>{user?.name || ''}:</LastRoomMessageName>
|
|
28
|
+
<View
|
|
29
|
+
style={{
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: 'row',
|
|
32
|
+
gap: '4px',
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
{imgSrc ? (
|
|
36
|
+
<Image
|
|
37
|
+
source={{ uri: imgSrc }}
|
|
38
|
+
style={{
|
|
39
|
+
borderRadius: 16,
|
|
40
|
+
width: 20,
|
|
41
|
+
height: 20,
|
|
42
|
+
}}
|
|
43
|
+
onError={() => setImgSrc(fallbackImage)}
|
|
44
|
+
/>
|
|
45
|
+
) : (
|
|
46
|
+
<FileIcon style={{ width: '20px', height: '20px' }} />
|
|
47
|
+
)}
|
|
48
|
+
<LastRoomMessageText>{originalName || 'file'}</LastRoomMessageText>
|
|
49
|
+
</View>
|
|
50
|
+
</LastRoomMessageContainer>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default LastMessageFile;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import styled from 'styled-components/native';
|
|
3
|
+
import { LastMessage } from '../../../types/types';
|
|
4
|
+
import {
|
|
5
|
+
LastMessageImg,
|
|
6
|
+
LastRoomMessageContainer,
|
|
7
|
+
LastRoomMessageName,
|
|
8
|
+
LastRoomMessageText,
|
|
9
|
+
ShadeWrapper,
|
|
10
|
+
} from './StyledRoomComponents';
|
|
11
|
+
import { View } from 'react-native';
|
|
12
|
+
|
|
13
|
+
const PhotoContainer = styled.View`
|
|
14
|
+
position: relative;
|
|
15
|
+
width: 20px;
|
|
16
|
+
height: 20px;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
border-radius: 8px;
|
|
19
|
+
width: 20px;
|
|
20
|
+
height: 20px;
|
|
21
|
+
object-fit: cover;
|
|
22
|
+
pointer-events: none;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
interface LastMessagePhotoProps
|
|
26
|
+
extends Pick<LastMessage, 'user' | 'originalName' | 'locationPreview'> {}
|
|
27
|
+
|
|
28
|
+
const LastMessagePhoto: FC<LastMessagePhotoProps> = ({
|
|
29
|
+
user,
|
|
30
|
+
locationPreview,
|
|
31
|
+
originalName,
|
|
32
|
+
}) => {
|
|
33
|
+
return (
|
|
34
|
+
<LastRoomMessageContainer>
|
|
35
|
+
<LastRoomMessageName>{user?.name || ''}:</LastRoomMessageName>
|
|
36
|
+
<View
|
|
37
|
+
style={{
|
|
38
|
+
display: 'flex',
|
|
39
|
+
flexDirection: 'row',
|
|
40
|
+
gap: '4px',
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<PhotoContainer>
|
|
44
|
+
<ShadeWrapper>
|
|
45
|
+
<LastMessageImg src={locationPreview} />
|
|
46
|
+
</ShadeWrapper>
|
|
47
|
+
</PhotoContainer>
|
|
48
|
+
<LastRoomMessageText>{originalName || 'file'}</LastRoomMessageText>
|
|
49
|
+
</View>
|
|
50
|
+
</LastRoomMessageContainer>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default LastMessagePhoto;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import styled from 'styled-components/native';
|
|
3
|
+
import { LastMessage } from '../../../types/types';
|
|
4
|
+
import {
|
|
5
|
+
LastRoomMessageContainer,
|
|
6
|
+
LastRoomMessageName,
|
|
7
|
+
LastRoomMessageText,
|
|
8
|
+
ShadeWrapper,
|
|
9
|
+
} from './StyledRoomComponents';
|
|
10
|
+
import { Text, View } from 'react-native';
|
|
11
|
+
|
|
12
|
+
const VideoContainer = styled.View`
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 20px;
|
|
15
|
+
height: 20px;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
border-radius: 8px;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const Thumbnail = styled.Image`
|
|
21
|
+
width: 20px;
|
|
22
|
+
height: 20px;
|
|
23
|
+
border-radius: 8px;
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const PlayButton = styled.View`
|
|
27
|
+
position: absolute;
|
|
28
|
+
width: 8px;
|
|
29
|
+
height: 9px;
|
|
30
|
+
border-radius: 50%;
|
|
31
|
+
display: flex;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
align-items: center;
|
|
34
|
+
color: white;
|
|
35
|
+
font-size: 10px;
|
|
36
|
+
pointer-events: none;
|
|
37
|
+
z-index: 100;
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
interface LastMessageVideoProps
|
|
41
|
+
extends Pick<LastMessage, 'user' | 'location' | 'originalName'> {}
|
|
42
|
+
|
|
43
|
+
const LastMessageVideo: FC<LastMessageVideoProps> = ({
|
|
44
|
+
user,
|
|
45
|
+
location,
|
|
46
|
+
originalName,
|
|
47
|
+
}) => {
|
|
48
|
+
return (
|
|
49
|
+
<LastRoomMessageContainer>
|
|
50
|
+
<LastRoomMessageName>{user?.name || ''}:</LastRoomMessageName>
|
|
51
|
+
<View
|
|
52
|
+
style={{
|
|
53
|
+
display: 'flex',
|
|
54
|
+
flexDirection: 'row',
|
|
55
|
+
gap: '4px',
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
<VideoContainer>
|
|
59
|
+
<ShadeWrapper>
|
|
60
|
+
<Thumbnail src={location} />
|
|
61
|
+
</ShadeWrapper>
|
|
62
|
+
<PlayButton><Text>▶</Text></PlayButton>
|
|
63
|
+
</VideoContainer>
|
|
64
|
+
<LastRoomMessageText>{originalName || 'file'}</LastRoomMessageText>
|
|
65
|
+
</View>
|
|
66
|
+
</LastRoomMessageContainer>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default LastMessageVideo;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LastRoomMessageContainer,
|
|
4
|
+
LastRoomMessageName,
|
|
5
|
+
LastRoomMessageText,
|
|
6
|
+
} from './StyledRoomComponents';
|
|
7
|
+
import { LastMessage } from '../../../types/types';
|
|
8
|
+
import { decodeHTMLEntities } from '../../../helpers/parseMessageBody';
|
|
9
|
+
|
|
10
|
+
interface LastMessageEmojiProps extends Pick<LastMessage, 'user' | 'body'> {}
|
|
11
|
+
|
|
12
|
+
const getPlainText = (body: string | undefined): string => {
|
|
13
|
+
if (!body || typeof body !== 'string') {
|
|
14
|
+
return 'Chat created';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let text = decodeHTMLEntities(body);
|
|
18
|
+
|
|
19
|
+
text = text.replace(/^#{1,6}\s+/gm, '');
|
|
20
|
+
|
|
21
|
+
text = text.replace(/\*\*([^*]+)\*\*/g, '$1');
|
|
22
|
+
text = text.replace(/__([^_]+)__/g, '$1');
|
|
23
|
+
|
|
24
|
+
text = text.replace(/\*([^*]+)\*/g, '$1');
|
|
25
|
+
text = text.replace(/_([^_]+)_/g, '$1');
|
|
26
|
+
|
|
27
|
+
text = text.replace(/~~([^~]+)~~/g, '$1');
|
|
28
|
+
|
|
29
|
+
text = text.replace(/`([^`]+)`/g, '$1');
|
|
30
|
+
|
|
31
|
+
text = text.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1');
|
|
32
|
+
|
|
33
|
+
text = text.replace(/^[\s]*[-*+]\s+/gm, '');
|
|
34
|
+
|
|
35
|
+
text = text.replace(/^\s*\d+\.\s+/gm, '');
|
|
36
|
+
|
|
37
|
+
text = text.replace(/\|/g, ' ');
|
|
38
|
+
|
|
39
|
+
text = text.replace(/```[\s\S]*?```/g, '');
|
|
40
|
+
|
|
41
|
+
text = text.replace(/<[^>]+>/g, '');
|
|
42
|
+
|
|
43
|
+
text = text.replace(/\s+/g, ' ');
|
|
44
|
+
|
|
45
|
+
text = text.replace(/\n/g, ' ').trim();
|
|
46
|
+
|
|
47
|
+
return text || 'Chat created';
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const LastTextMessage: FC<LastMessageEmojiProps> = ({ user, body }) => {
|
|
51
|
+
const plainText = getPlainText(body);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<LastRoomMessageContainer>
|
|
55
|
+
<LastRoomMessageName numberOfLines={1} ellipsizeMode="tail">
|
|
56
|
+
{user?.name}
|
|
57
|
+
</LastRoomMessageName>
|
|
58
|
+
<LastRoomMessageText numberOfLines={1} ellipsizeMode="tail">
|
|
59
|
+
{plainText}
|
|
60
|
+
</LastRoomMessageText>
|
|
61
|
+
</LastRoomMessageContainer>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default LastTextMessage;
|