@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,471 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
CenterContainer,
|
|
4
|
+
UserInfo,
|
|
5
|
+
UserName,
|
|
6
|
+
UserStatus,
|
|
7
|
+
ModalContainerFullScreen,
|
|
8
|
+
Label,
|
|
9
|
+
BorderedContainer,
|
|
10
|
+
LabelData,
|
|
11
|
+
Viewider,
|
|
12
|
+
Divider,
|
|
13
|
+
} from '../styledModalComponents';
|
|
14
|
+
import { Pressable, View, Text, ScrollView, Alert, Linking, Platform } from 'react-native';
|
|
15
|
+
import ModalHeaderComponent from '../ModalHeaderComponent';
|
|
16
|
+
import { ProfileImagePlaceholder } from '../../MainComponents/ProfileImagePlaceholder';
|
|
17
|
+
import { useDispatch, useSelector } from 'react-redux';
|
|
18
|
+
import { RootState, getActiveRoom } from '../../../roomStore';
|
|
19
|
+
import { uploadFile } from '../../../networking/api-requests/auth.api';
|
|
20
|
+
import { useXmppClient } from '../../../context/xmppProvider';
|
|
21
|
+
import { updateRoom } from '../../../roomStore/roomsSlice';
|
|
22
|
+
import ImagePicker from 'react-native-image-crop-picker';
|
|
23
|
+
import {
|
|
24
|
+
check,
|
|
25
|
+
request,
|
|
26
|
+
PERMISSIONS,
|
|
27
|
+
RESULTS,
|
|
28
|
+
Permission,
|
|
29
|
+
} from 'react-native-permissions';
|
|
30
|
+
import Loader from '../../styled/Loader';
|
|
31
|
+
import Button from '../../styled/Button';
|
|
32
|
+
import { DeleteIcon, MoreIcon, QrIcon } from '../../../assets/icons';
|
|
33
|
+
import Switch from '../../MainComponents/Switch';
|
|
34
|
+
import { useChatSettingState } from '../../../hooks/useChatSettingState';
|
|
35
|
+
import { deleteRoomMember } from '../../../networking/api-requests/rooms.api';
|
|
36
|
+
import { RoomMember } from '../../../types/models/room.model';
|
|
37
|
+
import { setActiveModal, setSelectedUser } from '../../../roomStore/chatSettingsSlice';
|
|
38
|
+
import { MODAL_TYPES } from '../../../helpers/constants/MODAL_TYPES';
|
|
39
|
+
import DropdownMenu, { MenuOption } from '../../DropdownMenu/DropdownMenu';
|
|
40
|
+
import SelectUsersModal from '../SelectUsersModal/SelectUsersModal';
|
|
41
|
+
import { useToast } from '../../../context/ToastContext';
|
|
42
|
+
import DeleteChatModal from './DeleteChatModal';
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
interface ChatProfileModalProps {
|
|
46
|
+
handleCloseModal: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ChatProfileModal: React.FC<ChatProfileModalProps> = ({
|
|
50
|
+
handleCloseModal,
|
|
51
|
+
}) => {
|
|
52
|
+
const [loading, setLoading] = useState<boolean>(false);
|
|
53
|
+
const [visible, setVisible] = useState<boolean>(false);
|
|
54
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
55
|
+
|
|
56
|
+
const { showToast } = useToast();
|
|
57
|
+
|
|
58
|
+
const chatMenuOptions = useMemo(
|
|
59
|
+
() => [
|
|
60
|
+
{
|
|
61
|
+
label: 'Delete chat',
|
|
62
|
+
icon: <DeleteIcon />,
|
|
63
|
+
onClick: () => {
|
|
64
|
+
setIsModalOpen(true);
|
|
65
|
+
},
|
|
66
|
+
styles: { color: 'red' },
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
[]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const dispatch = useDispatch();
|
|
73
|
+
|
|
74
|
+
const { client } = useXmppClient();
|
|
75
|
+
const { user: stateUser, config } = useChatSettingState();
|
|
76
|
+
const activeRoom = useSelector((state: RootState) => getActiveRoom(state));
|
|
77
|
+
|
|
78
|
+
// Pull live member list from the MUC when the modal opens — REST
|
|
79
|
+
// hydration only fills the *count* (item.participants /
|
|
80
|
+
// item.members.length); the actual roster comes from a `getRoomMembers`
|
|
81
|
+
// IQ which onGetMembers in stanzaHandlers parses into `roomMembers`.
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (client && activeRoom?.jid) {
|
|
84
|
+
try {
|
|
85
|
+
client.getRoomMembersStanza?.(activeRoom.jid);
|
|
86
|
+
} catch {
|
|
87
|
+
/* non-fatal */
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, [client, activeRoom?.jid]);
|
|
91
|
+
|
|
92
|
+
const checkPermission = async (permission: Permission) => {
|
|
93
|
+
const status = await check(permission);
|
|
94
|
+
if (status === RESULTS.GRANTED) {
|
|
95
|
+
return status;
|
|
96
|
+
} else if (status === RESULTS.DENIED) {
|
|
97
|
+
const requestStatus = await request(permission);
|
|
98
|
+
return requestStatus;
|
|
99
|
+
}
|
|
100
|
+
return status;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const onUpload = async () => {
|
|
104
|
+
let loadingSet = false;
|
|
105
|
+
try {
|
|
106
|
+
setLoading(true);
|
|
107
|
+
loadingSet = true;
|
|
108
|
+
|
|
109
|
+
const permission =
|
|
110
|
+
Platform.OS === 'ios'
|
|
111
|
+
? PERMISSIONS.IOS.PHOTO_LIBRARY
|
|
112
|
+
: PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE;
|
|
113
|
+
const permissionStatus = await checkPermission(permission);
|
|
114
|
+
|
|
115
|
+
if (permissionStatus !== RESULTS.GRANTED) {
|
|
116
|
+
Alert.alert(
|
|
117
|
+
'Permission required',
|
|
118
|
+
'Photo library permission is needed to select images.',
|
|
119
|
+
[
|
|
120
|
+
{
|
|
121
|
+
text: 'Cancel',
|
|
122
|
+
onPress: () => {
|
|
123
|
+
setLoading(false);
|
|
124
|
+
console.log('Photo permission cancelled');
|
|
125
|
+
},
|
|
126
|
+
style: 'cancel',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
text: 'Open Settings',
|
|
130
|
+
onPress: () => Linking.openSettings(),
|
|
131
|
+
},
|
|
132
|
+
]
|
|
133
|
+
);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const image = await ImagePicker.openPicker({
|
|
138
|
+
width: 300,
|
|
139
|
+
height: 300,
|
|
140
|
+
cropping: true,
|
|
141
|
+
cropperCircleOverlay: true,
|
|
142
|
+
compressImageQuality: 0.8,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const originalName = image.path.split('/').pop();
|
|
146
|
+
const fileObject = {
|
|
147
|
+
uri: image.path,
|
|
148
|
+
type: image.mime || 'image/jpeg',
|
|
149
|
+
name: originalName || `profile_${Date.now()}.jpg`,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const mediaData = new FormData();
|
|
153
|
+
mediaData.append('files', fileObject as any);
|
|
154
|
+
|
|
155
|
+
const uploadResult = await uploadFile(mediaData);
|
|
156
|
+
const location = uploadResult?.data?.results?.[0]?.location;
|
|
157
|
+
|
|
158
|
+
if (location) {
|
|
159
|
+
client.setRoomImageStanza(activeRoom?.jid || '', location, 'icon', 'none');
|
|
160
|
+
dispatch(
|
|
161
|
+
updateRoom({ jid: activeRoom?.jid || '', updates: { icon: location } })
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
showToast({
|
|
165
|
+
id: Date.now().toString(),
|
|
166
|
+
title: 'Success',
|
|
167
|
+
message: 'Room image updated successfully',
|
|
168
|
+
type: 'success',
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
} catch (error: any) {
|
|
172
|
+
if (error?.code === 'E_PICKER_CANCELLED' || error?.code === 'E_NO_CAMERA_PERMISSION') {
|
|
173
|
+
console.log('User cancelled image selection');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
console.error('File upload failed or location is missing:', error);
|
|
178
|
+
showToast({
|
|
179
|
+
id: Date.now().toString(),
|
|
180
|
+
title: 'Error',
|
|
181
|
+
message: 'Failed to upload image',
|
|
182
|
+
type: 'error',
|
|
183
|
+
});
|
|
184
|
+
} finally {
|
|
185
|
+
if (loadingSet) {
|
|
186
|
+
setLoading(false);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const handleDeleteUser = async (userId: string) => {
|
|
192
|
+
try {
|
|
193
|
+
await deleteRoomMember({
|
|
194
|
+
roomId: activeRoom?.jid?.split('@')[0] || '',
|
|
195
|
+
members: [userId],
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
dispatch(
|
|
199
|
+
updateRoom({
|
|
200
|
+
jid: activeRoom?.jid || '',
|
|
201
|
+
updates: {
|
|
202
|
+
roomMembers: activeRoom?.roomMembers?.filter(
|
|
203
|
+
(user) => user.xmppUsername !== userId
|
|
204
|
+
),
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
showToast({
|
|
210
|
+
id: Date.now().toString(),
|
|
211
|
+
title: 'Success',
|
|
212
|
+
message: `${userId} has been removed from the room.`,
|
|
213
|
+
type: 'success',
|
|
214
|
+
});
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.error('Failed to delete user:', error);
|
|
217
|
+
showToast({
|
|
218
|
+
id: Date.now().toString(),
|
|
219
|
+
title: 'Error',
|
|
220
|
+
message: 'Failed to delete user.',
|
|
221
|
+
type: 'error',
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const onRemoveClick = async () => {
|
|
227
|
+
client.setRoomImageStanza(activeRoom?.jid || '', '', 'icon', 'none');
|
|
228
|
+
dispatch(updateRoom({ jid: activeRoom?.jid || '', updates: { icon: null } }));
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const handleUserAvatarClick = (user: RoomMember): void => {
|
|
232
|
+
dispatch(setActiveModal(MODAL_TYPES.PROFILE));
|
|
233
|
+
dispatch(
|
|
234
|
+
setSelectedUser({
|
|
235
|
+
id: user._id,
|
|
236
|
+
firstName: user.firstName,
|
|
237
|
+
lastName: user.lastName,
|
|
238
|
+
name: `${user.firstName} ${user.lastName}`,
|
|
239
|
+
userJID: user?.xmppUsername,
|
|
240
|
+
})
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const menuOptions = useMemo(
|
|
245
|
+
() => (userId: string) => [
|
|
246
|
+
{
|
|
247
|
+
label: 'Appoint as an admin',
|
|
248
|
+
icon: null,
|
|
249
|
+
onClick: () => {
|
|
250
|
+
dispatch(setActiveModal(MODAL_TYPES.PROFILE));
|
|
251
|
+
console.log('Profile clicked');
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
label: 'Unban',
|
|
256
|
+
icon: null,
|
|
257
|
+
onClick: () => {
|
|
258
|
+
dispatch(setActiveModal(MODAL_TYPES.SETTINGS));
|
|
259
|
+
console.log('Settings clicked');
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
label: 'Delete',
|
|
264
|
+
icon: null,
|
|
265
|
+
onClick: (e: any) => {
|
|
266
|
+
e?.preventDefault();
|
|
267
|
+
handleDeleteUser(userId);
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
[]
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
if (!activeRoom) {
|
|
276
|
+
dispatch(setActiveModal());
|
|
277
|
+
}
|
|
278
|
+
}, [activeRoom, dispatch]);
|
|
279
|
+
|
|
280
|
+
if (!activeRoom) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return (
|
|
285
|
+
<ModalContainerFullScreen style={{ position: 'relative' }}>
|
|
286
|
+
<ModalHeaderComponent
|
|
287
|
+
handleCloseModal={handleCloseModal}
|
|
288
|
+
headerTitle={'Chat Profile'}
|
|
289
|
+
rightMenu={
|
|
290
|
+
<>
|
|
291
|
+
{activeRoom?.type === 'public' && (
|
|
292
|
+
<Button EndIcon={<QrIcon />} onPress={() => setVisible(true)} />
|
|
293
|
+
)}
|
|
294
|
+
{activeRoom.role === 'moderator' &&
|
|
295
|
+
activeRoom.type !== 'private' && (
|
|
296
|
+
<DropdownMenu
|
|
297
|
+
position="right"
|
|
298
|
+
options={chatMenuOptions}
|
|
299
|
+
openButton={
|
|
300
|
+
<Button
|
|
301
|
+
style={{ padding: 8, height: 40 }}
|
|
302
|
+
EndIcon={<MoreIcon />}
|
|
303
|
+
unstyled
|
|
304
|
+
/>
|
|
305
|
+
}
|
|
306
|
+
/>
|
|
307
|
+
)}
|
|
308
|
+
</>
|
|
309
|
+
}
|
|
310
|
+
/>
|
|
311
|
+
<CenterContainer>
|
|
312
|
+
<ProfileImagePlaceholder
|
|
313
|
+
name={activeRoom.title || activeRoom.name}
|
|
314
|
+
icon={activeRoom.icon}
|
|
315
|
+
upload={{
|
|
316
|
+
onUpload,
|
|
317
|
+
active: activeRoom?.role !== 'participant' ? true : false,
|
|
318
|
+
}}
|
|
319
|
+
remove={{ enabled: true, onRemoveClick }}
|
|
320
|
+
role={activeRoom?.role}
|
|
321
|
+
size={128}
|
|
322
|
+
/>
|
|
323
|
+
<UserInfo>
|
|
324
|
+
<UserName>{activeRoom.title || activeRoom.name}</UserName>
|
|
325
|
+
<UserStatus>
|
|
326
|
+
{activeRoom.usersCnt}{' '}
|
|
327
|
+
{activeRoom.usersCnt > 1 ? 'members' : 'member'}
|
|
328
|
+
</UserStatus>
|
|
329
|
+
</UserInfo>
|
|
330
|
+
{activeRoom.role === 'moderator' && activeRoom.type === 'group' && (
|
|
331
|
+
<>
|
|
332
|
+
{/* <AddMembersModal /> */}
|
|
333
|
+
<SelectUsersModal />
|
|
334
|
+
</>
|
|
335
|
+
)}
|
|
336
|
+
{!config?.disableChatInfo?.disableDescription && (
|
|
337
|
+
<BorderedContainer>
|
|
338
|
+
<LabelData>Description</LabelData>
|
|
339
|
+
<Label>{activeRoom?.description || '—'}</Label>
|
|
340
|
+
</BorderedContainer>
|
|
341
|
+
)}
|
|
342
|
+
{!config?.disableChatInfo?.disableType && (
|
|
343
|
+
<BorderedContainer>
|
|
344
|
+
<LabelData>Chat type</LabelData>
|
|
345
|
+
<Label>{activeRoom.type || '—'}</Label>
|
|
346
|
+
</BorderedContainer>
|
|
347
|
+
)}
|
|
348
|
+
{/* <BorderedContainer
|
|
349
|
+
style={{
|
|
350
|
+
justifyContent: 'space-between',
|
|
351
|
+
flexDirection: 'row',
|
|
352
|
+
alignItems: 'center',
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
<Label>Notifications</Label>
|
|
356
|
+
<Label>
|
|
357
|
+
<Switch
|
|
358
|
+
onToggle={function (isOn: boolean): void {
|
|
359
|
+
throw new Error('Function not implemented.');
|
|
360
|
+
}}
|
|
361
|
+
bgColor={config?.colors?.primary}
|
|
362
|
+
/>
|
|
363
|
+
</Label>
|
|
364
|
+
</BorderedContainer> */}
|
|
365
|
+
{!config?.disableChatInfo?.hideMembers && (
|
|
366
|
+
<BorderedContainer style={{ paddingHorizontal: 16, paddingVertical: 8 }}>
|
|
367
|
+
{loading ? (
|
|
368
|
+
<Loader />
|
|
369
|
+
) : (activeRoom?.roomMembers?.length ?? 0) === 0 ? (
|
|
370
|
+
<Label style={{ opacity: 0.6, textAlign: 'center', paddingVertical: 8 }}>
|
|
371
|
+
Member list unavailable
|
|
372
|
+
</Label>
|
|
373
|
+
) : (
|
|
374
|
+
<ScrollView
|
|
375
|
+
style={{ maxHeight: 400 }}
|
|
376
|
+
showsVerticalScrollIndicator={true}
|
|
377
|
+
nestedScrollEnabled={true}
|
|
378
|
+
>
|
|
379
|
+
{activeRoom?.roomMembers?.map((user, index) => (
|
|
380
|
+
<View
|
|
381
|
+
key={user.xmppUsername}
|
|
382
|
+
style={{
|
|
383
|
+
flexDirection: 'column',
|
|
384
|
+
alignItems: 'flex-start',
|
|
385
|
+
}}
|
|
386
|
+
>
|
|
387
|
+
<View
|
|
388
|
+
style={{
|
|
389
|
+
flexDirection: 'row',
|
|
390
|
+
justifyContent: 'flex-start',
|
|
391
|
+
paddingHorizontal: 8,
|
|
392
|
+
paddingVertical: 0,
|
|
393
|
+
alignItems: 'center',
|
|
394
|
+
width: '100%',
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
<Pressable
|
|
398
|
+
style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start', gap: 16 }}
|
|
399
|
+
onPress={() => handleUserAvatarClick(user)}
|
|
400
|
+
>
|
|
401
|
+
<ProfileImagePlaceholder
|
|
402
|
+
name={`${user.firstName} ${user.lastName}`}
|
|
403
|
+
size={40}
|
|
404
|
+
/>
|
|
405
|
+
<View
|
|
406
|
+
style={{
|
|
407
|
+
flexDirection: 'column',
|
|
408
|
+
gap: 2,
|
|
409
|
+
alignItems: 'flex-start',
|
|
410
|
+
justifyContent: 'center',
|
|
411
|
+
}}
|
|
412
|
+
>
|
|
413
|
+
<Label style={{ fontSize: 16, fontWeight: 600 }}>
|
|
414
|
+
{user.firstName} {user.lastName}
|
|
415
|
+
</Label>
|
|
416
|
+
{user.last_active && (
|
|
417
|
+
<LabelData>
|
|
418
|
+
{new Date(user.last_active * 1000).toLocaleString()}
|
|
419
|
+
</LabelData>
|
|
420
|
+
)}
|
|
421
|
+
</View>
|
|
422
|
+
</Pressable>
|
|
423
|
+
{user.role && user.role !== 'none' && (
|
|
424
|
+
<Text
|
|
425
|
+
style={{
|
|
426
|
+
backgroundColor:
|
|
427
|
+
user.ban_status !== 'banned' ? '#F3F6FC' : '#FFEBEE',
|
|
428
|
+
color:
|
|
429
|
+
user.ban_status !== 'banned' ? '#0052CD' : '#F44336',
|
|
430
|
+
padding: 5,
|
|
431
|
+
borderRadius: 16,
|
|
432
|
+
fontSize: 12,
|
|
433
|
+
}}
|
|
434
|
+
>
|
|
435
|
+
{user.role}
|
|
436
|
+
</Text>
|
|
437
|
+
)}
|
|
438
|
+
{stateUser.xmppUsername !== user.xmppUsername &&
|
|
439
|
+
activeRoom.role === 'moderator' &&
|
|
440
|
+
activeRoom.type !== 'private' && (
|
|
441
|
+
<DropdownMenu
|
|
442
|
+
options={menuOptions(user.xmppUsername) as MenuOption[]}
|
|
443
|
+
openButton={
|
|
444
|
+
<Button
|
|
445
|
+
onPress={() => {}}
|
|
446
|
+
>
|
|
447
|
+
<Text>More Options</Text>
|
|
448
|
+
</Button>
|
|
449
|
+
}
|
|
450
|
+
onClose={() => console.log('Dropdown closed')}
|
|
451
|
+
/>
|
|
452
|
+
)}
|
|
453
|
+
</View>
|
|
454
|
+
{index < (activeRoom?.roomMembers?.length || 0) - 1 && <Divider />}
|
|
455
|
+
</View>
|
|
456
|
+
))}
|
|
457
|
+
</ScrollView>
|
|
458
|
+
)}
|
|
459
|
+
</BorderedContainer>
|
|
460
|
+
)}
|
|
461
|
+
</CenterContainer>
|
|
462
|
+
|
|
463
|
+
<DeleteChatModal
|
|
464
|
+
isModalOpen={isModalOpen}
|
|
465
|
+
setIsModalOpen={setIsModalOpen}
|
|
466
|
+
/>
|
|
467
|
+
</ModalContainerFullScreen>
|
|
468
|
+
);
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
export default ChatProfileModal;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import Button from '../../styled/Button';
|
|
3
|
+
import { useDispatch, useSelector } from 'react-redux';
|
|
4
|
+
import { getActiveRoom, RootState } from '../../../roomStore';
|
|
5
|
+
import {
|
|
6
|
+
CloseButton,
|
|
7
|
+
GroupContainer,
|
|
8
|
+
ModalBackground,
|
|
9
|
+
ModalContainer,
|
|
10
|
+
ModalTitle,
|
|
11
|
+
} from '../styledModalComponents';
|
|
12
|
+
import { deleteRoom as deleteRoomApi } from '../../../networking/api-requests/rooms.api';
|
|
13
|
+
import { deleteRoom as deleteRoomAction } from '../../../roomStore/roomsSlice';
|
|
14
|
+
import { Text } from 'react-native';
|
|
15
|
+
import { useToast } from '../../../context/ToastContext';
|
|
16
|
+
|
|
17
|
+
interface DeleteChatModalProps {
|
|
18
|
+
isModalOpen: boolean;
|
|
19
|
+
setIsModalOpen: (isOpen: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DeleteChatModal: React.FC<DeleteChatModalProps> = ({
|
|
23
|
+
isModalOpen,
|
|
24
|
+
setIsModalOpen,
|
|
25
|
+
}) => {
|
|
26
|
+
const dispatch = useDispatch();
|
|
27
|
+
const { showToast } = useToast();
|
|
28
|
+
const activeRoom = useSelector((state: RootState) => getActiveRoom(state));
|
|
29
|
+
|
|
30
|
+
const handleOpenModal = () => setIsModalOpen(true);
|
|
31
|
+
const handleCloseModal = () => setIsModalOpen(false);
|
|
32
|
+
|
|
33
|
+
const handleDeleteChat = async () => {
|
|
34
|
+
try {
|
|
35
|
+
await deleteRoomApi(activeRoom?.jid?.split('@')[0] || '');
|
|
36
|
+
dispatch(deleteRoomAction({ jid: activeRoom?.jid || '' }));
|
|
37
|
+
handleCloseModal();
|
|
38
|
+
showToast({
|
|
39
|
+
id: Date.now().toString(),
|
|
40
|
+
title: 'Success',
|
|
41
|
+
message: 'Chat deleted successfully',
|
|
42
|
+
type: 'success',
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Failed to delete chat:', error);
|
|
46
|
+
showToast({
|
|
47
|
+
id: Date.now().toString(),
|
|
48
|
+
title: 'Error',
|
|
49
|
+
message: 'Failed to delete chat',
|
|
50
|
+
type: 'error',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
isModalOpen && (
|
|
57
|
+
<ModalBackground>
|
|
58
|
+
<ModalContainer>
|
|
59
|
+
<CloseButton onPress={handleCloseModal}>
|
|
60
|
+
<Text style={{ fontSize: 24 }}>×</Text>
|
|
61
|
+
</CloseButton>
|
|
62
|
+
<ModalTitle>Delete this chat ?</ModalTitle>
|
|
63
|
+
|
|
64
|
+
<GroupContainer>
|
|
65
|
+
<Button
|
|
66
|
+
onPress={handleCloseModal}
|
|
67
|
+
text={'Cancel'}
|
|
68
|
+
style={{ width: '100%' }}
|
|
69
|
+
unstyled
|
|
70
|
+
variant="filled"
|
|
71
|
+
/>
|
|
72
|
+
<Button
|
|
73
|
+
onPress={handleDeleteChat}
|
|
74
|
+
text={'Delete'}
|
|
75
|
+
style={{
|
|
76
|
+
width: '100%',
|
|
77
|
+
borderWidth: 1,
|
|
78
|
+
borderColor: 'red',
|
|
79
|
+
}}
|
|
80
|
+
color="red"
|
|
81
|
+
unstyled
|
|
82
|
+
variant="outlined"
|
|
83
|
+
/>
|
|
84
|
+
</GroupContainer>
|
|
85
|
+
</ModalContainer>
|
|
86
|
+
</ModalBackground>
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default DeleteChatModal;
|