Skip to content

Commit

Permalink
fix timeline health
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Nov 12, 2024
1 parent 5f66729 commit 7d2d888
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/timeline-page/timeline-health/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useState } from "react";
import { useState } from "react";
import {
Box,
Spinner,
Expand All @@ -14,6 +14,7 @@ import {
Tr,
useColorMode,
} from "@chakra-ui/react";
import { getSeenRelays } from "applesauce-core/helpers";

import TimelineLoader from "../../../classes/timeline-loader";
import { NostrEvent } from "../../../types/nostr-event";
Expand All @@ -23,14 +24,12 @@ import { BroadcastEventIcon } from "../../icons";
import Timestamp from "../../timestamp";
import { usePublishEvent } from "../../../providers/global/publish-provider";
import useEventIntersectionRef from "../../../hooks/use-event-intersection-ref";
import { getSeenRelays } from "applesauce-core/helpers";

function EventRow({
event,
relays,
...props
}: { event: NostrEvent; relays: string[] } & Omit<TableRowProps, "children">) {
// const sub = useMemo(() => getEventRelays(event.id), [event.id]);
const publish = usePublishEvent();

const ref = useEventIntersectionRef(event);
Expand All @@ -42,7 +41,7 @@ function EventRow({
const [broadcasting, setBroadcasting] = useState(false);
const broadcast = async () => {
setBroadcasting(true);
await publish("Broadcast", event);
await publish("Broadcast", event, relays);
setBroadcasting(false);
};

Expand Down Expand Up @@ -72,7 +71,7 @@ function EventRow({
}

export default function TimelineHealth({ timeline, loader }: { loader: TimelineLoader; timeline: NostrEvent[] }) {
const relays = Array.from(Object.keys(loader.relays));
const relays = loader.relays.map((r) => r.url);

return (
<>
Expand Down
5 changes: 5 additions & 0 deletions src/providers/global/publish-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { eventStore } from "../../services/event-store";
import { addPubkeyRelayHints } from "../../helpers/nostr/post";
import useCurrentAccount from "../../hooks/use-current-account";
import { useUserOutbox } from "../../hooks/use-user-mailboxes";
import { addSeenRelay } from "applesauce-core/helpers";

type PublishContextType = {
log: PublishAction[];
Expand Down Expand Up @@ -116,6 +117,10 @@ export default function PublishProvider({ children }: PropsWithChildren) {
const pub = new PublishAction(label, relays, signed);
setLog((arr) => arr.concat(pub));

pub.onResult.subscribe((result) => {
if (result.success) addSeenRelay(signed, result.relay.url);
});

// send it to the local relay
if (localRelay) localRelay.publish(signed);

Expand Down

0 comments on commit 7d2d888

Please sign in to comment.