@openpeepshq/react 0.8.6 → 0.9.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/components/conversations/DirectMessageSearch.d.ts +7 -0
- package/dist/components/conversations/DirectMessageSearch.js +46 -0
- package/dist/components/conversations/MessageInThread.d.ts +2 -1
- package/dist/components/conversations/MessageInThread.js +3 -3
- package/dist/components/conversations/index.d.ts +1 -0
- package/dist/components/conversations/index.js +1 -0
- package/dist/contexts/openpeeps/hooks/conversations.d.ts +3 -2
- package/dist/contexts/openpeeps/hooks/conversations.js +8 -1
- package/dist/pages/admin/ConfigurationCommunity.js +1 -1
- package/dist/pages/admin/community/CommunityAccess.d.ts +6 -0
- package/dist/pages/admin/community/CommunityAccess.js +60 -0
- package/dist/pages/conversations/Index.js +17 -11
- package/dist/pages/conversations/Show.js +63 -12
- package/dist/pages/index.d.ts +1 -0
- package/dist/pages/index.js +1 -0
- package/package.json +5 -5
- package/src/components/conversations/DirectMessageSearch.tsx +130 -0
- package/src/components/conversations/MessageInThread.tsx +9 -2
- package/src/components/conversations/index.ts +1 -0
- package/src/contexts/openpeeps/hooks/conversations.ts +16 -3
- package/src/pages/admin/ConfigurationCommunity.tsx +4 -0
- package/src/pages/admin/community/CommunityAccess.tsx +129 -0
- package/src/pages/conversations/Index.tsx +51 -32
- package/src/pages/conversations/Show.tsx +97 -18
- package/src/pages/index.ts +1 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type DirectMessageSearchHit } from '@openpeepshq/common';
|
|
2
|
+
export declare const DirectMessageSearch: ({ conversationId, autoFocus, onQueryChange, onSelect, }: {
|
|
3
|
+
conversationId?: string;
|
|
4
|
+
autoFocus?: boolean;
|
|
5
|
+
onQueryChange?: (query: string) => void;
|
|
6
|
+
onSelect: (hit: DirectMessageSearchHit) => void;
|
|
7
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { conversationLabel, messagePreviewText, profileName, } from '@openpeepshq/common';
|
|
4
|
+
import { Input, UpdatingDate } from '@openpeepshq/react-ui';
|
|
5
|
+
import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
|
|
6
|
+
import { useT } from '../../i18n/index.js';
|
|
7
|
+
import { useCurrentProfile } from '../layout/IdentityContext.js';
|
|
8
|
+
export const DirectMessageSearch = ({ conversationId, autoFocus, onQueryChange, onSelect, }) => {
|
|
9
|
+
const t = useT();
|
|
10
|
+
const me = useCurrentProfile();
|
|
11
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
12
|
+
const [input, setInput] = useState('');
|
|
13
|
+
const [query, setQuery] = useState('');
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const handle = setTimeout(() => setQuery(input.trim()), 300);
|
|
16
|
+
return () => clearTimeout(handle);
|
|
17
|
+
}, [input]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
onQueryChange?.(query);
|
|
20
|
+
}, [query, onQueryChange]);
|
|
21
|
+
const search = openpeepsApi.useSearchDirectMessages(query, conversationId);
|
|
22
|
+
const active = query.length >= 2;
|
|
23
|
+
const hits = search.data ?? [];
|
|
24
|
+
const placeholder = conversationId
|
|
25
|
+
? t('conversations.search.inConversation', {
|
|
26
|
+
defaultValue: 'Search this conversation…',
|
|
27
|
+
})
|
|
28
|
+
: t('conversations.search.placeholder', {
|
|
29
|
+
defaultValue: 'Search all messages…',
|
|
30
|
+
});
|
|
31
|
+
return (_jsxs("form", { role: "search", className: "border-border space-y-2 border-b p-3", onSubmit: (event) => event.preventDefault(), children: [_jsx(Input, { type: "search", value: input, onChange: (event) => setInput(event.target.value), placeholder: placeholder, "aria-label": placeholder, autoFocus: autoFocus, "data-testid": "dm-search-input" }), active && search.isFetching ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t('conversations.search.searching', { defaultValue: 'Searching…' }) })) : null, active && search.isError ? (_jsx("p", { className: "text-destructive text-sm", children: t('conversations.search.error', { defaultValue: 'Search failed' }) })) : null, active && !search.isFetching && !search.isError && hits.length === 0 ? (_jsx("p", { className: "text-muted-foreground text-sm", children: t('conversations.search.empty', {
|
|
32
|
+
defaultValue: 'No messages match "{{query}}"',
|
|
33
|
+
query,
|
|
34
|
+
}) })) : null, active && hits.length > 0 ? (_jsx("ul", { "aria-label": t('conversations.search.results', {
|
|
35
|
+
defaultValue: 'Message search results',
|
|
36
|
+
}), className: "max-h-64 overflow-y-auto", "data-testid": "dm-search-results", children: hits.map((hit) => {
|
|
37
|
+
const senderId = hit.message.profile.id;
|
|
38
|
+
const sender = senderId === me?.id
|
|
39
|
+
? t('common.you', { defaultValue: 'You' })
|
|
40
|
+
: profileName(hit.message.profile);
|
|
41
|
+
const others = conversationLabel(hit.message, me?.id);
|
|
42
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", className: "hover:bg-surface w-full rounded-md px-2 py-2 text-left", title: t('conversations.search.openResult', {
|
|
43
|
+
defaultValue: 'Show this message',
|
|
44
|
+
}), "data-testid": "dm-search-result", onClick: () => onSelect(hit), children: [!conversationId && others ? (_jsx("span", { className: "block truncate text-sm font-semibold", children: others })) : null, _jsxs("span", { className: "text-muted-foreground block truncate text-sm", children: [sender, ' · ', _jsx(UpdatingDate, { date: hit.message.createdAt })] }), _jsx("span", { className: "line-clamp-2 text-sm", children: messagePreviewText(hit.message) })] }) }, hit.message.id));
|
|
45
|
+
}) })) : null] }));
|
|
46
|
+
};
|
|
@@ -4,10 +4,11 @@ export interface MessageInThreadProps {
|
|
|
4
4
|
message: PublicPost;
|
|
5
5
|
multipleParticipants?: boolean;
|
|
6
6
|
conversationRootId?: string;
|
|
7
|
+
highlighted?: boolean;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Translation of `@openpeepshq/svelte` `MessageInThread.svelte`: renders a single
|
|
10
11
|
* thread message together with the participant system messages (started/added/
|
|
11
12
|
* left/removed) derived from how the audience changed between posts.
|
|
12
13
|
*/
|
|
13
|
-
export declare function MessageInThread({ previous, message, multipleParticipants, conversationRootId, }: MessageInThreadProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function MessageInThread({ previous, message, multipleParticipants, conversationRootId, highlighted, }: MessageInThreadProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { profileName } from '@openpeepshq/common';
|
|
3
3
|
import { useT } from '../../i18n/index.js';
|
|
4
4
|
import { usePostViewRef } from '../../lib/postViewCounter.js';
|
|
@@ -21,7 +21,7 @@ const audienceDiff = (previous, message) => {
|
|
|
21
21
|
* thread message together with the participant system messages (started/added/
|
|
22
22
|
* left/removed) derived from how the audience changed between posts.
|
|
23
23
|
*/
|
|
24
|
-
export function MessageInThread({ previous, message, multipleParticipants = true, conversationRootId, }) {
|
|
24
|
+
export function MessageInThread({ previous, message, multipleParticipants = true, conversationRootId, highlighted = false, }) {
|
|
25
25
|
const t = useT();
|
|
26
26
|
const me = useCurrentProfile();
|
|
27
27
|
const isUnread = isUnreadPostForViewer(message, me?.id);
|
|
@@ -35,7 +35,7 @@ export function MessageInThread({ previous, message, multipleParticipants = true
|
|
|
35
35
|
const removedOthers = removed.filter((p) => p.id !== message.profile.id);
|
|
36
36
|
const name = profileName(message.profile);
|
|
37
37
|
const isMe = message.profile.id === me?.id;
|
|
38
|
-
return (_jsxs(
|
|
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
|
|
39
39
|
? t('conversations.messageInThread.addedBy', { name })
|
|
40
40
|
: t('conversations.messageInThread.startedBy', { name }) })), previous &&
|
|
41
41
|
inAudience(previous, message.profile) &&
|
|
@@ -2,6 +2,7 @@ export { CreateNewConversation } from './CreateNewConversation';
|
|
|
2
2
|
export type { CreateNewConversationProps } from './CreateNewConversation';
|
|
3
3
|
export { CreateNewConversationProvider, useCreateNewConversation, } from './CreateNewConversationContext';
|
|
4
4
|
export type { CreateConversationOptions } from './CreateNewConversationContext';
|
|
5
|
+
export { DirectMessageSearch } from './DirectMessageSearch';
|
|
5
6
|
export { DirectMessagesHeaderActions } from './DirectMessagesHeaderActions';
|
|
6
7
|
export { ConversationParticipantsModal } from './ConversationParticipantsModal';
|
|
7
8
|
export type { ConversationParticipantsModalProps } from './ConversationParticipantsModal';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { CreateNewConversation } from './CreateNewConversation.js';
|
|
2
2
|
export { CreateNewConversationProvider, useCreateNewConversation, } from './CreateNewConversationContext.js';
|
|
3
|
+
export { DirectMessageSearch } from './DirectMessageSearch.js';
|
|
3
4
|
export { DirectMessagesHeaderActions } from './DirectMessagesHeaderActions.js';
|
|
4
5
|
export { ConversationParticipantsModal } from './ConversationParticipantsModal.js';
|
|
5
6
|
export { ConversationMessageBubble } from './ConversationMessageBubble.js';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { OpenpeepsClient } from '@openpeepshq/client';
|
|
2
|
-
import type { PostCreationData, PublicPost, SuccessFailureResponse, SuccessResponse } from '@openpeepshq/common';
|
|
2
|
+
import type { DirectMessageSearchHit, PostCreationData, PublicPost, SuccessFailureResponse, SuccessResponse } from '@openpeepshq/common';
|
|
3
3
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
type Query<T> = UseQueryResult<T, SuccessFailureResponse>;
|
|
5
5
|
export type ConversationHooks = {
|
|
6
6
|
useConversations: () => Query<PublicPost[][]>;
|
|
7
7
|
useArchivedConversations: () => Query<PublicPost[][]>;
|
|
8
|
-
useConversation: (id: string) => Query<PublicPost[]>;
|
|
8
|
+
useConversation: (id: string, messageId?: string) => Query<PublicPost[]>;
|
|
9
|
+
useSearchDirectMessages: (q: string, conversationId?: string) => Query<DirectMessageSearchHit[]>;
|
|
9
10
|
createConversationPostAction: (defaultPathParams?: {
|
|
10
11
|
id: string;
|
|
11
12
|
}) => (input: PostCreationData) => Promise<PublicPost>;
|
|
@@ -4,7 +4,14 @@ export const conversationHooks = (client) => ({
|
|
|
4
4
|
useArchivedConversations: () => client.conversations.archived
|
|
5
5
|
? apiHook(client.conversations.archived)
|
|
6
6
|
: { data: [], isPending: false },
|
|
7
|
-
useConversation: (id) => apiHook(client.conversations.findById, {
|
|
7
|
+
useConversation: (id, messageId) => apiHook(client.conversations.findById, {
|
|
8
|
+
pathParams: { id },
|
|
9
|
+
queryParams: messageId ? { message: messageId } : undefined,
|
|
10
|
+
}),
|
|
11
|
+
useSearchDirectMessages: (q, conversationId) => apiHook(client.conversations.search, {
|
|
12
|
+
queryParams: conversationId ? { q, conversationId } : { q },
|
|
13
|
+
enabled: q.trim().length >= 2,
|
|
14
|
+
}),
|
|
8
15
|
createConversationPostAction: payloadMutation(client.conversations.newPost, [
|
|
9
16
|
['conversations'],
|
|
10
17
|
]),
|
|
@@ -3,5 +3,5 @@ import { useSetPageHeader } from '../../index.js';
|
|
|
3
3
|
import { ConfigMenuButton } from '../../components/index.js';
|
|
4
4
|
export function AdminConfigurationCommunity() {
|
|
5
5
|
useSetPageHeader('Community Customization');
|
|
6
|
-
return (_jsxs("div", { className: "p-4", children: [_jsx(ConfigMenuButton, { translationPrefix: "configuration.community.info", action: "/admin/configuration/community/info" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.favicons", action: "/admin/configuration/community/favicons" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.theme", action: "/admin/configuration/community/theme" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomePage", action: "/admin/configuration/community/welcome-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.codeOfConduct", action: "/admin/configuration/community/code-of-conduct" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomeEmail", action: "/admin/configuration/community/welcome-email" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.aboutPage", action: "/admin/configuration/community/about-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.links", action: "/admin/configuration/community/links" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.profileFields", action: "/admin/configuration/community/profile-fields" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.forbiddenUsernames", action: "/admin/configuration/community/forbidden-usernames", testId: "admin-community-forbidden-usernames" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.roles", action: "/admin/configuration/community/roles" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.language", action: "/admin/configuration/community/language" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.timezone", action: "/admin/configuration/community/timezone" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.feed", action: "/admin/configuration/community/feed" })] }));
|
|
6
|
+
return (_jsxs("div", { className: "p-4", children: [_jsx(ConfigMenuButton, { translationPrefix: "configuration.community.info", action: "/admin/configuration/community/info" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.access", action: "/admin/configuration/community/access" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.favicons", action: "/admin/configuration/community/favicons" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.theme", action: "/admin/configuration/community/theme" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomePage", action: "/admin/configuration/community/welcome-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.codeOfConduct", action: "/admin/configuration/community/code-of-conduct" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.welcomeEmail", action: "/admin/configuration/community/welcome-email" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.aboutPage", action: "/admin/configuration/community/about-page" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.links", action: "/admin/configuration/community/links" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.profileFields", action: "/admin/configuration/community/profile-fields" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.forbiddenUsernames", action: "/admin/configuration/community/forbidden-usernames", testId: "admin-community-forbidden-usernames" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.roles", action: "/admin/configuration/community/roles" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.language", action: "/admin/configuration/community/language" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.timezone", action: "/admin/configuration/community/timezone" }), _jsx(ConfigMenuButton, { translationPrefix: "configuration.community.feed", action: "/admin/configuration/community/feed" })] }));
|
|
7
7
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open signups and public content live in the `openpeeps.core` config under
|
|
3
|
+
* `server.*`, but are surfaced here (under Community Customization) so an
|
|
4
|
+
* admin can update them without opening the raw Server settings tree editor.
|
|
5
|
+
*/
|
|
6
|
+
export declare function AdminConfigurationCommunityAccess(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import {} from '@openpeepshq/common/types';
|
|
4
|
+
import { useT, useSetPageHeader, useOpenpeeps, diffConfigTrees, } from '../../../index.js';
|
|
5
|
+
import { Label, Switch, Toast } from '@openpeepshq/react-ui';
|
|
6
|
+
/**
|
|
7
|
+
* Open signups and public content live in the `openpeeps.core` config under
|
|
8
|
+
* `server.*`, but are surfaced here (under Community Customization) so an
|
|
9
|
+
* admin can update them without opening the raw Server settings tree editor.
|
|
10
|
+
*/
|
|
11
|
+
export function AdminConfigurationCommunityAccess() {
|
|
12
|
+
const t = useT();
|
|
13
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
14
|
+
const configQuery = openpeepsApi.admin.useConfigRead('openpeeps', 'core');
|
|
15
|
+
const updateConfig = openpeepsApi.admin.updateConfigAction({
|
|
16
|
+
namespace: 'openpeeps',
|
|
17
|
+
name: 'core',
|
|
18
|
+
});
|
|
19
|
+
useSetPageHeader(t('configuration.community.access.title', { defaultValue: 'Access' }));
|
|
20
|
+
const base = configQuery.data?.config;
|
|
21
|
+
const [status, setStatus] = useState(null);
|
|
22
|
+
const signUpsOpen = base?.server?.signUpsOpen ?? true;
|
|
23
|
+
const publicContent = base?.server?.publicContent ?? false;
|
|
24
|
+
const persist = async (patch) => {
|
|
25
|
+
if (!base)
|
|
26
|
+
return;
|
|
27
|
+
setStatus(null);
|
|
28
|
+
try {
|
|
29
|
+
const diff = diffConfigTrees(base.server, patch);
|
|
30
|
+
if (Object.keys(diff).length === 0)
|
|
31
|
+
return;
|
|
32
|
+
await updateConfig({
|
|
33
|
+
config: { server: diff },
|
|
34
|
+
});
|
|
35
|
+
setStatus({
|
|
36
|
+
type: 'success',
|
|
37
|
+
message: t('configuration.community.access.updated', {
|
|
38
|
+
defaultValue: 'Access settings updated',
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
setStatus({ type: 'error', message: err.message });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
if (configQuery.isLoading || !base) {
|
|
47
|
+
return (_jsx("div", { className: "text-muted-foreground flex h-32 items-center justify-center text-sm", children: t('common.form.loading', { defaultValue: 'Loading…' }) }));
|
|
48
|
+
}
|
|
49
|
+
return (_jsxs("div", { className: "space-y-6 p-4", children: [_jsx("p", { className: "text-muted-foreground text-sm", children: t('configuration.community.access.description', {
|
|
50
|
+
defaultValue: 'Control who can join your community and who can see it',
|
|
51
|
+
}) }), _jsx(Label, { title: t('configuration.community.openRegistrations.title', {
|
|
52
|
+
defaultValue: 'Open Signups',
|
|
53
|
+
}), description: t('configuration.community.openRegistrations.description', {
|
|
54
|
+
defaultValue: 'Allow visitors to sign up for the community',
|
|
55
|
+
}), forCheckbox: true, children: _jsx(Switch, { checked: signUpsOpen, onCheckedChange: (next) => void persist({ ...base.server, signUpsOpen: next }), "data-testid": "admin-community-access-signups" }) }), _jsx(Label, { title: t('configuration.community.publicContent.title', {
|
|
56
|
+
defaultValue: 'Public content',
|
|
57
|
+
}), description: t('configuration.community.publicContent.description', {
|
|
58
|
+
defaultValue: 'Allow visitors to read public posts without an account',
|
|
59
|
+
}), forCheckbox: true, children: _jsx(Switch, { checked: publicContent, onCheckedChange: (next) => void persist({ ...base.server, publicContent: next }), "data-testid": "admin-community-access-public-content" }) }), status ? (_jsx(Toast, { variant: status.type, testId: "admin-community-access-toast", onDismiss: () => setStatus(null), children: status.message })) : null] }));
|
|
60
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from 'react';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
4
|
import { MessageCircleOff, Calendar, MessageSquarePlus } from 'lucide-react';
|
|
4
5
|
import { canCreatePost, formatBadgeCount, truncateText, } from '@openpeepshq/common';
|
|
5
6
|
import { useT, useOpenpeeps, useSetPlusButtonActions, useSetPageHeader, } from '../../index.js';
|
|
6
|
-
import { Avatar, PostMarkdown, useAuthData, useCurrentProfile, useCreateNewConversation, AccessDeniedLoader, } from '../../components/index.js';
|
|
7
|
+
import { Avatar, DirectMessageSearch, PostMarkdown, useAuthData, useCurrentProfile, useCreateNewConversation, AccessDeniedLoader, } from '../../components/index.js';
|
|
7
8
|
import { UpdatingDate } from '@openpeepshq/react-ui';
|
|
8
9
|
function ChatPreview({ conversation, unreadCount = 0, }) {
|
|
9
10
|
const t = useT();
|
|
@@ -29,6 +30,7 @@ function TabButton({ onClick, className, children, }) {
|
|
|
29
30
|
}
|
|
30
31
|
export function ConversationsIndex() {
|
|
31
32
|
const t = useT();
|
|
33
|
+
const navigate = useNavigate();
|
|
32
34
|
const { openpeepsApi } = useOpenpeeps();
|
|
33
35
|
const { openCreateConversation } = useCreateNewConversation();
|
|
34
36
|
const authData = useAuthData();
|
|
@@ -38,6 +40,8 @@ export function ConversationsIndex() {
|
|
|
38
40
|
const unseenByConversation = unseenCountsQuery.data?.direct ?? {};
|
|
39
41
|
const canCreate = canCreatePost(authData, 'note', 'direct');
|
|
40
42
|
const [tab, setTab] = useState('active');
|
|
43
|
+
const [messageSearch, setMessageSearch] = useState('');
|
|
44
|
+
const searching = messageSearch.trim().length >= 2;
|
|
41
45
|
const conversations = (tab === 'active' ? query.data : archivedQuery.data) ?? [];
|
|
42
46
|
const plusButton = useMemo(() => canCreate
|
|
43
47
|
? {
|
|
@@ -58,14 +62,16 @@ export function ConversationsIndex() {
|
|
|
58
62
|
? 'border-primary border-b-2 font-semibold'
|
|
59
63
|
: 'text-muted-foreground hover:text-foreground', children: t('conversations.tabs.archived', { defaultValue: 'Archived' }) })] })), [tab, t]);
|
|
60
64
|
useSetPageHeader(t('navigation.messages', { defaultValue: 'Messages' }), headerActions, 'conversations-page-heading');
|
|
61
|
-
return (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
return (_jsxs("div", { children: [activeQuery.isError ? null : (_jsx(DirectMessageSearch, { onQueryChange: setMessageSearch, onSelect: (hit) => {
|
|
66
|
+
navigate(`/conversations/${hit.conversationId}?message=${hit.message.id}`);
|
|
67
|
+
} })), searching ? null : (_jsx(AccessDeniedLoader, { queries: [activeQuery], children: conversations.length === 0 ? (_jsxs("div", { className: "flex h-[80vh] items-center justify-center gap-2", children: [_jsx(MessageCircleOff, { size: 40 }), _jsx("p", { className: "text-muted-foreground", children: t('conversations.empty', {
|
|
68
|
+
defaultValue: 'No direct messages here',
|
|
69
|
+
}) })] })) : (_jsx("div", { children: conversations.map((conversation) => {
|
|
70
|
+
const first = conversation[0];
|
|
71
|
+
if (!first)
|
|
72
|
+
return null;
|
|
73
|
+
return (_jsx("a", { href: `/conversations/${first.id}`, className: "hover:bg-surface block text-left transition-all", title: t('conversations.open', {
|
|
74
|
+
defaultValue: 'Open conversation',
|
|
75
|
+
}), children: _jsx(ChatPreview, { conversation: conversation, unreadCount: unseenByConversation[first.id] ?? 0 }) }, first.id));
|
|
76
|
+
}) })) }))] }));
|
|
71
77
|
}
|
|
@@ -1,25 +1,45 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { useParams } from 'react-router-dom';
|
|
4
|
-
import { Info } from 'lucide-react';
|
|
3
|
+
import { useParams, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { Info, Search } from 'lucide-react';
|
|
5
5
|
import { useT, useOpenpeeps, useSetPageHeader, usePostViewFlush, adjustUnseenCounts, useNavigate, } from '../../index.js';
|
|
6
6
|
import { canCreatePost } from '@openpeepshq/common';
|
|
7
|
-
import { Avatar, ConversationParticipantsModal, MessageInThread, OpenpeepsMarkdownInput, ProfileCard, useAuthData, useCurrentProfile, useToast, } from '../../components/index.js';
|
|
7
|
+
import { Avatar, ConversationParticipantsModal, DirectMessageSearch, MessageInThread, OpenpeepsMarkdownInput, ProfileCard, useAuthData, useCurrentProfile, useToast, } from '../../components/index.js';
|
|
8
8
|
import { Button, LoadingSpinner } from '@openpeepshq/react-ui';
|
|
9
9
|
const MAX_LENGTH = 500;
|
|
10
|
+
const isMessageId = (value) => !!value &&
|
|
11
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
10
12
|
export function ConversationShow() {
|
|
11
13
|
const t = useT();
|
|
12
14
|
const { id = '' } = useParams();
|
|
15
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
16
|
+
const messageParam = searchParams.get('message');
|
|
17
|
+
const focusId = isMessageId(messageParam) ? messageParam : undefined;
|
|
13
18
|
const { openpeepsApi, queryClient, client } = useOpenpeeps();
|
|
14
19
|
const me = useCurrentProfile();
|
|
15
20
|
const authData = useAuthData();
|
|
16
21
|
const toast = useToast();
|
|
17
22
|
const endRef = useRef(null);
|
|
18
|
-
const conversationQuery = openpeepsApi.useConversation(id);
|
|
23
|
+
const conversationQuery = openpeepsApi.useConversation(id, focusId);
|
|
19
24
|
const createMessage = openpeepsApi.createConversationPostAction({ id });
|
|
20
25
|
const markPostsSeen = openpeepsApi.markPostsSeenAction();
|
|
21
26
|
const flushPostViews = usePostViewFlush();
|
|
22
|
-
|
|
27
|
+
// Keep the open thread visible while a search hit refetches an older
|
|
28
|
+
// message. Switching conversations clears it so the previous thread
|
|
29
|
+
// does not linger.
|
|
30
|
+
const [shownMessages, setShownMessages] = useState([]);
|
|
31
|
+
const [shownFor, setShownFor] = useState(id);
|
|
32
|
+
const [searchOpen, setSearchOpen] = useState(false);
|
|
33
|
+
if (shownFor !== id) {
|
|
34
|
+
setShownFor(id);
|
|
35
|
+
setShownMessages([]);
|
|
36
|
+
setSearchOpen(false);
|
|
37
|
+
}
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (conversationQuery.data)
|
|
40
|
+
setShownMessages(conversationQuery.data);
|
|
41
|
+
}, [conversationQuery.data]);
|
|
42
|
+
const messages = shownMessages;
|
|
23
43
|
const lastMessage = messages[messages.length - 1];
|
|
24
44
|
const participants = lastMessage?.audience?.filter((a) => a.id !== me?.id) ?? [];
|
|
25
45
|
const hasLeft = lastMessage?.profile?.id === me?.id &&
|
|
@@ -39,9 +59,16 @@ export function ConversationShow() {
|
|
|
39
59
|
return (_jsx("button", { type: "button", className: "min-w-0 truncate text-left text-xl font-semibold", onClick: () => setParticipantsOpen(true), title: openParticipantsLabel, "aria-haspopup": "dialog", "data-testid": "conversation-participants-open", children: participantNames }));
|
|
40
60
|
}, [multipleParticipants, participantNames, openParticipantsLabel]);
|
|
41
61
|
const navigate = useNavigate();
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
const searchLabel = searchOpen
|
|
63
|
+
? t('common.close', { defaultValue: 'Close' })
|
|
64
|
+
: t('conversations.search.toggle', {
|
|
65
|
+
defaultValue: 'Search this conversation',
|
|
66
|
+
});
|
|
67
|
+
const headerActions = useMemo(() => (_jsxs("div", { className: "flex items-center", children: [_jsx("button", { type: "button", onClick: () => setSearchOpen((open) => !open), title: searchLabel, "aria-label": searchLabel, "aria-expanded": searchOpen, "aria-controls": searchOpen ? 'conversation-message-search' : undefined, "data-testid": "conversation-search-toggle", className: `rounded-md p-1.5 ${searchOpen
|
|
68
|
+
? 'bg-muted text-foreground'
|
|
69
|
+
: 'text-muted-foreground hover:text-foreground'}`, children: _jsx(Search, { size: 18 }) }), _jsx("button", { type: "button", onClick: () => navigate({ type: 'conversation', id, view: 'info' }), title: t('conversations.info.title', {
|
|
70
|
+
defaultValue: 'Conversation info',
|
|
71
|
+
}), className: "text-muted-foreground hover:text-foreground rounded-md p-1.5", children: _jsx(Info, { size: 18 }) })] })), [id, navigate, searchLabel, searchOpen, t]);
|
|
45
72
|
useSetPageHeader(headerTitle, headerActions);
|
|
46
73
|
const [text, setText] = useState('');
|
|
47
74
|
const [sending, setSending] = useState(false);
|
|
@@ -74,8 +101,27 @@ export function ConversationShow() {
|
|
|
74
101
|
}
|
|
75
102
|
};
|
|
76
103
|
useEffect(() => {
|
|
104
|
+
if (focusId)
|
|
105
|
+
return;
|
|
77
106
|
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
78
|
-
}, [messages.length]);
|
|
107
|
+
}, [messages.length, focusId]);
|
|
108
|
+
// The ?message= param sticks around after focusing, so scroll only the
|
|
109
|
+
// first time the message renders — re-scrolling on every messages change
|
|
110
|
+
// would fight the user while they read.
|
|
111
|
+
const scrolledToMessageRef = useRef(null);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (!focusId) {
|
|
114
|
+
scrolledToMessageRef.current = null;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (scrolledToMessageRef.current === focusId)
|
|
118
|
+
return;
|
|
119
|
+
const element = document.querySelector(`[data-message-id="${focusId}"]`);
|
|
120
|
+
if (!element)
|
|
121
|
+
return;
|
|
122
|
+
scrolledToMessageRef.current = focusId;
|
|
123
|
+
element.scrollIntoView({ block: 'center' });
|
|
124
|
+
}, [focusId, messages]);
|
|
79
125
|
useEffect(() => {
|
|
80
126
|
if (!id)
|
|
81
127
|
return;
|
|
@@ -106,13 +152,18 @@ export function ConversationShow() {
|
|
|
106
152
|
return;
|
|
107
153
|
void markPostsSeen({ postIds: unseenIds });
|
|
108
154
|
}, [id, me, messages, conversationQuery.isLoading, markPostsSeen]);
|
|
109
|
-
if (conversationQuery.isLoading) {
|
|
155
|
+
if (conversationQuery.isLoading && messages.length === 0) {
|
|
110
156
|
return (_jsx("div", { className: "text-muted-foreground flex h-32 items-center justify-center text-sm", children: _jsx(LoadingSpinner, {}) }));
|
|
111
157
|
}
|
|
112
158
|
const overLimit = text.length > MAX_LENGTH;
|
|
113
|
-
return (_jsxs("div", { className: "flex h-[calc(100vh-8rem)] flex-col", children: [_jsx("header", { className: "border-b", children: participants.length === 1 && participants[0] ? (_jsx(ProfileCard, { profile: participants[0], showAction: false })) : multipleParticipants ? (_jsxs("button", { type: "button", className: "flex w-full min-w-0 items-center gap-2 p-3 text-left", onClick: () => setParticipantsOpen(true), title: openParticipantsLabel, "aria-haspopup": "dialog", children: [_jsx("div", { className: "flex shrink-0 -space-x-2", children: participants.slice(0, 4).map((p) => (_jsx(Avatar, { profile: p, size: 2.25, borderless: true }, p.id))) }), _jsx("div", { className: "min-w-0 truncate text-sm font-medium", children: participantNames })] })) : null }), _jsx(ConversationParticipantsModal, { open: participantsOpen, onOpenChange: setParticipantsOpen, participants: participants }),
|
|
159
|
+
return (_jsxs("div", { className: "flex h-[calc(100vh-8rem)] flex-col", children: [_jsx("header", { className: "border-b", children: participants.length === 1 && participants[0] ? (_jsx(ProfileCard, { profile: participants[0], showAction: false })) : multipleParticipants ? (_jsxs("button", { type: "button", className: "flex w-full min-w-0 items-center gap-2 p-3 text-left", onClick: () => setParticipantsOpen(true), title: openParticipantsLabel, "aria-haspopup": "dialog", children: [_jsx("div", { className: "flex shrink-0 -space-x-2", children: participants.slice(0, 4).map((p) => (_jsx(Avatar, { profile: p, size: 2.25, borderless: true }, p.id))) }), _jsx("div", { className: "min-w-0 truncate text-sm font-medium", children: participantNames })] })) : null }), _jsx(ConversationParticipantsModal, { open: participantsOpen, onOpenChange: setParticipantsOpen, participants: participants }), searchOpen ? (_jsx("div", { id: "conversation-message-search", children: _jsx(DirectMessageSearch, { conversationId: id, autoFocus: true, onSelect: (hit) => {
|
|
160
|
+
const next = new URLSearchParams(searchParams);
|
|
161
|
+
next.set('message', hit.message.id);
|
|
162
|
+
setSearchParams(next);
|
|
163
|
+
setSearchOpen(false);
|
|
164
|
+
} }) })) : null, _jsxs("div", { role: "log", "aria-live": "polite", "aria-label": t('conversations.messageLog', {
|
|
114
165
|
defaultValue: 'Messages',
|
|
115
|
-
}), className: "flex-1 overflow-y-auto px-3", children: [messages.map((m, index) => (_jsx(MessageInThread, { previous: messages[index - 1], message: m, multipleParticipants: multipleParticipants, conversationRootId: id }, m.id))), _jsx("div", { ref: endRef })] }), canCreate && (_jsxs("footer", { className: "space-y-2 border-t p-3", children: [_jsx(OpenpeepsMarkdownInput, { rows: 3, value: text, onChange: setText, maxLength: MAX_LENGTH, placeholder: t('conversations.placeholder', {
|
|
166
|
+
}), className: "flex-1 overflow-y-auto px-3", children: [messages.map((m, index) => (_jsx(MessageInThread, { previous: messages[index - 1], message: m, multipleParticipants: multipleParticipants, conversationRootId: id, highlighted: m.id === focusId }, m.id))), _jsx("div", { ref: endRef })] }), canCreate && (_jsxs("footer", { className: "space-y-2 border-t p-3", children: [_jsx(OpenpeepsMarkdownInput, { rows: 3, value: text, onChange: setText, maxLength: MAX_LENGTH, placeholder: t('conversations.placeholder', {
|
|
116
167
|
defaultValue: 'Write a message…',
|
|
117
168
|
}) }), _jsx("div", { className: "flex justify-end", children: _jsx(Button, { title: "Send", variant: "default", action: send, disabled: sending || !text.trim() || overLimit, children: sending
|
|
118
169
|
? t('common.sending', { defaultValue: 'Sending…' })
|
package/dist/pages/index.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ export { ConfigurationPluginPage } from './admin/ConfigurationPluginPage';
|
|
|
76
76
|
export { AdminConfigurationCommunity } from './admin/ConfigurationCommunity';
|
|
77
77
|
export { AdminConfigEditor } from './admin/ConfigEditor';
|
|
78
78
|
export { AdminConfigurationI18n } from './admin/ConfigurationI18n';
|
|
79
|
+
export { AdminConfigurationCommunityAccess } from './admin/community/CommunityAccess';
|
|
79
80
|
export { AdminConfigurationCommunityInfo } from './admin/community/CommunityInfo';
|
|
80
81
|
export { AdminConfigurationCommunityLinks } from './admin/community/CommunityLinks';
|
|
81
82
|
export { CommunityMarkdownPage } from './admin/community/CommunityMarkdownPage';
|
package/dist/pages/index.js
CHANGED
|
@@ -76,6 +76,7 @@ export { ConfigurationPluginPage } from './admin/ConfigurationPluginPage.js';
|
|
|
76
76
|
export { AdminConfigurationCommunity } from './admin/ConfigurationCommunity.js';
|
|
77
77
|
export { AdminConfigEditor } from './admin/ConfigEditor.js';
|
|
78
78
|
export { AdminConfigurationI18n } from './admin/ConfigurationI18n.js';
|
|
79
|
+
export { AdminConfigurationCommunityAccess } from './admin/community/CommunityAccess.js';
|
|
79
80
|
export { AdminConfigurationCommunityInfo } from './admin/community/CommunityInfo.js';
|
|
80
81
|
export { AdminConfigurationCommunityLinks } from './admin/community/CommunityLinks.js';
|
|
81
82
|
export { CommunityMarkdownPage } from './admin/community/CommunityMarkdownPage.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@livekit/components-styles": "^1.1.6",
|
|
35
35
|
"@tanstack/react-query": "5.90.16",
|
|
36
36
|
"@videojs/react": "^10.0.0-beta.24",
|
|
37
|
-
"dompurify": "^3.4.
|
|
37
|
+
"dompurify": "^3.4.17",
|
|
38
38
|
"emoji-picker-element": "^1.29.1",
|
|
39
39
|
"heic2any": "^0.0.4",
|
|
40
40
|
"i18next": "^24.2.3",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"react-i18next": "^15.4.1",
|
|
52
52
|
"simple-icons": "^16.31.0",
|
|
53
53
|
"uuidv7": "^1.0.2",
|
|
54
|
-
"@openpeepshq/
|
|
55
|
-
"@openpeepshq/
|
|
54
|
+
"@openpeepshq/common": "^0.5.0",
|
|
55
|
+
"@openpeepshq/react-ui": "^0.4.1",
|
|
56
56
|
"@openpeepshq/greenscreen": "^0.2.1",
|
|
57
|
-
"@openpeepshq/
|
|
57
|
+
"@openpeepshq/client": "^0.3.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^18.3.0 || ^19.0.0",
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
conversationLabel,
|
|
4
|
+
messagePreviewText,
|
|
5
|
+
profileName,
|
|
6
|
+
type DirectMessageSearchHit,
|
|
7
|
+
} from '@openpeepshq/common';
|
|
8
|
+
import { Input, UpdatingDate } from '@openpeepshq/react-ui';
|
|
9
|
+
import { useOpenpeeps } from '../../contexts/openpeeps';
|
|
10
|
+
import { useT } from '../../i18n';
|
|
11
|
+
import { useCurrentProfile } from '../layout/IdentityContext';
|
|
12
|
+
|
|
13
|
+
export const DirectMessageSearch = ({
|
|
14
|
+
conversationId,
|
|
15
|
+
autoFocus,
|
|
16
|
+
onQueryChange,
|
|
17
|
+
onSelect,
|
|
18
|
+
}: {
|
|
19
|
+
conversationId?: string;
|
|
20
|
+
autoFocus?: boolean;
|
|
21
|
+
onQueryChange?: (query: string) => void;
|
|
22
|
+
onSelect: (hit: DirectMessageSearchHit) => void;
|
|
23
|
+
}) => {
|
|
24
|
+
const t = useT();
|
|
25
|
+
const me = useCurrentProfile();
|
|
26
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
27
|
+
const [input, setInput] = useState('');
|
|
28
|
+
const [query, setQuery] = useState('');
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const handle = setTimeout(() => setQuery(input.trim()), 300);
|
|
32
|
+
return () => clearTimeout(handle);
|
|
33
|
+
}, [input]);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
onQueryChange?.(query);
|
|
37
|
+
}, [query, onQueryChange]);
|
|
38
|
+
|
|
39
|
+
const search = openpeepsApi.useSearchDirectMessages(query, conversationId);
|
|
40
|
+
const active = query.length >= 2;
|
|
41
|
+
const hits = search.data ?? [];
|
|
42
|
+
const placeholder = conversationId
|
|
43
|
+
? t('conversations.search.inConversation', {
|
|
44
|
+
defaultValue: 'Search this conversation…',
|
|
45
|
+
})
|
|
46
|
+
: t('conversations.search.placeholder', {
|
|
47
|
+
defaultValue: 'Search all messages…',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<form
|
|
52
|
+
role="search"
|
|
53
|
+
className="border-border space-y-2 border-b p-3"
|
|
54
|
+
onSubmit={(event) => event.preventDefault()}
|
|
55
|
+
>
|
|
56
|
+
<Input
|
|
57
|
+
type="search"
|
|
58
|
+
value={input}
|
|
59
|
+
onChange={(event) => setInput(event.target.value)}
|
|
60
|
+
placeholder={placeholder}
|
|
61
|
+
aria-label={placeholder}
|
|
62
|
+
autoFocus={autoFocus}
|
|
63
|
+
data-testid="dm-search-input"
|
|
64
|
+
/>
|
|
65
|
+
{active && search.isFetching ? (
|
|
66
|
+
<p className="text-muted-foreground text-sm">
|
|
67
|
+
{t('conversations.search.searching', { defaultValue: 'Searching…' })}
|
|
68
|
+
</p>
|
|
69
|
+
) : null}
|
|
70
|
+
{active && search.isError ? (
|
|
71
|
+
<p className="text-destructive text-sm">
|
|
72
|
+
{t('conversations.search.error', { defaultValue: 'Search failed' })}
|
|
73
|
+
</p>
|
|
74
|
+
) : null}
|
|
75
|
+
{active && !search.isFetching && !search.isError && hits.length === 0 ? (
|
|
76
|
+
<p className="text-muted-foreground text-sm">
|
|
77
|
+
{t('conversations.search.empty', {
|
|
78
|
+
defaultValue: 'No messages match "{{query}}"',
|
|
79
|
+
query,
|
|
80
|
+
})}
|
|
81
|
+
</p>
|
|
82
|
+
) : null}
|
|
83
|
+
{active && hits.length > 0 ? (
|
|
84
|
+
<ul
|
|
85
|
+
aria-label={t('conversations.search.results', {
|
|
86
|
+
defaultValue: 'Message search results',
|
|
87
|
+
})}
|
|
88
|
+
className="max-h-64 overflow-y-auto"
|
|
89
|
+
data-testid="dm-search-results"
|
|
90
|
+
>
|
|
91
|
+
{hits.map((hit) => {
|
|
92
|
+
const senderId = hit.message.profile.id;
|
|
93
|
+
const sender =
|
|
94
|
+
senderId === me?.id
|
|
95
|
+
? t('common.you', { defaultValue: 'You' })
|
|
96
|
+
: profileName(hit.message.profile);
|
|
97
|
+
const others = conversationLabel(hit.message, me?.id);
|
|
98
|
+
return (
|
|
99
|
+
<li key={hit.message.id}>
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
className="hover:bg-surface w-full rounded-md px-2 py-2 text-left"
|
|
103
|
+
title={t('conversations.search.openResult', {
|
|
104
|
+
defaultValue: 'Show this message',
|
|
105
|
+
})}
|
|
106
|
+
data-testid="dm-search-result"
|
|
107
|
+
onClick={() => onSelect(hit)}
|
|
108
|
+
>
|
|
109
|
+
{!conversationId && others ? (
|
|
110
|
+
<span className="block truncate text-sm font-semibold">
|
|
111
|
+
{others}
|
|
112
|
+
</span>
|
|
113
|
+
) : null}
|
|
114
|
+
<span className="text-muted-foreground block truncate text-sm">
|
|
115
|
+
{sender}
|
|
116
|
+
{' · '}
|
|
117
|
+
<UpdatingDate date={hit.message.createdAt} />
|
|
118
|
+
</span>
|
|
119
|
+
<span className="line-clamp-2 text-sm">
|
|
120
|
+
{messagePreviewText(hit.message)}
|
|
121
|
+
</span>
|
|
122
|
+
</button>
|
|
123
|
+
</li>
|
|
124
|
+
);
|
|
125
|
+
})}
|
|
126
|
+
</ul>
|
|
127
|
+
) : null}
|
|
128
|
+
</form>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
@@ -28,6 +28,7 @@ export interface MessageInThreadProps {
|
|
|
28
28
|
message: PublicPost;
|
|
29
29
|
multipleParticipants?: boolean;
|
|
30
30
|
conversationRootId?: string;
|
|
31
|
+
highlighted?: boolean;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -40,6 +41,7 @@ export function MessageInThread({
|
|
|
40
41
|
message,
|
|
41
42
|
multipleParticipants = true,
|
|
42
43
|
conversationRootId,
|
|
44
|
+
highlighted = false,
|
|
43
45
|
}: MessageInThreadProps) {
|
|
44
46
|
const t = useT();
|
|
45
47
|
const me = useCurrentProfile();
|
|
@@ -56,7 +58,12 @@ export function MessageInThread({
|
|
|
56
58
|
const isMe = message.profile.id === me?.id;
|
|
57
59
|
|
|
58
60
|
return (
|
|
59
|
-
|
|
61
|
+
<div
|
|
62
|
+
data-message-id={message.id}
|
|
63
|
+
className={
|
|
64
|
+
highlighted ? 'bg-muted ring-ring rounded-md ring-2' : undefined
|
|
65
|
+
}
|
|
66
|
+
>
|
|
60
67
|
{!previous && (
|
|
61
68
|
<div className="mt-2 w-full text-center text-sm">
|
|
62
69
|
{message.inReplyToId
|
|
@@ -117,6 +124,6 @@ export function MessageInThread({
|
|
|
117
124
|
{multipleParticipants && !isMe && <span>{name} · </span>}
|
|
118
125
|
<UpdatingDate date={message.createdAt} />
|
|
119
126
|
</div>
|
|
120
|
-
|
|
127
|
+
</div>
|
|
121
128
|
);
|
|
122
129
|
}
|
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
useCreateNewConversation,
|
|
6
6
|
} from './CreateNewConversationContext';
|
|
7
7
|
export type { CreateConversationOptions } from './CreateNewConversationContext';
|
|
8
|
+
export { DirectMessageSearch } from './DirectMessageSearch';
|
|
8
9
|
export { DirectMessagesHeaderActions } from './DirectMessagesHeaderActions';
|
|
9
10
|
export { ConversationParticipantsModal } from './ConversationParticipantsModal';
|
|
10
11
|
export type { ConversationParticipantsModalProps } from './ConversationParticipantsModal';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenpeepsClient } from '@openpeepshq/client';
|
|
2
2
|
import type {
|
|
3
|
+
DirectMessageSearchHit,
|
|
3
4
|
PostCreationData,
|
|
4
5
|
PublicPost,
|
|
5
6
|
SuccessFailureResponse,
|
|
@@ -13,7 +14,11 @@ type Query<T> = UseQueryResult<T, SuccessFailureResponse>;
|
|
|
13
14
|
export type ConversationHooks = {
|
|
14
15
|
useConversations: () => Query<PublicPost[][]>;
|
|
15
16
|
useArchivedConversations: () => Query<PublicPost[][]>;
|
|
16
|
-
useConversation: (id: string) => Query<PublicPost[]>;
|
|
17
|
+
useConversation: (id: string, messageId?: string) => Query<PublicPost[]>;
|
|
18
|
+
useSearchDirectMessages: (
|
|
19
|
+
q: string,
|
|
20
|
+
conversationId?: string,
|
|
21
|
+
) => Query<DirectMessageSearchHit[]>;
|
|
17
22
|
createConversationPostAction: (defaultPathParams?: {
|
|
18
23
|
id: string;
|
|
19
24
|
}) => (input: PostCreationData) => Promise<PublicPost>;
|
|
@@ -30,8 +35,16 @@ export const conversationHooks = (
|
|
|
30
35
|
client.conversations.archived
|
|
31
36
|
? apiHook(client.conversations.archived)
|
|
32
37
|
: ({ data: [], isPending: false } as never),
|
|
33
|
-
useConversation: (id: string) =>
|
|
34
|
-
apiHook(client.conversations.findById, {
|
|
38
|
+
useConversation: (id: string, messageId?: string) =>
|
|
39
|
+
apiHook(client.conversations.findById, {
|
|
40
|
+
pathParams: { id },
|
|
41
|
+
queryParams: messageId ? { message: messageId } : undefined,
|
|
42
|
+
}),
|
|
43
|
+
useSearchDirectMessages: (q: string, conversationId?: string) =>
|
|
44
|
+
apiHook(client.conversations.search, {
|
|
45
|
+
queryParams: conversationId ? { q, conversationId } : { q },
|
|
46
|
+
enabled: q.trim().length >= 2,
|
|
47
|
+
}),
|
|
35
48
|
createConversationPostAction: payloadMutation(client.conversations.newPost, [
|
|
36
49
|
['conversations'],
|
|
37
50
|
]),
|
|
@@ -10,6 +10,10 @@ export function AdminConfigurationCommunity() {
|
|
|
10
10
|
translationPrefix="configuration.community.info"
|
|
11
11
|
action="/admin/configuration/community/info"
|
|
12
12
|
/>
|
|
13
|
+
<ConfigMenuButton
|
|
14
|
+
translationPrefix="configuration.community.access"
|
|
15
|
+
action="/admin/configuration/community/access"
|
|
16
|
+
/>
|
|
13
17
|
<ConfigMenuButton
|
|
14
18
|
translationPrefix="configuration.community.favicons"
|
|
15
19
|
action="/admin/configuration/community/favicons"
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { type CoreConfig, type ConfigTree } from '@openpeepshq/common/types';
|
|
3
|
+
import {
|
|
4
|
+
useT,
|
|
5
|
+
useSetPageHeader,
|
|
6
|
+
useOpenpeeps,
|
|
7
|
+
diffConfigTrees,
|
|
8
|
+
} from '../../../index';
|
|
9
|
+
import { Label, Switch, Toast } from '@openpeepshq/react-ui';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Open signups and public content live in the `openpeeps.core` config under
|
|
13
|
+
* `server.*`, but are surfaced here (under Community Customization) so an
|
|
14
|
+
* admin can update them without opening the raw Server settings tree editor.
|
|
15
|
+
*/
|
|
16
|
+
export function AdminConfigurationCommunityAccess() {
|
|
17
|
+
const t = useT();
|
|
18
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
19
|
+
const configQuery = openpeepsApi.admin.useConfigRead('openpeeps', 'core');
|
|
20
|
+
const updateConfig = openpeepsApi.admin.updateConfigAction({
|
|
21
|
+
namespace: 'openpeeps',
|
|
22
|
+
name: 'core',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
useSetPageHeader(
|
|
26
|
+
t('configuration.community.access.title', { defaultValue: 'Access' }),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const base = configQuery.data?.config as CoreConfig | undefined;
|
|
30
|
+
const [status, setStatus] = useState<{
|
|
31
|
+
type: 'success' | 'error';
|
|
32
|
+
message: string;
|
|
33
|
+
} | null>(null);
|
|
34
|
+
|
|
35
|
+
const signUpsOpen = base?.server?.signUpsOpen ?? true;
|
|
36
|
+
const publicContent = base?.server?.publicContent ?? false;
|
|
37
|
+
|
|
38
|
+
const persist = async (patch: CoreConfig['server']) => {
|
|
39
|
+
if (!base) return;
|
|
40
|
+
setStatus(null);
|
|
41
|
+
try {
|
|
42
|
+
const diff = diffConfigTrees(
|
|
43
|
+
base.server as unknown as ConfigTree,
|
|
44
|
+
patch as unknown as ConfigTree,
|
|
45
|
+
);
|
|
46
|
+
if (Object.keys(diff).length === 0) return;
|
|
47
|
+
await updateConfig({
|
|
48
|
+
config: { server: diff } as Partial<CoreConfig>,
|
|
49
|
+
});
|
|
50
|
+
setStatus({
|
|
51
|
+
type: 'success',
|
|
52
|
+
message: t('configuration.community.access.updated', {
|
|
53
|
+
defaultValue: 'Access settings updated',
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
} catch (err) {
|
|
57
|
+
setStatus({ type: 'error', message: (err as Error).message });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (configQuery.isLoading || !base) {
|
|
62
|
+
return (
|
|
63
|
+
<div className="text-muted-foreground flex h-32 items-center justify-center text-sm">
|
|
64
|
+
{t('common.form.loading', { defaultValue: 'Loading…' })}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className="space-y-6 p-4">
|
|
71
|
+
<p className="text-muted-foreground text-sm">
|
|
72
|
+
{t('configuration.community.access.description', {
|
|
73
|
+
defaultValue:
|
|
74
|
+
'Control who can join your community and who can see it',
|
|
75
|
+
})}
|
|
76
|
+
</p>
|
|
77
|
+
|
|
78
|
+
<Label
|
|
79
|
+
title={t('configuration.community.openRegistrations.title', {
|
|
80
|
+
defaultValue: 'Open Signups',
|
|
81
|
+
})}
|
|
82
|
+
description={t(
|
|
83
|
+
'configuration.community.openRegistrations.description',
|
|
84
|
+
{
|
|
85
|
+
defaultValue: 'Allow visitors to sign up for the community',
|
|
86
|
+
},
|
|
87
|
+
)}
|
|
88
|
+
forCheckbox
|
|
89
|
+
>
|
|
90
|
+
<Switch
|
|
91
|
+
checked={signUpsOpen}
|
|
92
|
+
onCheckedChange={(next) =>
|
|
93
|
+
void persist({ ...base.server, signUpsOpen: next })
|
|
94
|
+
}
|
|
95
|
+
data-testid="admin-community-access-signups"
|
|
96
|
+
/>
|
|
97
|
+
</Label>
|
|
98
|
+
|
|
99
|
+
<Label
|
|
100
|
+
title={t('configuration.community.publicContent.title', {
|
|
101
|
+
defaultValue: 'Public content',
|
|
102
|
+
})}
|
|
103
|
+
description={t('configuration.community.publicContent.description', {
|
|
104
|
+
defaultValue:
|
|
105
|
+
'Allow visitors to read public posts without an account',
|
|
106
|
+
})}
|
|
107
|
+
forCheckbox
|
|
108
|
+
>
|
|
109
|
+
<Switch
|
|
110
|
+
checked={publicContent}
|
|
111
|
+
onCheckedChange={(next) =>
|
|
112
|
+
void persist({ ...base.server, publicContent: next })
|
|
113
|
+
}
|
|
114
|
+
data-testid="admin-community-access-public-content"
|
|
115
|
+
/>
|
|
116
|
+
</Label>
|
|
117
|
+
|
|
118
|
+
{status ? (
|
|
119
|
+
<Toast
|
|
120
|
+
variant={status.type}
|
|
121
|
+
testId="admin-community-access-toast"
|
|
122
|
+
onDismiss={() => setStatus(null)}
|
|
123
|
+
>
|
|
124
|
+
{status.message}
|
|
125
|
+
</Toast>
|
|
126
|
+
) : null}
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
2
3
|
import { MessageCircleOff, Calendar, MessageSquarePlus } from 'lucide-react';
|
|
3
4
|
import type { PublicPost } from '@openpeepshq/common/types';
|
|
4
5
|
import {
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
} from '../../index';
|
|
15
16
|
import {
|
|
16
17
|
Avatar,
|
|
18
|
+
DirectMessageSearch,
|
|
17
19
|
PostMarkdown,
|
|
18
20
|
useAuthData,
|
|
19
21
|
useCurrentProfile,
|
|
@@ -121,6 +123,7 @@ function TabButton({
|
|
|
121
123
|
|
|
122
124
|
export function ConversationsIndex() {
|
|
123
125
|
const t = useT();
|
|
126
|
+
const navigate = useNavigate();
|
|
124
127
|
const { openpeepsApi } = useOpenpeeps();
|
|
125
128
|
const { openCreateConversation } = useCreateNewConversation();
|
|
126
129
|
const authData = useAuthData();
|
|
@@ -131,6 +134,8 @@ export function ConversationsIndex() {
|
|
|
131
134
|
|
|
132
135
|
const canCreate = canCreatePost(authData, 'note', 'direct');
|
|
133
136
|
const [tab, setTab] = useState<ConversationsTab>('active');
|
|
137
|
+
const [messageSearch, setMessageSearch] = useState('');
|
|
138
|
+
const searching = messageSearch.trim().length >= 2;
|
|
134
139
|
|
|
135
140
|
const conversations =
|
|
136
141
|
(tab === 'active' ? query.data : archivedQuery.data) ?? [];
|
|
@@ -192,39 +197,53 @@ export function ConversationsIndex() {
|
|
|
192
197
|
);
|
|
193
198
|
|
|
194
199
|
return (
|
|
195
|
-
<
|
|
196
|
-
{
|
|
197
|
-
<
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
})}
|
|
203
|
-
</p>
|
|
204
|
-
</div>
|
|
205
|
-
) : (
|
|
206
|
-
<div>
|
|
207
|
-
{conversations.map((conversation) => {
|
|
208
|
-
const first = conversation[0];
|
|
209
|
-
if (!first) return null;
|
|
210
|
-
return (
|
|
211
|
-
<a
|
|
212
|
-
key={first.id}
|
|
213
|
-
href={`/conversations/${first.id}`}
|
|
214
|
-
className="hover:bg-surface block text-left transition-all"
|
|
215
|
-
title={t('conversations.open', {
|
|
216
|
-
defaultValue: 'Open conversation',
|
|
217
|
-
})}
|
|
218
|
-
>
|
|
219
|
-
<ChatPreview
|
|
220
|
-
conversation={conversation}
|
|
221
|
-
unreadCount={unseenByConversation[first.id] ?? 0}
|
|
222
|
-
/>
|
|
223
|
-
</a>
|
|
200
|
+
<div>
|
|
201
|
+
{activeQuery.isError ? null : (
|
|
202
|
+
<DirectMessageSearch
|
|
203
|
+
onQueryChange={setMessageSearch}
|
|
204
|
+
onSelect={(hit) => {
|
|
205
|
+
navigate(
|
|
206
|
+
`/conversations/${hit.conversationId}?message=${hit.message.id}`,
|
|
224
207
|
);
|
|
225
|
-
}
|
|
226
|
-
|
|
208
|
+
}}
|
|
209
|
+
/>
|
|
210
|
+
)}
|
|
211
|
+
{searching ? null : (
|
|
212
|
+
<AccessDeniedLoader queries={[activeQuery]}>
|
|
213
|
+
{conversations.length === 0 ? (
|
|
214
|
+
<div className="flex h-[80vh] items-center justify-center gap-2">
|
|
215
|
+
<MessageCircleOff size={40} />
|
|
216
|
+
<p className="text-muted-foreground">
|
|
217
|
+
{t('conversations.empty', {
|
|
218
|
+
defaultValue: 'No direct messages here',
|
|
219
|
+
})}
|
|
220
|
+
</p>
|
|
221
|
+
</div>
|
|
222
|
+
) : (
|
|
223
|
+
<div>
|
|
224
|
+
{conversations.map((conversation) => {
|
|
225
|
+
const first = conversation[0];
|
|
226
|
+
if (!first) return null;
|
|
227
|
+
return (
|
|
228
|
+
<a
|
|
229
|
+
key={first.id}
|
|
230
|
+
href={`/conversations/${first.id}`}
|
|
231
|
+
className="hover:bg-surface block text-left transition-all"
|
|
232
|
+
title={t('conversations.open', {
|
|
233
|
+
defaultValue: 'Open conversation',
|
|
234
|
+
})}
|
|
235
|
+
>
|
|
236
|
+
<ChatPreview
|
|
237
|
+
conversation={conversation}
|
|
238
|
+
unreadCount={unseenByConversation[first.id] ?? 0}
|
|
239
|
+
/>
|
|
240
|
+
</a>
|
|
241
|
+
);
|
|
242
|
+
})}
|
|
243
|
+
</div>
|
|
244
|
+
)}
|
|
245
|
+
</AccessDeniedLoader>
|
|
227
246
|
)}
|
|
228
|
-
</
|
|
247
|
+
</div>
|
|
229
248
|
);
|
|
230
249
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { useParams } from 'react-router-dom';
|
|
3
|
-
import type { PostCreationData } from '@openpeepshq/common/types';
|
|
4
|
-
import { Info } from 'lucide-react';
|
|
2
|
+
import { useParams, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import type { PostCreationData, PublicPost } from '@openpeepshq/common/types';
|
|
4
|
+
import { Info, Search } from 'lucide-react';
|
|
5
5
|
import {
|
|
6
6
|
useT,
|
|
7
7
|
useOpenpeeps,
|
|
@@ -14,6 +14,7 @@ import { canCreatePost } from '@openpeepshq/common';
|
|
|
14
14
|
import {
|
|
15
15
|
Avatar,
|
|
16
16
|
ConversationParticipantsModal,
|
|
17
|
+
DirectMessageSearch,
|
|
17
18
|
MessageInThread,
|
|
18
19
|
OpenpeepsMarkdownInput,
|
|
19
20
|
ProfileCard,
|
|
@@ -25,21 +26,43 @@ import { Button, LoadingSpinner } from '@openpeepshq/react-ui';
|
|
|
25
26
|
|
|
26
27
|
const MAX_LENGTH = 500;
|
|
27
28
|
|
|
29
|
+
const isMessageId = (value: string | null): value is string =>
|
|
30
|
+
!!value &&
|
|
31
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
32
|
+
|
|
28
33
|
export function ConversationShow() {
|
|
29
34
|
const t = useT();
|
|
30
35
|
const { id = '' } = useParams<{ id: string }>();
|
|
36
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
37
|
+
const messageParam = searchParams.get('message');
|
|
38
|
+
const focusId = isMessageId(messageParam) ? messageParam : undefined;
|
|
31
39
|
const { openpeepsApi, queryClient, client } = useOpenpeeps();
|
|
32
40
|
const me = useCurrentProfile();
|
|
33
41
|
const authData = useAuthData();
|
|
34
42
|
const toast = useToast();
|
|
35
43
|
const endRef = useRef<HTMLDivElement | null>(null);
|
|
36
44
|
|
|
37
|
-
const conversationQuery = openpeepsApi.useConversation(id);
|
|
45
|
+
const conversationQuery = openpeepsApi.useConversation(id, focusId);
|
|
38
46
|
const createMessage = openpeepsApi.createConversationPostAction({ id });
|
|
39
47
|
const markPostsSeen = openpeepsApi.markPostsSeenAction();
|
|
40
48
|
const flushPostViews = usePostViewFlush();
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
// Keep the open thread visible while a search hit refetches an older
|
|
51
|
+
// message. Switching conversations clears it so the previous thread
|
|
52
|
+
// does not linger.
|
|
53
|
+
const [shownMessages, setShownMessages] = useState<PublicPost[]>([]);
|
|
54
|
+
const [shownFor, setShownFor] = useState(id);
|
|
55
|
+
const [searchOpen, setSearchOpen] = useState(false);
|
|
56
|
+
if (shownFor !== id) {
|
|
57
|
+
setShownFor(id);
|
|
58
|
+
setShownMessages([]);
|
|
59
|
+
setSearchOpen(false);
|
|
60
|
+
}
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (conversationQuery.data) setShownMessages(conversationQuery.data);
|
|
63
|
+
}, [conversationQuery.data]);
|
|
64
|
+
|
|
65
|
+
const messages = shownMessages;
|
|
43
66
|
const lastMessage = messages[messages.length - 1];
|
|
44
67
|
const participants =
|
|
45
68
|
lastMessage?.audience?.filter((a) => a.id !== me?.id) ?? [];
|
|
@@ -77,20 +100,44 @@ export function ConversationShow() {
|
|
|
77
100
|
|
|
78
101
|
const navigate = useNavigate();
|
|
79
102
|
|
|
103
|
+
const searchLabel = searchOpen
|
|
104
|
+
? t('common.close', { defaultValue: 'Close' })
|
|
105
|
+
: t('conversations.search.toggle', {
|
|
106
|
+
defaultValue: 'Search this conversation',
|
|
107
|
+
});
|
|
108
|
+
|
|
80
109
|
const headerActions = useMemo(
|
|
81
110
|
() => (
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
<div className="flex items-center">
|
|
112
|
+
<button
|
|
113
|
+
type="button"
|
|
114
|
+
onClick={() => setSearchOpen((open) => !open)}
|
|
115
|
+
title={searchLabel}
|
|
116
|
+
aria-label={searchLabel}
|
|
117
|
+
aria-expanded={searchOpen}
|
|
118
|
+
aria-controls={searchOpen ? 'conversation-message-search' : undefined}
|
|
119
|
+
data-testid="conversation-search-toggle"
|
|
120
|
+
className={`rounded-md p-1.5 ${
|
|
121
|
+
searchOpen
|
|
122
|
+
? 'bg-muted text-foreground'
|
|
123
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
124
|
+
}`}
|
|
125
|
+
>
|
|
126
|
+
<Search size={18} />
|
|
127
|
+
</button>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
onClick={() => navigate({ type: 'conversation', id, view: 'info' })}
|
|
131
|
+
title={t('conversations.info.title', {
|
|
132
|
+
defaultValue: 'Conversation info',
|
|
133
|
+
})}
|
|
134
|
+
className="text-muted-foreground hover:text-foreground rounded-md p-1.5"
|
|
135
|
+
>
|
|
136
|
+
<Info size={18} />
|
|
137
|
+
</button>
|
|
138
|
+
</div>
|
|
92
139
|
),
|
|
93
|
-
[id, navigate, t],
|
|
140
|
+
[id, navigate, searchLabel, searchOpen, t],
|
|
94
141
|
);
|
|
95
142
|
|
|
96
143
|
useSetPageHeader(headerTitle, headerActions);
|
|
@@ -127,8 +174,25 @@ export function ConversationShow() {
|
|
|
127
174
|
};
|
|
128
175
|
|
|
129
176
|
useEffect(() => {
|
|
177
|
+
if (focusId) return;
|
|
130
178
|
endRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
131
|
-
}, [messages.length]);
|
|
179
|
+
}, [messages.length, focusId]);
|
|
180
|
+
|
|
181
|
+
// The ?message= param sticks around after focusing, so scroll only the
|
|
182
|
+
// first time the message renders — re-scrolling on every messages change
|
|
183
|
+
// would fight the user while they read.
|
|
184
|
+
const scrolledToMessageRef = useRef<string | null>(null);
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (!focusId) {
|
|
187
|
+
scrolledToMessageRef.current = null;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (scrolledToMessageRef.current === focusId) return;
|
|
191
|
+
const element = document.querySelector(`[data-message-id="${focusId}"]`);
|
|
192
|
+
if (!element) return;
|
|
193
|
+
scrolledToMessageRef.current = focusId;
|
|
194
|
+
element.scrollIntoView({ block: 'center' });
|
|
195
|
+
}, [focusId, messages]);
|
|
132
196
|
|
|
133
197
|
useEffect(() => {
|
|
134
198
|
if (!id) return;
|
|
@@ -159,7 +223,7 @@ export function ConversationShow() {
|
|
|
159
223
|
void markPostsSeen({ postIds: unseenIds });
|
|
160
224
|
}, [id, me, messages, conversationQuery.isLoading, markPostsSeen]);
|
|
161
225
|
|
|
162
|
-
if (conversationQuery.isLoading) {
|
|
226
|
+
if (conversationQuery.isLoading && messages.length === 0) {
|
|
163
227
|
return (
|
|
164
228
|
<div className="text-muted-foreground flex h-32 items-center justify-center text-sm">
|
|
165
229
|
<LoadingSpinner />
|
|
@@ -198,6 +262,20 @@ export function ConversationShow() {
|
|
|
198
262
|
onOpenChange={setParticipantsOpen}
|
|
199
263
|
participants={participants}
|
|
200
264
|
/>
|
|
265
|
+
{searchOpen ? (
|
|
266
|
+
<div id="conversation-message-search">
|
|
267
|
+
<DirectMessageSearch
|
|
268
|
+
conversationId={id}
|
|
269
|
+
autoFocus
|
|
270
|
+
onSelect={(hit) => {
|
|
271
|
+
const next = new URLSearchParams(searchParams);
|
|
272
|
+
next.set('message', hit.message.id);
|
|
273
|
+
setSearchParams(next);
|
|
274
|
+
setSearchOpen(false);
|
|
275
|
+
}}
|
|
276
|
+
/>
|
|
277
|
+
</div>
|
|
278
|
+
) : null}
|
|
201
279
|
|
|
202
280
|
<div
|
|
203
281
|
role="log"
|
|
@@ -214,6 +292,7 @@ export function ConversationShow() {
|
|
|
214
292
|
message={m}
|
|
215
293
|
multipleParticipants={multipleParticipants}
|
|
216
294
|
conversationRootId={id}
|
|
295
|
+
highlighted={m.id === focusId}
|
|
217
296
|
/>
|
|
218
297
|
))}
|
|
219
298
|
<div ref={endRef} />
|
package/src/pages/index.ts
CHANGED
|
@@ -77,6 +77,7 @@ export { ConfigurationPluginPage } from './admin/ConfigurationPluginPage';
|
|
|
77
77
|
export { AdminConfigurationCommunity } from './admin/ConfigurationCommunity';
|
|
78
78
|
export { AdminConfigEditor } from './admin/ConfigEditor';
|
|
79
79
|
export { AdminConfigurationI18n } from './admin/ConfigurationI18n';
|
|
80
|
+
export { AdminConfigurationCommunityAccess } from './admin/community/CommunityAccess';
|
|
80
81
|
export { AdminConfigurationCommunityInfo } from './admin/community/CommunityInfo';
|
|
81
82
|
export { AdminConfigurationCommunityLinks } from './admin/community/CommunityLinks';
|
|
82
83
|
export { CommunityMarkdownPage } from './admin/community/CommunityMarkdownPage';
|