@openpeepshq/react 0.9.1 → 0.9.22

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.
@@ -1,5 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { profileName } from '@openpeepshq/common';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { isConversationLeavePost, profileName } from '@openpeepshq/common';
3
3
  import { useT } from '../../i18n/index.js';
4
4
  import { usePostViewRef } from '../../lib/postViewCounter.js';
5
5
  import { isUnreadPostForViewer } from '../../lib/postUnread.js';
@@ -7,7 +7,6 @@ import { UpdatingDate } from '@openpeepshq/react-ui';
7
7
  import { Avatar } from '../profile/index.js';
8
8
  import { useCurrentProfile } from '../layout/IdentityContext.js';
9
9
  import { ConversationMessageBubble } from './ConversationMessageBubble.js';
10
- const inAudience = (post, profile) => !!post.audience?.some((p) => p.id === profile.id);
11
10
  const audienceDiff = (previous, message) => {
12
11
  const before = previous?.audience ?? [];
13
12
  const after = message.audience ?? [];
@@ -33,11 +32,14 @@ export function MessageInThread({ previous, message, multipleParticipants = true
33
32
  // The author leaving their own conversation is shown via the "left" label
34
33
  // below, so exclude them from the "removedBy" avatars to avoid redundancy.
35
34
  const removedOthers = removed.filter((p) => p.id !== message.profile.id);
35
+ // A leave post (isConversationLeavePost) renders only the "left" label
36
+ // (no message bubble); the view-ref moves to that label so the post is
37
+ // still marked seen. It holds even when the leave is the first loaded
38
+ // post, so no comparison against the previous post is needed.
39
+ const isLeave = isConversationLeavePost(message);
36
40
  const name = profileName(message.profile);
37
41
  const isMe = message.profile.id === me?.id;
38
- return (_jsxs("div", { "data-message-id": message.id, className: highlighted ? 'bg-muted ring-ring rounded-md ring-2' : undefined, children: [!previous && (_jsx("div", { className: "mt-2 w-full text-center text-sm", children: message.inReplyToId
42
+ return (_jsxs("div", { "data-message-id": message.id, className: highlighted ? 'bg-muted ring-ring rounded-md ring-2' : undefined, children: [!previous && !isLeave && (_jsx("div", { className: "mt-2 w-full text-center text-sm", children: message.inReplyToId
39
43
  ? t('conversations.messageInThread.addedBy', { name })
40
- : t('conversations.messageInThread.startedBy', { name }) })), previous &&
41
- inAudience(previous, message.profile) &&
42
- !inAudience(message, message.profile) && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Avatar, { profile: message.profile, size: 2.5, borderless: true, navigate: true }), t('conversations.messageInThread.left', { name })] })), previous && added.length > 0 && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex -space-x-2", children: added.map((p) => (_jsx(Avatar, { profile: p, size: 2.5, borderless: true, navigate: true }, p.id))) }), t('conversations.messageInThread.addedBy', { name })] })), removedOthers.length > 0 && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex -space-x-2", children: removedOthers.map((p) => (_jsx(Avatar, { profile: p, size: 2.5, borderless: true, navigate: true }, p.id))) }), t('conversations.messageInThread.removedBy', { name })] })), _jsxs("article", { ref: postViewRef, className: "flex", children: [!isMe && multipleParticipants && (_jsx(Avatar, { containerClassName: "mt-6 mr-2", profile: message.profile, size: 2.5, borderless: true, navigate: true })), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(ConversationMessageBubble, { message: message, unread: isUnread }) })] }), _jsxs("div", { className: `mt-2 w-full text-sm ${isMe ? 'text-right' : 'text-left'}`, children: [multipleParticipants && !isMe && _jsxs("span", { children: [name, " \u00B7 "] }), _jsx(UpdatingDate, { date: message.createdAt })] })] }));
44
+ : t('conversations.messageInThread.startedBy', { name }) })), isLeave && (_jsxs("article", { ref: postViewRef, className: "flex items-center gap-2", children: [_jsx(Avatar, { profile: message.profile, size: 2.5, borderless: true, navigate: true }), t('conversations.messageInThread.left', { name })] })), !isLeave && (_jsxs(_Fragment, { children: [previous && added.length > 0 && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex -space-x-2", children: added.map((p) => (_jsx(Avatar, { profile: p, size: 2.5, borderless: true, navigate: true }, p.id))) }), t('conversations.messageInThread.addedBy', { name })] })), removedOthers.length > 0 && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "flex -space-x-2", children: removedOthers.map((p) => (_jsx(Avatar, { profile: p, size: 2.5, borderless: true, navigate: true }, p.id))) }), t('conversations.messageInThread.removedBy', { name })] })), _jsxs("article", { ref: postViewRef, className: "flex", children: [!isMe && multipleParticipants && (_jsx(Avatar, { containerClassName: "mt-6 mr-2", profile: message.profile, size: 2.5, borderless: true, navigate: true })), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(ConversationMessageBubble, { message: message, unread: isUnread }) })] }), _jsxs("div", { className: `mt-2 w-full text-sm ${isMe ? 'text-right' : 'text-left'}`, children: [multipleParticipants && !isMe && _jsxs("span", { children: [name, " \u00B7 "] }), _jsx(UpdatingDate, { date: message.createdAt })] })] }))] }));
43
45
  }
@@ -0,0 +1,113 @@
1
+ /** @vitest-environment jsdom */
2
+ import { act, createElement } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { MessageInThread } from './MessageInThread.js';
6
+ const { postViewRef } = vi.hoisted(() => ({
7
+ postViewRef: { current: null },
8
+ }));
9
+ vi.mock('../../lib/postViewCounter', () => ({
10
+ usePostViewRef: () => postViewRef,
11
+ }));
12
+ vi.mock('../../i18n', () => {
13
+ const translations = {
14
+ 'conversations.messageInThread.startedBy': 'Started by {{name}}',
15
+ 'conversations.messageInThread.addedBy': 'Added by {{name}}',
16
+ 'conversations.messageInThread.left': '{{name}} left',
17
+ 'conversations.messageInThread.removedBy': 'Removed by {{name}}',
18
+ };
19
+ return {
20
+ useT: () => (key, opts) => (translations[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_match, name) => opts?.[name] ?? ''),
21
+ };
22
+ });
23
+ vi.mock('../layout/IdentityContext', () => ({
24
+ useCurrentProfile: () => undefined,
25
+ }));
26
+ vi.mock('../profile', () => ({
27
+ Avatar: () => null,
28
+ }));
29
+ vi.mock('./ConversationMessageBubble', () => ({
30
+ ConversationMessageBubble: () => createElement('div', { 'data-testid': 'message-bubble' }, 'message bubble'),
31
+ }));
32
+ vi.mock('@openpeepshq/react-ui', () => ({
33
+ UpdatingDate: () => createElement('time', null, 'a moment ago'),
34
+ }));
35
+ const bob = {
36
+ id: 'bob',
37
+ displayName: 'Bob',
38
+ handle: 'bob',
39
+ };
40
+ const alice = {
41
+ id: 'alice',
42
+ displayName: 'Alice',
43
+ handle: 'alice',
44
+ };
45
+ const post = (over = {}) => ({
46
+ id: 'post-1',
47
+ profile: bob,
48
+ audience: [alice, bob],
49
+ createdAt: '2026-01-01T00:00:00.000Z',
50
+ data: { type: 'note', content: 'hello' },
51
+ ...over,
52
+ });
53
+ describe('MessageInThread', () => {
54
+ let root;
55
+ let container;
56
+ beforeEach(() => {
57
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
58
+ postViewRef.current = null;
59
+ container = document.createElement('div');
60
+ document.body.appendChild(container);
61
+ root = createRoot(container);
62
+ });
63
+ afterEach(() => {
64
+ act(() => {
65
+ root?.unmount();
66
+ });
67
+ container?.remove();
68
+ root = undefined;
69
+ container = undefined;
70
+ });
71
+ const render = (element) => {
72
+ act(() => {
73
+ root?.render(element);
74
+ });
75
+ };
76
+ it('renders only the "left" label for a leave post and attaches the view ref to it', () => {
77
+ render(createElement(MessageInThread, {
78
+ previous: post({ id: 'prev-1' }),
79
+ message: post({ inReplyToId: 'prev-1', audience: [alice] }),
80
+ }));
81
+ expect(container?.textContent).toContain('Bob left');
82
+ expect(container?.textContent).not.toContain('Added by');
83
+ expect(container?.textContent).not.toContain('Removed by');
84
+ expect(container?.querySelector('[data-testid=message-bubble]')).toBeNull();
85
+ expect(postViewRef.current).not.toBeNull();
86
+ expect(postViewRef.current?.textContent).toContain('Bob left');
87
+ });
88
+ it('renders a leave post as "left" even when it is the first loaded post', () => {
89
+ render(createElement(MessageInThread, {
90
+ previous: undefined,
91
+ message: post({ inReplyToId: 'prev-1', audience: [alice] }),
92
+ }));
93
+ expect(container?.textContent).toContain('Bob left');
94
+ expect(container?.textContent).not.toContain('Added by');
95
+ expect(container?.querySelector('[data-testid=message-bubble]')).toBeNull();
96
+ });
97
+ it('renders a root post outside its own audience as a message, not a leave', () => {
98
+ render(createElement(MessageInThread, {
99
+ previous: undefined,
100
+ message: post({ audience: [alice] }),
101
+ }));
102
+ expect(container?.querySelector('[data-testid=message-bubble]')).not.toBeNull();
103
+ expect(container?.textContent).not.toContain('left');
104
+ });
105
+ it('renders a reply the author takes part in as a message', () => {
106
+ render(createElement(MessageInThread, {
107
+ previous: post({ id: 'prev-1' }),
108
+ message: post({ inReplyToId: 'prev-1' }),
109
+ }));
110
+ expect(container?.querySelector('[data-testid=message-bubble]')).not.toBeNull();
111
+ expect(container?.textContent).not.toContain('Bob left');
112
+ });
113
+ });
@@ -37,6 +37,20 @@ function JamRoomInner() {
37
37
  document.addEventListener('visibilitychange', onVisibility);
38
38
  return () => document.removeEventListener('visibilitychange', onVisibility);
39
39
  }, [reconnectPrefs, tryReconnect]);
40
+ // Warn before an accidental tab close drops the user from a live call;
41
+ // browsers ignore custom text. Armed while a session exists — connected
42
+ // or app-level reconnecting — so the guard survives the reconnection view
43
+ // where the conference (and any LiveKit-scoped guard) is unmounted.
44
+ useEffect(() => {
45
+ if (!connection && !reconnectPrefs)
46
+ return;
47
+ const onBeforeUnload = (event) => {
48
+ event.preventDefault();
49
+ event.returnValue = true;
50
+ };
51
+ window.addEventListener('beforeunload', onBeforeUnload);
52
+ return () => window.removeEventListener('beforeunload', onBeforeUnload);
53
+ }, [connection, reconnectPrefs]);
40
54
  if (!livekitEnabled) {
41
55
  return (_jsx("div", { className: "mx-auto flex h-full w-full items-center justify-center p-4", children: _jsxs("div", { className: "w-full max-w-md space-y-5 text-center", children: [_jsx("h3", { className: "text-lg", children: jamEvent.name }), _jsxs("div", { className: "bg-surface flex w-full flex-col items-center justify-center space-y-3 rounded border p-4", children: [_jsx(LivekitUnavailableNotice, {}), _jsx("a", { href: `/posts/${jamPost.id}`, className: "text-primary text-sm underline", children: t('jams.room.viewEvent', { defaultValue: 'View event' }) })] })] }) }));
42
56
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,120 @@
1
+ /** @vitest-environment jsdom */
2
+ import { act, createElement } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { JamRoom } from './JamRoom.js';
6
+ const roomStateRef = vi.hoisted(() => ({
7
+ connection: undefined,
8
+ reconnectPrefs: undefined,
9
+ }));
10
+ vi.mock('../../hooks/jams/useJamRoom', () => ({
11
+ useJamRoom: () => ({
12
+ me: undefined,
13
+ post: { id: 'post' },
14
+ jamPost: { id: 'post' },
15
+ jamEvent: { name: 'Test jam' },
16
+ observer: false,
17
+ occurrence: undefined,
18
+ livekitEnabled: true,
19
+ connection: roomStateRef.connection,
20
+ reconnectPrefs: roomStateRef.reconnectPrefs,
21
+ reconnectError: undefined,
22
+ observerError: undefined,
23
+ autoRsvpError: undefined,
24
+ shouldAutoRsvp: false,
25
+ capacityBlock: { blocked: false },
26
+ canDirectJoin: false,
27
+ canRequestJoin: false,
28
+ handleJoin: () => { },
29
+ handleDisconnected: () => { },
30
+ tryReconnect: () => { },
31
+ }),
32
+ }));
33
+ vi.mock('./JamContext', () => ({
34
+ JamProvider: ({ children }) => createElement('div', null, children),
35
+ }));
36
+ vi.mock('../../i18n', () => ({
37
+ useT: () => (_key, opts) => opts?.defaultValue ?? _key,
38
+ }));
39
+ vi.mock('./JamVideoCall', () => ({
40
+ JamVideoCall: () => null,
41
+ }));
42
+ const jamPost = { id: 'post' };
43
+ const fireBeforeUnload = () => {
44
+ const event = new Event('beforeunload', { cancelable: true });
45
+ window.dispatchEvent(event);
46
+ return event.defaultPrevented;
47
+ };
48
+ describe('JamRoom tab-close warning', () => {
49
+ let root;
50
+ let container;
51
+ beforeEach(() => {
52
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
53
+ roomStateRef.connection = undefined;
54
+ roomStateRef.reconnectPrefs = undefined;
55
+ });
56
+ afterEach(() => {
57
+ act(() => {
58
+ root?.unmount();
59
+ });
60
+ container?.remove();
61
+ root = undefined;
62
+ container = undefined;
63
+ });
64
+ const mount = () => {
65
+ container = document.createElement('div');
66
+ document.body.appendChild(container);
67
+ const newRoot = createRoot(container);
68
+ root = newRoot;
69
+ act(() => {
70
+ newRoot.render(createElement(JamRoom, { jamPost }));
71
+ });
72
+ return { root: newRoot };
73
+ };
74
+ const rerender = (target) => {
75
+ act(() => {
76
+ target.render(createElement(JamRoom, { jamPost }));
77
+ });
78
+ };
79
+ it('does not warn while no jam session exists', () => {
80
+ mount();
81
+ expect(fireBeforeUnload()).toBe(false);
82
+ });
83
+ it('warns while connected and stops after unmount', () => {
84
+ const { root: target } = mount();
85
+ expect(fireBeforeUnload()).toBe(false);
86
+ roomStateRef.connection = {
87
+ token: 'token',
88
+ livekitUrl: 'url',
89
+ audio: true,
90
+ video: true,
91
+ };
92
+ rerender(target);
93
+ expect(fireBeforeUnload()).toBe(true);
94
+ act(() => {
95
+ target.unmount();
96
+ });
97
+ expect(fireBeforeUnload()).toBe(false);
98
+ });
99
+ it('warns while the app-level reconnect view is showing', () => {
100
+ const { root: target } = mount();
101
+ roomStateRef.reconnectPrefs = { audio: true, video: true };
102
+ rerender(target);
103
+ expect(fireBeforeUnload()).toBe(true);
104
+ });
105
+ it('stops warning once the session ends', () => {
106
+ const { root: target } = mount();
107
+ roomStateRef.connection = {
108
+ token: 'token',
109
+ livekitUrl: 'url',
110
+ audio: true,
111
+ video: true,
112
+ };
113
+ rerender(target);
114
+ expect(fireBeforeUnload()).toBe(true);
115
+ roomStateRef.connection = undefined;
116
+ roomStateRef.reconnectPrefs = undefined;
117
+ rerender(target);
118
+ expect(fireBeforeUnload()).toBe(false);
119
+ });
120
+ });
@@ -23,7 +23,7 @@ export function AdminInvites() {
23
23
  return (_jsxs("div", { className: "p-4", children: [_jsx("form", { role: "search", className: "mb-4", onSubmit: (e) => {
24
24
  e.preventDefault();
25
25
  }, children: _jsx(Input, { placeholder: t('admin.invites.searchPlaceholder', {
26
- defaultValue: 'Search by name or email',
26
+ defaultValue: 'Search by name or handle',
27
27
  }), value: search, onChange: (e) => setSearch(e.target.value) }) }), filtered.length === 0 ? (_jsx("div", { className: "flex w-full items-center justify-center p-4", children: _jsx("h2", { className: "text-lg", children: t('admin.invites.noInvitesFound', {
28
28
  defaultValue: 'No invites found',
29
29
  }) }) })) : (_jsx("div", { className: "rounded-md border", children: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { className: "bg-surface", children: _jsxs("tr", { children: [_jsx("th", { className: "p-2 text-left", children: t('admin.invites.linkColumn', { defaultValue: 'Link' }) }), _jsx("th", { className: "p-2 text-left", children: t('admin.invites.createdByColumn', {
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useMemo, useState } from 'react';
3
3
  import { useNavigate } from 'react-router-dom';
4
4
  import { MessageCircleOff, Calendar, MessageSquarePlus } from 'lucide-react';
5
- import { canCreatePost, formatBadgeCount, truncateText, } from '@openpeepshq/common';
5
+ import { canCreatePost, formatBadgeCount, isConversationLeavePost, profileName, truncateText, } from '@openpeepshq/common';
6
6
  import { useT, useOpenpeeps, useSetPlusButtonActions, useSetPageHeader, } from '../../index.js';
7
7
  import { Avatar, DirectMessageSearch, PostMarkdown, useAuthData, useCurrentProfile, useCreateNewConversation, AccessDeniedLoader, } from '../../components/index.js';
8
8
  import { UpdatingDate } from '@openpeepshq/react-ui';
@@ -13,6 +13,9 @@ function ChatPreview({ conversation, unreadCount = 0, }) {
13
13
  if (!lastMessage)
14
14
  return null;
15
15
  const participants = lastMessage.audience ?? [];
16
+ // A leave post (isConversationLeavePost) leaves its author out of the
17
+ // audience; show an "X left" preview instead of an empty message.
18
+ const isLeave = isConversationLeavePost(lastMessage);
16
19
  const otherNames = participants
17
20
  .filter((p) => p.id !== me?.id)
18
21
  .map((p) => p.displayName || `@${p.handle}`)
@@ -23,7 +26,9 @@ function ChatPreview({ conversation, unreadCount = 0, }) {
23
26
  names: otherNames,
24
27
  })
25
28
  : t('common.you', { defaultValue: 'You' });
26
- return (_jsxs("article", { className: "flex w-full flex-col gap-x-1 border-b p-3 text-left sm:p-4", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx("div", { className: "flex -space-x-2", children: participants.slice(0, 3).map((p) => (_jsx(Avatar, { profile: p, size: 2.5, borderless: true }, p.id))) }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [_jsx("span", { className: "truncate font-bold", children: truncateText(title, 20) }), unreadCount > 0 ? (_jsx("span", { className: "bg-destructive text-destructive-foreground flex size-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1 text-xs font-semibold", "aria-label": `${unreadCount} unread messages`, children: formatBadgeCount(unreadCount) })) : null] })] }), _jsx("span", { className: "text-muted-foreground text-sm", children: _jsx(UpdatingDate, { date: lastMessage.createdAt }) }), _jsxs("div", { className: "mt-2 flex flex-row items-start gap-x-2 overflow-hidden text-sm", children: [_jsxs("div", { className: "flex flex-row items-center", children: [_jsx("span", { children: "~" }), me?.id === lastMessage.profile.id ? (_jsx("span", { className: "ml-1", children: "Me" })) : (_jsxs("span", { className: "ml-1", children: ["@", truncateText(lastMessage.profile.handle, 8)] })), _jsx("span", { className: "mx-1", children: ":" })] }), lastMessage.data?.type === 'event' ? (_jsxs(_Fragment, { children: [_jsx(Calendar, { className: "size-4" }), lastMessage.data.name] })) : (_jsx(PostMarkdown, { source: lastMessage.data.content || '' }))] })] }));
29
+ return (_jsxs("article", { className: "flex w-full flex-col gap-x-1 border-b p-3 text-left sm:p-4", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx("div", { className: "flex -space-x-2", children: participants.slice(0, 3).map((p) => (_jsx(Avatar, { profile: p, size: 2.5, borderless: true }, p.id))) }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-2", children: [_jsx("span", { className: "truncate font-bold", children: truncateText(title, 20) }), unreadCount > 0 ? (_jsx("span", { className: "bg-destructive text-destructive-foreground flex size-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1 text-xs font-semibold", "aria-label": `${unreadCount} unread messages`, children: formatBadgeCount(unreadCount) })) : null] })] }), _jsx("span", { className: "text-muted-foreground text-sm", children: _jsx(UpdatingDate, { date: lastMessage.createdAt }) }), _jsx("div", { className: "mt-2 flex flex-row items-start gap-x-2 overflow-hidden text-sm", children: isLeave ? (_jsx("span", { className: "text-muted-foreground", children: t('conversations.messageInThread.left', {
30
+ name: profileName(lastMessage.profile),
31
+ }) })) : (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex flex-row items-center", children: [_jsx("span", { children: "~" }), me?.id === lastMessage.profile.id ? (_jsx("span", { className: "ml-1", children: t('common.you', { defaultValue: 'You' }) })) : (_jsxs("span", { className: "ml-1", children: ["@", truncateText(lastMessage.profile.handle, 8)] })), _jsx("span", { className: "mx-1", children: ":" })] }), lastMessage.data?.type === 'event' ? (_jsxs(_Fragment, { children: [_jsx(Calendar, { className: "size-4" }), lastMessage.data.name] })) : (_jsx(PostMarkdown, { source: lastMessage.data.content || '' }))] })) })] }));
27
32
  }
28
33
  function TabButton({ onClick, className, children, }) {
29
34
  return (_jsx("button", { type: "button", onClick: onClick, className: `px-4 py-2 text-sm ${className ?? ''}`, children: children }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/react",
3
- "version": "0.9.1",
3
+ "version": "0.9.22",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,9 +52,9 @@
52
52
  "simple-icons": "^16.31.0",
53
53
  "uuidv7": "^1.0.2",
54
54
  "@openpeepshq/client": "^0.3.0",
55
+ "@openpeepshq/common": "^0.5.12",
55
56
  "@openpeepshq/greenscreen": "^0.2.1",
56
- "@openpeepshq/react-ui": "^0.4.1",
57
- "@openpeepshq/common": "^0.5.0"
57
+ "@openpeepshq/react-ui": "^0.4.1"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": "^18.3.0 || ^19.0.0",
@@ -1,5 +1,5 @@
1
- import type { PublicPost, PublicProfile } from '@openpeepshq/common/types';
2
- import { profileName } from '@openpeepshq/common';
1
+ import type { PublicPost } from '@openpeepshq/common/types';
2
+ import { isConversationLeavePost, profileName } from '@openpeepshq/common';
3
3
  import { useT } from '../../i18n';
4
4
  import { usePostViewRef } from '../../lib/postViewCounter';
5
5
  import { isUnreadPostForViewer } from '../../lib/postUnread';
@@ -8,9 +8,6 @@ import { Avatar } from '../profile';
8
8
  import { useCurrentProfile } from '../layout/IdentityContext';
9
9
  import { ConversationMessageBubble } from './ConversationMessageBubble';
10
10
 
11
- const inAudience = (post: PublicPost, profile: PublicProfile) =>
12
- !!post.audience?.some((p) => p.id === profile.id);
13
-
14
11
  const audienceDiff = (
15
12
  previous: PublicPost | undefined,
16
13
  message: PublicPost,
@@ -54,6 +51,11 @@ export function MessageInThread({
54
51
  // The author leaving their own conversation is shown via the "left" label
55
52
  // below, so exclude them from the "removedBy" avatars to avoid redundancy.
56
53
  const removedOthers = removed.filter((p) => p.id !== message.profile.id);
54
+ // A leave post (isConversationLeavePost) renders only the "left" label
55
+ // (no message bubble); the view-ref moves to that label so the post is
56
+ // still marked seen. It holds even when the leave is the first loaded
57
+ // post, so no comparison against the previous post is needed.
58
+ const isLeave = isConversationLeavePost(message);
57
59
  const name = profileName(message.profile);
58
60
  const isMe = message.profile.id === me?.id;
59
61
 
@@ -64,7 +66,7 @@ export function MessageInThread({
64
66
  highlighted ? 'bg-muted ring-ring rounded-md ring-2' : undefined
65
67
  }
66
68
  >
67
- {!previous && (
69
+ {!previous && !isLeave && (
68
70
  <div className="mt-2 w-full text-center text-sm">
69
71
  {message.inReplyToId
70
72
  ? t('conversations.messageInThread.addedBy', { name })
@@ -72,58 +74,72 @@ export function MessageInThread({
72
74
  </div>
73
75
  )}
74
76
 
75
- {previous &&
76
- inAudience(previous, message.profile) &&
77
- !inAudience(message, message.profile) && (
78
- <div className="flex items-center gap-2">
79
- <Avatar profile={message.profile} size={2.5} borderless navigate />
80
- {t('conversations.messageInThread.left', { name })}
81
- </div>
82
- )}
83
-
84
- {previous && added.length > 0 && (
85
- <div className="flex items-center gap-2">
86
- <div className="flex -space-x-2">
87
- {added.map((p) => (
88
- <Avatar key={p.id} profile={p} size={2.5} borderless navigate />
89
- ))}
90
- </div>
91
- {t('conversations.messageInThread.addedBy', { name })}
92
- </div>
77
+ {isLeave && (
78
+ <article ref={postViewRef} className="flex items-center gap-2">
79
+ <Avatar profile={message.profile} size={2.5} borderless navigate />
80
+ {t('conversations.messageInThread.left', { name })}
81
+ </article>
93
82
  )}
94
83
 
95
- {removedOthers.length > 0 && (
96
- <div className="flex items-center gap-2">
97
- <div className="flex -space-x-2">
98
- {removedOthers.map((p) => (
99
- <Avatar key={p.id} profile={p} size={2.5} borderless navigate />
100
- ))}
101
- </div>
102
- {t('conversations.messageInThread.removedBy', { name })}
103
- </div>
104
- )}
84
+ {!isLeave && (
85
+ <>
86
+ {previous && added.length > 0 && (
87
+ <div className="flex items-center gap-2">
88
+ <div className="flex -space-x-2">
89
+ {added.map((p) => (
90
+ <Avatar
91
+ key={p.id}
92
+ profile={p}
93
+ size={2.5}
94
+ borderless
95
+ navigate
96
+ />
97
+ ))}
98
+ </div>
99
+ {t('conversations.messageInThread.addedBy', { name })}
100
+ </div>
101
+ )}
105
102
 
106
- <article ref={postViewRef} className="flex">
107
- {!isMe && multipleParticipants && (
108
- <Avatar
109
- containerClassName="mt-6 mr-2"
110
- profile={message.profile}
111
- size={2.5}
112
- borderless
113
- navigate
114
- />
115
- )}
116
- <div className="min-w-0 flex-1">
117
- <ConversationMessageBubble message={message} unread={isUnread} />
118
- </div>
119
- </article>
103
+ {removedOthers.length > 0 && (
104
+ <div className="flex items-center gap-2">
105
+ <div className="flex -space-x-2">
106
+ {removedOthers.map((p) => (
107
+ <Avatar
108
+ key={p.id}
109
+ profile={p}
110
+ size={2.5}
111
+ borderless
112
+ navigate
113
+ />
114
+ ))}
115
+ </div>
116
+ {t('conversations.messageInThread.removedBy', { name })}
117
+ </div>
118
+ )}
120
119
 
121
- <div
122
- className={`mt-2 w-full text-sm ${isMe ? 'text-right' : 'text-left'}`}
123
- >
124
- {multipleParticipants && !isMe && <span>{name} &middot; </span>}
125
- <UpdatingDate date={message.createdAt} />
126
- </div>
120
+ <article ref={postViewRef} className="flex">
121
+ {!isMe && multipleParticipants && (
122
+ <Avatar
123
+ containerClassName="mt-6 mr-2"
124
+ profile={message.profile}
125
+ size={2.5}
126
+ borderless
127
+ navigate
128
+ />
129
+ )}
130
+ <div className="min-w-0 flex-1">
131
+ <ConversationMessageBubble message={message} unread={isUnread} />
132
+ </div>
133
+ </article>
134
+
135
+ <div
136
+ className={`mt-2 w-full text-sm ${isMe ? 'text-right' : 'text-left'}`}
137
+ >
138
+ {multipleParticipants && !isMe && <span>{name} &middot; </span>}
139
+ <UpdatingDate date={message.createdAt} />
140
+ </div>
141
+ </>
142
+ )}
127
143
  </div>
128
144
  );
129
145
  }
@@ -76,6 +76,20 @@ function JamRoomInner() {
76
76
  return () => document.removeEventListener('visibilitychange', onVisibility);
77
77
  }, [reconnectPrefs, tryReconnect]);
78
78
 
79
+ // Warn before an accidental tab close drops the user from a live call;
80
+ // browsers ignore custom text. Armed while a session exists — connected
81
+ // or app-level reconnecting — so the guard survives the reconnection view
82
+ // where the conference (and any LiveKit-scoped guard) is unmounted.
83
+ useEffect(() => {
84
+ if (!connection && !reconnectPrefs) return;
85
+ const onBeforeUnload = (event: BeforeUnloadEvent) => {
86
+ event.preventDefault();
87
+ event.returnValue = true;
88
+ };
89
+ window.addEventListener('beforeunload', onBeforeUnload);
90
+ return () => window.removeEventListener('beforeunload', onBeforeUnload);
91
+ }, [connection, reconnectPrefs]);
92
+
79
93
  if (!livekitEnabled) {
80
94
  return (
81
95
  <div className="mx-auto flex h-full w-full items-center justify-center p-4">
@@ -64,7 +64,7 @@ export function AdminInvites() {
64
64
  >
65
65
  <Input
66
66
  placeholder={t('admin.invites.searchPlaceholder', {
67
- defaultValue: 'Search by name or email',
67
+ defaultValue: 'Search by name or handle',
68
68
  })}
69
69
  value={search}
70
70
  onChange={(e) => setSearch(e.target.value)}
@@ -5,6 +5,8 @@ import type { PublicPost } from '@openpeepshq/common/types';
5
5
  import {
6
6
  canCreatePost,
7
7
  formatBadgeCount,
8
+ isConversationLeavePost,
9
+ profileName,
8
10
  truncateText,
9
11
  } from '@openpeepshq/common';
10
12
  import {
@@ -36,6 +38,9 @@ function ChatPreview({
36
38
  const lastMessage = conversation[conversation.length - 1];
37
39
  if (!lastMessage) return null;
38
40
  const participants = lastMessage.audience ?? [];
41
+ // A leave post (isConversationLeavePost) leaves its author out of the
42
+ // audience; show an "X left" preview instead of an empty message.
43
+ const isLeave = isConversationLeavePost(lastMessage);
39
44
 
40
45
  const otherNames = participants
41
46
  .filter((p) => p.id !== me?.id)
@@ -73,26 +78,40 @@ function ChatPreview({
73
78
  </span>
74
79
 
75
80
  <div className="mt-2 flex flex-row items-start gap-x-2 overflow-hidden text-sm">
76
- <div className="flex flex-row items-center">
77
- <span>~</span>
78
- {me?.id === lastMessage.profile.id ? (
79
- <span className="ml-1">Me</span>
80
- ) : (
81
- <span className="ml-1">
82
- @{truncateText(lastMessage.profile.handle, 8)}
83
- </span>
84
- )}
85
- <span className="mx-1">:</span>
86
- </div>
87
- {lastMessage.data?.type === 'event' ? (
81
+ {isLeave ? (
82
+ <span className="text-muted-foreground">
83
+ {t('conversations.messageInThread.left', {
84
+ name: profileName(lastMessage.profile),
85
+ })}
86
+ </span>
87
+ ) : (
88
88
  <>
89
- <Calendar className="size-4" />
90
- {(lastMessage.data as { name?: string }).name}
89
+ <div className="flex flex-row items-center">
90
+ <span>~</span>
91
+ {me?.id === lastMessage.profile.id ? (
92
+ <span className="ml-1">
93
+ {t('common.you', { defaultValue: 'You' })}
94
+ </span>
95
+ ) : (
96
+ <span className="ml-1">
97
+ @{truncateText(lastMessage.profile.handle, 8)}
98
+ </span>
99
+ )}
100
+ <span className="mx-1">:</span>
101
+ </div>
102
+ {lastMessage.data?.type === 'event' ? (
103
+ <>
104
+ <Calendar className="size-4" />
105
+ {(lastMessage.data as { name?: string }).name}
106
+ </>
107
+ ) : (
108
+ <PostMarkdown
109
+ source={
110
+ (lastMessage.data as { content?: string }).content || ''
111
+ }
112
+ />
113
+ )}
91
114
  </>
92
- ) : (
93
- <PostMarkdown
94
- source={(lastMessage.data as { content?: string }).content || ''}
95
- />
96
115
  )}
97
116
  </div>
98
117
  </article>