@ethora/chat-component-rn 26.5.16 → 26.5.18
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/lib/commonjs/assets/EmptyChatIllustration.js +106 -0
- package/lib/commonjs/assets/EmptyChatIllustration.js.map +1 -0
- package/lib/commonjs/assets/icons.js +13 -2
- package/lib/commonjs/assets/icons.js.map +1 -1
- package/lib/commonjs/components/DropdownMenu/DropdownMenu.js +2 -1
- package/lib/commonjs/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ChatHeader.js +2 -1
- package/lib/commonjs/components/MainComponents/ChatHeader.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ChatRoom.js +5 -2
- package/lib/commonjs/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ChooseChatMessage.js +9 -2
- package/lib/commonjs/components/MainComponents/ChooseChatMessage.js.map +1 -1
- package/lib/commonjs/components/MainComponents/EditWrapper.js +12 -4
- package/lib/commonjs/components/MainComponents/EditWrapper.js.map +1 -1
- package/lib/commonjs/components/MainComponents/MessageList.js +2 -1
- package/lib/commonjs/components/MainComponents/MessageList.js.map +1 -1
- package/lib/commonjs/components/MainComponents/NoMessagesPlaceholder.js +11 -3
- package/lib/commonjs/components/MainComponents/NoMessagesPlaceholder.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ProfileImagePlaceholder.js +12 -7
- package/lib/commonjs/components/MainComponents/ProfileImagePlaceholder.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ReduxWrapper.js +4 -0
- package/lib/commonjs/components/MainComponents/ReduxWrapper.js.map +1 -1
- package/lib/commonjs/components/MainComponents/RoomList.js +2 -1
- package/lib/commonjs/components/MainComponents/RoomList.js.map +1 -1
- package/lib/commonjs/components/MessageBubble/Avatar.js +16 -7
- package/lib/commonjs/components/MessageBubble/Avatar.js.map +1 -1
- package/lib/commonjs/components/MessageBubble/Message.js +16 -1
- package/lib/commonjs/components/MessageBubble/Message.js.map +1 -1
- package/lib/commonjs/components/Modals/ModalWrapper/ModalWrapper.js +9 -0
- package/lib/commonjs/components/Modals/ModalWrapper/ModalWrapper.js.map +1 -1
- package/lib/commonjs/components/styled/Button.js +4 -2
- package/lib/commonjs/components/styled/Button.js.map +1 -1
- package/lib/commonjs/components/styled/DateLabel.js +12 -4
- package/lib/commonjs/components/styled/DateLabel.js.map +1 -1
- package/lib/commonjs/components/styled/SendInput.js +4 -3
- package/lib/commonjs/components/styled/SendInput.js.map +1 -1
- package/lib/commonjs/context/xmppProvider.js +12 -1
- package/lib/commonjs/context/xmppProvider.js.map +1 -1
- package/lib/commonjs/helpers/getAvatarColor.js +33 -0
- package/lib/commonjs/helpers/getAvatarColor.js.map +1 -0
- package/lib/commonjs/helpers/getDateLabelColor.js +9 -0
- package/lib/commonjs/helpers/getDateLabelColor.js.map +1 -0
- package/lib/commonjs/helpers/getIconColor.js +9 -0
- package/lib/commonjs/helpers/getIconColor.js.map +1 -0
- package/lib/commonjs/helpers/getSenderNameColor.js +9 -0
- package/lib/commonjs/helpers/getSenderNameColor.js.map +1 -0
- package/lib/commonjs/helpers/historyPreloadScheduler.js +118 -113
- package/lib/commonjs/helpers/historyPreloadScheduler.js.map +1 -1
- package/lib/commonjs/hooks/useChatFonts.js +137 -0
- package/lib/commonjs/hooks/useChatFonts.js.map +1 -0
- package/lib/commonjs/hooks/useSendMessage.js +72 -22
- package/lib/commonjs/hooks/useSendMessage.js.map +1 -1
- package/lib/commonjs/hooks/useUnreadMessagesCounter.js +4 -2
- package/lib/commonjs/hooks/useUnreadMessagesCounter.js.map +1 -1
- package/lib/commonjs/main.js +7 -0
- package/lib/commonjs/main.js.map +1 -1
- package/lib/commonjs/networking/outboundQueue.js +22 -4
- package/lib/commonjs/networking/outboundQueue.js.map +1 -1
- package/lib/commonjs/networking/xmppClient.js +50 -0
- package/lib/commonjs/networking/xmppClient.js.map +1 -1
- package/lib/commonjs/roomStore/Middleware/newMessageMidlleware.js +22 -0
- package/lib/commonjs/roomStore/Middleware/newMessageMidlleware.js.map +1 -1
- package/lib/commonjs/roomStore/roomsSlice.js +22 -2
- package/lib/commonjs/roomStore/roomsSlice.js.map +1 -1
- package/lib/module/assets/EmptyChatIllustration.js +99 -0
- package/lib/module/assets/EmptyChatIllustration.js.map +1 -0
- package/lib/module/assets/icons.js +13 -2
- package/lib/module/assets/icons.js.map +1 -1
- package/lib/module/components/DropdownMenu/DropdownMenu.js +2 -1
- package/lib/module/components/DropdownMenu/DropdownMenu.js.map +1 -1
- package/lib/module/components/MainComponents/ChatHeader.js +2 -1
- package/lib/module/components/MainComponents/ChatHeader.js.map +1 -1
- package/lib/module/components/MainComponents/ChatRoom.js +5 -2
- package/lib/module/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/module/components/MainComponents/ChooseChatMessage.js +9 -2
- package/lib/module/components/MainComponents/ChooseChatMessage.js.map +1 -1
- package/lib/module/components/MainComponents/EditWrapper.js +12 -4
- package/lib/module/components/MainComponents/EditWrapper.js.map +1 -1
- package/lib/module/components/MainComponents/MessageList.js +2 -1
- package/lib/module/components/MainComponents/MessageList.js.map +1 -1
- package/lib/module/components/MainComponents/NoMessagesPlaceholder.js +11 -3
- package/lib/module/components/MainComponents/NoMessagesPlaceholder.js.map +1 -1
- package/lib/module/components/MainComponents/ProfileImagePlaceholder.js +12 -7
- package/lib/module/components/MainComponents/ProfileImagePlaceholder.js.map +1 -1
- package/lib/module/components/MainComponents/ReduxWrapper.js +4 -0
- package/lib/module/components/MainComponents/ReduxWrapper.js.map +1 -1
- package/lib/module/components/MainComponents/RoomList.js +2 -1
- package/lib/module/components/MainComponents/RoomList.js.map +1 -1
- package/lib/module/components/MessageBubble/Avatar.js +16 -7
- package/lib/module/components/MessageBubble/Avatar.js.map +1 -1
- package/lib/module/components/MessageBubble/Message.js +16 -1
- package/lib/module/components/MessageBubble/Message.js.map +1 -1
- package/lib/module/components/Modals/ModalWrapper/ModalWrapper.js +9 -0
- package/lib/module/components/Modals/ModalWrapper/ModalWrapper.js.map +1 -1
- package/lib/module/components/styled/Button.js +4 -2
- package/lib/module/components/styled/Button.js.map +1 -1
- package/lib/module/components/styled/DateLabel.js +12 -4
- package/lib/module/components/styled/DateLabel.js.map +1 -1
- package/lib/module/components/styled/SendInput.js +4 -3
- package/lib/module/components/styled/SendInput.js.map +1 -1
- package/lib/module/context/xmppProvider.js +13 -2
- package/lib/module/context/xmppProvider.js.map +1 -1
- package/lib/module/helpers/getAvatarColor.js +28 -0
- package/lib/module/helpers/getAvatarColor.js.map +1 -0
- package/lib/module/helpers/getDateLabelColor.js +4 -0
- package/lib/module/helpers/getDateLabelColor.js.map +1 -0
- package/lib/module/helpers/getIconColor.js +4 -0
- package/lib/module/helpers/getIconColor.js.map +1 -0
- package/lib/module/helpers/getSenderNameColor.js +4 -0
- package/lib/module/helpers/getSenderNameColor.js.map +1 -0
- package/lib/module/helpers/historyPreloadScheduler.js +119 -114
- package/lib/module/helpers/historyPreloadScheduler.js.map +1 -1
- package/lib/module/hooks/useChatFonts.js +132 -0
- package/lib/module/hooks/useChatFonts.js.map +1 -0
- package/lib/module/hooks/useSendMessage.js +72 -22
- package/lib/module/hooks/useSendMessage.js.map +1 -1
- package/lib/module/hooks/useUnreadMessagesCounter.js +4 -2
- package/lib/module/hooks/useUnreadMessagesCounter.js.map +1 -1
- package/lib/module/main.js +2 -0
- package/lib/module/main.js.map +1 -1
- package/lib/module/networking/outboundQueue.js +21 -4
- package/lib/module/networking/outboundQueue.js.map +1 -1
- package/lib/module/networking/xmppClient.js +50 -0
- package/lib/module/networking/xmppClient.js.map +1 -1
- package/lib/module/roomStore/Middleware/newMessageMidlleware.js +22 -0
- package/lib/module/roomStore/Middleware/newMessageMidlleware.js.map +1 -1
- package/lib/module/roomStore/roomsSlice.js +20 -1
- package/lib/module/roomStore/roomsSlice.js.map +1 -1
- package/lib/typescript/assets/EmptyChatIllustration.d.ts +10 -0
- package/lib/typescript/assets/EmptyChatIllustration.d.ts.map +1 -0
- package/lib/typescript/assets/icons.d.ts +3 -12
- package/lib/typescript/assets/icons.d.ts.map +1 -1
- package/lib/typescript/components/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ChatHeader.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ChatRoom.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ChooseChatMessage.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/EditWrapper.d.ts +5 -1
- package/lib/typescript/components/MainComponents/EditWrapper.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/MessageList.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/NoMessagesPlaceholder.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ProfileImagePlaceholder.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ReduxWrapper.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/RoomList.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble/Avatar.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble/Message.d.ts.map +1 -1
- package/lib/typescript/components/Modals/ModalWrapper/ModalWrapper.d.ts.map +1 -1
- package/lib/typescript/components/styled/Button.d.ts +1 -0
- package/lib/typescript/components/styled/Button.d.ts.map +1 -1
- package/lib/typescript/components/styled/DateLabel.d.ts +9 -8
- package/lib/typescript/components/styled/DateLabel.d.ts.map +1 -1
- package/lib/typescript/components/styled/SendInput.d.ts.map +1 -1
- package/lib/typescript/context/xmppProvider.d.ts.map +1 -1
- package/lib/typescript/helpers/getAvatarColor.d.ts +7 -0
- package/lib/typescript/helpers/getAvatarColor.d.ts.map +1 -0
- package/lib/typescript/helpers/getDateLabelColor.d.ts +8 -0
- package/lib/typescript/helpers/getDateLabelColor.d.ts.map +1 -0
- package/lib/typescript/helpers/getIconColor.d.ts +8 -0
- package/lib/typescript/helpers/getIconColor.d.ts.map +1 -0
- package/lib/typescript/helpers/getSenderNameColor.d.ts +8 -0
- package/lib/typescript/helpers/getSenderNameColor.d.ts.map +1 -0
- package/lib/typescript/helpers/historyPreloadScheduler.d.ts.map +1 -1
- package/lib/typescript/hooks/useChatFonts.d.ts +23 -0
- package/lib/typescript/hooks/useChatFonts.d.ts.map +1 -0
- package/lib/typescript/hooks/useSendMessage.d.ts +1 -1
- package/lib/typescript/hooks/useSendMessage.d.ts.map +1 -1
- package/lib/typescript/hooks/useUnreadMessagesCounter.d.ts +1 -0
- package/lib/typescript/hooks/useUnreadMessagesCounter.d.ts.map +1 -1
- package/lib/typescript/main.d.ts +2 -1
- package/lib/typescript/main.d.ts.map +1 -1
- package/lib/typescript/networking/outboundQueue.d.ts +16 -1
- package/lib/typescript/networking/outboundQueue.d.ts.map +1 -1
- package/lib/typescript/networking/xmppClient.d.ts +3 -0
- package/lib/typescript/networking/xmppClient.d.ts.map +1 -1
- package/lib/typescript/roomStore/Middleware/newMessageMidlleware.d.ts.map +1 -1
- package/lib/typescript/roomStore/roomsSlice.d.ts +3 -1
- package/lib/typescript/roomStore/roomsSlice.d.ts.map +1 -1
- package/lib/typescript/types/models/message.model.d.ts +1 -0
- package/lib/typescript/types/models/message.model.d.ts.map +1 -1
- package/lib/typescript/types/types.d.ts +53 -0
- package/lib/typescript/types/types.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/assets/EmptyChatIllustration.tsx +49 -0
- package/src/assets/icons.tsx +64 -81
- package/src/components/DropdownMenu/DropdownMenu.tsx +2 -1
- package/src/components/MainComponents/ChatHeader.tsx +2 -1
- package/src/components/MainComponents/ChatRoom.tsx +5 -2
- package/src/components/MainComponents/ChooseChatMessage.tsx +5 -2
- package/src/components/MainComponents/EditWrapper.tsx +9 -6
- package/src/components/MainComponents/MessageList.tsx +2 -1
- package/src/components/MainComponents/NoMessagesPlaceholder.tsx +4 -1
- package/src/components/MainComponents/ProfileImagePlaceholder.tsx +14 -7
- package/src/components/MainComponents/ReduxWrapper.tsx +4 -0
- package/src/components/MainComponents/RoomList.tsx +2 -1
- package/src/components/MessageBubble/Avatar.tsx +18 -9
- package/src/components/MessageBubble/Message.tsx +16 -1
- package/src/components/Modals/ModalWrapper/ModalWrapper.tsx +6 -0
- package/src/components/styled/Button.tsx +5 -1
- package/src/components/styled/DateLabel.tsx +10 -7
- package/src/components/styled/SendInput.tsx +4 -3
- package/src/context/xmppProvider.tsx +11 -1
- package/src/helpers/getAvatarColor.ts +31 -0
- package/src/helpers/getDateLabelColor.ts +3 -0
- package/src/helpers/getIconColor.ts +3 -0
- package/src/helpers/getSenderNameColor.ts +3 -0
- package/src/helpers/historyPreloadScheduler.ts +7 -1
- package/src/hooks/useChatFonts.ts +153 -0
- package/src/hooks/useSendMessage.tsx +101 -58
- package/src/hooks/useUnreadMessagesCounter.ts +5 -2
- package/src/main.ts +4 -0
- package/src/networking/outboundQueue.ts +25 -4
- package/src/networking/xmppClient.ts +47 -0
- package/src/roomStore/Middleware/newMessageMidlleware.tsx +25 -0
- package/src/roomStore/roomsSlice.ts +26 -1
- package/src/types/models/message.model.ts +3 -0
- package/src/types/types.ts +59 -1
|
@@ -98,132 +98,137 @@ const runHistoryPreloadScheduler = async options => {
|
|
|
98
98
|
if (signal?.aborted) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const readyItems = queue.filter(item => item.readyAt <= now && !inFlightByRoom.has(item.jid));
|
|
136
|
-
if (readyItems.length === 0) {
|
|
137
|
-
await sleep(60);
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const batch = readyItems.slice(0, Math.max(1, concurrency));
|
|
141
|
-
|
|
142
|
-
// Snapshot each room's historyPreloadState BEFORE marking the
|
|
143
|
-
// batch as 'loading'. Without this snapshot the per-task
|
|
144
|
-
// `currentRoom.historyPreloadState === 'done'` skip check below
|
|
145
|
-
// is dead — the dispatch immediately overwrites 'done' with
|
|
146
|
-
// 'loading', so the task never sees the original value and
|
|
147
|
-
// always re-fetches.
|
|
148
|
-
const preBatchPreloadStateByJid = new Map(batch.map(item => [item.jid, _roomStore.store.getState().rooms.rooms[item.jid]?.historyPreloadState]));
|
|
149
|
-
_roomStore.store.dispatch((0, _roomsSlice.applyRoomsPreloadBatch)({
|
|
150
|
-
rooms: batch.map(item => ({
|
|
151
|
-
jid: item.jid,
|
|
152
|
-
historyPreloadState: 'loading'
|
|
153
|
-
}))
|
|
154
|
-
}));
|
|
155
|
-
await Promise.all(batch.map(async item => {
|
|
156
|
-
const queueIndex = queue.findIndex(queued => queued.jid === item.jid);
|
|
157
|
-
if (queueIndex !== -1) {
|
|
158
|
-
queue.splice(queueIndex, 1);
|
|
101
|
+
_roomStore.store.dispatch((0, _roomsSlice.setUnreadSyncing)(true));
|
|
102
|
+
try {
|
|
103
|
+
const state = _roomStore.store.getState();
|
|
104
|
+
const rooms = state.rooms.rooms || {};
|
|
105
|
+
const defaultSet = new Set(defaultRoomJids);
|
|
106
|
+
const sortedQueue = Object.entries(rooms).map(([jid, room]) => ({
|
|
107
|
+
jid,
|
|
108
|
+
priority: getRoomPriority(jid, room, selectedRoomJid, defaultSet),
|
|
109
|
+
activityScore: getRoomLastActivityScore(room),
|
|
110
|
+
attempts: 0,
|
|
111
|
+
readyAt: Date.now()
|
|
112
|
+
})).sort((a, b) => {
|
|
113
|
+
if (a.priority !== b.priority) {
|
|
114
|
+
return a.priority - b.priority;
|
|
115
|
+
}
|
|
116
|
+
if (a.activityScore !== b.activityScore) {
|
|
117
|
+
return b.activityScore - a.activityScore;
|
|
118
|
+
}
|
|
119
|
+
return a.jid.localeCompare(b.jid);
|
|
120
|
+
});
|
|
121
|
+
const queue = roomLimit && roomLimit > 0 ? sortedQueue.slice(0, roomLimit) : sortedQueue;
|
|
122
|
+
const inFlightByRoom = new Map();
|
|
123
|
+
let consecutiveErrorCount = 0;
|
|
124
|
+
while (queue.length > 0) {
|
|
125
|
+
if (signal?.aborted) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (!client.isActiveRoomGateOpen()) {
|
|
129
|
+
await sleep(80);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (shouldPauseForVisibility()) {
|
|
133
|
+
await sleep(250);
|
|
134
|
+
continue;
|
|
159
135
|
}
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
136
|
+
const now = Date.now();
|
|
137
|
+
const readyItems = queue.filter(item => item.readyAt <= now && !inFlightByRoom.has(item.jid));
|
|
138
|
+
if (readyItems.length === 0) {
|
|
139
|
+
await sleep(60);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const batch = readyItems.slice(0, Math.max(1, concurrency));
|
|
143
|
+
|
|
144
|
+
// Snapshot each room's historyPreloadState BEFORE marking the
|
|
145
|
+
// batch as 'loading'. Without this snapshot the per-task
|
|
146
|
+
// `currentRoom.historyPreloadState === 'done'` skip check below
|
|
147
|
+
// is dead — the dispatch immediately overwrites 'done' with
|
|
148
|
+
// 'loading', so the task never sees the original value and
|
|
149
|
+
// always re-fetches.
|
|
150
|
+
const preBatchPreloadStateByJid = new Map(batch.map(item => [item.jid, _roomStore.store.getState().rooms.rooms[item.jid]?.historyPreloadState]));
|
|
151
|
+
_roomStore.store.dispatch((0, _roomsSlice.applyRoomsPreloadBatch)({
|
|
152
|
+
rooms: batch.map(item => ({
|
|
153
|
+
jid: item.jid,
|
|
154
|
+
historyPreloadState: 'loading'
|
|
155
|
+
}))
|
|
156
|
+
}));
|
|
157
|
+
await Promise.all(batch.map(async item => {
|
|
158
|
+
const queueIndex = queue.findIndex(queued => queued.jid === item.jid);
|
|
159
|
+
if (queueIndex !== -1) {
|
|
160
|
+
queue.splice(queueIndex, 1);
|
|
171
161
|
}
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
162
|
+
const task = (async () => {
|
|
163
|
+
const currentRoom = _roomStore.store.getState().rooms.rooms[item.jid];
|
|
164
|
+
const preState = preBatchPreloadStateByJid.get(item.jid);
|
|
165
|
+
if (!currentRoom || !forceReload && preState === 'done') {
|
|
166
|
+
_roomStore.store.dispatch((0, _roomsSlice.applyRoomsPreloadBatch)({
|
|
167
|
+
rooms: [{
|
|
168
|
+
jid: item.jid,
|
|
169
|
+
historyPreloadState: 'done'
|
|
170
|
+
}]
|
|
171
|
+
}));
|
|
179
172
|
return;
|
|
180
173
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
_roomStore.store.dispatch((0, _roomsSlice.applyRoomsPreloadBatch)({
|
|
187
|
-
rooms: [{
|
|
188
|
-
jid: item.jid,
|
|
189
|
-
messages: fetchedMessages || [],
|
|
190
|
-
unreadCapped,
|
|
191
|
-
historyPreloadState: 'done'
|
|
192
|
-
}]
|
|
193
|
-
}));
|
|
194
|
-
consecutiveErrorCount = 0;
|
|
195
|
-
} catch {
|
|
196
|
-
const retries = item.attempts + 1;
|
|
197
|
-
const canRetry = retries <= retryLimit;
|
|
198
|
-
if (canRetry) {
|
|
199
|
-
const jitter = Math.floor(Math.random() * 120);
|
|
200
|
-
const backoff = Math.min(1600, 240 * 2 ** item.attempts) + jitter;
|
|
201
|
-
queue.push({
|
|
202
|
-
...item,
|
|
203
|
-
attempts: retries,
|
|
204
|
-
readyAt: Date.now() + backoff
|
|
174
|
+
try {
|
|
175
|
+
const fetchedMessages = await client.getHistoryStanza(item.jid, pageSize, undefined, undefined, {
|
|
176
|
+
coalesceRoom: true,
|
|
177
|
+
skipIfPreloaded: !forceReload,
|
|
178
|
+
source: 'background'
|
|
205
179
|
});
|
|
206
|
-
|
|
180
|
+
if (signal?.aborted) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (typeof fetchedMessages === 'undefined') {
|
|
184
|
+
throw new Error('history_timeout');
|
|
185
|
+
}
|
|
186
|
+
const nextRoom = _roomStore.store.getState().rooms.rooms[item.jid];
|
|
187
|
+
const unreadCapped = computeUnreadCapped(nextRoom, fetchedMessages || [], pageSize);
|
|
207
188
|
_roomStore.store.dispatch((0, _roomsSlice.applyRoomsPreloadBatch)({
|
|
208
189
|
rooms: [{
|
|
209
190
|
jid: item.jid,
|
|
210
|
-
|
|
191
|
+
messages: fetchedMessages || [],
|
|
192
|
+
unreadCapped,
|
|
193
|
+
historyPreloadState: 'done'
|
|
211
194
|
}]
|
|
212
195
|
}));
|
|
213
|
-
}
|
|
214
|
-
consecutiveErrorCount += 1;
|
|
215
|
-
if (consecutiveErrorCount >= 3) {
|
|
216
|
-
await sleep(300);
|
|
217
196
|
consecutiveErrorCount = 0;
|
|
197
|
+
} catch {
|
|
198
|
+
const retries = item.attempts + 1;
|
|
199
|
+
const canRetry = retries <= retryLimit;
|
|
200
|
+
if (canRetry) {
|
|
201
|
+
const jitter = Math.floor(Math.random() * 120);
|
|
202
|
+
const backoff = Math.min(1600, 240 * 2 ** item.attempts) + jitter;
|
|
203
|
+
queue.push({
|
|
204
|
+
...item,
|
|
205
|
+
attempts: retries,
|
|
206
|
+
readyAt: Date.now() + backoff
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
_roomStore.store.dispatch((0, _roomsSlice.applyRoomsPreloadBatch)({
|
|
210
|
+
rooms: [{
|
|
211
|
+
jid: item.jid,
|
|
212
|
+
historyPreloadState: 'error'
|
|
213
|
+
}]
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
consecutiveErrorCount += 1;
|
|
217
|
+
if (consecutiveErrorCount >= 3) {
|
|
218
|
+
await sleep(300);
|
|
219
|
+
consecutiveErrorCount = 0;
|
|
220
|
+
}
|
|
218
221
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}));
|
|
222
|
+
})();
|
|
223
|
+
inFlightByRoom.set(item.jid, task);
|
|
224
|
+
await task.finally(() => inFlightByRoom.delete(item.jid));
|
|
225
|
+
}));
|
|
224
226
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
// Yield to JS event loop (no requestIdleCallback in RN).
|
|
228
|
+
await new Promise(r => setTimeout(r, 0));
|
|
229
|
+
}
|
|
230
|
+
} finally {
|
|
231
|
+
_roomStore.store.dispatch((0, _roomsSlice.setUnreadSyncing)(false));
|
|
227
232
|
}
|
|
228
233
|
};
|
|
229
234
|
exports.runHistoryPreloadScheduler = runHistoryPreloadScheduler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_roomStore","_roomsSlice","DEFAULT_CONCURRENCY","DEFAULT_PAGE_SIZE","DEFAULT_RETRY_LIMIT","sleep","ms","Promise","resolve","setTimeout","messageTimestamp","m","t","timestamp","Number","isFinite","id","getRoomLastActivityScore","room","messages","length","reduce","max","Math","computeUnreadCapped","pageSize","historyComplete","countable","filter","msg","pending","lastViewed","lastViewedTimestamp","oldestTs","minTs","ts","min","MAX_SAFE_INTEGER","getRoomPriority","jid","_room","selectedRoomJid","defaultRoomJids","has","shouldPauseForVisibility","AppState","currentState","runHistoryPreloadScheduler","options","client","signal","concurrency","retryLimit","roomLimit","forceReload","aborted","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_roomStore","_roomsSlice","DEFAULT_CONCURRENCY","DEFAULT_PAGE_SIZE","DEFAULT_RETRY_LIMIT","sleep","ms","Promise","resolve","setTimeout","messageTimestamp","m","t","timestamp","Number","isFinite","id","getRoomLastActivityScore","room","messages","length","reduce","max","Math","computeUnreadCapped","pageSize","historyComplete","countable","filter","msg","pending","lastViewed","lastViewedTimestamp","oldestTs","minTs","ts","min","MAX_SAFE_INTEGER","getRoomPriority","jid","_room","selectedRoomJid","defaultRoomJids","has","shouldPauseForVisibility","AppState","currentState","runHistoryPreloadScheduler","options","client","signal","concurrency","retryLimit","roomLimit","forceReload","aborted","store","dispatch","setUnreadSyncing","state","getState","rooms","defaultSet","Set","sortedQueue","Object","entries","map","priority","activityScore","attempts","readyAt","Date","now","sort","a","b","localeCompare","queue","slice","inFlightByRoom","Map","consecutiveErrorCount","isActiveRoomGateOpen","readyItems","item","batch","preBatchPreloadStateByJid","historyPreloadState","applyRoomsPreloadBatch","all","queueIndex","findIndex","queued","splice","task","currentRoom","preState","get","fetchedMessages","getHistoryStanza","undefined","coalesceRoom","skipIfPreloaded","source","Error","nextRoom","unreadCapped","retries","canRetry","jitter","floor","random","backoff","push","set","finally","delete","r","exports","_default","default"],"sourceRoot":"../../../src","sources":["helpers/historyPreloadScheduler.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAuBA,MAAMG,mBAAmB,GAAG,CAAC;AAC7B;AACA;AACA;AACA,MAAMC,iBAAiB,GAAG,EAAE;AAC5B,MAAMC,mBAAmB,GAAG,CAAC;AAE7B,MAAMC,KAAK,GAAIC,EAAU,IAAK,IAAIC,OAAO,CAAEC,OAAO,IAAKC,UAAU,CAACD,OAAO,EAAEF,EAAE,CAAC,CAAC;AAE/E,MAAMI,gBAAgB,GAAIC,CAAW,IAAa;EAChD,IAAI,CAACA,CAAC,EAAE;IAAC,OAAO,CAAC;EAAC;EAClB,MAAMC,CAAC,GAAID,CAAC,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;YACJ,CAAC,MAAM;cACLzD,gBAAK,CAACC,QAAQ,CACZ,IAAAgC,kCAAsB,EAAC;gBACrB5B,KAAK,EAAE,CAAC;kBAAEtB,GAAG,EAAE8C,IAAI,CAAC9C,GAAG;kBAAEiD,mBAAmB,EAAE;gBAAQ,CAAC;cACzD,CAAC,CACH,CAAC;YACH;YACAN,qBAAqB,IAAI,CAAC;YAC1B,IAAIA,qBAAqB,IAAI,CAAC,EAAE;cAC9B,MAAM7E,KAAK,CAAC,GAAG,CAAC;cAChB6E,qBAAqB,GAAG,CAAC;YAC3B;UACF;QACF,CAAC,EAAE,CAAC;QAEJF,cAAc,CAACmC,GAAG,CAAC9B,IAAI,CAAC9C,GAAG,EAAEwD,IAAI,CAAC;QAClC,MAAMA,IAAI,CAACqB,OAAO,CAAC,MAAMpC,cAAc,CAACqC,MAAM,CAAChC,IAAI,CAAC9C,GAAG,CAAC,CAAC;MAC3D,CAAC,CACH,CAAC;;MAED;MACA,MAAM,IAAIhC,OAAO,CAAE+G,CAAC,IAAK7G,UAAU,CAAC6G,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C;EACA,CAAC,SAAS;IACR9D,gBAAK,CAACC,QAAQ,CAAC,IAAAC,4BAAgB,EAAC,KAAK,CAAC,CAAC;EACzC;AACF,CAAC;AAAC6D,OAAA,CAAAxE,0BAAA,GAAAA,0BAAA;AAAA,IAAAyE,QAAA,GAAAD,OAAA,CAAAE,OAAA,GAEa1E,0BAA0B","ignoreList":[]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useChatFonts = useChatFonts;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
/**
|
|
11
|
+
* Loads and applies the host-provided font configuration for the chat UI.
|
|
12
|
+
*
|
|
13
|
+
* React Native has no web-style runtime `@font-face`, so a custom font must be
|
|
14
|
+
* registered with `expo-font` before it can be used. This hook:
|
|
15
|
+
* 1. loads every entry in `typography.fonts` via `expo-font` (remote URL or
|
|
16
|
+
* bundled `require(...)`), then
|
|
17
|
+
* 2. sets the resolved `fontFamily` as the default for all `<Text>` and
|
|
18
|
+
* `<TextInput>` rendered by the chat — mirroring how the web SDK sets a
|
|
19
|
+
* CSS variable. Individual components can still override per-style.
|
|
20
|
+
*
|
|
21
|
+
* `expo-font` is an optional peer dependency: if the host hasn't installed it,
|
|
22
|
+
* the hook degrades gracefully (font simply isn't loaded) instead of throwing.
|
|
23
|
+
*
|
|
24
|
+
* No-op when `typography` is undefined — the system font is kept, so existing
|
|
25
|
+
* integrations are unaffected.
|
|
26
|
+
*
|
|
27
|
+
* @returns `true` once fonts are ready (or when there's nothing to load), so
|
|
28
|
+
* callers can gate first paint to avoid a font "flash" if desired.
|
|
29
|
+
*/
|
|
30
|
+
function useChatFonts(typography) {
|
|
31
|
+
const [ready, setReady] = (0, _react.useState)(!typography?.fonts?.length);
|
|
32
|
+
applyDefaultFont(typography);
|
|
33
|
+
(0, _react.useEffect)(() => {
|
|
34
|
+
let cancelled = false;
|
|
35
|
+
async function load() {
|
|
36
|
+
// Apply the default family immediately so already-available fonts
|
|
37
|
+
// (system, or host-loaded) take effect without waiting on a download.
|
|
38
|
+
applyDefaultFont(typography);
|
|
39
|
+
if (!typography?.fonts?.length) {
|
|
40
|
+
setReady(true);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
// Optional dependency — resolve lazily so apps that don't use custom
|
|
45
|
+
// fonts don't need expo-font installed.
|
|
46
|
+
const ExpoFont = await Promise.resolve().then(() => _interopRequireWildcard(require('expo-font'))).catch(() => null);
|
|
47
|
+
if (!ExpoFont) {
|
|
48
|
+
if (!cancelled) setReady(true);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const map = {};
|
|
52
|
+
for (const f of typography.fonts) map[f.family] = f.source;
|
|
53
|
+
await ExpoFont.loadAsync(map);
|
|
54
|
+
if (!cancelled) {
|
|
55
|
+
applyDefaultFont(typography);
|
|
56
|
+
setReady(true);
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
// Loading failed (e.g. bad URL) — keep the fallback font, don't block UI.
|
|
60
|
+
if (!cancelled) setReady(true);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
load();
|
|
64
|
+
return () => {
|
|
65
|
+
cancelled = true;
|
|
66
|
+
};
|
|
67
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
+
}, [typography?.fontFamily, JSON.stringify(typography?.fonts ?? []), JSON.stringify(typography?.weightFamilies ?? {})]);
|
|
69
|
+
return ready;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The family currently applied as the chat-wide default. Read at render time
|
|
74
|
+
* by the patched components below, so updating it (then triggering a re-render)
|
|
75
|
+
* restyles the whole tree.
|
|
76
|
+
*/
|
|
77
|
+
let activeFamily;
|
|
78
|
+
function wrapFactory(orig) {
|
|
79
|
+
if (typeof orig !== 'function') return orig;
|
|
80
|
+
if (orig.__ethoraFontWrapped) return orig;
|
|
81
|
+
const wrapped = function (type, props, ...rest) {
|
|
82
|
+
if (activeFamily && props && (type === _reactNative.Text || type === _reactNative.TextInput)) {
|
|
83
|
+
props = {
|
|
84
|
+
...props,
|
|
85
|
+
style: [{
|
|
86
|
+
fontFamily: activeFamily
|
|
87
|
+
}, props.style]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return orig.call(this, type, props, ...rest);
|
|
91
|
+
};
|
|
92
|
+
wrapped.__ethoraFontWrapped = true;
|
|
93
|
+
return wrapped;
|
|
94
|
+
}
|
|
95
|
+
let factoriesPatched = false;
|
|
96
|
+
function ensurePatched() {
|
|
97
|
+
if (factoriesPatched) return;
|
|
98
|
+
let any = false;
|
|
99
|
+
const patchMod = mod => {
|
|
100
|
+
if (!mod) return;
|
|
101
|
+
for (const fn of ['jsx', 'jsxs', 'jsxDEV']) {
|
|
102
|
+
if (typeof mod[fn] === 'function' && !mod[fn].__ethoraFontWrapped) {
|
|
103
|
+
mod[fn] = wrapFactory(mod[fn]);
|
|
104
|
+
any = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
patchMod(require('react/jsx-runtime'));
|
|
110
|
+
} catch {
|
|
111
|
+
/* ignore */
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
patchMod(require('react/jsx-dev-runtime'));
|
|
115
|
+
} catch {
|
|
116
|
+
/* ignore */
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const React = require('react');
|
|
120
|
+
if (typeof React.createElement === 'function' && !React.createElement.__ethoraFontWrapped) {
|
|
121
|
+
React.createElement = wrapFactory(React.createElement);
|
|
122
|
+
any = true;
|
|
123
|
+
}
|
|
124
|
+
} catch {
|
|
125
|
+
/* ignore */
|
|
126
|
+
}
|
|
127
|
+
if (any) factoriesPatched = true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Set (or clear) the chat-wide default font family.
|
|
132
|
+
*/
|
|
133
|
+
function applyDefaultFont(typography) {
|
|
134
|
+
activeFamily = typography?.fontFamily;
|
|
135
|
+
if (activeFamily) ensurePatched();
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=useChatFonts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","useChatFonts","typography","ready","setReady","useState","fonts","length","applyDefaultFont","useEffect","cancelled","load","ExpoFont","Promise","resolve","then","catch","map","family","source","loadAsync","fontFamily","JSON","stringify","weightFamilies","activeFamily","wrapFactory","orig","__ethoraFontWrapped","wrapped","type","props","rest","Text","TextInput","style","factoriesPatched","ensurePatched","any","patchMod","mod","fn","React","createElement"],"sourceRoot":"../../../src","sources":["hooks/useChatFonts.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAA+C,SAAAE,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,CAAAC,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,K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","ignoreList":[]}
|
|
@@ -20,11 +20,25 @@ var _useEventHandlers = require("./useEventHandlers");
|
|
|
20
20
|
// long after the optimistic dispatch, mark it failed so the bubble
|
|
21
21
|
// flips out of the "sending..." state. Covers the silent-failure
|
|
22
22
|
// case (e.g. device offline before the message ever made it to the
|
|
23
|
-
// XMPP socket) — bug #18.
|
|
24
|
-
//
|
|
25
|
-
//
|
|
23
|
+
// XMPP socket) — bug #18.
|
|
24
|
+
//
|
|
25
|
+
// 5s window: a brief network blip that reconnects inside this window
|
|
26
|
+
// still resolves on its own — the offline send is buffered in the
|
|
27
|
+
// outbound queue (OUTBOUND_QUEUE_TTL_MS, kept in lockstep) and replayed
|
|
28
|
+
// the moment the stream comes back, so the server echo flips the bubble
|
|
29
|
+
// to delivered. Only a drop that outlasts 5s flips it to "Failed → tap
|
|
30
|
+
// to retry". If a slow send completes just after the window, the
|
|
31
|
+
// delivery clears the failed flag (see newMessageMidlleware) so it
|
|
32
|
+
// doesn't get stuck showing "Failed".
|
|
26
33
|
const PENDING_WATCHDOG_MS = 30_000;
|
|
27
34
|
|
|
35
|
+
// Media gets a longer window than text: the optimistic bubble appears before
|
|
36
|
+
// the file upload even starts, and a large file (up to the 50MB cap) over a
|
|
37
|
+
// slow link can legitimately take far longer than 5s to upload + send. Failing
|
|
38
|
+
// it at 5s mid-upload would flash a wrong "Failed" and let the user kick off a
|
|
39
|
+
// duplicate upload. The text watchdog stays at 5s per product spec.
|
|
40
|
+
const MEDIA_PENDING_WATCHDOG_MS = 30_000;
|
|
41
|
+
|
|
28
42
|
// Monotonic counter for stanza ids. Bumped on each send within a single
|
|
29
43
|
// process. Two rapid sends in the same millisecond used to collide on
|
|
30
44
|
// `send-text-message-${Date.now()}`; that collision made
|
|
@@ -63,7 +77,7 @@ const useSendMessage = _configOverride => {
|
|
|
63
77
|
handleMessageRetry
|
|
64
78
|
} = (0, _useEventHandlers.useEventHandlers)(config);
|
|
65
79
|
const failedMessages = (0, _reactRedux.useSelector)(state => state.roomHeapSlice?.failedMessages || {});
|
|
66
|
-
const sendMessage = (0, _react.useCallback)(async (message, activeRoomJID, isReply, isChecked, mainMessage) => {
|
|
80
|
+
const sendMessage = (0, _react.useCallback)(async (message, activeRoomJID, isReply, isChecked, mainMessage, existingId) => {
|
|
67
81
|
if (editAction?.isEdit) {
|
|
68
82
|
try {
|
|
69
83
|
client?.editMessageStanza(editAction.roomJid, editAction.messageId, message);
|
|
@@ -97,7 +111,7 @@ const useSendMessage = _configOverride => {
|
|
|
97
111
|
// dedupes by id and flips `pending: false` → DoubleTick renders.
|
|
98
112
|
// Without this, the user taps send and sees nothing for ~200ms
|
|
99
113
|
// until the echo lands, which feels broken.
|
|
100
|
-
const optimisticId = nextStanzaId('send-text-message');
|
|
114
|
+
const optimisticId = existingId || nextStanzaId('send-text-message');
|
|
101
115
|
const optimisticDate = new Date().toISOString();
|
|
102
116
|
const selfId = user?.xmppUsername || user?.walletAddress || '';
|
|
103
117
|
const optimisticMessage = {
|
|
@@ -118,7 +132,11 @@ const useSendMessage = _configOverride => {
|
|
|
118
132
|
name: `${user?.firstName || ''} ${user?.lastName || ''}`.trim() || selfId
|
|
119
133
|
}
|
|
120
134
|
};
|
|
121
|
-
|
|
135
|
+
// On retry (`existingId`) the original optimistic bubble is still in
|
|
136
|
+
// the room (pending:true) — clearMessageFailure just flipped it back out
|
|
137
|
+
// of the "failed" state — so re-adding would duplicate it. Only push a
|
|
138
|
+
// fresh bubble for a brand-new send.
|
|
139
|
+
if (!config?.disableSentLogic && !existingId) {
|
|
122
140
|
dispatch((0, _roomsSlice.addRoomMessage)({
|
|
123
141
|
roomJID: activeRoomJID,
|
|
124
142
|
message: optimisticMessage
|
|
@@ -154,26 +172,46 @@ const useSendMessage = _configOverride => {
|
|
|
154
172
|
}
|
|
155
173
|
}, PENDING_WATCHDOG_MS);
|
|
156
174
|
try {
|
|
157
|
-
|
|
175
|
+
// The single send closure, used both for the immediate send and for
|
|
176
|
+
// the buffered replay. Passing the optimistic id as the stanza id
|
|
177
|
+
// means the server echoes it back with the same value, so the
|
|
178
|
+
// reducer's dedupe matches and the bubble flips pending → delivered
|
|
179
|
+
// in-place (rather than rendering a second copy).
|
|
180
|
+
const replaySend = c => c.sendMessage(activeRoomJID, user.firstName, user.lastName, '', user.walletAddress, message, '', isReply || false, isChecked || false, mainMessage || '', optimisticId);
|
|
181
|
+
|
|
182
|
+
// Always buffer a copy BEFORE attempting the live send. The WebSocket
|
|
183
|
+
// can still read `status: 'online'` for a beat after the network
|
|
184
|
+
// actually drops (the WS error lands a moment later), so a stanza sent
|
|
185
|
+
// "while online" can vanish into a dying socket and never get echoed.
|
|
186
|
+
// Buffering every send means the onOnline reconnect flush replays
|
|
187
|
+
// anything that wasn't confirmed within the window. The server echo
|
|
188
|
+
// removes the entry (see newMessageMidlleware), so a healthy online
|
|
189
|
+
// send never actually replays — only genuinely-lost ones do.
|
|
190
|
+
(0, _outboundQueue.enqueueOutboundSend)({
|
|
191
|
+
optimisticId,
|
|
192
|
+
roomJID: activeRoomJID,
|
|
193
|
+
enqueuedAt: Date.now(),
|
|
194
|
+
send: replaySend
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Only treat a client as usable if its underlying stream is actually
|
|
198
|
+
// `online` — the instance survives a network drop with a stale
|
|
199
|
+
// 'connecting'/'offline' status, and sending through it would just
|
|
200
|
+
// lose the stanza.
|
|
201
|
+
const effectiveClient = [client, (0, _clientRegistry.getGlobalXmppClient)(), _roomStore.store.getState()?.chatSettingStore?.client].find(c => c && c.status === 'online');
|
|
158
202
|
if (!effectiveClient) {
|
|
203
|
+
// No live stream — kick a reconnect; the buffered copy above is
|
|
204
|
+
// replayed by the onOnline flush once the stream is back.
|
|
159
205
|
const anyClient = client || (0, _clientRegistry.getGlobalXmppClient)() || _roomStore.store.getState()?.chatSettingStore?.client;
|
|
160
206
|
try {
|
|
161
207
|
anyClient?.forceReconnect?.();
|
|
162
208
|
} catch {}
|
|
163
|
-
(0, _outboundQueue.enqueueOutboundSend)({
|
|
164
|
-
optimisticId,
|
|
165
|
-
roomJID: activeRoomJID,
|
|
166
|
-
enqueuedAt: Date.now(),
|
|
167
|
-
send: c => c.sendMessage(activeRoomJID, user.firstName, user.lastName, '', user.walletAddress, message, '', isReply || false, isChecked || false, mainMessage || '', optimisticId)
|
|
168
|
-
});
|
|
169
209
|
return;
|
|
170
210
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// ids don't match).
|
|
176
|
-
effectiveClient.sendMessage(activeRoomJID, user.firstName, user.lastName, '', user.walletAddress, message, '', isReply || false, isChecked || false, mainMessage || '', optimisticId);
|
|
211
|
+
replaySend(effectiveClient);
|
|
212
|
+
try {
|
|
213
|
+
effectiveClient.ensureStreamAlive?.();
|
|
214
|
+
} catch {}
|
|
177
215
|
await handleMessageSent({
|
|
178
216
|
message,
|
|
179
217
|
roomJID: activeRoomJID,
|
|
@@ -313,7 +351,7 @@ const useSendMessage = _configOverride => {
|
|
|
313
351
|
messageType: 'media'
|
|
314
352
|
});
|
|
315
353
|
}
|
|
316
|
-
},
|
|
354
|
+
}, MEDIA_PENDING_WATCHDOG_MS);
|
|
317
355
|
|
|
318
356
|
// Help RN's FormData polyfill build a proper multipart/file part
|
|
319
357
|
// (instead of serialising the JS object as JSON). On iOS the
|
|
@@ -390,11 +428,17 @@ const useSendMessage = _configOverride => {
|
|
|
390
428
|
// Stanza id == placeholder id so the MUC echo's outer
|
|
391
429
|
// <message id="..."> matches xmppId on the placeholder and
|
|
392
430
|
// insertMessageWithDelimiter merges in place + flips pending.
|
|
393
|
-
|
|
431
|
+
// Same online-only guard as the text path: a surviving-but-offline
|
|
432
|
+
// client must NOT be used (the stanza would vanish into a dead
|
|
433
|
+
// socket) — fall through to enqueue so the reconnect flush replays.
|
|
434
|
+
const effectiveMediaClient = [client, (0, _clientRegistry.getGlobalXmppClient)(), _roomStore.store.getState()?.chatSettingStore?.client].find(c => c && c.status === 'online');
|
|
394
435
|
if (effectiveMediaClient) {
|
|
395
436
|
effectiveMediaClient.setActiveRoomJid?.(activeRoomJID);
|
|
396
437
|
await Promise.resolve(effectiveMediaClient.prioritizeRoomPresence?.(activeRoomJID)).catch(() => false);
|
|
397
438
|
effectiveMediaClient.sendMediaMessageStanza(activeRoomJID, messagePayload, id);
|
|
439
|
+
try {
|
|
440
|
+
effectiveMediaClient.ensureStreamAlive?.();
|
|
441
|
+
} catch {}
|
|
398
442
|
} else {
|
|
399
443
|
const anyMediaClient = client || (0, _clientRegistry.getGlobalXmppClient)() || _roomStore.store.getState()?.chatSettingStore?.client;
|
|
400
444
|
try {
|
|
@@ -404,6 +448,9 @@ const useSendMessage = _configOverride => {
|
|
|
404
448
|
optimisticId: id,
|
|
405
449
|
roomJID: activeRoomJID,
|
|
406
450
|
enqueuedAt: Date.now(),
|
|
451
|
+
// Match the media watchdog so a reconnect within the (longer)
|
|
452
|
+
// media window still auto-replays the buffered stanza.
|
|
453
|
+
ttlMs: MEDIA_PENDING_WATCHDOG_MS,
|
|
407
454
|
send: c => c.sendMediaMessageStanza(activeRoomJID, messagePayload, id)
|
|
408
455
|
});
|
|
409
456
|
}
|
|
@@ -484,7 +531,10 @@ const useSendMessage = _configOverride => {
|
|
|
484
531
|
messageType: payload.kind
|
|
485
532
|
});
|
|
486
533
|
if (payload.kind === 'text') {
|
|
487
|
-
await sendMessage(payload.body, payload.roomJID, payload.isReply, payload.isChecked, payload.mainMessage
|
|
534
|
+
await sendMessage(payload.body, payload.roomJID, payload.isReply, payload.isChecked, payload.mainMessage,
|
|
535
|
+
// Re-use the failed message's id so the retry resends in place
|
|
536
|
+
// instead of spawning a duplicate bubble.
|
|
537
|
+
failedId);
|
|
488
538
|
} else {
|
|
489
539
|
await sendMedia(payload.data, payload.type, payload.roomJID, payload.isReply, payload.isChecked, payload.mainMessage, failedId);
|
|
490
540
|
}
|