@poolse/react 3.0.0 → 3.1.0
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/CHANGELOG.md +10 -0
- package/README.md +71 -293
- package/dist/index.cjs +33 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -438,7 +438,7 @@ interface UseAttachmentUrlState {
|
|
|
438
438
|
* re-keys on a timer.
|
|
439
439
|
*
|
|
440
440
|
* ```tsx
|
|
441
|
-
* const { url } = useAttachmentUrl(message.
|
|
441
|
+
* const { url } = useAttachmentUrl(message.attachments?.[0]?.id ?? null);
|
|
442
442
|
* return url ? <img src={url} /> : <Spinner />;
|
|
443
443
|
* ```
|
|
444
444
|
*/
|
|
@@ -525,7 +525,7 @@ interface UseCallRoom {
|
|
|
525
525
|
* earpiece, but it does have several microphones and a pair of
|
|
526
526
|
* headphones, and choosing between them is the same job. Sparse on
|
|
527
527
|
* React Native, where routing goes through the platform audio session
|
|
528
|
-
* instead (
|
|
528
|
+
* instead (`setAudioOutput` in `@poolse/native`).
|
|
529
529
|
*/
|
|
530
530
|
devices: Record<CallDeviceKind, CallDevice[]>;
|
|
531
531
|
/** Device id in use per kind, where the platform reports one. */
|
package/dist/index.d.ts
CHANGED
|
@@ -438,7 +438,7 @@ interface UseAttachmentUrlState {
|
|
|
438
438
|
* re-keys on a timer.
|
|
439
439
|
*
|
|
440
440
|
* ```tsx
|
|
441
|
-
* const { url } = useAttachmentUrl(message.
|
|
441
|
+
* const { url } = useAttachmentUrl(message.attachments?.[0]?.id ?? null);
|
|
442
442
|
* return url ? <img src={url} /> : <Spinner />;
|
|
443
443
|
* ```
|
|
444
444
|
*/
|
|
@@ -525,7 +525,7 @@ interface UseCallRoom {
|
|
|
525
525
|
* earpiece, but it does have several microphones and a pair of
|
|
526
526
|
* headphones, and choosing between them is the same job. Sparse on
|
|
527
527
|
* React Native, where routing goes through the platform audio session
|
|
528
|
-
* instead (
|
|
528
|
+
* instead (`setAudioOutput` in `@poolse/native`).
|
|
529
529
|
*/
|
|
530
530
|
devices: Record<CallDeviceKind, CallDevice[]>;
|
|
531
531
|
/** Device id in use per kind, where the platform reports one. */
|
package/dist/index.js
CHANGED
|
@@ -172,9 +172,21 @@ function useConversations() {
|
|
|
172
172
|
const fromMe = by_user_id === me.id;
|
|
173
173
|
setConversations((prev) => mergeUpdated(prev, conversation, fromMe));
|
|
174
174
|
});
|
|
175
|
+
let wasConnected = chat.realtime.getStatus() === "connected";
|
|
176
|
+
let connectedBefore = wasConnected;
|
|
177
|
+
const offStatus = chat.realtime.onStatus((status) => {
|
|
178
|
+
const reconnected = status === "connected" && !wasConnected && connectedBefore;
|
|
179
|
+
connectedBefore ||= status === "connected";
|
|
180
|
+
if (reconnected) {
|
|
181
|
+
chat.conversations.list().then((list) => setConversations(list.data)).catch(() => {
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
wasConnected = status === "connected";
|
|
185
|
+
});
|
|
175
186
|
return () => {
|
|
176
187
|
offCreated();
|
|
177
188
|
offUpdated();
|
|
189
|
+
offStatus();
|
|
178
190
|
};
|
|
179
191
|
}, [chat, me]);
|
|
180
192
|
const markConversationRead = useCallback((conversationId) => {
|
|
@@ -381,11 +393,24 @@ function useMessages(conversationId) {
|
|
|
381
393
|
return updated;
|
|
382
394
|
});
|
|
383
395
|
});
|
|
396
|
+
let wasConnected = chat.realtime.getStatus() === "connected";
|
|
397
|
+
let connectedBefore = wasConnected;
|
|
398
|
+
const offStatus = chat.realtime.onStatus((status) => {
|
|
399
|
+
const reconnected = status === "connected" && !wasConnected && connectedBefore;
|
|
400
|
+
wasConnected = status === "connected";
|
|
401
|
+
connectedBefore ||= wasConnected;
|
|
402
|
+
if (!reconnected || cancelled) return;
|
|
403
|
+
handle.list({ limit: PAGE_SIZE }).then((page) => {
|
|
404
|
+
if (!cancelled) setMessages((prev) => mergeLatest(prev, page.data));
|
|
405
|
+
}).catch(() => {
|
|
406
|
+
});
|
|
407
|
+
});
|
|
384
408
|
return () => {
|
|
385
409
|
cancelled = true;
|
|
386
410
|
offNew();
|
|
387
411
|
offUpdated();
|
|
388
412
|
offDeleted();
|
|
413
|
+
offStatus();
|
|
389
414
|
};
|
|
390
415
|
}, [chat, conversationId]);
|
|
391
416
|
const loadMore = useCallback(async () => {
|
|
@@ -526,6 +551,11 @@ function upsertById(prev, msg) {
|
|
|
526
551
|
next[idx] = msg;
|
|
527
552
|
return next;
|
|
528
553
|
}
|
|
554
|
+
function mergeLatest(prev, page) {
|
|
555
|
+
let next = prev;
|
|
556
|
+
for (const msg of page) next = upsertById(next, msg);
|
|
557
|
+
return next === prev ? prev : [...next].sort((a, b) => a.sequence - b.sequence);
|
|
558
|
+
}
|
|
529
559
|
function useReactions(messageId, opts) {
|
|
530
560
|
const chat = usePoolse();
|
|
531
561
|
const [reactions, setReactions] = useState(opts.initialReactions ?? {});
|
|
@@ -1275,9 +1305,11 @@ function useLiveCall(conversationId) {
|
|
|
1275
1305
|
apply(null);
|
|
1276
1306
|
});
|
|
1277
1307
|
let wasConnected = chat.realtime.getStatus() === "connected";
|
|
1308
|
+
let connectedBefore = wasConnected;
|
|
1278
1309
|
const offStatus = chat.realtime.onStatus((status) => {
|
|
1279
|
-
if (status === "connected" && !wasConnected) refresh();
|
|
1310
|
+
if (status === "connected" && !wasConnected && connectedBefore) refresh();
|
|
1280
1311
|
wasConnected = status === "connected";
|
|
1312
|
+
connectedBefore ||= wasConnected;
|
|
1281
1313
|
});
|
|
1282
1314
|
return () => {
|
|
1283
1315
|
offStarted();
|