wip: new chat screen

This commit is contained in:
Ren Amamiya
2023-10-04 11:15:10 +07:00
parent ca57ef1760
commit 480580890e
17 changed files with 314 additions and 357 deletions

View File

@@ -2,24 +2,24 @@ import { NDKEvent } from '@nostr-dev-kit/ndk';
import { nip04 } from 'nostr-tools';
import { useEffect, useState } from 'react';
export function useDecryptMessage(
message: NDKEvent,
userPubkey: string,
userPriv: string
) {
export function useDecryptMessage(message: NDKEvent, pubkey: string, privkey: string) {
const [content, setContent] = useState(message.content);
useEffect(() => {
async function decrypt() {
const pubkey =
userPubkey === message.pubkey
? message.tags.find((el) => el[0] === 'p')[1]
: message.pubkey;
const result = await nip04.decrypt(userPriv, pubkey, message.content);
setContent(result);
async function decryptContent() {
try {
const sender =
pubkey === message.pubkey
? message.tags.find((el) => el[0] === 'p')[1]
: message.pubkey;
const result = await nip04.decrypt(privkey, sender, message.content);
setContent(result);
} catch (e) {
console.error(e);
}
}
decrypt().catch(console.error);
decryptContent();
}, []);
return content;