Skip to content

Commit

Permalink
problem: relay hints are dumb but ok
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Jan 25, 2024
1 parent f6da9e7 commit c6ec2e0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 39 deletions.
30 changes: 8 additions & 22 deletions src/components/comments/CommentsWrapper.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import { consensusTipState } from "$lib/stores/nostrocket_state/master_state";
import type { Problem } from "$lib/stores/nostrocket_state/types";
import { NDKEvent } from "@nostr-dev-kit/ndk";
import type {
ExtendedBaseType
} from "@nostr-dev-kit/ndk-svelte";
import type { ExtendedBaseType } from "@nostr-dev-kit/ndk-svelte";
import {
Button,
ButtonSet,
Expand All @@ -29,6 +27,7 @@
import { derived, type Readable } from "svelte/store";
import LoginButtonWithError from "../elements/LoginButtonWithError.svelte";
import CommentUser from "./CommentUser.svelte";
import { relayHint } from "../../settings";
export let parentId: string;
export let isRoot: boolean;
Expand All @@ -55,12 +54,15 @@
const eventId = commentId ?? parentId;
ndkEvent.kind = 1;
ndkEvent.content = content;
ndkEvent.tags = [...ndkEvent.tags, ...[["e", eventId, "", eventMarker]]];
ndkEvent.tags.push(["e", problem.UID, "", "root"]);
ndkEvent.tags = [
...ndkEvent.tags,
...[["e", eventId, relayHint, eventMarker]],
];
ndkEvent.tags.push(["e", problem.UID, relayHint, "root"]);
ndkEvent.tags.push(["p", problem.CreatedBy]);
if (event) {
ndkEvent.tags.push(["p", event.pubkey]);
ndkEvent.tags.push(["e", event.id, "", "reply"]);
ndkEvent.tags.push(["e", event.id, relayHint, "reply"]);
}
await ndkEvent.publish();
Expand Down Expand Up @@ -110,25 +112,9 @@
}
}
//console.log(arr)
return arr;
}
);
// commentsFromRelays = $ndk_profiles.storeSubscribe<NDKEvent>(
// { "#e": [parentId], kinds: [1] },
// { closeOnEose: false }
// );
// commentsFromRelays.subscribe((c) => {
// comments.update(co=>{
// for (let e of c) {
// co.set(e.id, e)
// }
// return co
// })
// });
commentsToRender = derived(cachedComments, ($fromRelays) => {
numberOfComments = $fromRelays.length;
if (problem) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers/eventMaker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rootTag } from "../../settings";
import { relayHint, rootTag } from "../../settings";
import { NDKEvent } from "@nostr-dev-kit/ndk";
import { get } from "svelte/store";
import { BitcoinHeightTag } from "./bitcoin";
Expand All @@ -25,7 +25,7 @@ export default function makeEvent(settings: eventSettings): NDKEvent {
switch (typeof settings.rocket) {
case "string":
if (settings.rocket.length == 64) {
e.tags.push(["e", settings.rocket, "", "rocket"]);
e.tags.push(["e", settings.rocket, relayHint, "rocket"]);
}
break;
case "object":
Expand Down
36 changes: 21 additions & 15 deletions src/lib/helpers/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from "$lib/stores/nostrocket_state/types";
import { get } from "svelte/store";
import makeEvent from "./eventMaker";
import { simulateEvents } from "../../settings";
import { relayHint, simulateEvents } from "../../settings";
import type { NDKEvent } from "@nostr-dev-kit/ndk";

export function problemStatus(problem: Problem, state: Nostrocket) {
Expand All @@ -25,30 +25,36 @@ export function problemStatus(problem: Problem, state: Nostrocket) {
return problem.Status;
}

export function PublishProblem(problem: Problem, parent: Problem|Problem[], rocket?: Rocket):Promise<NDKEvent> {
export function PublishProblem(
problem: Problem,
parent: Problem | Problem[],
rocket?: Rocket
): Promise<NDKEvent> {
return new Promise((resolve, reject) => {
if (!parent) {
reject("could not find parent");
}
if (!Array.isArray(parent)) {parent = [parent]}
if (!Array.isArray(parent)) {
parent = [parent];
}
let e = makeEvent({
kind: 1971,
//rocket: rocket ? rocket.UID : parent[0].Rocket,
});
let pushed = new Set()
let pushed = new Set();
for (let p of parent) {
if (!pushed.has(p.Rocket)) {
pushed.add(p.Rocket)
e.tags.push(["e", p.Rocket, "", "rocket"])
pushed.add(p.Rocket);
e.tags.push(["e", p.Rocket, relayHint, "rocket"]);
}
if (!pushed.has(p.UID)) {
pushed.add(p.UID)
e.tags.push(["e", p.UID, "", "parent"])
pushed.add(p.UID);
e.tags.push(["e", p.UID, relayHint, "parent"]);
}
}
if (rocket) {
if (!pushed.has(rocket.UID)) {
e.tags.push(["e", rocket.UID, "", "rocket"])
e.tags.push(["e", rocket.UID, relayHint, "rocket"]);
}
}
e.tags.push(["text", problem.Title, "tldr"]);
Expand All @@ -62,9 +68,9 @@ export function PublishProblem(problem: Problem, parent: Problem|Problem[], rock
e.tags.push(["new"]);
}
if (problem.UID) {
e.tags.push(["e", problem.UID, "", "problem"])
e.tags.push(["e", problem.UID, relayHint, "problem"]);
}

e.tags.push(["status", problem.Status]);
e.tags.push(["alt", "This is a Nostrocket problem"]);
e.content =
Expand All @@ -83,16 +89,16 @@ export function PublishProblem(problem: Problem, parent: Problem|Problem[], rock
e.publish()
.then((x) => {
console.log(e.rawEvent(), x);
resolve(e)
resolve(e);
})
.catch((err) => {
console.log(err, e);
reject("failed to publish Problem event. " + err);
reject("failed to publish Problem event. " + err);
});
} else {
e.sign().then(() => {
console.log("simulation mode, not publishing events")
resolve(e)
console.log("simulation mode, not publishing events");
resolve(e);
});
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ export const defaultRelays = [
export const ignoreConsensusEvent = "f61353291a91f61c289aefe479b1314f024ba188df33a94bb66027431a777fbc"

export const NewRocketProblem = "cc5bcc23caa8bfda2ef7920c1ea9600282bcdba81456b13d1611d84967aa473b"

export const relayHint = "nostr.688.org"

0 comments on commit c6ec2e0

Please sign in to comment.