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>
|
</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') {
|
if (item.data.type === 'npub') {
|
||||||
return <MentionedUserDisplay pubkey={item.data.data} />;
|
return <MentionedUserDisplay pubkey={item.data.data} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
const { showProfile } = useModalState();
|
const { showProfile } = useModalState();
|
||||||
const timelineContext = useTimelineContext();
|
const timelineContext = useTimelineContext();
|
||||||
|
|
||||||
|
const [reacted, setReacted] = createSignal(false);
|
||||||
|
const [reposted, setReposted] = createSignal(false);
|
||||||
const [showReplyForm, setShowReplyForm] = createSignal(false);
|
const [showReplyForm, setShowReplyForm] = createSignal(false);
|
||||||
const closeReplyForm = () => setShowReplyForm(false);
|
const closeReplyForm = () => setShowReplyForm(false);
|
||||||
const [showOverflow, setShowOverflow] = createSignal(false);
|
const [showOverflow, setShowOverflow] = createSignal(false);
|
||||||
@@ -61,11 +63,21 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
pubkey: props.event.pubkey,
|
pubkey: props.event.pubkey,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { reactions, isReactedBy, invalidateReactions } = useReactions(() => ({
|
const {
|
||||||
|
reactions,
|
||||||
|
isReactedBy,
|
||||||
|
invalidateReactions,
|
||||||
|
query: reactionsQuery,
|
||||||
|
} = useReactions(() => ({
|
||||||
eventId: props.event.id,
|
eventId: props.event.id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { reposts, isRepostedBy, invalidateReposts } = useReposts(() => ({
|
const {
|
||||||
|
reposts,
|
||||||
|
isRepostedBy,
|
||||||
|
invalidateReposts,
|
||||||
|
query: repostsQuery,
|
||||||
|
} = useReposts(() => ({
|
||||||
eventId: props.event.id,
|
eventId: props.event.id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -81,7 +93,9 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
console.error('failed to publish reaction: ', err);
|
console.error('failed to publish reaction: ', err);
|
||||||
},
|
},
|
||||||
onSettled: () => {
|
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);
|
console.error('failed to publish repost: ', err);
|
||||||
},
|
},
|
||||||
onSettled: () => {
|
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 isReactedByMe = createMemo(() => {
|
||||||
const p = pubkey();
|
const p = pubkey();
|
||||||
return p != null && isReactedBy(p);
|
return (p != null && isReactedBy(p)) || reacted();
|
||||||
});
|
});
|
||||||
const isRepostedByMe = createMemo(() => {
|
const isRepostedByMe = createMemo(() => {
|
||||||
const p = pubkey();
|
const p = pubkey();
|
||||||
return p != null && isRepostedBy(p);
|
return (p != null && isRepostedBy(p)) || reposted();
|
||||||
});
|
});
|
||||||
|
|
||||||
const showReplyEvent = (): string | undefined => {
|
const showReplyEvent = (): string | undefined => {
|
||||||
@@ -192,6 +208,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
eventId: eventIdNonNull,
|
eventId: eventIdNonNull,
|
||||||
notifyPubkey: props.event.pubkey,
|
notifyPubkey: props.event.pubkey,
|
||||||
});
|
});
|
||||||
|
setReposted(true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,6 +228,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
eventId: eventIdNonNull,
|
eventId: eventIdNonNull,
|
||||||
notifyPubkey: props.event.pubkey,
|
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';
|
import EventLink from '@/components/EventLink';
|
||||||
// eslint-disable-next-line import/no-cycle
|
// eslint-disable-next-line import/no-cycle
|
||||||
@@ -13,22 +15,29 @@ type TextNoteDisplayByIdProps = Omit<TextNoteDisplayProps, 'event'> & {
|
|||||||
|
|
||||||
const TextNoteDisplayById: Component<TextNoteDisplayByIdProps> = (props) => {
|
const TextNoteDisplayById: Component<TextNoteDisplayByIdProps> = (props) => {
|
||||||
const { shouldMuteEvent } = useConfig();
|
const { shouldMuteEvent } = useConfig();
|
||||||
const { event, query: eventQuery } = useEvent(() =>
|
const { event: fetchedEvent, query: eventQuery } = useEvent(() =>
|
||||||
ensureNonNull([props.eventId] as const)(([eventIdNonNull]) => ({
|
ensureNonNull([props.eventId] as const)(([eventIdNonNull]) => ({
|
||||||
eventId: eventIdNonNull,
|
eventId: eventIdNonNull,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
const hidden = (): boolean => {
|
const hidden = (): boolean => {
|
||||||
const ev = event();
|
const ev = fetchedEvent();
|
||||||
return ev != null && shouldMuteEvent(ev);
|
return ev != null && shouldMuteEvent(ev);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Switch fallback="投稿が見つかりません">
|
<Switch fallback="投稿が見つかりません">
|
||||||
<Match when={hidden()}>{null}</Match>
|
<Match when={hidden()}>{null}</Match>
|
||||||
<Match when={event()} keyed>
|
<Match when={fetchedEvent()} keyed>
|
||||||
{(ev) => <TextNoteDisplay event={ev} {...props} />}
|
{(event) => (
|
||||||
|
<Show
|
||||||
|
when={event.kind === Kind.Text}
|
||||||
|
fallback={<div>未対応のイベント種別({event.kind})</div>}
|
||||||
|
>
|
||||||
|
<TextNoteDisplay event={event} {...props} />
|
||||||
|
</Show>
|
||||||
|
)}
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={eventQuery.isLoading && props.eventId} keyed>
|
<Match when={eventQuery.isLoading && props.eventId} keyed>
|
||||||
{(id) => (
|
{(id) => (
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ export const useProfile = (propsProvider: () => UseProfileProps | null): UseProf
|
|||||||
try {
|
try {
|
||||||
queryClient.setQueryData(queryKey, latestEvent());
|
queryClient.setQueryData(queryKey, latestEvent());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('updating profile error', err);
|
console.error('updating profile error: ', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return latestEvent();
|
return latestEvent();
|
||||||
@@ -472,7 +472,7 @@ export const useFollowings = (propsProvider: () => UseFollowingsProps | null): U
|
|||||||
try {
|
try {
|
||||||
queryClient.setQueryData(queryKey, latestEvent());
|
queryClient.setQueryData(queryKey, latestEvent());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('updating followings error', err);
|
console.error('updating followings error: ', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return latestEvent();
|
return latestEvent();
|
||||||
|
|||||||
Reference in New Issue
Block a user