problem: no voting notification for merit request

solution: after voting, also send a kind 1 event
This commit is contained in:
Bob
2024-07-29 21:42:22 +08:00
parent d13a9e5477
commit aadae07cd2
5 changed files with 130 additions and 47 deletions

View File

@@ -1,8 +1,8 @@
<script lang="ts">
import * as Card from '$lib/components/ui/card/index.js';
import { type MeritRequest } from '@/event_helpers/merits';
import { prepareMeritNoteEvent, type MeritRequest } from '@/event_helpers/merits';
import { ndk } from '@/ndk';
import { NDKEvent, type NDKKind } from '@nostr-dev-kit/ndk';
import { NDKKind } from '@nostr-dev-kit/ndk';
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
import { onDestroy } from 'svelte';
@@ -14,6 +14,7 @@
import { currentUser } from '@/stores/session';
import CornerDownLeft from 'lucide-svelte/icons/corner-down-left';
import type NDKSvelte from '@nostr-dev-kit/ndk-svelte';
export let merit: MeritRequest;
let comments = $ndk.storeSubscribe({ kinds: [1 as NDKKind], '#e': [merit.ID] });
@@ -28,18 +29,16 @@
if (!ndk.signer) {
throw new Error('no ndk signer found');
}
let e = new NDKEvent(ndk);
let author = $currentUser;
if (!author) {
throw new Error('no current user');
}
e.author = author;
e.kind = 1;
e.created_at = Math.floor(new Date().getTime() / 1000);
e.content = content;
e.tags.push(['p', merit.Pubkey]);
e.tags.push(['e', merit.ID, 'root', merit.Pubkey]);
console.log(e.rawEvent());
const e = prepareMeritNoteEvent({
ndk,
author,
merit,
content
});
e.publish().then((x) => {
console.log(x);
});

View File

@@ -1,38 +1,55 @@
<script lang="ts">
import { Button } from '@/components/ui/button';
import { MeritRequest } from '@/event_helpers/merits';
import {
MeritRequest,
prepareMeritNoteEvent,
prepareMeritVoteEvent,
type VoteDirection
} from '@/event_helpers/merits';
import type { Rocket } from '@/event_helpers/rockets';
import { ndk } from '@/ndk';
import { currentUser } from '@/stores/session';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import type NDKSvelte from '@nostr-dev-kit/ndk-svelte';
import { Name } from '@nostr-dev-kit/ndk-svelte-components';
import Login from './Login.svelte';
export let merit: MeritRequest;
export let rocket: Rocket;
function publish(ndk: NDKSvelte, direction: string) {
function publish(ndk: NDKSvelte, direction: VoteDirection) {
if (!ndk.signer) {
throw new Error('no ndk signer found');
}
let e = new NDKEvent(ndk);
let author = $currentUser;
if (!author) {
throw new Error('no current user');
}
e.author = author;
e.kind = 1410;
e.created_at = Math.floor(new Date().getTime() / 1000);
e.tags.push(['a', `31108:${rocket.Event.pubkey}:${rocket.Event.dTag}`]);
e.tags.push(['request', merit.ID]);
e.tags.push(['e', merit.ID]);
e.tags.push(['p', merit.Pubkey]);
e.tags.push(['vote', direction]);
console.log(e.rawEvent());
e.publish().then((x) => {
console.log(x);
});
prepareMeritVoteEvent({
ndk,
author,
rocket,
merit,
direction
})
.publish()
.then((x) => {
console.log(x);
});
let content;
if (direction === 'ratify') {
content = `I ratify your merit request: \n\n${merit.Problem()}`;
} else {
content = `I reject your merit request: \n\n${merit.Problem()}`;
}
prepareMeritNoteEvent({
ndk,
author,
merit,
content
})
.publish()
.then((x) => {
console.log(x);
});
}
$: currentUserHasVotepower = false;