@poolse/react 3.3.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 +48 -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/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { PoolseConfig, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
|
|
3
|
-
export { ApiError, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, NotificationPreferences, NotifyLevel, OwnMembership, OwnMembershipUpdateRequest, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
|
|
2
|
+
import { PoolseConfig, TrackActivityOptions, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, Presence, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
|
|
3
|
+
export { ApiError, ApiErrorCode, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DeviceKind, LinkPreview, LinkPreviewType, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageEdit, MessageEditList, MessageType, MessageUpdateRequest, NetworkError, NotificationPreferences, NotifyLevel, OwnMembership, OwnMembershipUpdateRequest, PoolseConfig, PoolseError, PoolseUserProfile, Presence, PresenceActivity, PresenceChangedEvent, PresenceState, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, ThreadParticipant, ThreadUpdatedEvent, TrackActivityOptions, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
interface PoolseProviderProps {
|
|
@@ -17,6 +17,16 @@ interface PoolseProviderProps {
|
|
|
17
17
|
* time); dev mode logs a warning when this happens.
|
|
18
18
|
*/
|
|
19
19
|
config: PoolseConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Report this device `active` / `idle` for presence from the browser
|
|
22
|
+
* (`poolse.presence.trackActivity`): idle while the page is hidden,
|
|
23
|
+
* the window is blurred, or after 5 minutes without input. On by
|
|
24
|
+
* default; does nothing without a `document` (React Native — call
|
|
25
|
+
* `usePoolse().presence.setActivity()` from `AppState` there). Pass
|
|
26
|
+
* `false` to report yourself, or options (`{ idleAfterMs }`). Read at
|
|
27
|
+
* mount.
|
|
28
|
+
*/
|
|
29
|
+
trackActivity?: boolean | Omit<TrackActivityOptions, 'document' | 'window'>;
|
|
20
30
|
children: ReactNode;
|
|
21
31
|
}
|
|
22
32
|
/**
|
|
@@ -32,7 +42,7 @@ interface PoolseProviderProps {
|
|
|
32
42
|
* The `Poolse` instance is destroyed on unmount — closes the WebSocket
|
|
33
43
|
* and drops every joined channel.
|
|
34
44
|
*/
|
|
35
|
-
declare function PoolseProvider({ config, children }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
|
|
45
|
+
declare function PoolseProvider({ config, trackActivity, children }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
|
|
36
46
|
/**
|
|
37
47
|
* Access the underlying `Poolse` instance. Most app code should prefer
|
|
38
48
|
* higher-level hooks (`useMessages`, `useTyping`, etc.) but the raw
|
|
@@ -87,6 +97,18 @@ interface UseConversationsState {
|
|
|
87
97
|
loading: boolean;
|
|
88
98
|
error: Error | null;
|
|
89
99
|
refetch: () => Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* The server has more conversations than are loaded (the list is
|
|
102
|
+
* paged, 50 a page). False on servers that don't page.
|
|
103
|
+
*/
|
|
104
|
+
hasMore: boolean;
|
|
105
|
+
/** A `loadMore()` is in flight. */
|
|
106
|
+
loadingMore: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Append the next page — e.g. when the list is scrolled to the end.
|
|
109
|
+
* A no-op without `hasMore`, and while a page is loading.
|
|
110
|
+
*/
|
|
111
|
+
loadMore: () => Promise<void>;
|
|
90
112
|
create: (attrs: ConversationCreateRequest) => Promise<Conversation>;
|
|
91
113
|
/**
|
|
92
114
|
* Per-conversation unread count, keyed by conversation id (only
|
|
@@ -122,6 +144,11 @@ interface UseConversationsState {
|
|
|
122
144
|
* optimistic `create()` followed by the realtime echo doesn't insert
|
|
123
145
|
* twice.
|
|
124
146
|
*
|
|
147
|
+
* The list is paged: the first page (50, most recently active first)
|
|
148
|
+
* loads on its own; `loadMore()` appends the next while `hasMore`.
|
|
149
|
+
* Unread badges (`unreadCounts`) cover the loaded rows plus any that
|
|
150
|
+
* realtime brings in.
|
|
151
|
+
*
|
|
125
152
|
* `refetch()` is still here for explicit re-syncs (e.g. after a
|
|
126
153
|
* mutation that the SDK doesn't yet observe — name changes,
|
|
127
154
|
* settings updates). `create()` returns the canonical server row.
|
|
@@ -215,7 +242,12 @@ interface UseMessagesState {
|
|
|
215
242
|
*
|
|
216
243
|
* * Initial REST fetch (newest 50) on mount.
|
|
217
244
|
* * WebSocket subscription for `message:new`, `message:updated`,
|
|
218
|
-
* `message:deleted` — applied in-place to the
|
|
245
|
+
* `message:deleted` and `thread:updated` — applied in-place to the
|
|
246
|
+
* cached array: an update (an edit, or link previews arriving) is
|
|
247
|
+
* merged into the row, a delete leaves the server's tombstone
|
|
248
|
+
* (and marks quotes of it deleted), and a thread summary
|
|
249
|
+
* (`reply_count`, `last_reply_at`, `thread_participants`) lands on
|
|
250
|
+
* its root.
|
|
219
251
|
* * Optimistic-send via `send()` — the message appears immediately
|
|
220
252
|
* under the SAME id the server will assign (we pre-generate it
|
|
221
253
|
* client-side and pass it through), so the realtime echo and the
|
|
@@ -377,11 +409,43 @@ interface UsePresenceState {
|
|
|
377
409
|
online: Set<string>;
|
|
378
410
|
}
|
|
379
411
|
/**
|
|
380
|
-
* Who's currently joined to `conversationId`'s channel
|
|
381
|
-
* Phoenix.Presence broadcasts
|
|
382
|
-
* `presence_diff` on changes).
|
|
412
|
+
* Who's currently joined to `conversationId`'s channel — who has the
|
|
413
|
+
* conversation open. Backed by Phoenix.Presence broadcasts
|
|
414
|
+
* (`presence_state` snapshot on join, `presence_diff` on changes).
|
|
415
|
+
* Also exported as `useConversationPresence`.
|
|
416
|
+
*
|
|
417
|
+
* For whether a person is online, away, in a call or offline anywhere,
|
|
418
|
+
* use `useUserPresence(id)` / `usePresenceMany(ids)`.
|
|
383
419
|
*/
|
|
384
420
|
declare function usePresence(conversationId: string): UsePresenceState;
|
|
421
|
+
/** Who has `conversationId` open right now — the same hook as `usePresence`. */
|
|
422
|
+
declare const useConversationPresence: typeof usePresence;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* One user's presence, by internal user id or `external_id`. Null until
|
|
426
|
+
* it is known (and for ids the server doesn't know); pass null / '' to
|
|
427
|
+
* opt out.
|
|
428
|
+
*
|
|
429
|
+
* ```tsx
|
|
430
|
+
* const presence = useUserPresence(member.external_id);
|
|
431
|
+
* <Avatar badge={presence?.state === 'online' ? 'green' : undefined} />
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* `presence.do_not_disturb` / `dnd_until` come from the lookup and
|
|
435
|
+
* aren't evented: they can be stale until the next lookup (a reconnect).
|
|
436
|
+
*/
|
|
437
|
+
declare function useUserPresence(id: string | null | undefined): Presence | null;
|
|
438
|
+
/**
|
|
439
|
+
* Several users' presence at once, keyed by the ids passed (internal
|
|
440
|
+
* user ids or `external_id`s). Ids not yet known are absent from the
|
|
441
|
+
* record. The array may be a fresh literal on every render.
|
|
442
|
+
*
|
|
443
|
+
* ```tsx
|
|
444
|
+
* const presences = usePresenceMany(members.map((m) => m.external_id));
|
|
445
|
+
* const online = members.filter((m) => presences[m.external_id]?.state === 'online');
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function usePresenceMany(ids: readonly (string | null | undefined)[]): Record<string, Presence>;
|
|
385
449
|
|
|
386
450
|
/**
|
|
387
451
|
* Connection status of the underlying WebSocket. Useful for showing a
|
|
@@ -766,4 +830,4 @@ declare function canEditOwnMessage(args: {
|
|
|
766
830
|
now?: number;
|
|
767
831
|
}): boolean;
|
|
768
832
|
|
|
769
|
-
export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
|
|
833
|
+
export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useUserPresence };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { PoolseConfig, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
|
|
3
|
-
export { ApiError, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, NotificationPreferences, NotifyLevel, OwnMembership, OwnMembershipUpdateRequest, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
|
|
2
|
+
import { PoolseConfig, TrackActivityOptions, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, Presence, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, AppEvent, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, LiveCall } from '@poolse/sdk';
|
|
3
|
+
export { ApiError, ApiErrorCode, AppEvent, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, ConversationReadEvent, DeviceKind, LinkPreview, LinkPreviewType, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageEdit, MessageEditList, MessageType, MessageUpdateRequest, NetworkError, NotificationPreferences, NotifyLevel, OwnMembership, OwnMembershipUpdateRequest, PoolseConfig, PoolseError, PoolseUserProfile, Presence, PresenceActivity, PresenceChangedEvent, PresenceState, RateLimitedError, ReadReceiptsState, RealtimeStatus, RoomSession, ThreadParticipant, ThreadUpdatedEvent, TrackActivityOptions, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
interface PoolseProviderProps {
|
|
@@ -17,6 +17,16 @@ interface PoolseProviderProps {
|
|
|
17
17
|
* time); dev mode logs a warning when this happens.
|
|
18
18
|
*/
|
|
19
19
|
config: PoolseConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Report this device `active` / `idle` for presence from the browser
|
|
22
|
+
* (`poolse.presence.trackActivity`): idle while the page is hidden,
|
|
23
|
+
* the window is blurred, or after 5 minutes without input. On by
|
|
24
|
+
* default; does nothing without a `document` (React Native — call
|
|
25
|
+
* `usePoolse().presence.setActivity()` from `AppState` there). Pass
|
|
26
|
+
* `false` to report yourself, or options (`{ idleAfterMs }`). Read at
|
|
27
|
+
* mount.
|
|
28
|
+
*/
|
|
29
|
+
trackActivity?: boolean | Omit<TrackActivityOptions, 'document' | 'window'>;
|
|
20
30
|
children: ReactNode;
|
|
21
31
|
}
|
|
22
32
|
/**
|
|
@@ -32,7 +42,7 @@ interface PoolseProviderProps {
|
|
|
32
42
|
* The `Poolse` instance is destroyed on unmount — closes the WebSocket
|
|
33
43
|
* and drops every joined channel.
|
|
34
44
|
*/
|
|
35
|
-
declare function PoolseProvider({ config, children }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
|
|
45
|
+
declare function PoolseProvider({ config, trackActivity, children }: PoolseProviderProps): react_jsx_runtime.JSX.Element;
|
|
36
46
|
/**
|
|
37
47
|
* Access the underlying `Poolse` instance. Most app code should prefer
|
|
38
48
|
* higher-level hooks (`useMessages`, `useTyping`, etc.) but the raw
|
|
@@ -87,6 +97,18 @@ interface UseConversationsState {
|
|
|
87
97
|
loading: boolean;
|
|
88
98
|
error: Error | null;
|
|
89
99
|
refetch: () => Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* The server has more conversations than are loaded (the list is
|
|
102
|
+
* paged, 50 a page). False on servers that don't page.
|
|
103
|
+
*/
|
|
104
|
+
hasMore: boolean;
|
|
105
|
+
/** A `loadMore()` is in flight. */
|
|
106
|
+
loadingMore: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Append the next page — e.g. when the list is scrolled to the end.
|
|
109
|
+
* A no-op without `hasMore`, and while a page is loading.
|
|
110
|
+
*/
|
|
111
|
+
loadMore: () => Promise<void>;
|
|
90
112
|
create: (attrs: ConversationCreateRequest) => Promise<Conversation>;
|
|
91
113
|
/**
|
|
92
114
|
* Per-conversation unread count, keyed by conversation id (only
|
|
@@ -122,6 +144,11 @@ interface UseConversationsState {
|
|
|
122
144
|
* optimistic `create()` followed by the realtime echo doesn't insert
|
|
123
145
|
* twice.
|
|
124
146
|
*
|
|
147
|
+
* The list is paged: the first page (50, most recently active first)
|
|
148
|
+
* loads on its own; `loadMore()` appends the next while `hasMore`.
|
|
149
|
+
* Unread badges (`unreadCounts`) cover the loaded rows plus any that
|
|
150
|
+
* realtime brings in.
|
|
151
|
+
*
|
|
125
152
|
* `refetch()` is still here for explicit re-syncs (e.g. after a
|
|
126
153
|
* mutation that the SDK doesn't yet observe — name changes,
|
|
127
154
|
* settings updates). `create()` returns the canonical server row.
|
|
@@ -215,7 +242,12 @@ interface UseMessagesState {
|
|
|
215
242
|
*
|
|
216
243
|
* * Initial REST fetch (newest 50) on mount.
|
|
217
244
|
* * WebSocket subscription for `message:new`, `message:updated`,
|
|
218
|
-
* `message:deleted` — applied in-place to the
|
|
245
|
+
* `message:deleted` and `thread:updated` — applied in-place to the
|
|
246
|
+
* cached array: an update (an edit, or link previews arriving) is
|
|
247
|
+
* merged into the row, a delete leaves the server's tombstone
|
|
248
|
+
* (and marks quotes of it deleted), and a thread summary
|
|
249
|
+
* (`reply_count`, `last_reply_at`, `thread_participants`) lands on
|
|
250
|
+
* its root.
|
|
219
251
|
* * Optimistic-send via `send()` — the message appears immediately
|
|
220
252
|
* under the SAME id the server will assign (we pre-generate it
|
|
221
253
|
* client-side and pass it through), so the realtime echo and the
|
|
@@ -377,11 +409,43 @@ interface UsePresenceState {
|
|
|
377
409
|
online: Set<string>;
|
|
378
410
|
}
|
|
379
411
|
/**
|
|
380
|
-
* Who's currently joined to `conversationId`'s channel
|
|
381
|
-
* Phoenix.Presence broadcasts
|
|
382
|
-
* `presence_diff` on changes).
|
|
412
|
+
* Who's currently joined to `conversationId`'s channel — who has the
|
|
413
|
+
* conversation open. Backed by Phoenix.Presence broadcasts
|
|
414
|
+
* (`presence_state` snapshot on join, `presence_diff` on changes).
|
|
415
|
+
* Also exported as `useConversationPresence`.
|
|
416
|
+
*
|
|
417
|
+
* For whether a person is online, away, in a call or offline anywhere,
|
|
418
|
+
* use `useUserPresence(id)` / `usePresenceMany(ids)`.
|
|
383
419
|
*/
|
|
384
420
|
declare function usePresence(conversationId: string): UsePresenceState;
|
|
421
|
+
/** Who has `conversationId` open right now — the same hook as `usePresence`. */
|
|
422
|
+
declare const useConversationPresence: typeof usePresence;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* One user's presence, by internal user id or `external_id`. Null until
|
|
426
|
+
* it is known (and for ids the server doesn't know); pass null / '' to
|
|
427
|
+
* opt out.
|
|
428
|
+
*
|
|
429
|
+
* ```tsx
|
|
430
|
+
* const presence = useUserPresence(member.external_id);
|
|
431
|
+
* <Avatar badge={presence?.state === 'online' ? 'green' : undefined} />
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* `presence.do_not_disturb` / `dnd_until` come from the lookup and
|
|
435
|
+
* aren't evented: they can be stale until the next lookup (a reconnect).
|
|
436
|
+
*/
|
|
437
|
+
declare function useUserPresence(id: string | null | undefined): Presence | null;
|
|
438
|
+
/**
|
|
439
|
+
* Several users' presence at once, keyed by the ids passed (internal
|
|
440
|
+
* user ids or `external_id`s). Ids not yet known are absent from the
|
|
441
|
+
* record. The array may be a fresh literal on every render.
|
|
442
|
+
*
|
|
443
|
+
* ```tsx
|
|
444
|
+
* const presences = usePresenceMany(members.map((m) => m.external_id));
|
|
445
|
+
* const online = members.filter((m) => presences[m.external_id]?.state === 'online');
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function usePresenceMany(ids: readonly (string | null | undefined)[]): Record<string, Presence>;
|
|
385
449
|
|
|
386
450
|
/**
|
|
387
451
|
* Connection status of the underlying WebSocket. Useful for showing a
|
|
@@ -766,4 +830,4 @@ declare function canEditOwnMessage(args: {
|
|
|
766
830
|
now?: number;
|
|
767
831
|
}): boolean;
|
|
768
832
|
|
|
769
|
-
export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
|
|
833
|
+
export { EDIT_WINDOW_MS, type GroupPosition, type MessageStream, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseLiveCall, type UseReadReceipts, type UseRoom, type UseRoomOptions, type UseUserState, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useUserPresence };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { Poolse, safeUuid, isCallLogMessage } from '@poolse/sdk';
|
|
3
|
-
export { ApiError, AuthError, NetworkError, PoolseError, RateLimitedError, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
|
|
2
|
+
import { Poolse, toTombstone, markQuoteDeleted, safeUuid, mergeMessage, isCallLogMessage, applyThreadUpdate } from '@poolse/sdk';
|
|
3
|
+
export { ApiError, AuthError, NetworkError, PoolseError, RateLimitedError, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, isTombstone, mergeMessage, parseCallLog, parseCallLogBody, toTombstone } from '@poolse/sdk';
|
|
4
4
|
import { createContext, useRef, useMemo, useEffect, useContext, useState, useCallback } from 'react';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
6
|
|
|
@@ -12,11 +12,22 @@ var ConversationsStore = class {
|
|
|
12
12
|
this.chat = chat;
|
|
13
13
|
}
|
|
14
14
|
chat;
|
|
15
|
-
state = {
|
|
15
|
+
state = {
|
|
16
|
+
conversations: [],
|
|
17
|
+
loading: true,
|
|
18
|
+
error: null,
|
|
19
|
+
hasMore: false,
|
|
20
|
+
loadingMore: false
|
|
21
|
+
};
|
|
16
22
|
listeners = /* @__PURE__ */ new Set();
|
|
17
23
|
loaded = false;
|
|
18
24
|
inflight = null;
|
|
25
|
+
moreInflight = null;
|
|
19
26
|
unbind = null;
|
|
27
|
+
/** Cursor of the next page not yet loaded; null when there is none. */
|
|
28
|
+
nextCursor = null;
|
|
29
|
+
/** Whether rows beyond the first page are held. */
|
|
30
|
+
pagedBeyondFirst = false;
|
|
20
31
|
getSnapshot() {
|
|
21
32
|
return this.state;
|
|
22
33
|
}
|
|
@@ -32,6 +43,33 @@ var ConversationsStore = class {
|
|
|
32
43
|
refetch() {
|
|
33
44
|
return this.load(true);
|
|
34
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Append the next page. Resolves at once when there is none or one
|
|
48
|
+
* is already loading. Rows already held (moved up by realtime) are
|
|
49
|
+
* not duplicated.
|
|
50
|
+
*/
|
|
51
|
+
loadMore() {
|
|
52
|
+
if (this.moreInflight) return this.moreInflight;
|
|
53
|
+
const cursor = this.nextCursor;
|
|
54
|
+
if (!cursor) return Promise.resolve();
|
|
55
|
+
this.set({ ...this.state, loadingMore: true });
|
|
56
|
+
const run = this.chat.conversations.list({ cursor }).then((page) => {
|
|
57
|
+
if (this.nextCursor !== cursor) return;
|
|
58
|
+
this.nextCursor = page.next_cursor ?? null;
|
|
59
|
+
this.pagedBeyondFirst = true;
|
|
60
|
+
const have = new Set(this.state.conversations.map((c) => c.id));
|
|
61
|
+
this.set({
|
|
62
|
+
...this.state,
|
|
63
|
+
conversations: [...this.state.conversations, ...page.data.filter((c) => !have.has(c.id))],
|
|
64
|
+
hasMore: this.nextCursor !== null
|
|
65
|
+
});
|
|
66
|
+
}).finally(() => {
|
|
67
|
+
if (this.moreInflight === run) this.moreInflight = null;
|
|
68
|
+
this.set({ ...this.state, loadingMore: false });
|
|
69
|
+
});
|
|
70
|
+
this.moreInflight = run;
|
|
71
|
+
return run;
|
|
72
|
+
}
|
|
35
73
|
async create(attrs) {
|
|
36
74
|
const conv = await this.chat.conversations.create(attrs);
|
|
37
75
|
this.setConversations((prev) => prepend(prev, conv));
|
|
@@ -118,7 +156,23 @@ var ConversationsStore = class {
|
|
|
118
156
|
const run = this.chat.conversations.list().then(
|
|
119
157
|
(list) => {
|
|
120
158
|
this.loaded = true;
|
|
121
|
-
|
|
159
|
+
let conversations = list.data;
|
|
160
|
+
if (this.pagedBeyondFirst) {
|
|
161
|
+
const fresh = new Set(list.data.map((c) => c.id));
|
|
162
|
+
conversations = [
|
|
163
|
+
...list.data,
|
|
164
|
+
...this.state.conversations.filter((c) => !fresh.has(c.id))
|
|
165
|
+
];
|
|
166
|
+
} else {
|
|
167
|
+
this.nextCursor = list.next_cursor ?? null;
|
|
168
|
+
}
|
|
169
|
+
this.set({
|
|
170
|
+
...this.state,
|
|
171
|
+
conversations,
|
|
172
|
+
loading: false,
|
|
173
|
+
error: null,
|
|
174
|
+
hasMore: this.nextCursor !== null
|
|
175
|
+
});
|
|
122
176
|
},
|
|
123
177
|
(err) => {
|
|
124
178
|
this.set({
|
|
@@ -178,7 +232,7 @@ function mergeUpdated(prev, next, fromMe) {
|
|
|
178
232
|
return [merged, ...rest];
|
|
179
233
|
}
|
|
180
234
|
var PoolseContext = createContext(null);
|
|
181
|
-
function PoolseProvider({ config, children }) {
|
|
235
|
+
function PoolseProvider({ config, trackActivity = true, children }) {
|
|
182
236
|
const configRef = useRef(config);
|
|
183
237
|
configRef.current = config;
|
|
184
238
|
const initialConnectionRef = useRef(null);
|
|
@@ -226,6 +280,12 @@ function PoolseProvider({ config, children }) {
|
|
|
226
280
|
chat.destroy();
|
|
227
281
|
};
|
|
228
282
|
}, [chat]);
|
|
283
|
+
const trackActivityRef = useRef(trackActivity);
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
const opts = trackActivityRef.current;
|
|
286
|
+
if (opts === false) return;
|
|
287
|
+
return chat.presence.trackActivity(opts === true ? {} : opts);
|
|
288
|
+
}, [chat]);
|
|
229
289
|
const value = useMemo(() => ({ chat, conversations: new ConversationsStore(chat) }), [chat]);
|
|
230
290
|
return /* @__PURE__ */ jsx(PoolseContext.Provider, { value, children });
|
|
231
291
|
}
|
|
@@ -321,12 +381,13 @@ function useConversations() {
|
|
|
321
381
|
return off;
|
|
322
382
|
}, [store]);
|
|
323
383
|
const refetch = useCallback(() => store.refetch(), [store]);
|
|
384
|
+
const loadMore = useCallback(() => store.loadMore(), [store]);
|
|
324
385
|
const create = useCallback((attrs) => store.create(attrs), [store]);
|
|
325
386
|
const markConversationRead = useCallback(
|
|
326
387
|
(conversationId) => store.markRead(conversationId),
|
|
327
388
|
[store]
|
|
328
389
|
);
|
|
329
|
-
const { conversations, loading, error } = snapshot;
|
|
390
|
+
const { conversations, loading, error, hasMore, loadingMore } = snapshot;
|
|
330
391
|
const unreadCounts = useMemo(() => countsOf(conversations, "unread_count"), [conversations]);
|
|
331
392
|
const mentionUnreadCounts = useMemo(
|
|
332
393
|
() => countsOf(conversations, "mention_unread_count"),
|
|
@@ -337,6 +398,9 @@ function useConversations() {
|
|
|
337
398
|
loading,
|
|
338
399
|
error,
|
|
339
400
|
refetch,
|
|
401
|
+
hasMore,
|
|
402
|
+
loadingMore,
|
|
403
|
+
loadMore,
|
|
340
404
|
create,
|
|
341
405
|
unreadCounts,
|
|
342
406
|
mentionUnreadCounts,
|
|
@@ -505,22 +569,23 @@ function useMessages(conversationId) {
|
|
|
505
569
|
setMessages((prev) => upsertById(prev, msg));
|
|
506
570
|
});
|
|
507
571
|
const offUpdated = conv.onMessageUpdated((msg) => {
|
|
508
|
-
setMessages((prev) => prev.
|
|
572
|
+
setMessages((prev) => patchById(prev, msg.id, (m) => mergeMessage(m, msg)));
|
|
509
573
|
});
|
|
510
574
|
const offDeleted = conv.onMessageDeleted((evt) => {
|
|
511
575
|
setMessages((prev) => {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
(m
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
return updated;
|
|
576
|
+
const rootId = evt.thread_root_id ?? prev.find((m) => m.id === evt.id)?.thread_root_id;
|
|
577
|
+
return prev.map((m) => {
|
|
578
|
+
if (m.id === evt.id) return toTombstone(m, evt.deleted_at);
|
|
579
|
+
if (rootId && m.id === rootId) {
|
|
580
|
+
m = { ...m, reply_count: Math.max(0, (m.reply_count ?? 0) - 1) };
|
|
581
|
+
}
|
|
582
|
+
return markQuoteDeleted(m, evt.id, evt.deleted_at);
|
|
583
|
+
});
|
|
522
584
|
});
|
|
523
585
|
});
|
|
586
|
+
const offThread = conv.onThreadUpdated((evt) => {
|
|
587
|
+
setMessages((prev) => patchById(prev, evt.message_id, (m) => applyThreadUpdate(m, evt)));
|
|
588
|
+
});
|
|
524
589
|
let wasConnected = chat.realtime.getStatus() === "connected";
|
|
525
590
|
let connectedBefore = wasConnected;
|
|
526
591
|
const offStatus = chat.realtime.onStatus((status) => {
|
|
@@ -538,6 +603,7 @@ function useMessages(conversationId) {
|
|
|
538
603
|
offNew();
|
|
539
604
|
offUpdated();
|
|
540
605
|
offDeleted();
|
|
606
|
+
offThread();
|
|
541
607
|
offStatus();
|
|
542
608
|
};
|
|
543
609
|
}, [chat, conversationId]);
|
|
@@ -638,7 +704,7 @@ function useMessages(conversationId) {
|
|
|
638
704
|
);
|
|
639
705
|
try {
|
|
640
706
|
const updated = await chat.messages.one(messageId).update({ body });
|
|
641
|
-
setMessages((prev) => prev
|
|
707
|
+
setMessages((prev) => patchById(prev, messageId, (m) => mergeMessage(m, updated)));
|
|
642
708
|
return updated;
|
|
643
709
|
} catch (err) {
|
|
644
710
|
if (previous) {
|
|
@@ -657,7 +723,7 @@ function useMessages(conversationId) {
|
|
|
657
723
|
(prev) => prev.map((m) => {
|
|
658
724
|
if (m.id !== messageId) return m;
|
|
659
725
|
previous = m;
|
|
660
|
-
return
|
|
726
|
+
return toTombstone(m, (/* @__PURE__ */ new Date()).toISOString());
|
|
661
727
|
})
|
|
662
728
|
);
|
|
663
729
|
try {
|
|
@@ -698,6 +764,13 @@ function useMessages(conversationId) {
|
|
|
698
764
|
refetch
|
|
699
765
|
};
|
|
700
766
|
}
|
|
767
|
+
function patchById(prev, id, fn) {
|
|
768
|
+
const idx = prev.findIndex((m) => m.id === id);
|
|
769
|
+
if (idx === -1) return prev;
|
|
770
|
+
const next = prev.slice();
|
|
771
|
+
next[idx] = fn(prev[idx]);
|
|
772
|
+
return next;
|
|
773
|
+
}
|
|
701
774
|
function upsertById(prev, msg) {
|
|
702
775
|
const idx = prev.findIndex((m) => m.id === msg.id);
|
|
703
776
|
if (idx === -1) return [...prev, msg];
|
|
@@ -809,11 +882,13 @@ function useThread(conversationId, rootMessageId) {
|
|
|
809
882
|
});
|
|
810
883
|
const offUpdated = conv.onMessageUpdated((msg) => {
|
|
811
884
|
if (msg.thread_root_id !== rootMessageId) return;
|
|
812
|
-
setReplies((prev) => prev.map((m) => m.id === msg.id ? msg : m));
|
|
885
|
+
setReplies((prev) => prev.map((m) => m.id === msg.id ? mergeMessage(m, msg) : m));
|
|
813
886
|
});
|
|
814
887
|
const offDeleted = conv.onMessageDeleted((evt) => {
|
|
815
888
|
setReplies(
|
|
816
|
-
(prev) => prev.map(
|
|
889
|
+
(prev) => prev.map(
|
|
890
|
+
(m) => m.id === evt.id ? toTombstone(m, evt.deleted_at) : markQuoteDeleted(m, evt.id, evt.deleted_at)
|
|
891
|
+
)
|
|
817
892
|
);
|
|
818
893
|
});
|
|
819
894
|
return () => {
|
|
@@ -885,7 +960,7 @@ function useThread(conversationId, rootMessageId) {
|
|
|
885
960
|
);
|
|
886
961
|
try {
|
|
887
962
|
const updated = await chat.messages.one(messageId).update({ body });
|
|
888
|
-
setReplies((prev) => prev.map((m) => m.id === messageId ? updated : m));
|
|
963
|
+
setReplies((prev) => prev.map((m) => m.id === messageId ? mergeMessage(m, updated) : m));
|
|
889
964
|
return updated;
|
|
890
965
|
} catch (err) {
|
|
891
966
|
if (previous) {
|
|
@@ -904,7 +979,7 @@ function useThread(conversationId, rootMessageId) {
|
|
|
904
979
|
(prev) => prev.map((m) => {
|
|
905
980
|
if (m.id !== messageId) return m;
|
|
906
981
|
previous = m;
|
|
907
|
-
return
|
|
982
|
+
return toTombstone(m, (/* @__PURE__ */ new Date()).toISOString());
|
|
908
983
|
})
|
|
909
984
|
);
|
|
910
985
|
try {
|
|
@@ -1102,6 +1177,48 @@ function usePresence(conversationId) {
|
|
|
1102
1177
|
}, [chat, conversationId]);
|
|
1103
1178
|
return { online };
|
|
1104
1179
|
}
|
|
1180
|
+
var useConversationPresence = usePresence;
|
|
1181
|
+
function useUserPresence(id) {
|
|
1182
|
+
const chat = usePoolse();
|
|
1183
|
+
const [presence, setPresence] = useState(
|
|
1184
|
+
() => id ? chat.presence.peek(id) ?? null : null
|
|
1185
|
+
);
|
|
1186
|
+
useEffect(() => {
|
|
1187
|
+
if (!id) {
|
|
1188
|
+
setPresence(null);
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
setPresence(chat.presence.peek(id) ?? null);
|
|
1192
|
+
return chat.presence.subscribe(id, () => setPresence(chat.presence.peek(id) ?? null));
|
|
1193
|
+
}, [chat, id]);
|
|
1194
|
+
return presence;
|
|
1195
|
+
}
|
|
1196
|
+
function usePresenceMany(ids) {
|
|
1197
|
+
const chat = usePoolse();
|
|
1198
|
+
const key = useMemo(
|
|
1199
|
+
() => JSON.stringify([...new Set(ids.filter((id) => !!id))].sort()),
|
|
1200
|
+
[ids]
|
|
1201
|
+
);
|
|
1202
|
+
const [presences, setPresences] = useState(
|
|
1203
|
+
() => collect(chat.presence.peek.bind(chat.presence), JSON.parse(key))
|
|
1204
|
+
);
|
|
1205
|
+
useEffect(() => {
|
|
1206
|
+
const list = JSON.parse(key);
|
|
1207
|
+
const read = () => setPresences(collect(chat.presence.peek.bind(chat.presence), list));
|
|
1208
|
+
read();
|
|
1209
|
+
if (list.length === 0) return;
|
|
1210
|
+
return chat.presence.subscribe(list, read);
|
|
1211
|
+
}, [chat, key]);
|
|
1212
|
+
return presences;
|
|
1213
|
+
}
|
|
1214
|
+
function collect(peek, ids) {
|
|
1215
|
+
const out = {};
|
|
1216
|
+
for (const id of ids) {
|
|
1217
|
+
const p = peek(id);
|
|
1218
|
+
if (p) out[id] = p;
|
|
1219
|
+
}
|
|
1220
|
+
return out;
|
|
1221
|
+
}
|
|
1105
1222
|
function useRealtimeStatus() {
|
|
1106
1223
|
const chat = usePoolse();
|
|
1107
1224
|
const [status, setStatus] = useState(chat.realtime.getStatus());
|
|
@@ -1646,6 +1763,6 @@ function canEditOwnMessage(args) {
|
|
|
1646
1763
|
return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
|
|
1647
1764
|
}
|
|
1648
1765
|
|
|
1649
|
-
export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser };
|
|
1766
|
+
export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAppEvent, useAttachmentUpload, useAttachmentUrl, useCallRoom, useConversation, useConversationPresence, useConversations, useLiveCall, useMe, useMembers, useMessageStreams, useMessages, usePoolse, usePresence, usePresenceMany, useReactions, useReadReceipts, useRealtimeStatus, useRoom, useThread, useTyping, useUser, useUserPresence };
|
|
1650
1767
|
//# sourceMappingURL=index.js.map
|
|
1651
1768
|
//# sourceMappingURL=index.js.map
|