@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,77 @@
|
|
|
1
|
+
import { Middleware, PayloadAction } from '@reduxjs/toolkit';
|
|
2
|
+
import { updateRoom } from '../roomsSlice';
|
|
3
|
+
import { IRoom, ReactionAction } from '../../types/types';
|
|
4
|
+
import { nanoToMs } from '../../helpers/nanoToMs';
|
|
5
|
+
|
|
6
|
+
export const reactionsMiddleware: Middleware =
|
|
7
|
+
(storeAPI) => (next) => (action: any) => {
|
|
8
|
+
if (action.type !== 'roomMessages/setReactions') {
|
|
9
|
+
return next(action);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!action.payload || typeof action.payload !== 'object') {
|
|
13
|
+
console.error('Invalid action payload for setReactions:', action);
|
|
14
|
+
return next(action);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const result = next(action);
|
|
18
|
+
const state = storeAPI.getState();
|
|
19
|
+
const rooms: { [jid: string]: IRoom } = state.rooms.rooms;
|
|
20
|
+
const { roomJID, reactions, latestReactionTimestamp, data, ...rest } =
|
|
21
|
+
action.payload;
|
|
22
|
+
|
|
23
|
+
const updLastMessage = () => {
|
|
24
|
+
if (!reactions?.[0]) {
|
|
25
|
+
const newLastMessage =
|
|
26
|
+
rooms[roomJID].messages[rooms[roomJID].messages.length - 1];
|
|
27
|
+
|
|
28
|
+
storeAPI.dispatch(
|
|
29
|
+
updateRoom({
|
|
30
|
+
jid: roomJID,
|
|
31
|
+
updates: {
|
|
32
|
+
lastMessageTimestamp: nanoToMs(
|
|
33
|
+
rooms[roomJID].messages[rooms[roomJID].messages.length - 1].id
|
|
34
|
+
),
|
|
35
|
+
lastMessage: newLastMessage,
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
} else {
|
|
40
|
+
const updates = {
|
|
41
|
+
lastMessageTimestamp: nanoToMs(latestReactionTimestamp) ?? 0,
|
|
42
|
+
lastMessage: {
|
|
43
|
+
...rest,
|
|
44
|
+
body: reactions[0],
|
|
45
|
+
emoji: reactions[0],
|
|
46
|
+
user: {
|
|
47
|
+
name: `${data.senderFirstName} ${data.senderLastName}`,
|
|
48
|
+
id: `emoji-${new Date().toString()}`,
|
|
49
|
+
},
|
|
50
|
+
date: new Date(nanoToMs(latestReactionTimestamp)).toISOString(),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
storeAPI.dispatch(
|
|
55
|
+
updateRoom({
|
|
56
|
+
jid: roomJID,
|
|
57
|
+
updates,
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (!rooms[roomJID]) {
|
|
64
|
+
console.warn(`Room ${roomJID} not found in reactions middleware`);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (
|
|
69
|
+
rooms[roomJID]?.lastMessageTimestamp <= nanoToMs(latestReactionTimestamp)
|
|
70
|
+
) {
|
|
71
|
+
updLastMessage();
|
|
72
|
+
} else if (!rooms[roomJID]?.lastMessageTimestamp) {
|
|
73
|
+
updLastMessage();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
|
|
3
|
+
export const testMiddleware: Middleware =
|
|
4
|
+
(storeAPI) => (next) => (action: any) => {
|
|
5
|
+
if (process.env.NODE_ENV === 'development') {
|
|
6
|
+
console.group(`🔍 TestMiddleware - Action: ${action.type}`);
|
|
7
|
+
console.log('📤 Action:', action);
|
|
8
|
+
console.log('📊 Current State:', storeAPI.getState());
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const result = next(action);
|
|
12
|
+
|
|
13
|
+
if (process.env.NODE_ENV === 'development') {
|
|
14
|
+
console.log('📥 Result:', result);
|
|
15
|
+
console.log('🔄 New State:', storeAPI.getState());
|
|
16
|
+
console.groupEnd();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { updateRoom } from '../roomsSlice';
|
|
3
|
+
import { IMessage } from '../../types/types';
|
|
4
|
+
|
|
5
|
+
let previousMessagesCount: { [jid: string]: number } = {};
|
|
6
|
+
|
|
7
|
+
export const unreadMiddleware: Middleware =
|
|
8
|
+
(storeAPI) => (next) => (action: any) => {
|
|
9
|
+
if (!action || !action.type) {
|
|
10
|
+
console.error('Invalid action in unreadMiddleware:', action);
|
|
11
|
+
return next(action);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (action?.type === 'roomMessages/deleteRoomMessage') {
|
|
15
|
+
return next(action);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const result = next(action);
|
|
19
|
+
|
|
20
|
+
const state = storeAPI.getState();
|
|
21
|
+
const rooms = state.rooms.rooms;
|
|
22
|
+
const activeChatJID = state.rooms.activeRoomJID;
|
|
23
|
+
|
|
24
|
+
if (rooms && Object.keys(rooms).length > 0) {
|
|
25
|
+
Object.keys(rooms).forEach((jid) => {
|
|
26
|
+
const room = rooms[jid];
|
|
27
|
+
if (room.lastViewedTimestamp !== 0 && jid !== activeChatJID) {
|
|
28
|
+
const currentMessagesLength = room.messages?.length || 0;
|
|
29
|
+
|
|
30
|
+
if (previousMessagesCount[jid] !== currentMessagesLength) {
|
|
31
|
+
previousMessagesCount[jid] = currentMessagesLength;
|
|
32
|
+
|
|
33
|
+
// Mirror `countNewerMessages` in roomsSlice: ignore the
|
|
34
|
+
// "delimiter-new" sentinel + locally-pending sends so the
|
|
35
|
+
// two paths never disagree.
|
|
36
|
+
const unreadMessagesCount = room.messages?.filter(
|
|
37
|
+
(msg: IMessage) =>
|
|
38
|
+
msg.id !== 'delimiter-new' &&
|
|
39
|
+
!msg.pending &&
|
|
40
|
+
new Date(msg.date).getTime() >
|
|
41
|
+
(room.lastViewedTimestamp || 0)
|
|
42
|
+
).length;
|
|
43
|
+
|
|
44
|
+
if (room.unreadMessages !== unreadMessagesCount) {
|
|
45
|
+
storeAPI.dispatch(
|
|
46
|
+
updateRoom({
|
|
47
|
+
jid,
|
|
48
|
+
updates: { unreadMessages: unreadMessagesCount },
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
2
|
+
import {
|
|
3
|
+
DeleteModal,
|
|
4
|
+
EditAction,
|
|
5
|
+
IConfig,
|
|
6
|
+
IUser,
|
|
7
|
+
ModalFile,
|
|
8
|
+
ModalType,
|
|
9
|
+
User,
|
|
10
|
+
} from '../types/types';
|
|
11
|
+
import { Iso639_1Codes } from '../types/models/language.model';
|
|
12
|
+
import { localStorageConstants } from '../helpers/constants/LOCAL_STORAGE';
|
|
13
|
+
import { asyncLocalStorage } from '../hooks/useLocalStorage';
|
|
14
|
+
|
|
15
|
+
interface ChatState {
|
|
16
|
+
user: User;
|
|
17
|
+
config?: IConfig;
|
|
18
|
+
activeModal?: ModalType;
|
|
19
|
+
deleteModal?: DeleteModal;
|
|
20
|
+
selectedUser?: IUser;
|
|
21
|
+
activeFile?: ModalFile;
|
|
22
|
+
client?: any;
|
|
23
|
+
langSource?: Iso639_1Codes;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const unpackAndTransform = (input?: User): User => {
|
|
27
|
+
return {
|
|
28
|
+
description: '',
|
|
29
|
+
token: input?.token || '',
|
|
30
|
+
profileImage: input?.profileImage || '',
|
|
31
|
+
_id: input?._id || '',
|
|
32
|
+
walletAddress: input?.defaultWallet?.walletAddress || '',
|
|
33
|
+
xmppPassword: input?.xmppPassword || '',
|
|
34
|
+
refreshToken: input?.refreshToken || '',
|
|
35
|
+
firstName: input?.firstName || '',
|
|
36
|
+
lastName: input?.lastName || '',
|
|
37
|
+
defaultWallet: {
|
|
38
|
+
walletAddress: input?.defaultWallet?.walletAddress || '',
|
|
39
|
+
},
|
|
40
|
+
email: input?.email || '',
|
|
41
|
+
username: input?.username || '',
|
|
42
|
+
appId: input?.appId || '',
|
|
43
|
+
homeScreen: input?.homeScreen || '',
|
|
44
|
+
registrationChannelType: input?.registrationChannelType || '',
|
|
45
|
+
updatedAt: input?.updatedAt || '',
|
|
46
|
+
authMethod: input?.authMethod || '',
|
|
47
|
+
resetPasswordExpires: input?.resetPasswordExpires || '',
|
|
48
|
+
resetPasswordToken: input?.resetPasswordToken || '',
|
|
49
|
+
xmppUsername: input?.xmppUsername || '',
|
|
50
|
+
roles: input?.roles || [],
|
|
51
|
+
tags: input?.tags || [],
|
|
52
|
+
__v: input?.__v || 0,
|
|
53
|
+
isProfileOpen: input?.isProfileOpen || false,
|
|
54
|
+
isAssetsOpen: input?.isAssetsOpen || false,
|
|
55
|
+
isAgreeWithTerms: input?.isAgreeWithTerms || false,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const initialState: ChatState = {
|
|
60
|
+
user: {
|
|
61
|
+
description: '',
|
|
62
|
+
token: '',
|
|
63
|
+
profileImage: '',
|
|
64
|
+
_id: '',
|
|
65
|
+
walletAddress: '',
|
|
66
|
+
xmppPassword: '',
|
|
67
|
+
refreshToken: '',
|
|
68
|
+
firstName: '',
|
|
69
|
+
lastName: '',
|
|
70
|
+
defaultWallet: {
|
|
71
|
+
walletAddress: '',
|
|
72
|
+
},
|
|
73
|
+
email: '',
|
|
74
|
+
username: '',
|
|
75
|
+
appId: '',
|
|
76
|
+
homeScreen: '',
|
|
77
|
+
registrationChannelType: '',
|
|
78
|
+
updatedAt: '',
|
|
79
|
+
authMethod: '',
|
|
80
|
+
resetPasswordExpires: '',
|
|
81
|
+
resetPasswordToken: '',
|
|
82
|
+
xmppUsername: '',
|
|
83
|
+
roles: [],
|
|
84
|
+
tags: [],
|
|
85
|
+
__v: 0,
|
|
86
|
+
isProfileOpen: true,
|
|
87
|
+
isAssetsOpen: true,
|
|
88
|
+
isAgreeWithTerms: false,
|
|
89
|
+
},
|
|
90
|
+
deleteModal: {
|
|
91
|
+
isDeleteModal: false,
|
|
92
|
+
roomJid: '',
|
|
93
|
+
messageId: '',
|
|
94
|
+
},
|
|
95
|
+
config: { colors: { primary: '#0052CD', secondary: '#F3F6FC' } },
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const chatSlice = createSlice({
|
|
99
|
+
name: 'chat',
|
|
100
|
+
initialState,
|
|
101
|
+
reducers: {
|
|
102
|
+
setUser: (state, action: PayloadAction<User>) => {
|
|
103
|
+
state.user = unpackAndTransform(action.payload);
|
|
104
|
+
asyncLocalStorage(localStorageConstants.ETHORA_USER).set(
|
|
105
|
+
unpackAndTransform(action.payload)
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
updateUser(state, action: PayloadAction<{ updates: Partial<User> }>) {
|
|
109
|
+
const { updates } = action.payload;
|
|
110
|
+
const user = state.user;
|
|
111
|
+
if (user) {
|
|
112
|
+
state.user = {
|
|
113
|
+
...user,
|
|
114
|
+
...updates,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
setConfig: (state, action: PayloadAction<IConfig | undefined>) => {
|
|
119
|
+
// Cast away immer's WritableDraft — IConfig contains callable
|
|
120
|
+
// fields (eventHandlers, customComponent) that confuse the draft
|
|
121
|
+
// type inference but are inert at write-time.
|
|
122
|
+
state.config = action.payload as any;
|
|
123
|
+
},
|
|
124
|
+
setActiveModal: (state, action: PayloadAction<ModalType | undefined>) => {
|
|
125
|
+
state.activeModal = action.payload;
|
|
126
|
+
},
|
|
127
|
+
setActiveFile: (state, action: PayloadAction<ModalFile>) => {
|
|
128
|
+
state.activeFile = action.payload;
|
|
129
|
+
},
|
|
130
|
+
setDeleteModal: (state, action: PayloadAction<DeleteModal | undefined>) => {
|
|
131
|
+
state.deleteModal = action.payload;
|
|
132
|
+
},
|
|
133
|
+
setStoreClient: (state, action: PayloadAction<any>) => {
|
|
134
|
+
state.client = action.payload;
|
|
135
|
+
},
|
|
136
|
+
setSelectedUser: (state, action: PayloadAction<IUser | undefined>) => {
|
|
137
|
+
state.selectedUser = action.payload;
|
|
138
|
+
},
|
|
139
|
+
refreshTokens: (
|
|
140
|
+
state,
|
|
141
|
+
action: PayloadAction<{ token: string; refreshToken: string }>
|
|
142
|
+
) => {
|
|
143
|
+
state.user.refreshToken = action.payload.refreshToken;
|
|
144
|
+
state.user.token = action.payload.token;
|
|
145
|
+
// AsyncStorage is async; fire-and-forget so the reducer stays sync.
|
|
146
|
+
asyncLocalStorage(localStorageConstants.ETHORA_USER).set(state.user);
|
|
147
|
+
},
|
|
148
|
+
logout: (state) => {
|
|
149
|
+
state.user = unpackAndTransform();
|
|
150
|
+
state.config = undefined;
|
|
151
|
+
state.client = undefined;
|
|
152
|
+
state.langSource = undefined;
|
|
153
|
+
asyncLocalStorage(localStorageConstants.ETHORA_USER).remove();
|
|
154
|
+
},
|
|
155
|
+
setLangSource: (
|
|
156
|
+
state,
|
|
157
|
+
action: PayloadAction<Iso639_1Codes | undefined>
|
|
158
|
+
) => {
|
|
159
|
+
state.langSource = action.payload;
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export const {
|
|
165
|
+
setUser,
|
|
166
|
+
setConfig,
|
|
167
|
+
refreshTokens,
|
|
168
|
+
logout,
|
|
169
|
+
setActiveModal,
|
|
170
|
+
setDeleteModal,
|
|
171
|
+
setSelectedUser,
|
|
172
|
+
updateUser,
|
|
173
|
+
setActiveFile,
|
|
174
|
+
setStoreClient,
|
|
175
|
+
setLangSource,
|
|
176
|
+
} = chatSlice.actions;
|
|
177
|
+
|
|
178
|
+
export default chatSlice.reducer;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { configureStore, combineReducers } from '@reduxjs/toolkit';
|
|
2
|
+
import chatSettingsReducer, { setUser } from './chatSettingsSlice';
|
|
3
|
+
import roomsSlice, { addRoom } from './roomsSlice';
|
|
4
|
+
import { roomHeapSlice } from './roomHeapSlice';
|
|
5
|
+
import { IRoom } from '../types/types';
|
|
6
|
+
import { unreadMiddleware } from './Middleware/unreadMidlleware';
|
|
7
|
+
import { logoutMiddleware } from './Middleware/logoutMiddleware';
|
|
8
|
+
import { newMessageMidlleware } from './Middleware/newMessageMidlleware';
|
|
9
|
+
import { reactionsMiddleware } from './Middleware/reactionsMiddleware';
|
|
10
|
+
import { persistenceMiddleware, readPersistedState } from './persistence';
|
|
11
|
+
|
|
12
|
+
const rootReducer = combineReducers({
|
|
13
|
+
chatSettingStore: chatSettingsReducer,
|
|
14
|
+
rooms: roomsSlice,
|
|
15
|
+
roomHeapSlice: roomHeapSlice.reducer,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const store = configureStore({
|
|
19
|
+
reducer: rootReducer,
|
|
20
|
+
middleware: (getDefaultMiddleware) =>
|
|
21
|
+
getDefaultMiddleware({
|
|
22
|
+
serializableCheck: {
|
|
23
|
+
// Slice names: chatSlice→'chat', roomsStore→'roomMessages'.
|
|
24
|
+
ignoredActions: [
|
|
25
|
+
'chat/addMessage',
|
|
26
|
+
'chat/setStoreClient',
|
|
27
|
+
'chat/setConfig',
|
|
28
|
+
'roomMessages/addRoom',
|
|
29
|
+
],
|
|
30
|
+
ignoredActionPaths: ['payload.client', 'payload.config'],
|
|
31
|
+
ignoredPaths: [
|
|
32
|
+
'chat.messages.timestamp',
|
|
33
|
+
'chatSettingStore.client',
|
|
34
|
+
'chatSettingStore.config',
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.concat(unreadMiddleware)
|
|
39
|
+
.concat(newMessageMidlleware)
|
|
40
|
+
.concat(reactionsMiddleware)
|
|
41
|
+
.concat(logoutMiddleware)
|
|
42
|
+
.concat(persistenceMiddleware),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export type RootState = ReturnType<typeof rootReducer>;
|
|
46
|
+
export type AppDispatch = typeof store.dispatch;
|
|
47
|
+
|
|
48
|
+
export const getActiveRoom = (state: RootState): IRoom | null => {
|
|
49
|
+
const roomMessagesState = state.rooms;
|
|
50
|
+
return roomMessagesState.activeRoomJID
|
|
51
|
+
? roomMessagesState.rooms[roomMessagesState.activeRoomJID]
|
|
52
|
+
: null;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Async rehydrate — read persisted slices and replay them as standard
|
|
56
|
+
// actions. Idempotent: only rehydrates when a slice has data.
|
|
57
|
+
export const persistorReady = (async () => {
|
|
58
|
+
const { chat, rooms } = await readPersistedState();
|
|
59
|
+
if (chat?.user && chat.user.walletAddress) {
|
|
60
|
+
store.dispatch(setUser(chat.user));
|
|
61
|
+
}
|
|
62
|
+
if (rooms?.rooms) {
|
|
63
|
+
for (const [jid, room] of Object.entries(rooms.rooms)) {
|
|
64
|
+
if (!jid || !room) {continue;}
|
|
65
|
+
store.dispatch(addRoom({ roomData: room as IRoom }));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
3
|
+
import { IMessage, IRoom, User } from '../types/types';
|
|
4
|
+
|
|
5
|
+
// -------------------------------------------------------------------
|
|
6
|
+
// Lightweight RN persistence layer. Mirrors what redux-persist gives
|
|
7
|
+
// the web component:
|
|
8
|
+
//
|
|
9
|
+
// - persist chatSettingStore.user (sanitized) and rooms state
|
|
10
|
+
// - blacklist transient fields (modals, activeRoomJID, etc.)
|
|
11
|
+
// - cap each room's messages to the most recent 50
|
|
12
|
+
// - debounced writes (200ms) on relevant action types
|
|
13
|
+
//
|
|
14
|
+
// Not encrypted. We rely on AsyncStorage's per-app sandbox.
|
|
15
|
+
// -------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
const KEY_CHAT = '@ethora/persist:chatSettingStore';
|
|
18
|
+
const KEY_ROOMS = '@ethora/persist:rooms';
|
|
19
|
+
|
|
20
|
+
const MESSAGE_LIMIT = 50;
|
|
21
|
+
|
|
22
|
+
interface PersistedChatState {
|
|
23
|
+
user: User;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface PersistedRoomsState {
|
|
27
|
+
rooms: Record<string, IRoom>;
|
|
28
|
+
// intentionally NOT persisted: activeRoomJID, editAction, isLoading
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const sanitizeUser = (user?: User): User | null => {
|
|
32
|
+
if (!user) {return null;}
|
|
33
|
+
// Drop secrets we don't want at rest — destructure to omit, then
|
|
34
|
+
// explicitly zero them in the persisted shape.
|
|
35
|
+
const {
|
|
36
|
+
token: _token,
|
|
37
|
+
refreshToken: _refreshToken,
|
|
38
|
+
xmppPassword: _xmppPassword,
|
|
39
|
+
...rest
|
|
40
|
+
} = user as any;
|
|
41
|
+
return {
|
|
42
|
+
...rest,
|
|
43
|
+
token: '',
|
|
44
|
+
refreshToken: '',
|
|
45
|
+
xmppPassword: '',
|
|
46
|
+
} as User;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const sanitizeMessages = (messages: IMessage[]): IMessage[] => {
|
|
50
|
+
if (!Array.isArray(messages)) {return [];}
|
|
51
|
+
if (messages.length <= MESSAGE_LIMIT) {return messages;}
|
|
52
|
+
return messages.slice(-MESSAGE_LIMIT);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const sanitizeRooms = (
|
|
56
|
+
rooms: Record<string, IRoom>
|
|
57
|
+
): Record<string, IRoom> => {
|
|
58
|
+
if (!rooms || typeof rooms !== 'object') {return {};}
|
|
59
|
+
const out: Record<string, IRoom> = {};
|
|
60
|
+
for (const [jid, room] of Object.entries(rooms)) {
|
|
61
|
+
if (!jid || typeof jid !== 'string' || !jid.includes('@')) {continue;}
|
|
62
|
+
if (!room || typeof room !== 'object' || Array.isArray(room)) {continue;}
|
|
63
|
+
out[jid] = {
|
|
64
|
+
...room,
|
|
65
|
+
messages: sanitizeMessages(room?.messages || []),
|
|
66
|
+
composing: false,
|
|
67
|
+
composingList: [],
|
|
68
|
+
isLoading: false,
|
|
69
|
+
historyPreloadState: 'idle',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
let writeTimer: ReturnType<typeof setTimeout> | null = null;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Middleware that debounces writes of the persisted slices to AsyncStorage.
|
|
79
|
+
* Only triggers on actions that actually mutate persisted state.
|
|
80
|
+
*/
|
|
81
|
+
export const persistenceMiddleware: Middleware = (storeAPI) => (next) => (
|
|
82
|
+
action: any
|
|
83
|
+
) => {
|
|
84
|
+
const result = next(action);
|
|
85
|
+
|
|
86
|
+
const type: string = action?.type || '';
|
|
87
|
+
if (
|
|
88
|
+
!type.startsWith('roomMessages/') &&
|
|
89
|
+
!type.startsWith('chat/setUser') &&
|
|
90
|
+
!type.startsWith('chat/updateUser') &&
|
|
91
|
+
!type.startsWith('chat/refreshTokens') &&
|
|
92
|
+
!type.startsWith('chat/logout')
|
|
93
|
+
) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (writeTimer) {clearTimeout(writeTimer);}
|
|
98
|
+
writeTimer = setTimeout(() => {
|
|
99
|
+
try {
|
|
100
|
+
const state = storeAPI.getState();
|
|
101
|
+
const chatPayload: PersistedChatState = {
|
|
102
|
+
user: sanitizeUser(state.chatSettingStore?.user) as User,
|
|
103
|
+
};
|
|
104
|
+
const roomsPayload: PersistedRoomsState = {
|
|
105
|
+
rooms: sanitizeRooms(state.rooms?.rooms || {}),
|
|
106
|
+
};
|
|
107
|
+
AsyncStorage.multiSet([
|
|
108
|
+
[KEY_CHAT, JSON.stringify(chatPayload)],
|
|
109
|
+
[KEY_ROOMS, JSON.stringify(roomsPayload)],
|
|
110
|
+
]).catch((e) => console.warn('persist write failed', e));
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.warn('persist serialize failed', e);
|
|
113
|
+
}
|
|
114
|
+
}, 200);
|
|
115
|
+
|
|
116
|
+
return result;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Read persisted slices from AsyncStorage. Called once at store creation;
|
|
121
|
+
* we DON'T hydrate synchronously (AsyncStorage is async) — instead, the
|
|
122
|
+
* caller dispatches rehydrate actions when the read resolves.
|
|
123
|
+
*/
|
|
124
|
+
export async function readPersistedState(): Promise<{
|
|
125
|
+
chat: PersistedChatState | null;
|
|
126
|
+
rooms: PersistedRoomsState | null;
|
|
127
|
+
}> {
|
|
128
|
+
try {
|
|
129
|
+
const [chatRaw, roomsRaw] = await AsyncStorage.multiGet([
|
|
130
|
+
KEY_CHAT,
|
|
131
|
+
KEY_ROOMS,
|
|
132
|
+
]);
|
|
133
|
+
const chat = chatRaw[1] ? (JSON.parse(chatRaw[1]) as PersistedChatState) : null;
|
|
134
|
+
const rooms = roomsRaw[1]
|
|
135
|
+
? (JSON.parse(roomsRaw[1]) as PersistedRoomsState)
|
|
136
|
+
: null;
|
|
137
|
+
return { chat, rooms };
|
|
138
|
+
} catch (e) {
|
|
139
|
+
console.warn('persist read failed', e);
|
|
140
|
+
return { chat: null, rooms: null };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function clearPersistedState(): Promise<void> {
|
|
145
|
+
try {
|
|
146
|
+
await AsyncStorage.multiRemove([KEY_CHAT, KEY_ROOMS]);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
console.warn('persist clear failed', e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export const PERSIST_KEYS = { KEY_CHAT, KEY_ROOMS };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
2
|
+
import { IMessage } from '../types/types';
|
|
3
|
+
|
|
4
|
+
interface roomHeapSliceState {
|
|
5
|
+
messageHeap: IMessage[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const initialState: roomHeapSliceState = {
|
|
9
|
+
messageHeap: [],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const roomHeapSlice = createSlice({
|
|
13
|
+
name: 'roomHeapStore',
|
|
14
|
+
initialState,
|
|
15
|
+
reducers: {
|
|
16
|
+
addMessageToHeap: (state, action: PayloadAction<IMessage>) => {
|
|
17
|
+
state.messageHeap.push(action.payload);
|
|
18
|
+
},
|
|
19
|
+
removeMessageFromHeapById: (state, action: PayloadAction<string>) => {
|
|
20
|
+
const index = state.messageHeap.findIndex((m) => m.id === action.payload);
|
|
21
|
+
if (index !== -1) {
|
|
22
|
+
state.messageHeap.splice(index, 1);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
clearHeap: (state) => {
|
|
26
|
+
state.messageHeap = [];
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const {
|
|
32
|
+
addMessageToHeap,
|
|
33
|
+
clearHeap,
|
|
34
|
+
removeMessageFromHeapById,
|
|
35
|
+
} = roomHeapSlice.actions;
|
|
36
|
+
|
|
37
|
+
export default roomHeapSlice.reducer;
|