@ethora/chat-component-rn 26.5.12 → 26.5.13
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/components/MainComponents/ChatRoom.js +59 -39
- package/lib/commonjs/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/commonjs/components/MainComponents/ReduxWrapper.js +24 -15
- package/lib/commonjs/components/MainComponents/ReduxWrapper.js.map +1 -1
- package/lib/commonjs/context/xmppProvider.js +63 -0
- package/lib/commonjs/context/xmppProvider.js.map +1 -1
- package/lib/commonjs/networking/xmppClient.js +26 -1
- package/lib/commonjs/networking/xmppClient.js.map +1 -1
- package/lib/commonjs/roomStore/Middleware/unreadMidlleware.js +10 -10
- package/lib/commonjs/roomStore/Middleware/unreadMidlleware.js.map +1 -1
- package/lib/commonjs/roomStore/roomsSlice.js +59 -4
- package/lib/commonjs/roomStore/roomsSlice.js.map +1 -1
- package/lib/module/components/MainComponents/ChatRoom.js +61 -41
- package/lib/module/components/MainComponents/ChatRoom.js.map +1 -1
- package/lib/module/components/MainComponents/ReduxWrapper.js +24 -15
- package/lib/module/components/MainComponents/ReduxWrapper.js.map +1 -1
- package/lib/module/context/xmppProvider.js +65 -2
- package/lib/module/context/xmppProvider.js.map +1 -1
- package/lib/module/networking/xmppClient.js +26 -1
- package/lib/module/networking/xmppClient.js.map +1 -1
- package/lib/module/roomStore/Middleware/unreadMidlleware.js +10 -10
- package/lib/module/roomStore/Middleware/unreadMidlleware.js.map +1 -1
- package/lib/module/roomStore/roomsSlice.js +57 -3
- package/lib/module/roomStore/roomsSlice.js.map +1 -1
- package/lib/typescript/components/MainComponents/ChatRoom.d.ts.map +1 -1
- package/lib/typescript/components/MainComponents/ReduxWrapper.d.ts.map +1 -1
- package/lib/typescript/context/xmppProvider.d.ts.map +1 -1
- package/lib/typescript/networking/xmppClient.d.ts.map +1 -1
- package/lib/typescript/roomStore/Middleware/unreadMidlleware.d.ts.map +1 -1
- package/lib/typescript/roomStore/roomsSlice.d.ts +18 -1
- package/lib/typescript/roomStore/roomsSlice.d.ts.map +1 -1
- package/lib/typescript/types/types.d.ts +2 -0
- package/lib/typescript/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/MainComponents/ChatRoom.tsx +60 -43
- package/src/components/MainComponents/ReduxWrapper.tsx +23 -9
- package/src/context/xmppProvider.tsx +55 -1
- package/src/networking/xmppClient.ts +24 -1
- package/src/roomStore/Middleware/unreadMidlleware.tsx +11 -8
- package/src/roomStore/roomsSlice.ts +59 -2
- package/src/types/types.ts +19 -0
|
@@ -37,13 +37,14 @@ import { ensureScopedChatCache } from '../helpers/ensureScopedChatCache';
|
|
|
37
37
|
import { getRooms as prefetchRoomsViaRest } from '../networking/api-requests/rooms.api';
|
|
38
38
|
import { allRoomPresences } from '../networking/xmpp/allRoomPresences.xmpp';
|
|
39
39
|
import { store } from '../roomStore';
|
|
40
|
-
import { logout, setStoreClient } from '../roomStore/chatSettingsSlice';
|
|
40
|
+
import { logout, setStoreClient, setConfig } from '../roomStore/chatSettingsSlice';
|
|
41
41
|
import {
|
|
42
42
|
setLogoutState,
|
|
43
43
|
setVisibleRoom,
|
|
44
44
|
clearVisibleRoom,
|
|
45
45
|
setLastViewedTimestamp,
|
|
46
46
|
deleteRoomMessage,
|
|
47
|
+
msgSortableMs,
|
|
47
48
|
} from '../roomStore/roomsSlice';
|
|
48
49
|
import { runHistoryPreloadScheduler } from '../helpers/historyPreloadScheduler';
|
|
49
50
|
import { asyncLocalStorage } from '../hooks/useLocalStorage';
|
|
@@ -343,6 +344,10 @@ export const XmppProvider: React.FC<XmppProviderProps> = ({ children, config, is
|
|
|
343
344
|
devPushLog('rn', `initBeforeLoad: user resolved (${resolved.xmppUsername})`);
|
|
344
345
|
applyResolvedUserToStore(resolved);
|
|
345
346
|
|
|
347
|
+
if (config) {
|
|
348
|
+
store.dispatch(setConfig(config));
|
|
349
|
+
}
|
|
350
|
+
|
|
346
351
|
// Kick off REST /chats/my; allRoomPresences below needs the
|
|
347
352
|
// room list to be in redux, otherwise it joins 0 MUCs and the
|
|
348
353
|
// user receives zero realtime messages until they manually tap
|
|
@@ -631,6 +636,55 @@ export const XmppProvider: React.FC<XmppProviderProps> = ({ children, config, is
|
|
|
631
636
|
}
|
|
632
637
|
}, [isVisible, client]);
|
|
633
638
|
|
|
639
|
+
useEffect(() => {
|
|
640
|
+
if (isVisible !== true) {return;}
|
|
641
|
+
let lastMessagesRef: any = null;
|
|
642
|
+
let lastStampedMs = 0;
|
|
643
|
+
let flushTimer: ReturnType<typeof setTimeout> | null = null;
|
|
644
|
+
|
|
645
|
+
const advance = () => {
|
|
646
|
+
const s = store.getState();
|
|
647
|
+
const jid = s.rooms?.activeRoomJID;
|
|
648
|
+
if (!jid) {return;}
|
|
649
|
+
const room = s.rooms?.rooms?.[jid];
|
|
650
|
+
if (!room) {return;}
|
|
651
|
+
if (room.messages === lastMessagesRef) {return;}
|
|
652
|
+
lastMessagesRef = room.messages;
|
|
653
|
+
|
|
654
|
+
let newest = 0;
|
|
655
|
+
const list = room.messages || [];
|
|
656
|
+
for (const m of list) {
|
|
657
|
+
if (!m || m.id === 'delimiter-new') {continue;}
|
|
658
|
+
const ms = msgSortableMs(m);
|
|
659
|
+
if (ms > newest) {newest = ms;}
|
|
660
|
+
}
|
|
661
|
+
if (newest <= lastStampedMs) {return;}
|
|
662
|
+
lastStampedMs = newest;
|
|
663
|
+
|
|
664
|
+
store.dispatch(
|
|
665
|
+
setLastViewedTimestamp({ chatJID: jid, timestamp: Date.now() })
|
|
666
|
+
);
|
|
667
|
+
|
|
668
|
+
if (flushTimer) {clearTimeout(flushTimer);}
|
|
669
|
+
if (client?.flushLastViewedToPrivateStoreStanza) {
|
|
670
|
+
flushTimer = setTimeout(() => {
|
|
671
|
+
client
|
|
672
|
+
.flushLastViewedToPrivateStoreStanza(store.getState().rooms?.rooms, {
|
|
673
|
+
visibleRoomJID: jid,
|
|
674
|
+
})
|
|
675
|
+
.catch(() => {});
|
|
676
|
+
}, 2000);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
advance();
|
|
681
|
+
const unsub = store.subscribe(advance);
|
|
682
|
+
return () => {
|
|
683
|
+
unsub();
|
|
684
|
+
if (flushTimer) {clearTimeout(flushTimer);}
|
|
685
|
+
};
|
|
686
|
+
}, [isVisible, client]);
|
|
687
|
+
|
|
634
688
|
// -----------------------------------------------------------
|
|
635
689
|
// NetInfo → proactive reconnect on network restore. Without this the
|
|
636
690
|
// only reconnect trigger is xmpp.js noticing the socket is dead, which
|
|
@@ -23,6 +23,8 @@ import { getRooms } from './xmpp/getRooms.xmpp';
|
|
|
23
23
|
import { handleStanza } from './xmpp/handleStanzas.xmpp';
|
|
24
24
|
import { pushLog as devPushLog } from '../utils/devLogger';
|
|
25
25
|
import { normalizeRoomJid } from '../helpers/normalizeRoomJid';
|
|
26
|
+
import { store } from '../roomStore';
|
|
27
|
+
import { applyPrivateStoreMarkers } from '../roomStore/roomsSlice';
|
|
26
28
|
import {
|
|
27
29
|
clearOutboundSends,
|
|
28
30
|
enqueueOutboundSend,
|
|
@@ -870,7 +872,28 @@ export class XmppClient {
|
|
|
870
872
|
getChatsPrivateStoreRequestStanza = async () => {
|
|
871
873
|
if (this.disableLastRead) {return null;}
|
|
872
874
|
try {
|
|
873
|
-
|
|
875
|
+
const markers = await getChatsPrivateStoreRequest(this.client);
|
|
876
|
+
// Hydrate the fetched server-side read markers into redux. Without
|
|
877
|
+
// this the markers were fetched on every init/reconnect and then
|
|
878
|
+
// silently dropped, so any room the user hadn't locally opened+left
|
|
879
|
+
// this session kept `lastViewedTimestamp: 0` and the unread
|
|
880
|
+
// middleware's `> 0` gate skipped it forever — `useUnread()` stayed
|
|
881
|
+
// at 0 with no badge. Done here on the single READ method so every
|
|
882
|
+
// caller (provider init, reconnect, ChatWrapper, push handlers, …)
|
|
883
|
+
// hydrates automatically and a future caller can't reintroduce the
|
|
884
|
+
// drop. The write helpers call the lower-level
|
|
885
|
+
// `getChatsPrivateStoreRequest` directly and intentionally skip this.
|
|
886
|
+
if (markers && typeof markers === 'object') {
|
|
887
|
+
const normalized: Record<string, number> = {};
|
|
888
|
+
for (const jid of Object.keys(markers as Record<string, unknown>)) {
|
|
889
|
+
const n = Number((markers as Record<string, unknown>)[jid]);
|
|
890
|
+
if (jid && Number.isFinite(n) && n > 0) {normalized[jid] = n;}
|
|
891
|
+
}
|
|
892
|
+
if (Object.keys(normalized).length > 0) {
|
|
893
|
+
store.dispatch(applyPrivateStoreMarkers(normalized));
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return markers;
|
|
874
897
|
} catch (error) {
|
|
875
898
|
console.log(error);
|
|
876
899
|
return null;
|
|
@@ -64,6 +64,10 @@ const TRIGGER_ACTIONS = new Set([
|
|
|
64
64
|
'roomMessages/setRoomMessages',
|
|
65
65
|
'roomMessages/editRoomMessage',
|
|
66
66
|
'roomMessages/setLastViewedTimestamp',
|
|
67
|
+
// Hydrating server-side read markers can move several rooms' baselines
|
|
68
|
+
// at once; recompute so the badges reflect the freshly-applied markers
|
|
69
|
+
// (with own-message filtering this middleware adds on top).
|
|
70
|
+
'roomMessages/applyPrivateStoreMarkers',
|
|
67
71
|
'roomMessages/setCurrentRoom',
|
|
68
72
|
'roomMessages/setVisibleRoom',
|
|
69
73
|
'roomMessages/clearVisibleRoom',
|
|
@@ -130,14 +134,13 @@ export const unreadMiddleware: Middleware =
|
|
|
130
134
|
}
|
|
131
135
|
if (!(room.lastViewedTimestamp > 0)) {return;}
|
|
132
136
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const fingerprint = `${currentMessagesLength}|${room.lastViewedTimestamp || 0}`;
|
|
137
|
+
const msgs = room.messages;
|
|
138
|
+
const currentMessagesLength = msgs?.length || 0;
|
|
139
|
+
const firstId = currentMessagesLength ? String(msgs![0]?.id ?? '') : '';
|
|
140
|
+
const lastId = currentMessagesLength
|
|
141
|
+
? String(msgs![currentMessagesLength - 1]?.id ?? '')
|
|
142
|
+
: '';
|
|
143
|
+
const fingerprint = `${currentMessagesLength}|${room.lastViewedTimestamp || 0}|${firstId}|${lastId}`;
|
|
141
144
|
if (triggerCache[jid] === fingerprint) {return;}
|
|
142
145
|
triggerCache[jid] = fingerprint;
|
|
143
146
|
|
|
@@ -98,6 +98,12 @@ export interface RoomMessagesState {
|
|
|
98
98
|
loadingText?: string;
|
|
99
99
|
usersSet?: Record<string, any>;
|
|
100
100
|
pendingNotificationJid?: string | null;
|
|
101
|
+
// Server-side read markers fetched from the XMPP private store
|
|
102
|
+
// (`{ roomJID: lastViewedMs }`). Kept here so a room that loads AFTER
|
|
103
|
+
// the markers were fetched still inherits its baseline via `addRoom`
|
|
104
|
+
// — see `applyPrivateStoreMarkers`. Re-fetched every init/reconnect,
|
|
105
|
+
// so it is intentionally NOT persisted.
|
|
106
|
+
privateStoreMarkers: Record<string, number>;
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
const initialState: RoomMessagesState = {
|
|
@@ -112,6 +118,7 @@ const initialState: RoomMessagesState = {
|
|
|
112
118
|
text: '',
|
|
113
119
|
},
|
|
114
120
|
pendingNotificationJid: null,
|
|
121
|
+
privateStoreMarkers: {},
|
|
115
122
|
};
|
|
116
123
|
|
|
117
124
|
const isValidRoomJid = (jid: unknown): jid is string => {
|
|
@@ -160,11 +167,19 @@ const reducers = {
|
|
|
160
167
|
// the previous session, so cold-start showed no unread badge for
|
|
161
168
|
// messages received while the app was closed (bug #19/#20). A real
|
|
162
169
|
// (non-zero) explicit value still wins; otherwise keep the existing
|
|
163
|
-
// value; otherwise
|
|
170
|
+
// value; otherwise fall back to the server-side read marker fetched
|
|
171
|
+
// from the private store (so a room the user has NEVER opened this
|
|
172
|
+
// session still gets a real baseline — without it the unread
|
|
173
|
+
// middleware's `lastViewedTimestamp > 0` gate skipped the room
|
|
174
|
+
// forever and the badge never lit up); otherwise anchor to the
|
|
175
|
+
// newest message in the payload.
|
|
176
|
+
const serverMarker = state.privateStoreMarkers?.[roomData.jid] || 0;
|
|
164
177
|
if (roomData.lastViewedTimestamp != null && roomData.lastViewedTimestamp !== 0) {
|
|
165
178
|
lastViewed = roomData.lastViewedTimestamp;
|
|
166
|
-
} else if (existing?.lastViewedTimestamp != null) {
|
|
179
|
+
} else if (existing?.lastViewedTimestamp != null && existing.lastViewedTimestamp > 0) {
|
|
167
180
|
lastViewed = existing.lastViewedTimestamp;
|
|
181
|
+
} else if (serverMarker > 0) {
|
|
182
|
+
lastViewed = serverMarker;
|
|
168
183
|
} else {
|
|
169
184
|
const msgs = roomData.messages || [];
|
|
170
185
|
let newest = 0;
|
|
@@ -346,6 +361,7 @@ const reducers = {
|
|
|
346
361
|
deleteAllRooms(state: WritableDraft<RoomMessagesState>) {
|
|
347
362
|
state.rooms = {};
|
|
348
363
|
state.visibleRoomJID = null;
|
|
364
|
+
state.privateStoreMarkers = {};
|
|
349
365
|
},
|
|
350
366
|
setComposing(
|
|
351
367
|
state: WritableDraft<RoomMessagesState>,
|
|
@@ -392,6 +408,45 @@ const reducers = {
|
|
|
392
408
|
}
|
|
393
409
|
}
|
|
394
410
|
},
|
|
411
|
+
/**
|
|
412
|
+
* Apply server-side read markers fetched from the XMPP private store
|
|
413
|
+
* (`{ roomJID: lastViewedMs }`) to redux. This is the hydration that
|
|
414
|
+
* was missing: `getChatsPrivateStoreRequest` fetched the markers on
|
|
415
|
+
* every init/reconnect and every caller then DISCARDED the result, so
|
|
416
|
+
* rooms kept `lastViewedTimestamp: 0` and the unread middleware's
|
|
417
|
+
* `> 0` gate skipped them forever — `useUnread()` stayed at 0 for any
|
|
418
|
+
* room the user hadn't locally opened+left this session. Centralised
|
|
419
|
+
* here (and consulted by `addRoom`) so BOTH already-loaded rooms and
|
|
420
|
+
* rooms that load later pick up the baseline.
|
|
421
|
+
*
|
|
422
|
+
* Monotonic: a marker only ever moves a baseline FORWARD, so a stale
|
|
423
|
+
* server value can't resurrect already-read messages and a more-recent
|
|
424
|
+
* local read (tab blur stamping Date.now()) always wins.
|
|
425
|
+
*/
|
|
426
|
+
applyPrivateStoreMarkers: (
|
|
427
|
+
state: WritableDraft<RoomMessagesState>,
|
|
428
|
+
action: PayloadAction<Record<string, number>>
|
|
429
|
+
) => {
|
|
430
|
+
const markers = action.payload;
|
|
431
|
+
if (!markers || typeof markers !== 'object') {return;}
|
|
432
|
+
if (!state.privateStoreMarkers) {state.privateStoreMarkers = {};}
|
|
433
|
+
for (const jid of Object.keys(markers)) {
|
|
434
|
+
const ts = Number(markers[jid]);
|
|
435
|
+
if (!jid || !Number.isFinite(ts) || ts <= 0) {continue;}
|
|
436
|
+
// Remember the marker so rooms that load LATER (via addRoom)
|
|
437
|
+
// inherit it even though they don't exist in the store yet.
|
|
438
|
+
if (ts > (state.privateStoreMarkers[jid] || 0)) {
|
|
439
|
+
state.privateStoreMarkers[jid] = ts;
|
|
440
|
+
}
|
|
441
|
+
// Upgrade an already-loaded room's baseline + recompute its badge.
|
|
442
|
+
// Only ever forward, so a later local read isn't clobbered.
|
|
443
|
+
const room = state.rooms[jid];
|
|
444
|
+
if (room && ts > (room.lastViewedTimestamp || 0)) {
|
|
445
|
+
room.lastViewedTimestamp = ts;
|
|
446
|
+
room.unreadMessages = countNewerMessages(room.messages, ts);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
},
|
|
395
450
|
setRoomRole: (
|
|
396
451
|
state: WritableDraft<RoomMessagesState>,
|
|
397
452
|
action: PayloadAction<{ chatJID: string; role: string }>
|
|
@@ -483,6 +538,7 @@ const reducers = {
|
|
|
483
538
|
state.activeRoomJID = null;
|
|
484
539
|
state.visibleRoomJID = null;
|
|
485
540
|
state.isLoading = false;
|
|
541
|
+
state.privateStoreMarkers = {};
|
|
486
542
|
},
|
|
487
543
|
setActiveMessage: (
|
|
488
544
|
state: WritableDraft<RoomMessagesState>,
|
|
@@ -674,6 +730,7 @@ export const {
|
|
|
674
730
|
setComposing,
|
|
675
731
|
setIsLoading,
|
|
676
732
|
setLastViewedTimestamp,
|
|
733
|
+
applyPrivateStoreMarkers,
|
|
677
734
|
setRoomNoMessages,
|
|
678
735
|
setCurrentRoom,
|
|
679
736
|
setVisibleRoom,
|
package/src/types/types.ts
CHANGED
|
@@ -372,6 +372,25 @@ export interface IConfig {
|
|
|
372
372
|
chatRoomStyles?: ViewStyle;
|
|
373
373
|
|
|
374
374
|
keyboardVerticalOffset?: number;
|
|
375
|
+
// Opt OUT of the built-in keyboard handling. By default <Chat> mounts
|
|
376
|
+
// its own react-native-keyboard-controller KeyboardProvider +
|
|
377
|
+
// KeyboardAvoidingView (behavior="padding"). If the HOST app already
|
|
378
|
+
// wraps <Chat> in its own KeyboardProvider / KeyboardAvoidingView, the
|
|
379
|
+
// built-in one becomes a SECOND avoider over the same tree — two of them
|
|
380
|
+
// animating padding on keyboard open is the Android flicker in bug #6.
|
|
381
|
+
// Set this so the component renders a plain View instead and drops its
|
|
382
|
+
// KeyboardProvider, leaving the host to own keyboard handling outright.
|
|
383
|
+
disableKeyboardAvoidingView?: boolean;
|
|
384
|
+
// Built-in keyboard strategy: instead of the default KeyboardAvoidingView
|
|
385
|
+
// (which adds bottom padding to the WHOLE chat tree — the message list
|
|
386
|
+
// reflows on keyboard open, the Android "messages jump/flash" in bug #6),
|
|
387
|
+
// wrap ONLY the input dock in a react-native-keyboard-controller
|
|
388
|
+
// KeyboardStickyView so just the input tracks the keyboard and the list
|
|
389
|
+
// is never resized. Best for edge-to-edge Android hosts (where the OS
|
|
390
|
+
// doesn't also resize the window). Ignored when
|
|
391
|
+
// `disableKeyboardAvoidingView` is set. Needs on-device tuning of any
|
|
392
|
+
// `keyboardVerticalOffset`.
|
|
393
|
+
keyboardStickyInput?: boolean;
|
|
375
394
|
|
|
376
395
|
// ----- interactions / messages -----
|
|
377
396
|
disableInteractions?: boolean;
|