mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-18 14:34:25 +01:00
feat: support nevent1 style mention
This commit is contained in:
@@ -61,6 +61,17 @@ const TextNoteContentDisplay = (props: TextNoteContentDisplayProps) => {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (item.data.type === 'nevent' && props.embedding) {
|
||||
return (
|
||||
<div class="my-1 rounded border p-1">
|
||||
<TextNoteDisplayById
|
||||
eventId={item.data.data.id}
|
||||
actions={false}
|
||||
embedding={false}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (item.data.type === 'npub') {
|
||||
return <MentionedUserDisplay pubkey={item.data.data} />;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
const { showProfile } = useModalState();
|
||||
const timelineContext = useTimelineContext();
|
||||
|
||||
const [reacted, setReacted] = createSignal(false);
|
||||
const [reposted, setReposted] = createSignal(false);
|
||||
const [showReplyForm, setShowReplyForm] = createSignal(false);
|
||||
const closeReplyForm = () => setShowReplyForm(false);
|
||||
const [showOverflow, setShowOverflow] = createSignal(false);
|
||||
@@ -61,11 +63,21 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
pubkey: props.event.pubkey,
|
||||
}));
|
||||
|
||||
const { reactions, isReactedBy, invalidateReactions } = useReactions(() => ({
|
||||
const {
|
||||
reactions,
|
||||
isReactedBy,
|
||||
invalidateReactions,
|
||||
query: reactionsQuery,
|
||||
} = useReactions(() => ({
|
||||
eventId: props.event.id,
|
||||
}));
|
||||
|
||||
const { reposts, isRepostedBy, invalidateReposts } = useReposts(() => ({
|
||||
const {
|
||||
reposts,
|
||||
isRepostedBy,
|
||||
invalidateReposts,
|
||||
query: repostsQuery,
|
||||
} = useReposts(() => ({
|
||||
eventId: props.event.id,
|
||||
}));
|
||||
|
||||
@@ -81,7 +93,9 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
console.error('failed to publish reaction: ', err);
|
||||
},
|
||||
onSettled: () => {
|
||||
invalidateReactions().catch((err) => console.error('failed to refetch reactions', err));
|
||||
invalidateReactions()
|
||||
.then(() => reactionsQuery.refetch())
|
||||
.catch((err) => console.error('failed to refetch reactions', err));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -95,7 +109,9 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
console.error('failed to publish repost: ', err);
|
||||
},
|
||||
onSettled: () => {
|
||||
invalidateReposts().catch((err) => console.error('failed to refetch reposts', err));
|
||||
invalidateReposts()
|
||||
.then(() => repostsQuery.refetch())
|
||||
.catch((err) => console.error('failed to refetch reposts', err));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -156,11 +172,11 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
|
||||
const isReactedByMe = createMemo(() => {
|
||||
const p = pubkey();
|
||||
return p != null && isReactedBy(p);
|
||||
return (p != null && isReactedBy(p)) || reacted();
|
||||
});
|
||||
const isRepostedByMe = createMemo(() => {
|
||||
const p = pubkey();
|
||||
return p != null && isRepostedBy(p);
|
||||
return (p != null && isRepostedBy(p)) || reposted();
|
||||
});
|
||||
|
||||
const showReplyEvent = (): string | undefined => {
|
||||
@@ -192,6 +208,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
eventId: eventIdNonNull,
|
||||
notifyPubkey: props.event.pubkey,
|
||||
});
|
||||
setReposted(true);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -211,6 +228,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
||||
eventId: eventIdNonNull,
|
||||
notifyPubkey: props.event.pubkey,
|
||||
});
|
||||
setReacted(true);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Switch, Match, type Component } from 'solid-js';
|
||||
import { Switch, Match, type Component, Show } from 'solid-js';
|
||||
|
||||
import { Kind } from 'nostr-tools';
|
||||
|
||||
import EventLink from '@/components/EventLink';
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
@@ -13,22 +15,29 @@ type TextNoteDisplayByIdProps = Omit<TextNoteDisplayProps, 'event'> & {
|
||||
|
||||
const TextNoteDisplayById: Component<TextNoteDisplayByIdProps> = (props) => {
|
||||
const { shouldMuteEvent } = useConfig();
|
||||
const { event, query: eventQuery } = useEvent(() =>
|
||||
const { event: fetchedEvent, query: eventQuery } = useEvent(() =>
|
||||
ensureNonNull([props.eventId] as const)(([eventIdNonNull]) => ({
|
||||
eventId: eventIdNonNull,
|
||||
})),
|
||||
);
|
||||
|
||||
const hidden = (): boolean => {
|
||||
const ev = event();
|
||||
const ev = fetchedEvent();
|
||||
return ev != null && shouldMuteEvent(ev);
|
||||
};
|
||||
|
||||
return (
|
||||
<Switch fallback="投稿が見つかりません">
|
||||
<Match when={hidden()}>{null}</Match>
|
||||
<Match when={event()} keyed>
|
||||
{(ev) => <TextNoteDisplay event={ev} {...props} />}
|
||||
<Match when={fetchedEvent()} keyed>
|
||||
{(event) => (
|
||||
<Show
|
||||
when={event.kind === Kind.Text}
|
||||
fallback={<div>未対応のイベント種別({event.kind})</div>}
|
||||
>
|
||||
<TextNoteDisplay event={event} {...props} />
|
||||
</Show>
|
||||
)}
|
||||
</Match>
|
||||
<Match when={eventQuery.isLoading && props.eventId} keyed>
|
||||
{(id) => (
|
||||
|
||||
Reference in New Issue
Block a user