auto add self
This commit is contained in:
parent
66a6a983ed
commit
9a1ee11a97
@ -10,6 +10,7 @@ import { getTwoLetters, truncateText } from "@/lib/utils";
|
|||||||
import ProfileFeed from "./_components/Feed";
|
import ProfileFeed from "./_components/Feed";
|
||||||
import Subscriptions from "./_components/Subscriptions";
|
import Subscriptions from "./_components/Subscriptions";
|
||||||
import { nip19 } from "nostr-tools";
|
import { nip19 } from "nostr-tools";
|
||||||
|
import useLists from "@/lib/hooks/useLists";
|
||||||
|
|
||||||
export default function ProfilePage({
|
export default function ProfilePage({
|
||||||
params: { npub },
|
params: { npub },
|
||||||
@ -19,7 +20,6 @@ export default function ProfilePage({
|
|||||||
};
|
};
|
||||||
}) {
|
}) {
|
||||||
const [activeTab, setActiveTab] = useState("feed");
|
const [activeTab, setActiveTab] = useState("feed");
|
||||||
console.log("calling with ", npub);
|
|
||||||
if (npub === "service-worker.js") {
|
if (npub === "service-worker.js") {
|
||||||
throw new Error("Invalid list");
|
throw new Error("Invalid list");
|
||||||
}
|
}
|
||||||
@ -30,18 +30,8 @@ export default function ProfilePage({
|
|||||||
}
|
}
|
||||||
const pubkey = data.toString();
|
const pubkey = data.toString();
|
||||||
const { profile } = useProfile(pubkey);
|
const { profile } = useProfile(pubkey);
|
||||||
|
const { init, lists } = useLists();
|
||||||
|
|
||||||
const demo = [
|
|
||||||
{
|
|
||||||
id: "1",
|
|
||||||
title: "BTC Radio",
|
|
||||||
description:
|
|
||||||
"BTC Radio is the best fuking show ever. you should sub to it. now",
|
|
||||||
picture:
|
|
||||||
"https://assets.whop.com/cdn-cgi/image/width=1080/https://assets.whop.com/images/images/51602.original.png?1693358530",
|
|
||||||
tags: ["music", "crypto", "art"],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
return (
|
return (
|
||||||
<div className="relative mx-auto max-w-5xl space-y-6">
|
<div className="relative mx-auto max-w-5xl space-y-6">
|
||||||
<div className="relative @container">
|
<div className="relative @container">
|
||||||
@ -116,9 +106,9 @@ export default function ProfilePage({
|
|||||||
</div>
|
</div>
|
||||||
<div className="mx-auto max-w-[800px] space-y-6">
|
<div className="mx-auto max-w-[800px] space-y-6">
|
||||||
<div className="flex max-w-2xl flex-col gap-4 px-4">
|
<div className="flex max-w-2xl flex-col gap-4 px-4">
|
||||||
{demo.map((e) => (
|
{/* {[].map((e) => (
|
||||||
<SubscriptionCard key={e.id} {...e} />
|
<SubscriptionCard key={e.id} {...e} />
|
||||||
))}
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
<div className="">
|
<div className="">
|
||||||
<Tabs
|
<Tabs
|
||||||
|
@ -13,6 +13,7 @@ import { getTagValues } from "@/lib/nostr/utils";
|
|||||||
import { NDKList } from "@nostr-dev-kit/ndk";
|
import { NDKList } from "@nostr-dev-kit/ndk";
|
||||||
import { saveEphemeralSigner } from "@/lib/actions/ephemeral";
|
import { saveEphemeralSigner } from "@/lib/actions/ephemeral";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
const CreateListSchema = z.object({
|
const CreateListSchema = z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
image: z.string().optional(),
|
image: z.string().optional(),
|
||||||
@ -49,6 +50,7 @@ export default function CreateList() {
|
|||||||
}
|
}
|
||||||
if (data.subscriptions) {
|
if (data.subscriptions) {
|
||||||
tags.push(["subscriptions", "true"]);
|
tags.push(["subscriptions", "true"]);
|
||||||
|
tags.push(["p", currentUser!.pubkey, "", "self", "4000000000"]);
|
||||||
}
|
}
|
||||||
if (data.price) {
|
if (data.price) {
|
||||||
tags.push(["price", satsToBtc(data.price).toString(), "btc", "year"]);
|
tags.push(["price", satsToBtc(data.price).toString(), "btc", "year"]);
|
||||||
|
@ -68,20 +68,14 @@ export async function createEventHandler(
|
|||||||
let publishedEvent: NDKEvent | null = null;
|
let publishedEvent: NDKEvent | null = null;
|
||||||
// Check if is private event
|
// Check if is private event
|
||||||
if (isPrivate) {
|
if (isPrivate) {
|
||||||
console.log("isPrivate");
|
|
||||||
const rawEventString = JSON.stringify(eventToPublish.rawEvent());
|
const rawEventString = JSON.stringify(eventToPublish.rawEvent());
|
||||||
console.log("rawEventString", rawEventString);
|
|
||||||
const passphrase = generateRandomString();
|
const passphrase = generateRandomString();
|
||||||
console.log("passphrase", passphrase);
|
|
||||||
const encryptedRawEventString = await encryptMessage(
|
const encryptedRawEventString = await encryptMessage(
|
||||||
rawEventString,
|
rawEventString,
|
||||||
passphrase,
|
passphrase,
|
||||||
);
|
);
|
||||||
console.log("encryptedRawEventString", encryptedRawEventString);
|
|
||||||
console.log("delegateSigner", delegateSigner);
|
|
||||||
const signer = delegateSigner ?? ndk.signer!;
|
const signer = delegateSigner ?? ndk.signer!;
|
||||||
const user = await signer.user();
|
const user = await signer.user();
|
||||||
console.log("signer user", user);
|
|
||||||
|
|
||||||
const newEvent = new NDKEvent(ndk, {
|
const newEvent = new NDKEvent(ndk, {
|
||||||
content: encryptedRawEventString,
|
content: encryptedRawEventString,
|
||||||
@ -132,80 +126,7 @@ export async function createEventHandler(
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
export async function createEncryptedEventOnPrivateList(
|
|
||||||
ndk: NDK,
|
|
||||||
event: {
|
|
||||||
content: string;
|
|
||||||
kind: number;
|
|
||||||
tags: string[][];
|
|
||||||
},
|
|
||||||
list: NDKList,
|
|
||||||
delegateSigner?: NDKPrivateKeySigner,
|
|
||||||
) {
|
|
||||||
const pubkey = await window.nostr?.getPublicKey();
|
|
||||||
if (!pubkey || !window.nostr) {
|
|
||||||
throw new Error("No public key provided!");
|
|
||||||
}
|
|
||||||
const eventToPublish = new NDKEvent(ndk, {
|
|
||||||
...event,
|
|
||||||
tags: [...event.tags, ["client", "flockstr"]],
|
|
||||||
pubkey,
|
|
||||||
created_at: unixTimeNowInSeconds(),
|
|
||||||
} as NostrEvent);
|
|
||||||
await eventToPublish.sign();
|
|
||||||
const rawEventString = JSON.stringify(eventToPublish.rawEvent());
|
|
||||||
const passphrase = generateRandomString();
|
|
||||||
const encryptedRawEventString = await encryptMessage(
|
|
||||||
rawEventString,
|
|
||||||
passphrase,
|
|
||||||
);
|
|
||||||
const signer = delegateSigner ?? ndk.signer!;
|
|
||||||
const user = await signer.user();
|
|
||||||
|
|
||||||
const newEvent = new NDKEvent(ndk, {
|
|
||||||
content: encryptedRawEventString,
|
|
||||||
kind: 3745,
|
|
||||||
tags: [
|
|
||||||
["kind", event.kind.toString()],
|
|
||||||
["client", "flockstr"],
|
|
||||||
],
|
|
||||||
pubkey: user.pubkey,
|
|
||||||
} as NostrEvent);
|
|
||||||
|
|
||||||
await newEvent.sign(signer);
|
|
||||||
|
|
||||||
await newEvent.publish();
|
|
||||||
|
|
||||||
const tag = newEvent.tagReference();
|
|
||||||
if (!tag) return;
|
|
||||||
|
|
||||||
// Add event to list
|
|
||||||
await list.addItem(tag, undefined, false);
|
|
||||||
await list.sign();
|
|
||||||
await list.publish();
|
|
||||||
|
|
||||||
// Send DMs to subscribers
|
|
||||||
const subscribers = getTagsValues("p", list.tags);
|
|
||||||
for (const subscriber of subscribers) {
|
|
||||||
const messageEvent = new NDKEvent(ndk, {
|
|
||||||
content: passphrase,
|
|
||||||
kind: 4,
|
|
||||||
tags: [
|
|
||||||
["p", subscriber],
|
|
||||||
["e", newEvent.id],
|
|
||||||
["client", "flockstr"],
|
|
||||||
],
|
|
||||||
pubkey: user.hexpubkey,
|
|
||||||
} as NostrEvent);
|
|
||||||
console.log("message to create", messageEvent);
|
|
||||||
await messageEvent.encrypt(new NDKUser({ hexpubkey: subscriber }), signer);
|
|
||||||
console.log("Encrypted message", messageEvent);
|
|
||||||
await messageEvent.sign(signer);
|
|
||||||
await messageEvent.publish();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
export async function createReaction(
|
export async function createReaction(
|
||||||
ndk: NDK,
|
ndk: NDK,
|
||||||
content: "+" | "-",
|
content: "+" | "-",
|
||||||
|
@ -146,22 +146,8 @@ export async function updateListUsersFromZaps(
|
|||||||
// Add self
|
// Add self
|
||||||
console.log("Adding self");
|
console.log("Adding self");
|
||||||
const selfIndex = validUsers.findIndex(([vu]) => vu === event.pubkey);
|
const selfIndex = validUsers.findIndex(([vu]) => vu === event.pubkey);
|
||||||
if (selfIndex !== -1) {
|
if (selfIndex === -1) {
|
||||||
console.log("Already there");
|
validUsers.push([event.pubkey, "", "self", "4000000000"]);
|
||||||
|
|
||||||
validUsers[selfIndex] = [
|
|
||||||
event.pubkey,
|
|
||||||
"",
|
|
||||||
"self",
|
|
||||||
(unixTimeNowInSeconds() + SECONDS_IN_YEAR).toString(),
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
validUsers.push([
|
|
||||||
event.pubkey,
|
|
||||||
"",
|
|
||||||
"self",
|
|
||||||
(unixTimeNowInSeconds() + SECONDS_IN_YEAR).toString(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
console.log("Valid users", validUsers);
|
console.log("Valid users", validUsers);
|
||||||
return createEvent(ndk, {
|
return createEvent(ndk, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user