@poolse/react 3.4.0 → 3.5.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 +44 -0
- package/README.md +34 -21
- package/dist/index.cjs +153 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -8
- package/dist/index.d.ts +72 -8
- package/dist/index.js +141 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,50 @@ All notable changes to `@poolse/react` are documented here. Format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
5
|
[semver](https://semver.org).
|
|
6
6
|
|
|
7
|
+
## [3.5.0] - 2026-11-21
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `useUserPresence(id)` → `Presence | null` and `usePresenceMany(ids)` →
|
|
12
|
+
`Record<id, Presence>`: people's presence (`online` / `away` / `in_call` /
|
|
13
|
+
`offline`) by user id or external id, from the one `poolse.presence` store
|
|
14
|
+
per provider — hooks mounted together make a single lookup, and
|
|
15
|
+
`presence:changed` keeps them live.
|
|
16
|
+
- `<PoolseProvider trackActivity>`: reports the browser tab `active` / `idle`
|
|
17
|
+
for presence (`poolse.presence.trackActivity`). On by default; a no-op
|
|
18
|
+
without `document` (React Native: call `usePoolse().presence.setActivity()`
|
|
19
|
+
from `AppState`); `false` turns it off, or pass `{ idleAfterMs }`.
|
|
20
|
+
- `useConversationPresence(conversationId)`, the same hook as
|
|
21
|
+
`usePresence(conversationId)` under a name that says what it lists (who has
|
|
22
|
+
the conversation open).
|
|
23
|
+
- Re-exported `Presence`, `PresenceState`, `PresenceActivity`,
|
|
24
|
+
`PresenceChangedEvent`, `TrackActivityOptions`.
|
|
25
|
+
|
|
26
|
+
- Conversation list paging: `useConversations().loadMore()`, `hasMore` and
|
|
27
|
+
`loadingMore`. The first page loads as before; `loadMore()` appends the
|
|
28
|
+
next (deduped by id, one request at a time; a failure rejects and keeps the
|
|
29
|
+
cursor). A quiet reload (remount, reconnect) refreshes the first page and
|
|
30
|
+
keeps rows of later pages already loaded.
|
|
31
|
+
|
|
32
|
+
- Re-exported `LinkPreview`, `LinkPreviewType`, `ThreadParticipant`,
|
|
33
|
+
`ThreadUpdatedEvent`, `MessageEdit`, `MessageEditList`,
|
|
34
|
+
`MessageUpdateRequest`, `ApiErrorCode`, and the helpers `isTombstone`,
|
|
35
|
+
`mergeMessage`, `toTombstone`.
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- `useMessages` handles `thread:updated`: the root's `reply_count`,
|
|
40
|
+
`last_reply_at` and `thread_participants` follow the server.
|
|
41
|
+
- `message:updated` (an edit, or link previews arriving) is merged into the
|
|
42
|
+
row instead of replacing it, in `useMessages` and `useThread`, so fields a
|
|
43
|
+
payload leaves out survive; `edit()` merges the server's row the same way.
|
|
44
|
+
- A deleted message — from `message:deleted` or an optimistic `delete()` —
|
|
45
|
+
becomes the server's tombstone (no body, mentions, reactions, attachments,
|
|
46
|
+
link previews or quote; thread fields kept), and messages quoting it get
|
|
47
|
+
`quoted_message.deleted_at` / `body: null`. A deleted reply lowers its
|
|
48
|
+
root's `reply_count` using the event's `thread_root_id` (it never did for
|
|
49
|
+
replies before, as replies aren't in the main list).
|
|
50
|
+
|
|
7
51
|
## [3.4.0] - 2026-11-21
|
|
8
52
|
|
|
9
53
|
- No changes; released with the other `@poolse/*` packages at 3.4.0.
|
package/README.md
CHANGED
|
@@ -62,27 +62,29 @@ new `key` to switch user.
|
|
|
62
62
|
|
|
63
63
|
## Hooks
|
|
64
64
|
|
|
65
|
-
| Hook | Returns
|
|
66
|
-
| -------------------------------------------------------------------------------- |
|
|
67
|
-
| `usePoolse()` | The `Poolse` instance.
|
|
68
|
-
| `useMe()` | `{ me, loading, error }`
|
|
69
|
-
| `useConversation(id \| null)` | `{ conversation, loading, error, refetch }`
|
|
70
|
-
| `useConversations()` | `{ conversations, loading, error, refetch, create, unreadCounts, mentionUnreadCounts, markConversationRead }`
|
|
71
|
-
| `useMessages(conversationId)` | `{ messages, loading, error, hasMore, loadMore, loadUntil(messageId), send, edit, delete, markReadUpTo, refetch }`, oldest first
|
|
72
|
-
| `useThread(conversationId, rootId)` | `{ replies, loading, error, hasMore, loadMore, sendReply, edit, delete }`
|
|
73
|
-
| `useReactions(messageId, { conversationId, initialReactions?, currentUserId? })` | `{ reactions, addReaction, removeReaction }`
|
|
74
|
-
| `useTyping(conversationId)` | `{ typing: Set<externalId>, signalTyping }`
|
|
75
|
-
| `usePresence(conversationId)`
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
65
|
+
| Hook | Returns |
|
|
66
|
+
| -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
67
|
+
| `usePoolse()` | The `Poolse` instance. |
|
|
68
|
+
| `useMe()` | `{ me, loading, error }` |
|
|
69
|
+
| `useConversation(id \| null)` | `{ conversation, loading, error, refetch }` |
|
|
70
|
+
| `useConversations()` | `{ conversations, loading, error, refetch, hasMore, loadingMore, loadMore, create, unreadCounts, mentionUnreadCounts, markConversationRead }` |
|
|
71
|
+
| `useMessages(conversationId)` | `{ messages, loading, error, hasMore, loadMore, loadUntil(messageId), send, edit, delete, markReadUpTo, refetch }`, oldest first |
|
|
72
|
+
| `useThread(conversationId, rootId)` | `{ replies, loading, error, hasMore, loadMore, sendReply, edit, delete }` |
|
|
73
|
+
| `useReactions(messageId, { conversationId, initialReactions?, currentUserId? })` | `{ reactions, addReaction, removeReaction }` |
|
|
74
|
+
| `useTyping(conversationId)` | `{ typing: Set<externalId>, signalTyping }` |
|
|
75
|
+
| `usePresence(conversationId)` / `useConversationPresence` | `{ online: Set<externalId> }` — who has the conversation open |
|
|
76
|
+
| `useUserPresence(id \| null)` | `Presence \| null` — `state`: `online`, `away`, `in_call`, `offline` |
|
|
77
|
+
| `usePresenceMany(ids)` | `Record<id, Presence>` (known ids only) |
|
|
78
|
+
| `useMembers(conversationId)` | `{ members, loading, error, refetch, addMembers(externalIds, { role? }), removeMember(externalId) }` |
|
|
79
|
+
| `useAttachmentUpload()` | `{ queue, attachment, uploading, error, upload(input), uploadAll(inputs), cancel(localId), remove(localId), reset }` |
|
|
80
|
+
| `useAttachmentUrl(id \| null)` | `{ url, loading, error }` (not renewed; URLs last one hour) |
|
|
81
|
+
| `useUser(externalId)` | `{ profile, loading }` |
|
|
82
|
+
| `useAppEvent(handler)` | Calls `handler({ type, data })` for each `app:event` sent to the user |
|
|
83
|
+
| `useRealtimeStatus()` | `'idle' \| 'connecting' \| 'connected' \| 'reconnecting' \| 'closed'` |
|
|
84
|
+
| `useReadReceipts()` | `{ visible, mode, shared, canChange, setShared }` |
|
|
85
|
+
| `useLiveCall(conversationId \| null)` | `{ call, participantIds, refresh }` |
|
|
86
|
+
| `useRoom(conversationId \| null, { livekit })` | `{ live, presentIds, joined, joining, join, leave, media, error }` |
|
|
87
|
+
| `useCallRoom(conversationId \| null, { livekit, … })` | Call media: participants, mic, camera, devices |
|
|
86
88
|
|
|
87
89
|
Helpers: `canEditOwnMessage`, `EDIT_WINDOW_MS`, `receiptsOf`,
|
|
88
90
|
`computeGroupPosition`, `sameGroup`, `sameDay`, `formatDayLabel`, plus
|
|
@@ -108,6 +110,17 @@ Notes that trip people up:
|
|
|
108
110
|
screen until the new one lands.
|
|
109
111
|
- If the user is removed from a conversation, its mounted hooks stop
|
|
110
112
|
updating; hooks mounted later join a fresh channel.
|
|
113
|
+
- `useUserPresence` / `usePresenceMany` take user ids or external ids and
|
|
114
|
+
share one store per provider: hooks mounted together make one lookup, and
|
|
115
|
+
`presence:changed` keeps them live. `<PoolseProvider>` reports the browser
|
|
116
|
+
tab `active` / `idle` (`trackActivity`, on by default; a no-op in React
|
|
117
|
+
Native, where you call `usePoolse().presence.setActivity()` from `AppState`).
|
|
118
|
+
- `useConversations` loads the first page (50); call `loadMore()` while
|
|
119
|
+
`hasMore` for the rest.
|
|
120
|
+
- `useMessages` / `useThread` merge `message:updated` (edits, link previews
|
|
121
|
+
arriving in `link_previews`), keep deleted messages as tombstones
|
|
122
|
+
(`deleted_at` set, `body: null`) and apply `thread:updated` to the root's
|
|
123
|
+
`reply_count`, `last_reply_at` and `thread_participants`.
|
|
111
124
|
|
|
112
125
|
## Links
|
|
113
126
|
|
package/dist/index.cjs
CHANGED
|
@@ -13,11 +13,22 @@ var ConversationsStore = class {
|
|
|
13
13
|
this.chat = chat;
|
|
14
14
|
}
|
|
15
15
|
chat;
|
|
16
|
-
state = {
|
|
16
|
+
state = {
|
|
17
|
+
conversations: [],
|
|
18
|
+
loading: true,
|
|
19
|
+
error: null,
|
|
20
|
+
hasMore: false,
|
|
21
|
+
loadingMore: false
|
|
22
|
+
};
|
|
17
23
|
listeners = /* @__PURE__ */ new Set();
|
|
18
24
|
loaded = false;
|
|
19
25
|
inflight = null;
|
|
26
|
+
moreInflight = null;
|
|
20
27
|
unbind = null;
|
|
28
|
+
/** Cursor of the next page not yet loaded; null when there is none. */
|
|
29
|
+
nextCursor = null;
|
|
30
|
+
/** Whether rows beyond the first page are held. */
|
|
31
|
+
pagedBeyondFirst = false;
|
|
21
32
|
getSnapshot() {
|
|
22
33
|
return this.state;
|
|
23
34
|
}
|
|
@@ -33,6 +44,33 @@ var ConversationsStore = class {
|
|
|
33
44
|
refetch() {
|
|
34
45
|
return this.load(true);
|
|
35
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Append the next page. Resolves at once when there is none or one
|
|
49
|
+
* is already loading. Rows already held (moved up by realtime) are
|
|
50
|
+
* not duplicated.
|
|
51
|
+
*/
|
|
52
|
+
loadMore() {
|
|
53
|
+
if (this.moreInflight) return this.moreInflight;
|
|
54
|
+
const cursor = this.nextCursor;
|
|
55
|
+
if (!cursor) return Promise.resolve();
|
|
56
|
+
this.set({ ...this.state, loadingMore: true });
|
|
57
|
+
const run = this.chat.conversations.list({ cursor }).then((page) => {
|
|
58
|
+
if (this.nextCursor !== cursor) return;
|
|
59
|
+
this.nextCursor = page.next_cursor ?? null;
|
|
60
|
+
this.pagedBeyondFirst = true;
|
|
61
|
+
const have = new Set(this.state.conversations.map((c) => c.id));
|
|
62
|
+
this.set({
|
|
63
|
+
...this.state,
|
|
64
|
+
conversations: [...this.state.conversations, ...page.data.filter((c) => !have.has(c.id))],
|
|
65
|
+
hasMore: this.nextCursor !== null
|
|
66
|
+
});
|
|
67
|
+
}).finally(() => {
|
|
68
|
+
if (this.moreInflight === run) this.moreInflight = null;
|
|
69
|
+
this.set({ ...this.state, loadingMore: false });
|
|
70
|
+
});
|
|
71
|
+
this.moreInflight = run;
|
|
72
|
+
return run;
|
|
73
|
+
}
|
|
36
74
|
async create(attrs) {
|
|
37
75
|
const conv = await this.chat.conversations.create(attrs);
|
|
38
76
|
this.setConversations((prev) => prepend(prev, conv));
|
|
@@ -119,7 +157,23 @@ var ConversationsStore = class {
|
|
|
119
157
|
const run = this.chat.conversations.list().then(
|
|
120
158
|
(list) => {
|
|
121
159
|
this.loaded = true;
|
|
122
|
-
|
|
160
|
+
let conversations = list.data;
|
|
161
|
+
if (this.pagedBeyondFirst) {
|
|
162
|
+
const fresh = new Set(list.data.map((c) => c.id));
|
|
163
|
+
conversations = [
|
|
164
|
+
...list.data,
|
|
165
|
+
...this.state.conversations.filter((c) => !fresh.has(c.id))
|
|
166
|
+
];
|
|
167
|
+
} else {
|
|
168
|
+
this.nextCursor = list.next_cursor ?? null;
|
|
169
|
+
}
|
|
170
|
+
this.set({
|
|
171
|
+
...this.state,
|
|
172
|
+
conversations,
|
|
173
|
+
loading: false,
|
|
174
|
+
error: null,
|
|
175
|
+
hasMore: this.nextCursor !== null
|
|
176
|
+
});
|
|
123
177
|
},
|
|
124
178
|
(err) => {
|
|
125
179
|
this.set({
|
|
@@ -179,7 +233,7 @@ function mergeUpdated(prev, next, fromMe) {
|
|
|
179
233
|
return [merged, ...rest];
|
|
180
234
|
}
|
|
181
235
|
var PoolseContext = react.createContext(null);
|
|
182
|
-
function PoolseProvider({ config, children }) {
|
|
236
|
+
function PoolseProvider({ config, trackActivity = true, children }) {
|
|
183
237
|
const configRef = react.useRef(config);
|
|
184
238
|
configRef.current = config;
|
|
185
239
|
const initialConnectionRef = react.useRef(null);
|
|
@@ -227,6 +281,12 @@ function PoolseProvider({ config, children }) {
|
|
|
227
281
|
chat.destroy();
|
|
228
282
|
};
|
|
229
283
|
}, [chat]);
|
|
284
|
+
const trackActivityRef = react.useRef(trackActivity);
|
|
285
|
+
react.useEffect(() => {
|
|
286
|
+
const opts = trackActivityRef.current;
|
|
287
|
+
if (opts === false) return;
|
|
288
|
+
return chat.presence.trackActivity(opts === true ? {} : opts);
|
|
289
|
+
}, [chat]);
|
|
230
290
|
const value = react.useMemo(() => ({ chat, conversations: new ConversationsStore(chat) }), [chat]);
|
|
231
291
|
return /* @__PURE__ */ jsxRuntime.jsx(PoolseContext.Provider, { value, children });
|
|
232
292
|
}
|
|
@@ -322,12 +382,13 @@ function useConversations() {
|
|
|
322
382
|
return off;
|
|
323
383
|
}, [store]);
|
|
324
384
|
const refetch = react.useCallback(() => store.refetch(), [store]);
|
|
385
|
+
const loadMore = react.useCallback(() => store.loadMore(), [store]);
|
|
325
386
|
const create = react.useCallback((attrs) => store.create(attrs), [store]);
|
|
326
387
|
const markConversationRead = react.useCallback(
|
|
327
388
|
(conversationId) => store.markRead(conversationId),
|
|
328
389
|
[store]
|
|
329
390
|
);
|
|
330
|
-
const { conversations, loading, error } = snapshot;
|
|
391
|
+
const { conversations, loading, error, hasMore, loadingMore } = snapshot;
|
|
331
392
|
const unreadCounts = react.useMemo(() => countsOf(conversations, "unread_count"), [conversations]);
|
|
332
393
|
const mentionUnreadCounts = react.useMemo(
|
|
333
394
|
() => countsOf(conversations, "mention_unread_count"),
|
|
@@ -338,6 +399,9 @@ function useConversations() {
|
|
|
338
399
|
loading,
|
|
339
400
|
error,
|
|
340
401
|
refetch,
|
|
402
|
+
hasMore,
|
|
403
|
+
loadingMore,
|
|
404
|
+
loadMore,
|
|
341
405
|
create,
|
|
342
406
|
unreadCounts,
|
|
343
407
|
mentionUnreadCounts,
|
|
@@ -506,22 +570,23 @@ function useMessages(conversationId) {
|
|
|
506
570
|
setMessages((prev) => upsertById(prev, msg));
|
|
507
571
|
});
|
|
508
572
|
const offUpdated = conv.onMessageUpdated((msg) => {
|
|
509
|
-
setMessages((prev) => prev.
|
|
573
|
+
setMessages((prev) => patchById(prev, msg.id, (m) => sdk.mergeMessage(m, msg)));
|
|
510
574
|
});
|
|
511
575
|
const offDeleted = conv.onMessageDeleted((evt) => {
|
|
512
576
|
setMessages((prev) => {
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
(m
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
return updated;
|
|
577
|
+
const rootId = evt.thread_root_id ?? prev.find((m) => m.id === evt.id)?.thread_root_id;
|
|
578
|
+
return prev.map((m) => {
|
|
579
|
+
if (m.id === evt.id) return sdk.toTombstone(m, evt.deleted_at);
|
|
580
|
+
if (rootId && m.id === rootId) {
|
|
581
|
+
m = { ...m, reply_count: Math.max(0, (m.reply_count ?? 0) - 1) };
|
|
582
|
+
}
|
|
583
|
+
return sdk.markQuoteDeleted(m, evt.id, evt.deleted_at);
|
|
584
|
+
});
|
|
523
585
|
});
|
|
524
586
|
});
|
|
587
|
+
const offThread = conv.onThreadUpdated((evt) => {
|
|
588
|
+
setMessages((prev) => patchById(prev, evt.message_id, (m) => sdk.applyThreadUpdate(m, evt)));
|
|
589
|
+
});
|
|
525
590
|
let wasConnected = chat.realtime.getStatus() === "connected";
|
|
526
591
|
let connectedBefore = wasConnected;
|
|
527
592
|
const offStatus = chat.realtime.onStatus((status) => {
|
|
@@ -539,6 +604,7 @@ function useMessages(conversationId) {
|
|
|
539
604
|
offNew();
|
|
540
605
|
offUpdated();
|
|
541
606
|
offDeleted();
|
|
607
|
+
offThread();
|
|
542
608
|
offStatus();
|
|
543
609
|
};
|
|
544
610
|
}, [chat, conversationId]);
|
|
@@ -639,7 +705,7 @@ function useMessages(conversationId) {
|
|
|
639
705
|
);
|
|
640
706
|
try {
|
|
641
707
|
const updated = await chat.messages.one(messageId).update({ body });
|
|
642
|
-
setMessages((prev) => prev
|
|
708
|
+
setMessages((prev) => patchById(prev, messageId, (m) => sdk.mergeMessage(m, updated)));
|
|
643
709
|
return updated;
|
|
644
710
|
} catch (err) {
|
|
645
711
|
if (previous) {
|
|
@@ -658,7 +724,7 @@ function useMessages(conversationId) {
|
|
|
658
724
|
(prev) => prev.map((m) => {
|
|
659
725
|
if (m.id !== messageId) return m;
|
|
660
726
|
previous = m;
|
|
661
|
-
return
|
|
727
|
+
return sdk.toTombstone(m, (/* @__PURE__ */ new Date()).toISOString());
|
|
662
728
|
})
|
|
663
729
|
);
|
|
664
730
|
try {
|
|
@@ -699,6 +765,13 @@ function useMessages(conversationId) {
|
|
|
699
765
|
refetch
|
|
700
766
|
};
|
|
701
767
|
}
|
|
768
|
+
function patchById(prev, id, fn) {
|
|
769
|
+
const idx = prev.findIndex((m) => m.id === id);
|
|
770
|
+
if (idx === -1) return prev;
|
|
771
|
+
const next = prev.slice();
|
|
772
|
+
next[idx] = fn(prev[idx]);
|
|
773
|
+
return next;
|
|
774
|
+
}
|
|
702
775
|
function upsertById(prev, msg) {
|
|
703
776
|
const idx = prev.findIndex((m) => m.id === msg.id);
|
|
704
777
|
if (idx === -1) return [...prev, msg];
|
|
@@ -810,11 +883,13 @@ function useThread(conversationId, rootMessageId) {
|
|
|
810
883
|
});
|
|
811
884
|
const offUpdated = conv.onMessageUpdated((msg) => {
|
|
812
885
|
if (msg.thread_root_id !== rootMessageId) return;
|
|
813
|
-
setReplies((prev) => prev.map((m) => m.id === msg.id ? msg : m));
|
|
886
|
+
setReplies((prev) => prev.map((m) => m.id === msg.id ? sdk.mergeMessage(m, msg) : m));
|
|
814
887
|
});
|
|
815
888
|
const offDeleted = conv.onMessageDeleted((evt) => {
|
|
816
889
|
setReplies(
|
|
817
|
-
(prev) => prev.map(
|
|
890
|
+
(prev) => prev.map(
|
|
891
|
+
(m) => m.id === evt.id ? sdk.toTombstone(m, evt.deleted_at) : sdk.markQuoteDeleted(m, evt.id, evt.deleted_at)
|
|
892
|
+
)
|
|
818
893
|
);
|
|
819
894
|
});
|
|
820
895
|
return () => {
|
|
@@ -886,7 +961,7 @@ function useThread(conversationId, rootMessageId) {
|
|
|
886
961
|
);
|
|
887
962
|
try {
|
|
888
963
|
const updated = await chat.messages.one(messageId).update({ body });
|
|
889
|
-
setReplies((prev) => prev.map((m) => m.id === messageId ? updated : m));
|
|
964
|
+
setReplies((prev) => prev.map((m) => m.id === messageId ? sdk.mergeMessage(m, updated) : m));
|
|
890
965
|
return updated;
|
|
891
966
|
} catch (err) {
|
|
892
967
|
if (previous) {
|
|
@@ -905,7 +980,7 @@ function useThread(conversationId, rootMessageId) {
|
|
|
905
980
|
(prev) => prev.map((m) => {
|
|
906
981
|
if (m.id !== messageId) return m;
|
|
907
982
|
previous = m;
|
|
908
|
-
return
|
|
983
|
+
return sdk.toTombstone(m, (/* @__PURE__ */ new Date()).toISOString());
|
|
909
984
|
})
|
|
910
985
|
);
|
|
911
986
|
try {
|
|
@@ -1103,6 +1178,48 @@ function usePresence(conversationId) {
|
|
|
1103
1178
|
}, [chat, conversationId]);
|
|
1104
1179
|
return { online };
|
|
1105
1180
|
}
|
|
1181
|
+
var useConversationPresence = usePresence;
|
|
1182
|
+
function useUserPresence(id) {
|
|
1183
|
+
const chat = usePoolse();
|
|
1184
|
+
const [presence, setPresence] = react.useState(
|
|
1185
|
+
() => id ? chat.presence.peek(id) ?? null : null
|
|
1186
|
+
);
|
|
1187
|
+
react.useEffect(() => {
|
|
1188
|
+
if (!id) {
|
|
1189
|
+
setPresence(null);
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
setPresence(chat.presence.peek(id) ?? null);
|
|
1193
|
+
return chat.presence.subscribe(id, () => setPresence(chat.presence.peek(id) ?? null));
|
|
1194
|
+
}, [chat, id]);
|
|
1195
|
+
return presence;
|
|
1196
|
+
}
|
|
1197
|
+
function usePresenceMany(ids) {
|
|
1198
|
+
const chat = usePoolse();
|
|
1199
|
+
const key = react.useMemo(
|
|
1200
|
+
() => JSON.stringify([...new Set(ids.filter((id) => !!id))].sort()),
|
|
1201
|
+
[ids]
|
|
1202
|
+
);
|
|
1203
|
+
const [presences, setPresences] = react.useState(
|
|
1204
|
+
() => collect(chat.presence.peek.bind(chat.presence), JSON.parse(key))
|
|
1205
|
+
);
|
|
1206
|
+
react.useEffect(() => {
|
|
1207
|
+
const list = JSON.parse(key);
|
|
1208
|
+
const read = () => setPresences(collect(chat.presence.peek.bind(chat.presence), list));
|
|
1209
|
+
read();
|
|
1210
|
+
if (list.length === 0) return;
|
|
1211
|
+
return chat.presence.subscribe(list, read);
|
|
1212
|
+
}, [chat, key]);
|
|
1213
|
+
return presences;
|
|
1214
|
+
}
|
|
1215
|
+
function collect(peek, ids) {
|
|
1216
|
+
const out = {};
|
|
1217
|
+
for (const id of ids) {
|
|
1218
|
+
const p = peek(id);
|
|
1219
|
+
if (p) out[id] = p;
|
|
1220
|
+
}
|
|
1221
|
+
return out;
|
|
1222
|
+
}
|
|
1106
1223
|
function useRealtimeStatus() {
|
|
1107
1224
|
const chat = usePoolse();
|
|
1108
1225
|
const [status, setStatus] = react.useState(chat.realtime.getStatus());
|
|
@@ -1691,6 +1808,14 @@ Object.defineProperty(exports, "isMessageVisibleTo", {
|
|
|
1691
1808
|
enumerable: true,
|
|
1692
1809
|
get: function () { return sdk.isMessageVisibleTo; }
|
|
1693
1810
|
});
|
|
1811
|
+
Object.defineProperty(exports, "isTombstone", {
|
|
1812
|
+
enumerable: true,
|
|
1813
|
+
get: function () { return sdk.isTombstone; }
|
|
1814
|
+
});
|
|
1815
|
+
Object.defineProperty(exports, "mergeMessage", {
|
|
1816
|
+
enumerable: true,
|
|
1817
|
+
get: function () { return sdk.mergeMessage; }
|
|
1818
|
+
});
|
|
1694
1819
|
Object.defineProperty(exports, "parseCallLog", {
|
|
1695
1820
|
enumerable: true,
|
|
1696
1821
|
get: function () { return sdk.parseCallLog; }
|
|
@@ -1699,6 +1824,10 @@ Object.defineProperty(exports, "parseCallLogBody", {
|
|
|
1699
1824
|
enumerable: true,
|
|
1700
1825
|
get: function () { return sdk.parseCallLogBody; }
|
|
1701
1826
|
});
|
|
1827
|
+
Object.defineProperty(exports, "toTombstone", {
|
|
1828
|
+
enumerable: true,
|
|
1829
|
+
get: function () { return sdk.toTombstone; }
|
|
1830
|
+
});
|
|
1702
1831
|
exports.EDIT_WINDOW_MS = EDIT_WINDOW_MS;
|
|
1703
1832
|
exports.PoolseProvider = PoolseProvider;
|
|
1704
1833
|
exports.canEditOwnMessage = canEditOwnMessage;
|
|
@@ -1712,6 +1841,7 @@ exports.useAttachmentUpload = useAttachmentUpload;
|
|
|
1712
1841
|
exports.useAttachmentUrl = useAttachmentUrl;
|
|
1713
1842
|
exports.useCallRoom = useCallRoom;
|
|
1714
1843
|
exports.useConversation = useConversation;
|
|
1844
|
+
exports.useConversationPresence = useConversationPresence;
|
|
1715
1845
|
exports.useConversations = useConversations;
|
|
1716
1846
|
exports.useLiveCall = useLiveCall;
|
|
1717
1847
|
exports.useMe = useMe;
|
|
@@ -1720,6 +1850,7 @@ exports.useMessageStreams = useMessageStreams;
|
|
|
1720
1850
|
exports.useMessages = useMessages;
|
|
1721
1851
|
exports.usePoolse = usePoolse;
|
|
1722
1852
|
exports.usePresence = usePresence;
|
|
1853
|
+
exports.usePresenceMany = usePresenceMany;
|
|
1723
1854
|
exports.useReactions = useReactions;
|
|
1724
1855
|
exports.useReadReceipts = useReadReceipts;
|
|
1725
1856
|
exports.useRealtimeStatus = useRealtimeStatus;
|
|
@@ -1727,5 +1858,6 @@ exports.useRoom = useRoom;
|
|
|
1727
1858
|
exports.useThread = useThread;
|
|
1728
1859
|
exports.useTyping = useTyping;
|
|
1729
1860
|
exports.useUser = useUser;
|
|
1861
|
+
exports.useUserPresence = useUserPresence;
|
|
1730
1862
|
//# sourceMappingURL=index.cjs.map
|
|
1731
1863
|
//# sourceMappingURL=index.cjs.map
|