@dubsdotapp/expo 0.5.26 → 0.5.28
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/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/provider.tsx +18 -3
package/package.json
CHANGED
package/src/chat/provider.tsx
CHANGED
|
@@ -87,8 +87,11 @@ export function ChatProvider({ children, autoConnect = true }: ChatProviderProps
|
|
|
87
87
|
const refreshMessages = useCallback(async () => {
|
|
88
88
|
try {
|
|
89
89
|
const res = await client.getChatMessages({ limit: 30 });
|
|
90
|
-
// API returns
|
|
91
|
-
|
|
90
|
+
// The dev API returns messages oldest-first (chatService applies a
|
|
91
|
+
// .reverse() for legacy chat-order callers). Inverted chat FlatLists
|
|
92
|
+
// — and onNewMessage's prepend below — assume newest-first. Flip
|
|
93
|
+
// here so the internal store is consistent everywhere.
|
|
94
|
+
setMessages([...res.messages].reverse());
|
|
92
95
|
} catch (err) {
|
|
93
96
|
console.error('[Dubs:ChatProvider] Failed to load messages:', err);
|
|
94
97
|
}
|
|
@@ -155,7 +158,19 @@ export function ChatProvider({ children, autoConnect = true }: ChatProviderProps
|
|
|
155
158
|
const host = new URL(baseUrl).origin;
|
|
156
159
|
|
|
157
160
|
chatSocket.setListeners({
|
|
158
|
-
|
|
161
|
+
// Refetch the message list whenever the socket reaches 'connected'.
|
|
162
|
+
// Covers both the initial connect AND every reconnect (app resumed
|
|
163
|
+
// from background, transient network blip, server restart). Without
|
|
164
|
+
// this, the provider's `messages` state is frozen at whatever it was
|
|
165
|
+
// when the app last connected — Socket.IO's auto-reconnect resumes
|
|
166
|
+
// delivery of *new* events but does not replay the gap.
|
|
167
|
+
onConnectionChange: (next) => {
|
|
168
|
+
setStatus(next);
|
|
169
|
+
if (next === 'connected') {
|
|
170
|
+
refreshMessages().catch(() => {});
|
|
171
|
+
refreshConversations().catch(() => {});
|
|
172
|
+
}
|
|
173
|
+
},
|
|
159
174
|
// Global chat
|
|
160
175
|
onNewMessage: (msg) => {
|
|
161
176
|
setMessages((prev) => {
|