forked from Kieran/zap.stream
Accept pubkey for chat popup
This commit is contained in:
parent
648ae65059
commit
602782118d
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"names":{
|
|
||||||
"_": "cf45a6ba1363ad7ed213a078e710d24115ae721c9b47bd1ebf4458eaefb4c2a5"
|
|
||||||
}
|
|
||||||
}
|
|
51
src/hooks/current-stream-feed.ts
Normal file
51
src/hooks/current-stream-feed.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { unwrap } from "@snort/shared";
|
||||||
|
import {
|
||||||
|
NostrLink,
|
||||||
|
NostrPrefix,
|
||||||
|
NoteCollection,
|
||||||
|
RequestBuilder,
|
||||||
|
} from "@snort/system";
|
||||||
|
import { useRequestBuilder } from "@snort/system-react";
|
||||||
|
import { LIVE_STREAM } from "const";
|
||||||
|
import { System } from "index";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
|
||||||
|
export function useCurrentStreamFeed(link: NostrLink, leaveOpen = false) {
|
||||||
|
const author =
|
||||||
|
link.type === NostrPrefix.Address ? unwrap(link.author) : link.id;
|
||||||
|
const sub = useMemo(() => {
|
||||||
|
const b = new RequestBuilder(`current-event:${link.id}`);
|
||||||
|
b.withOptions({
|
||||||
|
leaveOpen,
|
||||||
|
});
|
||||||
|
if (
|
||||||
|
link.type === NostrPrefix.PublicKey ||
|
||||||
|
link.type === NostrPrefix.Profile
|
||||||
|
) {
|
||||||
|
b.withFilter().authors([link.id]).kinds([LIVE_STREAM]).limit(1);
|
||||||
|
b.withFilter().tag("p", [link.id]).kinds([LIVE_STREAM]).limit(1);
|
||||||
|
} else if (link.type === NostrPrefix.Address) {
|
||||||
|
const f = b.withFilter().tag("d", [link.id]);
|
||||||
|
if (link.author) {
|
||||||
|
f.authors([link.author]);
|
||||||
|
}
|
||||||
|
if (link.kind) {
|
||||||
|
f.kinds([link.kind]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}, [link.id, leaveOpen]);
|
||||||
|
|
||||||
|
const q = useRequestBuilder(System, NoteCollection, sub);
|
||||||
|
|
||||||
|
return useMemo(() => {
|
||||||
|
const hosting = q.data?.filter(
|
||||||
|
(a) =>
|
||||||
|
a.pubkey === author ||
|
||||||
|
a.tags.some((b) => b[0] === "p" && b[1] === author && b[3] === "host")
|
||||||
|
);
|
||||||
|
return [...(hosting ?? [])]
|
||||||
|
.sort((a, b) => (b.created_at > a.created_at ? 1 : -1))
|
||||||
|
.at(0);
|
||||||
|
}, [q.data]);
|
||||||
|
}
|
@ -1,20 +1,22 @@
|
|||||||
import "./chat-popout.css";
|
import "./chat-popout.css";
|
||||||
import { LiveChat } from "element/live-chat";
|
import { LiveChat } from "element/live-chat";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { parseNostrLink } from "@snort/system";
|
import { NostrPrefix, encodeTLV, parseNostrLink } from "@snort/system";
|
||||||
import useEventFeed from "../hooks/event-feed";
|
import { useCurrentStreamFeed } from "hooks/current-stream-feed";
|
||||||
|
import { findTag } from "utils";
|
||||||
|
|
||||||
export function ChatPopout() {
|
export function ChatPopout() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const link = parseNostrLink(params.id!);
|
const link = parseNostrLink(params.id!);
|
||||||
const { data: ev } = useEventFeed(link, true);
|
const ev = useCurrentStreamFeed(link, true);
|
||||||
|
|
||||||
|
const lnk = parseNostrLink(encodeTLV(NostrPrefix.Address, findTag(ev, "d") ?? "", undefined, ev?.kind, ev?.pubkey));
|
||||||
const chat = Boolean(new URL(window.location.href).searchParams.get("chat"));
|
const chat = Boolean(new URL(window.location.href).searchParams.get("chat"));
|
||||||
return (
|
return (
|
||||||
<div className={`popout-chat${chat ? "" : " embed"}`}>
|
<div className={`popout-chat${chat ? "" : " embed"}`}>
|
||||||
<LiveChat
|
<LiveChat
|
||||||
ev={ev}
|
ev={ev}
|
||||||
link={link}
|
link={lnk}
|
||||||
options={{
|
options={{
|
||||||
canWrite: chat,
|
canWrite: chat,
|
||||||
showHeader: false,
|
showHeader: false,
|
||||||
|
@ -45,7 +45,6 @@ const config = {
|
|||||||
{ from: "public/robots.txt" },
|
{ from: "public/robots.txt" },
|
||||||
{ from: "public/icons.svg" },
|
{ from: "public/icons.svg" },
|
||||||
{ from: "public/logo.png" },
|
{ from: "public/logo.png" },
|
||||||
{ from: "public/nostr.json", to: ".well-known/nostr.json" },
|
|
||||||
{ from: "_headers" },
|
{ from: "_headers" },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user