@poolse/react 2.26.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
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, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } 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 {
@@ -783,4 +783,43 @@ interface UseLiveCall {
783
783
  */
784
784
  declare function useLiveCall(conversationId: string | null): UseLiveCall;
785
785
 
786
- export { type CallPhase, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseUserState, type UseVoiceRoom, computeGroupPosition, formatDayLabel, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
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
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, RealtimeStatus, Uuid, callLogDisplayFor, describeCallLog, formatCallDuration, formatCallLogPreview, isCallLogMessage, isMessageVisibleTo, parseCallLog, parseCallLogBody } 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 {
@@ -783,4 +783,43 @@ interface UseLiveCall {
783
783
  */
784
784
  declare function useLiveCall(conversationId: string | null): UseLiveCall;
785
785
 
786
- export { type CallPhase, type GroupPosition, PoolseProvider, type PoolseProviderProps, type ReactionMap, type UploadItem, type UploadItemStatus, type UseCallRoom, type UseCallRoomOptions, type UseCalls, type UseLiveCall, type UseUserState, type UseVoiceRoom, computeGroupPosition, formatDayLabel, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, useMe, useMembers, useMessages, usePoolse, usePresence, useReactions, useRealtimeStatus, useThread, useTyping, useUser, useVoiceRoom };
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]);
@@ -1663,7 +1666,35 @@ function useLiveCall(conversationId) {
1663
1666
  }, [chat, conversationId, apply, refresh]);
1664
1667
  return { call, participantIds, refresh };
1665
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
+ }
1666
1697
 
1667
- export { PoolseProvider, computeGroupPosition, formatDayLabel, sameDay, sameGroup, useAttachmentUpload, useAttachmentUrl, useCallRoom, useCalls, useConversation, useConversations, useLiveCall, 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 };
1668
1699
  //# sourceMappingURL=index.js.map
1669
1700
  //# sourceMappingURL=index.js.map