mirror of
https://github.com/aljazceru/hypergolic.git
synced 2025-12-18 22:14:21 +01:00
problem: users can't provide email address or npub for notifications
This commit is contained in:
@@ -35,7 +35,6 @@
|
||||
}
|
||||
const e = prepareMeritNoteEvent({
|
||||
ndk,
|
||||
author,
|
||||
merit,
|
||||
content
|
||||
});
|
||||
|
||||
@@ -1,21 +1,114 @@
|
||||
<script lang="ts">
|
||||
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import Button from '@/components/ui/button/button.svelte';
|
||||
import Input from '@/components/ui/input/input.svelte';
|
||||
import Label from '@/components/ui/label/label.svelte';
|
||||
import Separator from '@/components/ui/separator/separator.svelte';
|
||||
import { ndk } from '@/ndk';
|
||||
import { prepareEncryptedDirectMessageEvent } from '@/helpers';
|
||||
import { currentUser } from '@/stores/session';
|
||||
import Login from './Login.svelte';
|
||||
import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
|
||||
|
||||
let open = false;
|
||||
let email: string;
|
||||
$: emailInValid = true;
|
||||
$: emailError = '';
|
||||
const emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
|
||||
|
||||
$: if (email) {
|
||||
if (!emailRegex.test(email)) {
|
||||
emailInValid = true;
|
||||
emailError = 'Email is invalid';
|
||||
} else {
|
||||
emailInValid = false;
|
||||
emailError = '';
|
||||
}
|
||||
}
|
||||
|
||||
async function Subscribe() {
|
||||
const error = await publishEncryptedDirectMessage(
|
||||
`Please send me a direct message when Nostrocket updates. (Sent by Nostrocket)`
|
||||
);
|
||||
if (error instanceof Error) {
|
||||
console.error(error);
|
||||
}
|
||||
open = false;
|
||||
}
|
||||
|
||||
async function SubmitEmailAndSubscribe() {
|
||||
const error = await publishEncryptedDirectMessage(
|
||||
`Please notify me via email when Nostrocket updates. My email address is ${email}. (Sent by Nostrocket)`
|
||||
);
|
||||
if (error instanceof Error) {
|
||||
console.error(error);
|
||||
}
|
||||
open = false;
|
||||
}
|
||||
|
||||
async function publishEncryptedDirectMessage(content: string) {
|
||||
const RECEIVER = new NDKUser({
|
||||
pubkey: 'd91191e30e00444b942c0e82cad470b32af171764c2275bee0bd99377efd4075'
|
||||
});
|
||||
|
||||
const originalSigner = $ndk.signer;
|
||||
if (!$currentUser) {
|
||||
$ndk.signer = NDKPrivateKeySigner.generate();
|
||||
}
|
||||
|
||||
const event = await prepareEncryptedDirectMessageEvent({
|
||||
ndk: $ndk,
|
||||
receiver: RECEIVER,
|
||||
content
|
||||
});
|
||||
|
||||
if (event instanceof Error) {
|
||||
return event;
|
||||
}
|
||||
|
||||
const publishResult = await event.publish();
|
||||
console.log(publishResult);
|
||||
|
||||
if (!$currentUser) {
|
||||
$ndk.signer = originalSigner;
|
||||
}
|
||||
}
|
||||
|
||||
let open = false;
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Trigger
|
||||
><Badge href="#" variant="nostr" class="flex h-8 shrink-0 items-center justify-center rounded-sm">Nostrocket is sooooo not ready yet but whatever</Badge></Dialog.Trigger
|
||||
<Dialog.Trigger>
|
||||
<Badge
|
||||
href="#"
|
||||
variant="nostr"
|
||||
class="flex h-8 shrink-0 items-center justify-center rounded-sm"
|
||||
>
|
||||
Tell me via DM when there are updates
|
||||
</Badge>
|
||||
</Dialog.Trigger>
|
||||
<Dialog.Content>
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>Nostrocket is a work in progress</Dialog.Title>
|
||||
<Dialog.Description
|
||||
>It kind of works, but there's a lot more to do. There will be bugs.</Dialog.Description
|
||||
>
|
||||
<Dialog.Title>Subscribe for Updates</Dialog.Title>
|
||||
<Dialog.Description>
|
||||
Receive notifications about Nostrocket updates via Nostr DM or email.
|
||||
</Dialog.Description>
|
||||
<div class="flex flex-col gap-4 py-4">
|
||||
{#if $currentUser}
|
||||
<Button on:click={Subscribe}>Reveive DM</Button>
|
||||
{:else}
|
||||
<Login />
|
||||
{/if}
|
||||
<Separator />
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label for="email" class="text-right">Email</Label>
|
||||
<Input bind:value={email} id="email" placeholder="Your email" class="col-span-3" />
|
||||
</div>
|
||||
{#if emailError}
|
||||
<div class="ml-4 p-0 text-sm text-red-500">{emailError}</div>
|
||||
{/if}
|
||||
</div>
|
||||
<Button disabled={emailInValid} on:click={SubmitEmailAndSubscribe}>Reveive Email</Button>
|
||||
</Dialog.Header>
|
||||
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
}
|
||||
prepareMeritVoteEvent({
|
||||
ndk,
|
||||
author,
|
||||
rocket,
|
||||
merit,
|
||||
direction
|
||||
@@ -35,10 +34,9 @@
|
||||
console.log(x);
|
||||
});
|
||||
if (direction === 'ratify') {
|
||||
let content = `I've voted to ratify your merit request! ${merit.Problem()} \n\n ${merit.Solution()?merit.Solution():""}`;
|
||||
let content = `I've voted to ratify your merit request! ${merit.Problem()} \n\n ${merit.Solution() ? merit.Solution() : ''}`;
|
||||
prepareMeritNoteEvent({
|
||||
ndk,
|
||||
author,
|
||||
merit,
|
||||
content
|
||||
})
|
||||
|
||||
@@ -343,14 +343,13 @@ function pubkeyLatestVote(votes: Votes) {
|
||||
|
||||
export function prepareMeritNoteEvent(args: {
|
||||
ndk: NDKSvelte;
|
||||
author: NDKUser;
|
||||
merit: MeritRequest;
|
||||
content: string;
|
||||
}) {
|
||||
const tags = [
|
||||
['p', args.merit.Pubkey],
|
||||
['e', args.merit.ID, "wss://relay.nostrocket.org", 'reply'],
|
||||
args.merit.RocketTag?['a', args.merit.RocketTag]:[],
|
||||
['e', args.merit.ID, 'wss://relay.nostrocket.org', 'reply'],
|
||||
args.merit.RocketTag ? ['a', args.merit.RocketTag] : []
|
||||
];
|
||||
return prepareNostrEvent({
|
||||
...args,
|
||||
@@ -361,7 +360,6 @@ export function prepareMeritNoteEvent(args: {
|
||||
|
||||
export function prepareMeritVoteEvent(args: {
|
||||
ndk: NDKSvelte;
|
||||
author: NDKUser;
|
||||
rocket: Rocket;
|
||||
merit: MeritRequest;
|
||||
direction: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NDKZap, NDKEvent, type NDKKind, type NDKTag, type NDKUser } from '@nostr-dev-kit/ndk';
|
||||
import { NDKKind, NDKZap, NDKEvent, NDKUser, type NDKTag } from '@nostr-dev-kit/ndk';
|
||||
import type NDKSvelte from '@nostr-dev-kit/ndk-svelte';
|
||||
import { QrCode } from '$lib/qrcodegen';
|
||||
|
||||
@@ -19,8 +19,6 @@ export function getRocketURL(e: NDKEvent): string {
|
||||
return `${ignitionID}?d=${d}&p=${p}`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function unixTimeNow() {
|
||||
return Math.floor(new Date().getTime() / 1000);
|
||||
}
|
||||
@@ -166,15 +164,12 @@ export async function getAuthorizedZapper(rocket: NDKEvent): Promise<string> {
|
||||
|
||||
export function prepareNostrEvent(args: {
|
||||
ndk: NDKSvelte;
|
||||
author: NDKUser;
|
||||
kind: NDKKind;
|
||||
content: string;
|
||||
tags?: NDKTag[];
|
||||
}) {
|
||||
let e = new NDKEvent(args.ndk);
|
||||
e.author = args.author;
|
||||
e.kind = args.kind;
|
||||
e.created_at = Math.floor(new Date().getTime() / 1000);
|
||||
e.content = args.content;
|
||||
if (args.tags) {
|
||||
e.tags = args.tags;
|
||||
@@ -183,6 +178,25 @@ export function prepareNostrEvent(args: {
|
||||
return e;
|
||||
}
|
||||
|
||||
export async function prepareEncryptedDirectMessageEvent(args: {
|
||||
ndk: NDKSvelte;
|
||||
receiver: NDKUser;
|
||||
content: string;
|
||||
}) {
|
||||
const signer = args.ndk.signer;
|
||||
if (!signer) {
|
||||
return new Error('no signer');
|
||||
}
|
||||
const tags = [['p', args.receiver.pubkey]];
|
||||
const event = prepareNostrEvent({
|
||||
...args,
|
||||
kind: NDKKind.EncryptedDirectMessage,
|
||||
tags
|
||||
});
|
||||
await event.encrypt(args.receiver, signer);
|
||||
return event;
|
||||
}
|
||||
|
||||
export function drawSvgPath(qr: QrCode, border: number): string {
|
||||
if (border < 0) throw new RangeError('Border must be non-negative');
|
||||
let parts: Array<string> = [];
|
||||
|
||||
Reference in New Issue
Block a user