@openpeepshq/rn-components 0.12.5 → 0.13.1

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.
@@ -0,0 +1,144 @@
1
+ /**
2
+ * RN parity lock (issue #2131), updated for issue #2128: the native
3
+ * EventsCalendar must render exactly what the shared `useEventsCalendar` hook
4
+ * from `@openpeepshq/react` returns — the single source of truth, with no
5
+ * separate RN implementation. Since #2128 the hook is a date-range calendar:
6
+ * it reads one row per occurrence from the server's month-window range feed
7
+ * and buckets the rows by browser-local day keys. The mock below emulates
8
+ * that contract — it returns the rows for the selected day only, and an event
9
+ * the range feed did not return must not appear. If the native component ever
10
+ * rendered events from any other source (a query of its own, its own
11
+ * filtering), these assertions fail.
12
+ *
13
+ * `@openpeepshq/react` is mocked because the package's jest transform only
14
+ * covers this package — the same pattern every RN test here uses.
15
+ */
16
+ import React from 'react';
17
+ import ReactTestRenderer from 'react-test-renderer';
18
+ import type { PublicPost } from '@openpeepshq/common/types';
19
+
20
+ // --- react-native: host elements render as plain host tags ----------------
21
+ jest.mock('react-native', () => {
22
+ const React = require('react');
23
+ const make =
24
+ (tag: string) =>
25
+ (props: { children?: React.ReactNode; onPress?: () => void }) =>
26
+ React.createElement(tag, { onPress: props.onPress }, props.children);
27
+ return {
28
+ View: make('View'),
29
+ Pressable: make('Pressable'),
30
+ ActivityIndicator: () => null,
31
+ ScrollView: make('ScrollView'),
32
+ RefreshControl: () => null,
33
+ };
34
+ });
35
+
36
+ jest.mock('@react-navigation/native', () => ({
37
+ useNavigation: () => ({ navigate: jest.fn() }),
38
+ useFocusEffect: jest.fn(),
39
+ }));
40
+
41
+ jest.mock('react-i18next', () => ({
42
+ useTranslation: () => ({
43
+ t: (_key: string, opts?: { defaultValue?: string }) =>
44
+ opts?.defaultValue ?? _key,
45
+ }),
46
+ }));
47
+
48
+ jest.mock('../../../../theme/useThemeOpacity', () => ({
49
+ useThemeOpacity: () => ({ background: () => ({}) }),
50
+ }));
51
+
52
+ jest.mock('../../../navigation/types/index', () => ({
53
+ MainStackParamList: {},
54
+ }));
55
+
56
+ jest.mock('../../../../lib/utils', () => ({
57
+ cn: (...args: unknown[]) => args.filter(Boolean).join(' '),
58
+ }));
59
+
60
+ jest.mock('../../../ui/themed-text', () => ({
61
+ ThemedText: (props: Record<string, unknown>) =>
62
+ React.createElement('Text', props, props.children),
63
+ }));
64
+
65
+ jest.mock('../../../icons/index', () => ({
66
+ ChevronLeftIcon: () => null,
67
+ ChevronRightIcon: () => null,
68
+ }));
69
+
70
+ // --- shared hook contract: one row per occurrence, bucketed by local day ---
71
+ const future = {
72
+ id: 'future-event',
73
+ data: {
74
+ type: 'event',
75
+ name: 'future-event',
76
+ start: '2026-11-19T10:00:00.000Z',
77
+ end: '2026-11-19T11:00:00.000Z',
78
+ wholeDay: false,
79
+ },
80
+ } as unknown as PublicPost;
81
+
82
+ jest.mock('@openpeepshq/react', () => ({
83
+ useEventsCalendar: () => ({
84
+ cells: [
85
+ { key: '2026-11-18', inMonth: true },
86
+ { key: '2026-11-19', inMonth: true },
87
+ ],
88
+ byDay: new Map([['2026-11-19', [future]]]),
89
+ todayKey: '2026-11-18',
90
+ selected: '2026-11-19',
91
+ selectedEvents: [future],
92
+ selectedLabel: 'Selected day',
93
+ setSelectedKey: () => undefined,
94
+ monthLabel: 'Parity month',
95
+ weekdayLabels: ['S', 'M'],
96
+ isLoading: false,
97
+ isFetchingNextPage: false,
98
+ shiftMonth: () => undefined,
99
+ goToday: () => undefined,
100
+ }),
101
+ calendarDayNumber: (key: string) => key,
102
+ calendarEventName: (post: PublicPost) =>
103
+ post.data.type === 'event' ? (post.data.name ?? '') : '',
104
+ eventStartIso: (post: PublicPost) =>
105
+ post.occurrenceStart ?? (post.data as { start?: string }).start,
106
+ eventEndIso: (post: PublicPost) =>
107
+ post.occurrenceEnd ?? (post.data as { end?: string }).end,
108
+ }));
109
+
110
+ import { EventsCalendar } from './EventsCalendar';
111
+
112
+ const renderCalendar = async (props: Record<string, unknown> = {}) => {
113
+ jest.spyOn(console, 'error').mockImplementation(() => undefined);
114
+ jest.spyOn(console, 'warn').mockImplementation(() => undefined);
115
+ const renderer = ReactTestRenderer.create(<EventsCalendar {...props} />);
116
+ await ReactTestRenderer.act(async () => undefined);
117
+ return renderer;
118
+ };
119
+
120
+ describe('EventsCalendar (native) shared-hook parity', () => {
121
+ it('renders the shared hook output through the scope prop', async () => {
122
+ const renderer = await renderCalendar({});
123
+ const tree = renderer.toJSON();
124
+ expect(tree).not.toBeNull();
125
+ const text = JSON.stringify(tree);
126
+ expect(text).toContain('Parity month');
127
+ expect(text).toContain('Selected day');
128
+ });
129
+
130
+ it('shows the range-feed row on the selected day list', async () => {
131
+ const renderer = await renderCalendar({});
132
+ const text = JSON.stringify(renderer.toJSON());
133
+ expect(text).toContain('future-event');
134
+ });
135
+
136
+ it('never shows an event the shared hook did not return', async () => {
137
+ const renderer = await renderCalendar({});
138
+ const text = JSON.stringify(renderer.toJSON());
139
+ // The component has no query of its own; anything it shows came from the
140
+ // hook's `selectedEvents`. An event absent from that list must not leak
141
+ // into the grid or the day list.
142
+ expect(text).not.toContain('past-event');
143
+ });
144
+ });
@@ -10,8 +10,7 @@ import {
10
10
  eventEndIso,
11
11
  eventStartIso,
12
12
  useEventsCalendar,
13
- type EventsAgendaWindow,
14
- type EventsCalendarQuery,
13
+ type CalendarScopeProps,
15
14
  } from '@openpeepshq/react';
16
15
  import { ChevronLeftIcon, ChevronRightIcon } from '../../../icons/index';
17
16
  import { useThemeOpacity } from '../../../../theme/useThemeOpacity';
@@ -19,15 +18,12 @@ import { MainStackParamList } from '../../../navigation/types/index';
19
18
  import { ThemedText } from '../../../ui/themed-text';
20
19
  import { cn } from '../../../../lib/utils';
21
20
 
22
- export interface EventsCalendarProps {
23
- query: EventsCalendarQuery;
24
- agenda: EventsAgendaWindow;
25
- }
21
+ export type EventsCalendarProps = CalendarScopeProps;
26
22
 
27
23
  const postKey = (post: PublicPost) =>
28
24
  `${post.id}:${post.occurrenceRecurrenceId ?? ''}`;
29
25
 
30
- export const EventsCalendar = ({ query, agenda }: EventsCalendarProps) => {
26
+ export const EventsCalendar = (props: EventsCalendarProps) => {
31
27
  const { t } = useTranslation();
32
28
  const { background } = useThemeOpacity();
33
29
  const navigation =
@@ -46,7 +42,7 @@ export const EventsCalendar = ({ query, agenda }: EventsCalendarProps) => {
46
42
  isFetchingNextPage,
47
43
  shiftMonth,
48
44
  goToday,
49
- } = useEventsCalendar(query, agenda);
45
+ } = useEventsCalendar(props);
50
46
 
51
47
  const openEvent = (post: PublicPost) =>
52
48
  navigation.navigate('Post', {
@@ -1,30 +1,22 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { View } from 'react-native';
3
- import {
4
- useEventView,
5
- type EventsAgendaWindow,
6
- type EventsCalendarQuery,
7
- } from '@openpeepshq/react';
3
+ import { useEventView, type CalendarScopeProps } from '@openpeepshq/react';
8
4
  import { EventViewSwitch } from '../../EventViewSwitch';
9
5
  import { EventsCalendar } from './EventsCalendar';
10
6
 
11
7
  export interface EventsViewProps {
12
- query: EventsCalendarQuery;
13
- agenda: EventsAgendaWindow;
8
+ /** Scope for calendar — lists don't use this. */
9
+ calendar?: CalendarScopeProps;
14
10
  list: ReactNode;
15
11
  }
16
12
 
17
13
  /** List (the existing layout) or a month calendar, shared across event pages. */
18
- export const EventsView = ({ query, agenda, list }: EventsViewProps) => {
14
+ export const EventsView = ({ calendar, list }: EventsViewProps) => {
19
15
  const { view } = useEventView();
20
16
  return (
21
17
  <View className="flex-1">
22
18
  <EventViewSwitch />
23
- {view === 'calendar' ? (
24
- <EventsCalendar key={agenda} query={query} agenda={agenda} />
25
- ) : (
26
- list
27
- )}
19
+ {view === 'calendar' ? <EventsCalendar {...(calendar ?? {})} /> : list}
28
20
  </View>
29
21
  );
30
22
  };
@@ -11,11 +11,15 @@ import {
11
11
  BookmarkMinusIcon,
12
12
  Repeat2Icon,
13
13
  ThumbsUpIcon,
14
+ HistoryIcon,
14
15
  } from '../../icons/index';
15
16
  import { PopupMenu, PopupMenuButton, PopupSeparator } from '../../ui';
16
17
  import { useOpenpeeps } from '@openpeepshq/react';
17
18
  import { checkGroupCapabilities } from '@openpeepshq/common';
18
- import { checkRoleCapabilities } from '@openpeepshq/common/lib';
19
+ import {
20
+ checkRoleCapabilities,
21
+ postHasEditHistory,
22
+ } from '@openpeepshq/common/lib';
19
23
  import type { PublicPost } from '@openpeepshq/common/types';
20
24
  import { useNavigation } from '@react-navigation/native';
21
25
  import { NativeStackNavigationProp } from '@react-navigation/native-stack';
@@ -26,6 +30,7 @@ import { BottomSheetModal } from '@gorhom/bottom-sheet';
26
30
  import { DeletePostModal } from './modals/DeletePostModal';
27
31
  import { ReportProfileOrPostModal } from '../../profile/ReportProfileOrPostModal';
28
32
  import { RepostModal } from './modals/RepostModal';
33
+ import { PostEditHistoryModal } from './modals/PostEditHistoryModal';
29
34
  import { ReactionsModal } from './modals/ReactionsModal';
30
35
  import Toast from 'react-native-toast-message';
31
36
 
@@ -51,6 +56,12 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
51
56
  const [isFollowing, setIsFollowing] = React.useState(false);
52
57
  const [repostsModalOpen, setRepostsModalOpen] = React.useState(false);
53
58
  const [reactionsModalOpen, setReactionsModalOpen] = React.useState(false);
59
+ const [historyModalOpen, setHistoryModalOpen] = React.useState(false);
60
+
61
+ // Hidden (blocked-author tombstone) posts have their entry snapshots
62
+ // stripped server-side; never offer history for them or deleted posts.
63
+ const showEditHistory =
64
+ !post.hidden && !post.deletedAt && postHasEditHistory(post.entries);
54
65
 
55
66
  const { data: serverInfo } = openpeepsApi.useServerInfo();
56
67
  const canPinToGroup =
@@ -293,6 +304,16 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
293
304
  icon={ThumbsUpIcon}
294
305
  action={() => setReactionsModalOpen(true)}
295
306
  />
307
+ {showEditHistory ? (
308
+ <PopupMenuButton
309
+ title={t('posts.editHistory.menu', {
310
+ defaultValue: 'Edit history',
311
+ })}
312
+ text={t('posts.editHistory.menu', { defaultValue: 'Edit history' })}
313
+ icon={HistoryIcon}
314
+ action={() => setHistoryModalOpen(true)}
315
+ />
316
+ ) : null}
296
317
 
297
318
  {isBookmarked ? (
298
319
  <PopupMenuButton
@@ -457,6 +478,13 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
457
478
  open={reactionsModalOpen}
458
479
  onClose={() => setReactionsModalOpen(false)}
459
480
  />
481
+ {showEditHistory ? (
482
+ <PostEditHistoryModal
483
+ post={post}
484
+ open={historyModalOpen}
485
+ onClose={() => setHistoryModalOpen(false)}
486
+ />
487
+ ) : null}
460
488
  <DeletePostModal
461
489
  ref={deleteMessageModalRef}
462
490
  onDelete={handleDelete}
@@ -0,0 +1,166 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Image, Linking, Pressable, View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import type { PostDataUnion, PublicPost } from '@openpeepshq/common/types';
5
+ import {
6
+ formatEventWhen,
7
+ postEditVersionKind,
8
+ postEditVersionTitle,
9
+ postEditVersions,
10
+ type PostVersionOrder,
11
+ } from '@openpeepshq/common/lib';
12
+ import { BaseSheet } from '../../../custom/modals/common/index';
13
+ import { UpdatingDate } from '../../../custom/date/updating-date';
14
+ import { OpenpeepsMarkdown } from '../../../markdown';
15
+ import { ThemedText } from '../../../ui/themed-text';
16
+ import { Button } from '../../../ui/button';
17
+ import { useControlledSheet } from '../../../../hooks/use-controlled-sheet';
18
+
19
+ export interface PostEditHistoryModalProps {
20
+ post: PublicPost;
21
+ open: boolean;
22
+ onClose: () => void;
23
+ }
24
+
25
+ const VersionBody = ({
26
+ post,
27
+ data,
28
+ }: {
29
+ post: PublicPost;
30
+ data: PostDataUnion;
31
+ }) => {
32
+ const { t } = useTranslation();
33
+ const title = postEditVersionTitle(data);
34
+ const image = 'image' in data ? data.image : undefined;
35
+
36
+ return (
37
+ <View className="gap-2">
38
+ {image ? (
39
+ <Image
40
+ source={{ uri: image }}
41
+ accessibilityLabel={title ?? ''}
42
+ className="h-40 w-full rounded-md"
43
+ resizeMode="cover"
44
+ />
45
+ ) : null}
46
+ {title ? (
47
+ <ThemedText className="text-base font-semibold">{title}</ThemedText>
48
+ ) : null}
49
+ {data.type === 'event' ? (
50
+ <ThemedText className="text-sm text-muted-foreground">
51
+ {formatEventWhen(data.start, {
52
+ end: data.end,
53
+ timeZone: data.timeZone,
54
+ allDay: data.wholeDay,
55
+ })}
56
+ </ThemedText>
57
+ ) : null}
58
+ {data.content ? (
59
+ <OpenpeepsMarkdown source={data.content} mentions={post.mentions} />
60
+ ) : null}
61
+ {data.type === 'question'
62
+ ? data.options.map((option, index) => (
63
+ <ThemedText key={`${option.content}-${index}`} className="text-sm">
64
+ {`• ${option.content}`}
65
+ </ThemedText>
66
+ ))
67
+ : null}
68
+ {data.type === 'resource' && data.url ? (
69
+ <Pressable onPress={() => void Linking.openURL(data.url!)}>
70
+ <ThemedText className="text-sm text-primary">{data.url}</ThemedText>
71
+ </Pressable>
72
+ ) : null}
73
+ {/* Entry snapshots keep only attachment metadata (no binary), so the
74
+ placeholder covers removed attachments. Media referenced inline in the
75
+ note/event/event-agenda content is not snapshotted either and renders
76
+ as plain markdown text in a version. */}
77
+ {data.attachments?.length ? (
78
+ <View className="rounded-md border border-dashed border-border p-2">
79
+ <ThemedText className="text-xs text-muted-foreground">
80
+ {t('posts.editHistory.mediaUnavailable', {
81
+ defaultValue: 'Media from this version is no longer available',
82
+ })}
83
+ </ThemedText>
84
+ </View>
85
+ ) : null}
86
+ </View>
87
+ );
88
+ };
89
+
90
+ export const PostEditHistoryModal = ({
91
+ post,
92
+ open,
93
+ onClose,
94
+ }: PostEditHistoryModalProps) => {
95
+ const { t } = useTranslation();
96
+ const ref = useControlledSheet(open);
97
+ const [order, setOrder] = useState<PostVersionOrder>('newest');
98
+
99
+ useEffect(() => {
100
+ if (open) setOrder('newest');
101
+ }, [open]);
102
+
103
+ const versions = postEditVersions(post.entries, order);
104
+ const kindLabel = {
105
+ original: t('posts.editHistory.original', { defaultValue: 'Original' }),
106
+ edit: t('posts.editHistory.edit', { defaultValue: 'Edit' }),
107
+ current: t('posts.editHistory.current', { defaultValue: 'Current' }),
108
+ };
109
+
110
+ return (
111
+ <BaseSheet ref={ref} snapPoints={['80%']} scrollable onDismiss={onClose}>
112
+ <View className="gap-3 px-4 pb-3">
113
+ <ThemedText className="text-center text-xl font-semibold">
114
+ {t('posts.editHistory.title')}
115
+ </ThemedText>
116
+ <Button
117
+ variant="outline"
118
+ size="sm"
119
+ className="self-start"
120
+ onPress={() =>
121
+ setOrder((current) => (current === 'oldest' ? 'newest' : 'oldest'))
122
+ }
123
+ >
124
+ <ThemedText>
125
+ {order === 'oldest'
126
+ ? t('posts.editHistory.newestFirst')
127
+ : t('posts.editHistory.oldestFirst')}
128
+ </ThemedText>
129
+ </Button>
130
+ <View
131
+ accessibilityLabel={t('posts.editHistory.title', {
132
+ defaultValue: 'Edit history',
133
+ })}
134
+ accessibilityRole="list"
135
+ className="gap-3"
136
+ >
137
+ {versions.map((version) => (
138
+ <View
139
+ key={version.id}
140
+ className="gap-2 rounded-md border border-border p-3"
141
+ >
142
+ <View className="flex-row flex-wrap items-center gap-2">
143
+ <ThemedText className="text-xs font-medium">
144
+ {kindLabel[postEditVersionKind(version)]}
145
+ </ThemedText>
146
+ <UpdatingDate
147
+ date={version.createdAt}
148
+ className="text-xs text-muted-foreground"
149
+ />
150
+ {version.profile?.handle ? (
151
+ <ThemedText className="text-xs text-muted-foreground">
152
+ {t('posts.editHistory.editedBy', {
153
+ defaultValue: 'by @{{handle}}',
154
+ handle: version.profile.handle,
155
+ })}
156
+ </ThemedText>
157
+ ) : null}
158
+ </View>
159
+ <VersionBody post={post} data={version.data} />
160
+ </View>
161
+ ))}
162
+ </View>
163
+ </View>
164
+ </BaseSheet>
165
+ );
166
+ };
@@ -2,5 +2,6 @@ export * from './CancelEventModal';
2
2
  export * from './DeleteEventModal';
3
3
  export * from './DeletePostModal';
4
4
  export * from './PostOptionsSheet';
5
+ export * from './PostEditHistoryModal';
5
6
  export * from './ReactionsModal';
6
7
  export * from './RepostModal';
@@ -7,7 +7,7 @@ import {
7
7
  type NativeSyntheticEvent,
8
8
  type TextInputSelectionChangeEventData,
9
9
  } from 'react-native';
10
- import type { PublicProfile } from '@openpeepshq/common';
10
+ import { visibleTextLength, type PublicProfile } from '@openpeepshq/common';
11
11
  import { useOpenpeeps } from '@openpeepshq/react';
12
12
  import { useTranslation } from 'react-i18next';
13
13
  import { OpenpeepsMarkdown } from '../../markdown/index';
@@ -21,8 +21,13 @@ import { cn, maxContentLength } from '../../../lib/utils';
21
21
  export interface OpenpeepsMarkdownInputProps {
22
22
  value: string;
23
23
  onChange: (value: string) => void;
24
- /** Character budget; the counter turns red once exceeded. */
24
+ /** Visible-text character budget; the counter turns red once exceeded. */
25
25
  maxLength?: number;
26
+ /**
27
+ * Hard-stop typing at the budget. For forms that do not validate the
28
+ * length on submit.
29
+ */
30
+ blockOverflow?: boolean;
26
31
  placeholder?: string;
27
32
  rows?: number;
28
33
  /** Show the preview toggle button (mirrors web `previewButton`). */
@@ -47,6 +52,7 @@ export const OpenpeepsMarkdownInput = ({
47
52
  value,
48
53
  onChange,
49
54
  maxLength = maxContentLength,
55
+ blockOverflow = true,
50
56
  placeholder,
51
57
  rows = 5,
52
58
  previewButton = true,
@@ -134,7 +140,10 @@ export const OpenpeepsMarkdownInput = ({
134
140
  }
135
141
  };
136
142
 
137
- const overLimit = value.length > maxLength;
143
+ // With the native cap on (blockOverflow) the counter tracks the raw length
144
+ // it enforces; otherwise it tracks the visible text the submit check uses.
145
+ const shownLength = blockOverflow ? value.length : visibleTextLength(value);
146
+ const overLimit = shownLength > maxLength;
138
147
 
139
148
  return (
140
149
  <View className="relative w-full">
@@ -203,7 +212,7 @@ export const OpenpeepsMarkdownInput = ({
203
212
  autoFocus={autoFocus}
204
213
  numberOfLines={rows}
205
214
  value={value}
206
- maxLength={maxLength}
215
+ maxLength={blockOverflow ? maxLength : undefined}
207
216
  placeholder={placeholder ?? t('posts.form.content')}
208
217
  onChangeText={handleChange}
209
218
  onSelectionChange={handleSelectionChange}
@@ -217,7 +226,7 @@ export const OpenpeepsMarkdownInput = ({
217
226
  <ThemedText
218
227
  className={cn('text-right text-sm', overLimit && 'text-destructive')}
219
228
  >
220
- {value.length} / {maxLength}
229
+ {shownLength} / {maxLength}
221
230
  </ThemedText>
222
231
  </View>
223
232
  </View>
@@ -109,6 +109,7 @@ export const PostForm = ({
109
109
 
110
110
  <OpenpeepsMarkdownInput
111
111
  autoFocus={autoFocus}
112
+ blockOverflow={false}
112
113
  value={content}
113
114
  onChange={(text) => form.setValue('data.content', text)}
114
115
  placeholder={
@@ -0,0 +1,58 @@
1
+ import { canSendDmMessage } from '../../../react/src/hooks/conversations/dmMessage';
2
+ import {
3
+ hasVisibleText,
4
+ POST_MAX_VISIBLE_LENGTH,
5
+ visibleTextLength,
6
+ } from '@openpeepshq/common';
7
+
8
+ const attachments: never[] = [];
9
+
10
+ describe('DM visible-length send gate', () => {
11
+ it('shares the note budget with the server refine', () => {
12
+ expect(POST_MAX_VISIBLE_LENGTH).toBe(500);
13
+ });
14
+
15
+ it('blocks a message whose visible text is over the budget', () => {
16
+ const text = 'x'.repeat(POST_MAX_VISIBLE_LENGTH + 1);
17
+ expect(visibleTextLength(text)).toBeGreaterThan(POST_MAX_VISIBLE_LENGTH);
18
+ expect(
19
+ canSendDmMessage({
20
+ sending: false,
21
+ uploadsPending: false,
22
+ text,
23
+ attachments,
24
+ })
25
+ ).toBe(false);
26
+ });
27
+
28
+ it('allows a markdown link whose URL alone is longer than the budget', () => {
29
+ const text =
30
+ '[a long but visibly short link](https://example.com/' +
31
+ 'y'.repeat(600) +
32
+ ')';
33
+ expect(text.length).toBeGreaterThan(POST_MAX_VISIBLE_LENGTH);
34
+ expect(visibleTextLength(text)).toBeLessThanOrEqual(
35
+ POST_MAX_VISIBLE_LENGTH
36
+ );
37
+ expect(
38
+ canSendDmMessage({
39
+ sending: false,
40
+ uploadsPending: false,
41
+ text,
42
+ attachments,
43
+ })
44
+ ).toBe(true);
45
+ });
46
+
47
+ it('blocks whitespace-only text without attachments', () => {
48
+ expect(hasVisibleText(' \n ')).toBe(false);
49
+ expect(
50
+ canSendDmMessage({
51
+ sending: false,
52
+ uploadsPending: false,
53
+ text: ' \n ',
54
+ attachments,
55
+ })
56
+ ).toBe(false);
57
+ });
58
+ });
@@ -33,6 +33,8 @@ export function useStableLiveKitRoom(
33
33
  kind?: string
34
34
  ) => void;
35
35
  onEncryptionError?: (error: Error) => void;
36
+ /** Runs after the signal connection, before tracks are enabled. */
37
+ onSignalConnected?: () => void | Promise<void>;
36
38
  simulateParticipants?: number;
37
39
  }
38
40
  ): void {
@@ -49,6 +51,7 @@ export function useStableLiveKitRoom(
49
51
  onError,
50
52
  onMediaDeviceFailure,
51
53
  onEncryptionError,
54
+ onSignalConnected,
52
55
  simulateParticipants,
53
56
  } = params;
54
57
 
@@ -59,23 +62,30 @@ export function useStableLiveKitRoom(
59
62
  connectOptionsRef.current = connectOptions;
60
63
  const connectOptionsKey = JSON.stringify(connectOptions);
61
64
 
65
+ // Callers typically pass a fresh handler object literal on every render;
66
+ // keep a stable ref so the wiring effect does not resubscribe each render.
67
+ const onSignalConnectedRef = React.useRef(onSignalConnected);
68
+ onSignalConnectedRef.current = onSignalConnected;
69
+
62
70
  React.useEffect(() => {
63
71
  const onSignalConnected = () => {
64
72
  const localP = room.localParticipant;
65
73
 
66
- Promise.all([
67
- localP.setMicrophoneEnabled(
68
- !!audio,
69
- typeof audio !== 'boolean' ? audio : undefined
70
- ),
71
- localP.setCameraEnabled(
72
- !!video,
73
- typeof video !== 'boolean' ? video : undefined
74
- ),
75
- // Screen share (and its capture permission) is disabled in React Native jams.
76
- // localP.setScreenShareEnabled(!!screen, typeof screen !== 'boolean' ? screen : undefined),
77
- ]).catch((e: unknown) => {
78
- onError?.(e as Error);
74
+ void Promise.resolve(onSignalConnectedRef.current?.()).then(() => {
75
+ Promise.all([
76
+ localP.setMicrophoneEnabled(
77
+ !!audio,
78
+ typeof audio !== 'boolean' ? audio : undefined
79
+ ),
80
+ localP.setCameraEnabled(
81
+ !!video,
82
+ typeof video !== 'boolean' ? video : undefined
83
+ ),
84
+ // Screen share (and its capture permission) is disabled in React Native jams.
85
+ // localP.setScreenShareEnabled(!!screen, typeof screen !== 'boolean' ? screen : undefined),
86
+ ]).catch((e: unknown) => {
87
+ onError?.(e as Error);
88
+ });
79
89
  });
80
90
  };
81
91
 
package/src/lib/utils.ts CHANGED
@@ -3,6 +3,7 @@ import { twMerge } from 'tailwind-merge';
3
3
  import { lightFormat, parse, parseJSON } from 'date-fns';
4
4
  import {
5
5
  GroupData,
6
+ POST_MAX_VISIBLE_LENGTH,
6
7
  Profile,
7
8
  PublicProfile,
8
9
  SuccessFailureResponse,
@@ -21,7 +22,9 @@ const DATE_FORMAT = 'MM/dd/yyyy';
21
22
  const TIME_FORMAT = 'hh:mm aaa';
22
23
  const DATE_TIME_FORMAT = `${DATE_FORMAT} ${TIME_FORMAT}`;
23
24
 
24
- export const maxContentLength = 500;
25
+ // DM/post composer budget — sourced from the shared note budget so the RN
26
+ // default and the server-side refine can never drift apart.
27
+ export const maxContentLength = POST_MAX_VISIBLE_LENGTH;
25
28
  export const maxArticleContentLength = 10000;
26
29
 
27
30
  export const formatDateTime = (date: Date) =>