@poolse/react 2.25.0 → 2.27.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/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, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, VoiceStatus, VoiceParticipant, VoiceRoomOptions, IncomingCall, OutgoingCall, CallMedia } from '@poolse/sdk';
3
- export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, Conversation, ConversationCreateRequest, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
2
+ import { PoolseConfig, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, VoiceStatus, VoiceParticipant, VoiceRoomOptions, IncomingCall, OutgoingCall, CallMedia, LiveCall } from '@poolse/sdk';
3
+ export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface PoolseProviderProps {
@@ -766,4 +766,60 @@ interface UseCalls {
766
766
  */
767
767
  declare function useCalls(userId: string | null, opts?: UseCallsOptions): UseCalls;
768
768
 
769
- export { type CallPhase, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseUserState, type UseVoiceRoom, computeGroupPosition, formatDayLabel, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
769
+ interface UseLiveCall {
770
+ /** The call running on the conversation right now, or null. */
771
+ call: LiveCall | null;
772
+ /** User ids in the call's room at this moment (kept live by `call:participants`). */
773
+ participantIds: string[];
774
+ /** Re-read from the server. */
775
+ refresh: () => void;
776
+ }
777
+ /**
778
+ * Whether a call is running on `conversationId` — what a "Call in
779
+ * progress · Join" banner needs. Reads once on mount (and after every
780
+ * reconnect, since events sent while the socket was down are gone),
781
+ * then follows the conversation's `call:started`, `call:participants`
782
+ * and `call:finished` events. `null` id → always idle.
783
+ */
784
+ declare function useLiveCall(conversationId: string | null): UseLiveCall;
785
+
786
+ interface UseReadReceipts {
787
+ /**
788
+ * Whether this user sees other people's read state. False → show no
789
+ * check marks anywhere (the server withholds the data anyway).
790
+ */
791
+ visible: boolean;
792
+ /** `on`, `off`, or `user` (each user decides) — the workspace setting. */
793
+ mode: 'on' | 'off' | 'user';
794
+ /** Whether others see when this user reads. */
795
+ shared: boolean;
796
+ /** True only when the workspace lets users decide: offer a switch. */
797
+ canChange: boolean;
798
+ /**
799
+ * Turn this user's read receipts on or off (only where `canChange`).
800
+ * Reciprocal: off also hides other people's.
801
+ */
802
+ setShared: (share: boolean) => Promise<void>;
803
+ }
804
+ /** The workspace's read-receipt setting as it applies to the signed-in user. */
805
+ declare function useReadReceipts(): UseReadReceipts;
806
+ /** Read-receipt state from a `Me`; an older server without it means "on". */
807
+ declare function receiptsOf(me: Me | null): Omit<UseReadReceipts, 'setShared'>;
808
+ /** How long a message stays editable when read receipts are hidden. */
809
+ declare const EDIT_WINDOW_MS: number;
810
+ /**
811
+ * May the viewer edit their own message? With read receipts visible:
812
+ * until someone else has read it (`readState` is `read`), as in the
813
+ * messaging apps. With them hidden there is nothing to show why editing
814
+ * stopped, so it is a plain time window instead: 15 minutes from sending.
815
+ */
816
+ declare function canEditOwnMessage(args: {
817
+ isSelf: boolean;
818
+ deleted: boolean;
819
+ receiptsVisible: boolean;
820
+ readState: 'sent' | 'read' | undefined;
821
+ insertedAt: string;
822
+ now?: number;
823
+ }): boolean;
824
+
825
+ export { type CallPhase, EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseReadReceipts, type UseUserState, type UseVoiceRoom, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
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, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, VoiceStatus, VoiceParticipant, VoiceRoomOptions, IncomingCall, OutgoingCall, CallMedia } from '@poolse/sdk';
3
- export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, Conversation, ConversationCreateRequest, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
2
+ import { PoolseConfig, Poolse, Me, Uuid, Conversation, ConversationCreateRequest, Membership, MemberRole, Message, MessageCreateRequest, RealtimeStatus, Attachment, AttachmentUploadInput, PoolseUserProfile, CallRoomStatus, CallParticipant, CameraFacing, CallDeviceKind, CallDevice, LiveKitModule, VoiceStatus, VoiceParticipant, VoiceRoomOptions, IncomingCall, OutgoingCall, CallMedia, LiveCall } from '@poolse/sdk';
3
+ export { ApiError, Attachment, AttachmentStatus, AttachmentUploadInput, AttachmentUploadRequest, AttachmentUploadResponse, AuthError, CallEndReason, CallLog, CallLogDisplay, CallLogEntry, CallLogMedia, CallMissedEntry, CallParticipantStatus, Conversation, ConversationCreateRequest, DeviceKind, LiveCall, LiveCallMember, Me, MemberRole, Membership, Message, MessageCreateRequest, MessageType, NetworkError, PoolseConfig, PoolseError, PoolseUserProfile, RateLimitedError, ReadReceiptsState, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } from '@poolse/sdk';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  interface PoolseProviderProps {
@@ -766,4 +766,60 @@ interface UseCalls {
766
766
  */
767
767
  declare function useCalls(userId: string | null, opts?: UseCallsOptions): UseCalls;
768
768
 
769
- export { type CallPhase, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseUserState, type UseVoiceRoom, computeGroupPosition, formatDayLabel, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
769
+ interface UseLiveCall {
770
+ /** The call running on the conversation right now, or null. */
771
+ call: LiveCall | null;
772
+ /** User ids in the call's room at this moment (kept live by `call:participants`). */
773
+ participantIds: string[];
774
+ /** Re-read from the server. */
775
+ refresh: () => void;
776
+ }
777
+ /**
778
+ * Whether a call is running on `conversationId` — what a "Call in
779
+ * progress · Join" banner needs. Reads once on mount (and after every
780
+ * reconnect, since events sent while the socket was down are gone),
781
+ * then follows the conversation's `call:started`, `call:participants`
782
+ * and `call:finished` events. `null` id → always idle.
783
+ */
784
+ declare function useLiveCall(conversationId: string | null): UseLiveCall;
785
+
786
+ interface UseReadReceipts {
787
+ /**
788
+ * Whether this user sees other people's read state. False → show no
789
+ * check marks anywhere (the server withholds the data anyway).
790
+ */
791
+ visible: boolean;
792
+ /** `on`, `off`, or `user` (each user decides) — the workspace setting. */
793
+ mode: 'on' | 'off' | 'user';
794
+ /** Whether others see when this user reads. */
795
+ shared: boolean;
796
+ /** True only when the workspace lets users decide: offer a switch. */
797
+ canChange: boolean;
798
+ /**
799
+ * Turn this user's read receipts on or off (only where `canChange`).
800
+ * Reciprocal: off also hides other people's.
801
+ */
802
+ setShared: (share: boolean) => Promise<void>;
803
+ }
804
+ /** The workspace's read-receipt setting as it applies to the signed-in user. */
805
+ declare function useReadReceipts(): UseReadReceipts;
806
+ /** Read-receipt state from a `Me`; an older server without it means "on". */
807
+ declare function receiptsOf(me: Me | null): Omit<UseReadReceipts, 'setShared'>;
808
+ /** How long a message stays editable when read receipts are hidden. */
809
+ declare const EDIT_WINDOW_MS: number;
810
+ /**
811
+ * May the viewer edit their own message? With read receipts visible:
812
+ * until someone else has read it (`readState` is `read`), as in the
813
+ * messaging apps. With them hidden there is nothing to show why editing
814
+ * stopped, so it is a plain time window instead: 15 minutes from sending.
815
+ */
816
+ declare function canEditOwnMessage(args: {
817
+ isSelf: boolean;
818
+ deleted: boolean;
819
+ receiptsVisible: boolean;
820
+ readState: 'sent' | 'read' | undefined;
821
+ insertedAt: string;
822
+ now?: number;
823
+ }): boolean;
824
+
825
+ export { type CallPhase, EDIT_WINDOW_MS, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseReadReceipts, type UseUserState, type UseVoiceRoom, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
package/dist/index.js CHANGED
@@ -68,27 +68,30 @@ function usePoolse() {
68
68
  }
69
69
  function useMe() {
70
70
  const chat = usePoolse();
71
- const [state, setState] = useState({
72
- me: null,
73
- loading: true,
74
- error: null
71
+ const [state, setState] = useState(() => {
72
+ const known = chat.me.peek();
73
+ return { me: known, loading: known === null, error: null };
75
74
  });
76
75
  useEffect(() => {
77
76
  let cancelled = false;
78
77
  const controller = new AbortController();
78
+ const off = chat.me.onChange((me) => {
79
+ if (!cancelled) setState({ me, loading: false, error: null });
80
+ });
79
81
  chat.me.show(controller.signal).then((me) => {
80
82
  if (!cancelled) setState({ me, loading: false, error: null });
81
83
  }).catch((err) => {
82
84
  if (!cancelled) {
83
- setState({
84
- me: null,
85
+ setState((prev) => ({
86
+ me: prev.me,
85
87
  loading: false,
86
88
  error: err instanceof Error ? err : new Error(String(err))
87
- });
89
+ }));
88
90
  }
89
91
  });
90
92
  return () => {
91
93
  cancelled = true;
94
+ off();
92
95
  controller.abort();
93
96
  };
94
97
  }, [chat]);
@@ -1612,7 +1615,86 @@ function useCalls(userId, opts = {}) {
1612
1615
  reset
1613
1616
  };
1614
1617
  }
1618
+ function useLiveCall(conversationId) {
1619
+ const chat = usePoolse();
1620
+ const [call, setCall] = useState(null);
1621
+ const [participantIds, setParticipantIds] = useState([]);
1622
+ const callIdRef = useRef(null);
1623
+ const seq = useRef(0);
1624
+ const apply = useCallback((next) => {
1625
+ callIdRef.current = next?.id ?? null;
1626
+ setCall(next);
1627
+ setParticipantIds(next ? next.participants.map((p) => p.user_id) : []);
1628
+ }, []);
1629
+ const refresh = useCallback(() => {
1630
+ if (!conversationId) return;
1631
+ const mine = ++seq.current;
1632
+ chat.liveCalls.get(conversationId).then((c) => {
1633
+ if (mine === seq.current) apply(c);
1634
+ }).catch(() => {
1635
+ });
1636
+ }, [chat, conversationId, apply]);
1637
+ useEffect(() => {
1638
+ apply(null);
1639
+ if (!conversationId) return;
1640
+ refresh();
1641
+ const conv = chat.realtime.conversation(conversationId);
1642
+ const offStarted = conv.onCallStarted((evt) => {
1643
+ seq.current++;
1644
+ apply(evt.call);
1645
+ });
1646
+ const offParticipants = conv.onCallParticipants((evt) => {
1647
+ if (evt.call_id === callIdRef.current) setParticipantIds(evt.participants);
1648
+ else refresh();
1649
+ });
1650
+ const offFinished = conv.onCallFinished((evt) => {
1651
+ if (evt.call_id !== callIdRef.current) return;
1652
+ seq.current++;
1653
+ apply(null);
1654
+ });
1655
+ let wasConnected = chat.realtime.getStatus() === "connected";
1656
+ const offStatus = chat.realtime.onStatus((status) => {
1657
+ if (status === "connected" && !wasConnected) refresh();
1658
+ wasConnected = status === "connected";
1659
+ });
1660
+ return () => {
1661
+ offStarted();
1662
+ offParticipants();
1663
+ offFinished();
1664
+ offStatus();
1665
+ };
1666
+ }, [chat, conversationId, apply, refresh]);
1667
+ return { call, participantIds, refresh };
1668
+ }
1669
+ function useReadReceipts() {
1670
+ const chat = usePoolse();
1671
+ const { me } = useMe();
1672
+ const state = receiptsOf(me);
1673
+ const setShared = useCallback(
1674
+ async (share) => {
1675
+ await chat.me.update({ read_receipts: share });
1676
+ },
1677
+ [chat]
1678
+ );
1679
+ return { ...state, setShared };
1680
+ }
1681
+ function receiptsOf(me) {
1682
+ const r = me?.read_receipts;
1683
+ return {
1684
+ visible: r?.visible ?? true,
1685
+ mode: r?.mode ?? "on",
1686
+ shared: r?.shared ?? true,
1687
+ canChange: r?.can_change ?? false
1688
+ };
1689
+ }
1690
+ var EDIT_WINDOW_MS = 15 * 60 * 1e3;
1691
+ function canEditOwnMessage(args) {
1692
+ if (!args.isSelf || args.deleted) return false;
1693
+ if (args.receiptsVisible) return (args.readState ?? "sent") === "sent";
1694
+ const sent = Date.parse(args.insertedAt);
1695
+ return Number.isFinite(sent) && (args.now ?? Date.now()) - sent < EDIT_WINDOW_MS;
1696
+ }
1615
1697
 
1616
- export { PoolseProvider, computeGroupPosition, formatDayLabel, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
1698
+ export { EDIT_WINDOW_MS, PoolseProvider, canEditOwnMessage, computeGroupPosition, formatDayLabel, receiptsOf, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useReadReceipts, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
1617
1699
  //# sourceMappingURL=index.js.map
1618
1700
  //# sourceMappingURL=index.js.map