This commit is contained in:
Ren Amamiya
2023-05-26 09:28:49 +07:00
parent 225179dd6d
commit 5c7b18bf29
41 changed files with 404 additions and 461 deletions

View File

@@ -38,14 +38,14 @@ export default function ChatsListItem({ pubkey }: { pubkey: string }) {
>
<div className="relative h-5 w-5 shrink-0 rounded">
<Image
src={user.picture || DEFAULT_AVATAR}
src={user?.picture || DEFAULT_AVATAR}
alt={pubkey}
className="h-5 w-5 rounded bg-white object-cover"
/>
</div>
<div>
<h5 className="max-w-[9rem] truncate font-medium text-zinc-200 group-hover:text-white">
{user.nip05 || user.name || shortenKey(pubkey)}
{user?.nip05 || user.name || shortenKey(pubkey)}
</h5>
</div>
</a>

View File

@@ -2,16 +2,17 @@ import ChatsListItem from "@app/chat/components/item";
import ChatsListSelfItem from "@app/chat/components/self";
import { useActiveAccount } from "@utils/hooks/useActiveAccount";
import { getChats } from "@utils/storage";
import { getChatsByPubkey } from "@utils/storage";
import useSWR from "swr";
const fetcher = ([, account]) => getChats(account);
const fetcher = ([, pubkey]) => getChatsByPubkey(pubkey);
export default function ChatsList() {
const { account, isLoading, isError } = useActiveAccount();
const { data: chats, error }: any = useSWR(
!isLoading && !isError && account ? ["chats", account] : null,
!isLoading && !isError && account ? ["chats", account.pubkey] : null,
fetcher,
);
@@ -30,8 +31,8 @@ export default function ChatsList() {
</div>
</>
) : (
chats.map((item: { pubkey: string }) => (
<ChatsListItem key={item.pubkey} pubkey={item.pubkey} />
chats.map((item) => (
<ChatsListItem key={item.sender_pubkey} pubkey={item.sender_pubkey} />
))
)}
</div>

View File

@@ -9,7 +9,7 @@ import { useActiveAccount } from "@utils/hooks/useActiveAccount";
import { useAtom } from "jotai";
import { useResetAtom } from "jotai/utils";
import { getEventHash, nip04, signEvent } from "nostr-tools";
import { getEventHash, getSignature, nip04 } from "nostr-tools";
import { useCallback, useContext } from "react";
export default function ChatMessageForm({
@@ -40,7 +40,7 @@ export default function ChatMessageForm({
tags: [["p", receiverPubkey]],
};
event.id = getEventHash(event);
event.sig = signEvent(event, account.privkey);
event.sig = getSignature(event, account.privkey);
// publish note
pool.publish(event, WRITEONLY_RELAYS);
// reset state

View File

@@ -15,7 +15,6 @@ export default function ChatsListSelfItem() {
const pagePubkey = searchParams.pubkey;
const { account, isLoading, isError } = useActiveAccount();
const profile = account ? JSON.parse(account.metadata) : null;
return (
<>
@@ -39,14 +38,14 @@ export default function ChatsListSelfItem() {
>
<div className="relative h-5 w-5 shrink-0 rounded">
<Image
src={profile?.picture || DEFAULT_AVATAR}
src={account?.picture || DEFAULT_AVATAR}
alt={account.pubkey}
className="h-5 w-5 rounded bg-white object-cover"
/>
</div>
<div className="inline-flex items-baseline">
<h5 className="max-w-[9rem] truncate font-medium text-zinc-200">
{profile?.nip05 || profile?.name || shortenKey(account.pubkey)}
{account?.nip05 || account?.name || shortenKey(account.pubkey)}
</h5>
<span className="text-zinc-600">(you)</span>
</div>