@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,163 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import React, { useCallback } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
CenterContainer,
|
|
6
|
+
ChatContainerHeader,
|
|
7
|
+
ChatContainerHeaderBoxInfo,
|
|
8
|
+
ChatContainerHeaderInfo,
|
|
9
|
+
ChatContainerHeaderLabel,
|
|
10
|
+
} from '../styled/StyledComponents';
|
|
11
|
+
import RoomList from './RoomList';
|
|
12
|
+
import { IRoom } from '../../types/types';
|
|
13
|
+
import { ProfileImagePlaceholder } from './ProfileImagePlaceholder';
|
|
14
|
+
import Button from '../styled/Button';
|
|
15
|
+
import { BackIcon, BurgerMenuIcon } from '../../assets/icons';
|
|
16
|
+
import { useDispatch } from 'react-redux';
|
|
17
|
+
import Composing from '../styled/StyledInputComponents/Composing';
|
|
18
|
+
import {
|
|
19
|
+
deleteRoom,
|
|
20
|
+
setCurrentRoom,
|
|
21
|
+
setIsLoading,
|
|
22
|
+
} from '../../roomStore/roomsSlice';
|
|
23
|
+
import { useXmppClient } from '../../context/xmppProvider';
|
|
24
|
+
import { setActiveModal } from '../../roomStore/chatSettingsSlice';
|
|
25
|
+
import { MODAL_TYPES } from '../../helpers/constants/MODAL_TYPES';
|
|
26
|
+
import { RoomMenu } from '../MenuRoom/MenuRoom';
|
|
27
|
+
import { useRoomState } from '../../hooks/useRoomState';
|
|
28
|
+
import { useChatSettingState } from '../../hooks/useChatSettingState';
|
|
29
|
+
import { View, StyleSheet, Text, Keyboard } from 'react-native';
|
|
30
|
+
|
|
31
|
+
interface ChatHeaderProps {
|
|
32
|
+
currentRoom: IRoom;
|
|
33
|
+
handleBackClick?: (value: boolean) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ChatHeader: React.FC<ChatHeaderProps> = ({
|
|
37
|
+
currentRoom,
|
|
38
|
+
handleBackClick,
|
|
39
|
+
}) => {
|
|
40
|
+
const dispatch = useDispatch();
|
|
41
|
+
const { client } = useXmppClient();
|
|
42
|
+
|
|
43
|
+
const { roomsList, activeRoomJID } = useRoomState(currentRoom.jid);
|
|
44
|
+
const roomState = useRoomState(currentRoom.jid).room;
|
|
45
|
+
const composing = roomState?.composing;
|
|
46
|
+
const { config } = useChatSettingState();
|
|
47
|
+
|
|
48
|
+
const handleChangeChat = (chat: IRoom) => {
|
|
49
|
+
dispatch(setCurrentRoom({ roomJID: chat.jid }));
|
|
50
|
+
dispatch(setIsLoading({ chatJID: chat.jid, loading: true }));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleLeaveClick = useCallback(() => {
|
|
54
|
+
client.leaveTheRoomStanza(activeRoomJID!);
|
|
55
|
+
dispatch(deleteRoom({ jid: activeRoomJID! }));
|
|
56
|
+
|
|
57
|
+
const nextRoomJID = Object.keys(roomsList)[0] || null;
|
|
58
|
+
if (nextRoomJID) {
|
|
59
|
+
dispatch(setCurrentRoom({ roomJID: nextRoomJID }));
|
|
60
|
+
}
|
|
61
|
+
}, [activeRoomJID, roomsList, dispatch, client]);
|
|
62
|
+
|
|
63
|
+
const handleHeaderChatMenu = () => {
|
|
64
|
+
Keyboard.dismiss();
|
|
65
|
+
config?.headerChatMenu && config?.headerChatMenu();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<ChatContainerHeader>
|
|
71
|
+
{handleBackClick && !config?.headerChatMenu ? (
|
|
72
|
+
<View style={styles.leftContainer}>
|
|
73
|
+
<Button
|
|
74
|
+
EndIcon={<BackIcon />}
|
|
75
|
+
onPress={() => handleBackClick(false)}
|
|
76
|
+
/>
|
|
77
|
+
</View>
|
|
78
|
+
) : (
|
|
79
|
+
<View style={styles.leftContainer}>
|
|
80
|
+
<Button
|
|
81
|
+
style={styles.menuButton}
|
|
82
|
+
color="black"
|
|
83
|
+
unstyled
|
|
84
|
+
EndIcon={<BurgerMenuIcon color={config?.colors?.primary} />}
|
|
85
|
+
onPress={handleHeaderChatMenu}
|
|
86
|
+
/>
|
|
87
|
+
</View>
|
|
88
|
+
)}
|
|
89
|
+
<CenterContainer
|
|
90
|
+
rightSpace={config?.disableRoomConfig}
|
|
91
|
+
leftSpace={!!config?.headerChatMenu}
|
|
92
|
+
>
|
|
93
|
+
{config?.chatHeaderBurgerMenu && roomsList && (
|
|
94
|
+
<RoomList
|
|
95
|
+
chats={Object.values(roomsList)}
|
|
96
|
+
burgerMenu
|
|
97
|
+
onRoomClick={handleChangeChat}
|
|
98
|
+
/>
|
|
99
|
+
)}
|
|
100
|
+
<ChatContainerHeaderBoxInfo
|
|
101
|
+
onPress={() => dispatch(setActiveModal(MODAL_TYPES.CHAT_PROFILE))}
|
|
102
|
+
disabled={config?.disableProfilesInteractions}
|
|
103
|
+
>
|
|
104
|
+
<View>
|
|
105
|
+
<ProfileImagePlaceholder
|
|
106
|
+
name={currentRoom?.title || currentRoom?.name}
|
|
107
|
+
size={40}
|
|
108
|
+
icon={currentRoom?.icon}
|
|
109
|
+
active={!config?.disableProfilesInteractions || true}
|
|
110
|
+
/>
|
|
111
|
+
</View>
|
|
112
|
+
<ChatContainerHeaderInfo>
|
|
113
|
+
<ChatContainerHeaderLabel numberOfLines={1} ellipsizeMode="tail">
|
|
114
|
+
{currentRoom?.title || currentRoom?.name}
|
|
115
|
+
</ChatContainerHeaderLabel>
|
|
116
|
+
<View>
|
|
117
|
+
{composing ? (
|
|
118
|
+
<Composing usersTyping={currentRoom?.composingList} />
|
|
119
|
+
) : config?.disableUserCount ? undefined : (
|
|
120
|
+
<ChatContainerHeaderLabel style={styles.subLabel}>
|
|
121
|
+
<Text>{`${currentRoom?.usersCnt} users`}</Text>
|
|
122
|
+
</ChatContainerHeaderLabel>
|
|
123
|
+
)}
|
|
124
|
+
</View>
|
|
125
|
+
</ChatContainerHeaderInfo>
|
|
126
|
+
</ChatContainerHeaderBoxInfo>
|
|
127
|
+
</CenterContainer>
|
|
128
|
+
|
|
129
|
+
{!config?.disableRoomConfig ? (
|
|
130
|
+
<View style={styles.rightContainer}>
|
|
131
|
+
<RoomMenu handleLeaveClick={handleLeaveClick} />
|
|
132
|
+
</View>
|
|
133
|
+
) : (
|
|
134
|
+
<View style={styles.rightContainer} />
|
|
135
|
+
)}
|
|
136
|
+
</ChatContainerHeader>
|
|
137
|
+
{config?.chatHeaderAdditional?.enabled &&
|
|
138
|
+
config.chatHeaderAdditional.element()}
|
|
139
|
+
</>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const styles = StyleSheet.create({
|
|
144
|
+
subLabel: {
|
|
145
|
+
color: '#8C8C8C',
|
|
146
|
+
fontSize: 14,
|
|
147
|
+
},
|
|
148
|
+
menuButton: {
|
|
149
|
+
padding: 8,
|
|
150
|
+
borderRadius: 16,
|
|
151
|
+
backgroundColor: 'transparent',
|
|
152
|
+
},
|
|
153
|
+
leftContainer: {
|
|
154
|
+
alignItems: 'flex-start',
|
|
155
|
+
width: '15%',
|
|
156
|
+
},
|
|
157
|
+
rightContainer: {
|
|
158
|
+
alignItems: 'flex-end',
|
|
159
|
+
width: '15%',
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
export default ChatHeader;
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/** @format */
|
|
2
|
+
|
|
3
|
+
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
|
4
|
+
import { ChatContainer, NonRoomChat } from '../styled/StyledComponents';
|
|
5
|
+
import { useDispatch } from 'react-redux';
|
|
6
|
+
import MessageList from './MessageList';
|
|
7
|
+
import SendInput from '../styled/SendInput';
|
|
8
|
+
import {
|
|
9
|
+
deleteRoomMessage,
|
|
10
|
+
setEditAction,
|
|
11
|
+
setLastViewedTimestamp,
|
|
12
|
+
} from '../../roomStore/roomsSlice';
|
|
13
|
+
import Loader from '../styled/Loader';
|
|
14
|
+
import { useXmppClient } from '../../context/xmppProvider';
|
|
15
|
+
import ChatHeader from './ChatHeader';
|
|
16
|
+
import NoMessagesPlaceholder from './NoMessagesPlaceholder';
|
|
17
|
+
import NewChatModal from '../Modals/NewChatModal/NewChatModal';
|
|
18
|
+
import { EditWrapper } from './EditWrapper';
|
|
19
|
+
import { NoSelectedChatIcon } from '../../assets/icons';
|
|
20
|
+
import { ChooseChatMessage } from './ChooseChatMessage';
|
|
21
|
+
import { useRoomUrl } from '../../hooks/useRoomUrl';
|
|
22
|
+
import { useSendMessage } from '../../hooks/useSendMessage';
|
|
23
|
+
import { IConfig } from '../../types/models/config.model';
|
|
24
|
+
import { useRoomInitialization } from '../../hooks/useRoomInitialization';
|
|
25
|
+
import { useRoomState } from '../../hooks/useRoomState';
|
|
26
|
+
import { useChatSettingState } from '../../hooks/useChatSettingState';
|
|
27
|
+
import CustomTypingIndicator from '../styled/StyledInputComponents/CustomTypingIndicator';
|
|
28
|
+
// import {PanGestureHandler} from 'react-native-gesture-handler';
|
|
29
|
+
import { FlatList } from 'react-native';
|
|
30
|
+
import {
|
|
31
|
+
KeyboardAvoidingView,
|
|
32
|
+
Platform,
|
|
33
|
+
TouchableWithoutFeedback,
|
|
34
|
+
Keyboard,
|
|
35
|
+
View,
|
|
36
|
+
KeyboardEvent,
|
|
37
|
+
} from 'react-native';
|
|
38
|
+
import useComposing from '../../hooks/useComposing';
|
|
39
|
+
|
|
40
|
+
interface ChatRoomProps {
|
|
41
|
+
CustomMessageComponent?: any;
|
|
42
|
+
CustomInputComponent?: React.ComponentType<any>;
|
|
43
|
+
CustomScrollableArea?: React.ComponentType<any>;
|
|
44
|
+
CustomDaySeparator?: React.ComponentType<any>;
|
|
45
|
+
CustomNewMessageLabel?: React.ComponentType<any>;
|
|
46
|
+
handleBackClick?: (value: boolean) => void;
|
|
47
|
+
eventHandlers?: IConfig['eventHandlers'];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ChatRoom: React.FC<ChatRoomProps> = React.memo(
|
|
51
|
+
({
|
|
52
|
+
CustomMessageComponent,
|
|
53
|
+
CustomInputComponent,
|
|
54
|
+
CustomScrollableArea,
|
|
55
|
+
CustomDaySeparator,
|
|
56
|
+
CustomNewMessageLabel,
|
|
57
|
+
handleBackClick,
|
|
58
|
+
eventHandlers: propsEventHandlers,
|
|
59
|
+
}) => {
|
|
60
|
+
const { client } = useXmppClient();
|
|
61
|
+
const dispatch = useDispatch();
|
|
62
|
+
|
|
63
|
+
const [isLoadingMore, setIsLoadingMore] = useState<boolean>(false);
|
|
64
|
+
|
|
65
|
+
const { user, config: storeConfig } = useChatSettingState();
|
|
66
|
+
|
|
67
|
+
// Merge eventHandlers from props with config (props take precedence)
|
|
68
|
+
// This is necessary because functions can't be stored in Redux
|
|
69
|
+
const configWithEventHandlers = React.useMemo(() => {
|
|
70
|
+
if (propsEventHandlers && storeConfig) {
|
|
71
|
+
return {
|
|
72
|
+
...storeConfig,
|
|
73
|
+
eventHandlers: propsEventHandlers,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return storeConfig;
|
|
77
|
+
}, [storeConfig, propsEventHandlers]);
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
roomsList,
|
|
81
|
+
activeRoomJID,
|
|
82
|
+
editAction,
|
|
83
|
+
loading,
|
|
84
|
+
globalLoading,
|
|
85
|
+
roomMessages,
|
|
86
|
+
} = useRoomState();
|
|
87
|
+
const {
|
|
88
|
+
sendMessage: sendMs,
|
|
89
|
+
sendMedia: sendMessageMedia,
|
|
90
|
+
sendEditMessage,
|
|
91
|
+
isLastMessageFromUserAndProcessing,
|
|
92
|
+
} = useSendMessage(configWithEventHandlers);
|
|
93
|
+
const { sendStartComposing, sendEndComposing } = useComposing(
|
|
94
|
+
configWithEventHandlers || storeConfig,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const sendMessage = useCallback(
|
|
98
|
+
(message: string) => {
|
|
99
|
+
if (!activeRoomJID) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
dispatch(
|
|
103
|
+
setLastViewedTimestamp({
|
|
104
|
+
chatJID: activeRoomJID,
|
|
105
|
+
timestamp: 0,
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
108
|
+
sendMs(message, activeRoomJID);
|
|
109
|
+
},
|
|
110
|
+
[activeRoomJID],
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const sendMedia = useCallback(
|
|
114
|
+
(data: any, type: string) => {
|
|
115
|
+
sendMessageMedia(data, type, activeRoomJID || '');
|
|
116
|
+
},
|
|
117
|
+
[activeRoomJID],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const loadMoreMessages = useCallback(
|
|
121
|
+
async (chatJID: string, max: number, idOfMessageBefore?: number) => {
|
|
122
|
+
if (isLoadingMore || roomsList?.[chatJID]?.historyComplete) {return;}
|
|
123
|
+
const lastMsgId =
|
|
124
|
+
typeof idOfMessageBefore !== 'string'
|
|
125
|
+
? idOfMessageBefore
|
|
126
|
+
: Number(
|
|
127
|
+
roomsList[chatJID].messages[
|
|
128
|
+
roomsList[chatJID].messages.length - 2
|
|
129
|
+
]?.id,
|
|
130
|
+
);
|
|
131
|
+
setIsLoadingMore(true);
|
|
132
|
+
try {
|
|
133
|
+
// Return the promise so MessageList's `await loadMoreMessages`
|
|
134
|
+
// actually waits for MAM to respond before its own onEndReached
|
|
135
|
+
// re-arms — otherwise the awaited call resolves with `undefined`
|
|
136
|
+
// immediately and rapid scrolls fire repeat requests that step
|
|
137
|
+
// on each other.
|
|
138
|
+
await client?.getHistoryStanza(chatJID, max, lastMsgId);
|
|
139
|
+
} finally {
|
|
140
|
+
setIsLoadingMore(false);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
144
|
+
[client?.client?.jid, isLoadingMore, roomsList],
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const onCloseEdit = () => {
|
|
148
|
+
dispatch(setEditAction({ isEdit: false }));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (!activeRoomJID) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
dispatch(
|
|
157
|
+
setLastViewedTimestamp({
|
|
158
|
+
chatJID: activeRoomJID,
|
|
159
|
+
timestamp: 0,
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
setIsLoadingMore(false);
|
|
163
|
+
return () => {
|
|
164
|
+
if (client) {
|
|
165
|
+
client.actionSetTimestampToPrivateStoreStanza(
|
|
166
|
+
activeRoomJID,
|
|
167
|
+
new Date().getTime(),
|
|
168
|
+
Object.keys(roomsList),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
dispatch(
|
|
172
|
+
setLastViewedTimestamp({
|
|
173
|
+
chatJID: activeRoomJID,
|
|
174
|
+
timestamp: new Date().getTime(),
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
dispatch(
|
|
178
|
+
deleteRoomMessage({
|
|
179
|
+
roomJID: activeRoomJID,
|
|
180
|
+
messageId: 'delimiter-new',
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
setIsLoadingMore(false);
|
|
184
|
+
};
|
|
185
|
+
}, [activeRoomJID]);
|
|
186
|
+
|
|
187
|
+
// hooks useEffects
|
|
188
|
+
// useRoomUrl(activeRoomJID || "", roomsList, config);
|
|
189
|
+
|
|
190
|
+
useRoomInitialization(
|
|
191
|
+
activeRoomJID || '',
|
|
192
|
+
roomsList,
|
|
193
|
+
configWithEventHandlers || storeConfig || {},
|
|
194
|
+
roomMessages.length,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (Object.keys(roomsList)?.length < 1 && !loading && !globalLoading) {
|
|
198
|
+
return (
|
|
199
|
+
<NonRoomChat>
|
|
200
|
+
{/* <Text>No room. Let's create one!</Text> */}
|
|
201
|
+
<NewChatModal />
|
|
202
|
+
</NonRoomChat>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!activeRoomJID || !roomsList?.[activeRoomJID]) {
|
|
207
|
+
return <ChooseChatMessage />;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<View style={{ flex: 1 }}>
|
|
212
|
+
<ChatContainer
|
|
213
|
+
style={
|
|
214
|
+
configWithEventHandlers?.chatRoomStyles
|
|
215
|
+
? (configWithEventHandlers.chatRoomStyles as import('react-native').ViewStyle)
|
|
216
|
+
: undefined
|
|
217
|
+
}
|
|
218
|
+
>
|
|
219
|
+
{!configWithEventHandlers?.disableHeader && (
|
|
220
|
+
<ChatHeader
|
|
221
|
+
currentRoom={roomsList[activeRoomJID]}
|
|
222
|
+
handleBackClick={handleBackClick}
|
|
223
|
+
/>
|
|
224
|
+
)}
|
|
225
|
+
{configWithEventHandlers?.chatHeaderAdditional?.enabled &&
|
|
226
|
+
configWithEventHandlers.chatHeaderAdditional.element()}
|
|
227
|
+
<View style={{ flex: 1 }}>
|
|
228
|
+
{loading || globalLoading ? (
|
|
229
|
+
<View
|
|
230
|
+
style={{
|
|
231
|
+
flex: 1,
|
|
232
|
+
justifyContent: 'center',
|
|
233
|
+
alignItems: 'center',
|
|
234
|
+
}}
|
|
235
|
+
>
|
|
236
|
+
<Loader color={configWithEventHandlers?.colors?.primary} />
|
|
237
|
+
</View>
|
|
238
|
+
) : Object.keys(roomsList).length < 1 || !activeRoomJID ? (
|
|
239
|
+
<View
|
|
240
|
+
style={{
|
|
241
|
+
flex: 1,
|
|
242
|
+
justifyContent: 'center',
|
|
243
|
+
alignItems: 'center',
|
|
244
|
+
}}
|
|
245
|
+
>
|
|
246
|
+
<NoSelectedChatIcon />
|
|
247
|
+
</View>
|
|
248
|
+
) : !roomMessages || roomMessages.length === 0 ? (
|
|
249
|
+
<View
|
|
250
|
+
style={{
|
|
251
|
+
flex: 1,
|
|
252
|
+
justifyContent: 'center',
|
|
253
|
+
alignItems: 'center',
|
|
254
|
+
backgroundColor: '#ffffff',
|
|
255
|
+
}}
|
|
256
|
+
>
|
|
257
|
+
<NoMessagesPlaceholder />
|
|
258
|
+
</View>
|
|
259
|
+
) : CustomScrollableArea ? (
|
|
260
|
+
<CustomScrollableArea
|
|
261
|
+
roomJID={activeRoomJID}
|
|
262
|
+
messages={roomMessages}
|
|
263
|
+
decoratedMessages={roomMessages.map((msg, idx) => ({
|
|
264
|
+
message: msg,
|
|
265
|
+
showDateLabel:
|
|
266
|
+
idx === 0 ||
|
|
267
|
+
new Date(msg.date).toDateString() !==
|
|
268
|
+
new Date(roomMessages[idx - 1]?.date).toDateString(),
|
|
269
|
+
}))}
|
|
270
|
+
isLoading={isLoadingMore}
|
|
271
|
+
isReply={false}
|
|
272
|
+
loadMoreMessages={loadMoreMessages}
|
|
273
|
+
renderMessage={(decorated: {
|
|
274
|
+
message: any;
|
|
275
|
+
showDateLabel: boolean;
|
|
276
|
+
}) =>
|
|
277
|
+
CustomMessageComponent ? (
|
|
278
|
+
<CustomMessageComponent
|
|
279
|
+
message={decorated.message}
|
|
280
|
+
isUser={decorated.message.user.id === user.xmppUsername}
|
|
281
|
+
isReply={false}
|
|
282
|
+
/>
|
|
283
|
+
) : null
|
|
284
|
+
}
|
|
285
|
+
scrollController={{
|
|
286
|
+
scrollToBottom: () => {},
|
|
287
|
+
waitForImagesLoaded: async () => {},
|
|
288
|
+
showScrollButton: false,
|
|
289
|
+
newMessagesCount: 0,
|
|
290
|
+
resetNewMessageCounter: () => {},
|
|
291
|
+
}}
|
|
292
|
+
typingIndicator={
|
|
293
|
+
roomsList[activeRoomJID]?.composing ? (
|
|
294
|
+
configWithEventHandlers?.customTypingIndicator
|
|
295
|
+
?.customComponent ? (
|
|
296
|
+
<configWithEventHandlers.customTypingIndicator.customComponent
|
|
297
|
+
usersTyping={
|
|
298
|
+
roomsList[activeRoomJID]?.composingList || []
|
|
299
|
+
}
|
|
300
|
+
text={
|
|
301
|
+
typeof configWithEventHandlers.customTypingIndicator
|
|
302
|
+
.text === 'function'
|
|
303
|
+
? configWithEventHandlers.customTypingIndicator.text(
|
|
304
|
+
roomsList[activeRoomJID]?.composingList || [],
|
|
305
|
+
)
|
|
306
|
+
: configWithEventHandlers.customTypingIndicator
|
|
307
|
+
.text || 'Typing...'
|
|
308
|
+
}
|
|
309
|
+
isVisible={true}
|
|
310
|
+
/>
|
|
311
|
+
) : null
|
|
312
|
+
) : undefined
|
|
313
|
+
}
|
|
314
|
+
config={configWithEventHandlers}
|
|
315
|
+
/>
|
|
316
|
+
) : (
|
|
317
|
+
<MessageList
|
|
318
|
+
loadMoreMessages={loadMoreMessages}
|
|
319
|
+
CustomMessage={CustomMessageComponent}
|
|
320
|
+
CustomDaySeparator={CustomDaySeparator}
|
|
321
|
+
CustomNewMessageLabel={CustomNewMessageLabel}
|
|
322
|
+
user={user}
|
|
323
|
+
roomJID={activeRoomJID}
|
|
324
|
+
config={configWithEventHandlers}
|
|
325
|
+
loading={isLoadingMore}
|
|
326
|
+
isReply={false}
|
|
327
|
+
/>
|
|
328
|
+
)}
|
|
329
|
+
</View>
|
|
330
|
+
{editAction && editAction.isEdit && (
|
|
331
|
+
<EditWrapper text={editAction.text || ''} onClose={onCloseEdit} />
|
|
332
|
+
)}
|
|
333
|
+
{CustomInputComponent ? (
|
|
334
|
+
<CustomInputComponent
|
|
335
|
+
sendMessage={
|
|
336
|
+
editAction && editAction.isEdit ? sendEditMessage : sendMessage
|
|
337
|
+
}
|
|
338
|
+
sendMedia={sendMedia}
|
|
339
|
+
config={configWithEventHandlers}
|
|
340
|
+
isLoading={loading}
|
|
341
|
+
onFocus={sendStartComposing}
|
|
342
|
+
onBlur={sendEndComposing}
|
|
343
|
+
isMessageProcessing={isLastMessageFromUserAndProcessing(
|
|
344
|
+
activeRoomJID,
|
|
345
|
+
)}
|
|
346
|
+
editMessage={editAction && editAction.text}
|
|
347
|
+
/>
|
|
348
|
+
) : (
|
|
349
|
+
<SendInput
|
|
350
|
+
editMessage={editAction && editAction.text}
|
|
351
|
+
sendMessage={
|
|
352
|
+
editAction && editAction.isEdit ? sendEditMessage : sendMessage
|
|
353
|
+
}
|
|
354
|
+
sendMedia={sendMedia}
|
|
355
|
+
config={configWithEventHandlers}
|
|
356
|
+
isLoading={loading}
|
|
357
|
+
onFocus={sendStartComposing}
|
|
358
|
+
onBlur={sendEndComposing}
|
|
359
|
+
isMessageProcessing={isLastMessageFromUserAndProcessing(
|
|
360
|
+
activeRoomJID,
|
|
361
|
+
)}
|
|
362
|
+
/>
|
|
363
|
+
)}
|
|
364
|
+
|
|
365
|
+
{configWithEventHandlers?.customTypingIndicator?.enabled &&
|
|
366
|
+
(configWithEventHandlers.customTypingIndicator.position ===
|
|
367
|
+
'overlay' ||
|
|
368
|
+
configWithEventHandlers.customTypingIndicator.position ===
|
|
369
|
+
'floating') &&
|
|
370
|
+
roomsList[activeRoomJID]?.composing && (
|
|
371
|
+
<CustomTypingIndicator
|
|
372
|
+
usersTyping={
|
|
373
|
+
roomsList[activeRoomJID]?.composingList || ['User']
|
|
374
|
+
}
|
|
375
|
+
text={configWithEventHandlers.customTypingIndicator.text}
|
|
376
|
+
position={
|
|
377
|
+
configWithEventHandlers.customTypingIndicator.position
|
|
378
|
+
}
|
|
379
|
+
styles={configWithEventHandlers.customTypingIndicator.styles}
|
|
380
|
+
customComponent={
|
|
381
|
+
configWithEventHandlers.customTypingIndicator.customComponent
|
|
382
|
+
}
|
|
383
|
+
isVisible={roomsList[activeRoomJID]?.composing || false}
|
|
384
|
+
/>
|
|
385
|
+
)}
|
|
386
|
+
</ChatContainer>
|
|
387
|
+
</View>
|
|
388
|
+
);
|
|
389
|
+
},
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
export default ChatRoom;
|