refactor
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import { Image } from "@shared/image";
|
||||
|
||||
import { DEFAULT_AVATAR } from "@stores/constants";
|
||||
import { useProfile } from "@utils/hooks/useProfile";
|
||||
|
||||
export default function ActiveAccount({ user }: { user: any }) {
|
||||
const userData = JSON.parse(user.metadata);
|
||||
export default function ActiveAccount({ data }: { data: any }) {
|
||||
const { user } = useProfile(data.npub);
|
||||
|
||||
return (
|
||||
<button type="button" className="relative h-11 w-11 overflow-hidden">
|
||||
<Image
|
||||
src={userData.picture || DEFAULT_AVATAR}
|
||||
alt="user's avatar"
|
||||
src={user?.picture || DEFAULT_AVATAR}
|
||||
alt={data.npub}
|
||||
className="h-11 w-11 rounded-md object-cover"
|
||||
/>
|
||||
</button>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Image } from "@shared/image";
|
||||
|
||||
import { DEFAULT_AVATAR } from "@stores/constants";
|
||||
import { useProfile } from "@utils/hooks/useProfile";
|
||||
|
||||
export default function InactiveAccount({ user }: { user: any }) {
|
||||
const userData = JSON.parse(user.metadata);
|
||||
export default function InactiveAccount({ data }: { data: any }) {
|
||||
const { user } = useProfile(data.npub);
|
||||
|
||||
return (
|
||||
<div className="relative h-11 w-11 shrink rounded-md">
|
||||
<Image
|
||||
src={userData.picture || DEFAULT_AVATAR}
|
||||
alt="user's avatar"
|
||||
src={user?.picture || DEFAULT_AVATAR}
|
||||
alt={data.npub}
|
||||
className="h-11 w-11 rounded-lg object-cover"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { WRITEONLY_RELAYS } from "@stores/constants";
|
||||
|
||||
import { dateToUnix } from "@utils/date";
|
||||
|
||||
import { getEventHash, signEvent } from "nostr-tools";
|
||||
import { getEventHash, getSignature } from "nostr-tools";
|
||||
import { useCallback, useContext, useMemo, useState } from "react";
|
||||
import { Node, Transforms, createEditor } from "slate";
|
||||
import { withHistory } from "slate-history";
|
||||
@@ -91,7 +91,7 @@ export function Post({ pubkey, privkey }: { pubkey: string; privkey: string }) {
|
||||
tags: [],
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, privkey);
|
||||
event.sig = getSignature(event, privkey);
|
||||
|
||||
// publish note
|
||||
pool.publish(event, WRITEONLY_RELAYS);
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function EventCollector() {
|
||||
since: dateToUnix(now.current),
|
||||
},
|
||||
{
|
||||
kinds: [0, 3],
|
||||
kinds: [3],
|
||||
authors: [key.pubkey],
|
||||
},
|
||||
{
|
||||
@@ -60,10 +60,6 @@ export default function EventCollector() {
|
||||
READONLY_RELAYS,
|
||||
(event: any) => {
|
||||
switch (event.kind) {
|
||||
// metadata
|
||||
case 0:
|
||||
updateAccount("metadata", event.content, event.pubkey);
|
||||
break;
|
||||
// short text note
|
||||
case 1: {
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
@@ -82,15 +78,21 @@ export default function EventCollector() {
|
||||
break;
|
||||
}
|
||||
// contacts
|
||||
case 3:
|
||||
case 3: {
|
||||
const follows = nip02ToArray(event.tags);
|
||||
// update account's folllows with NIP-02 tag list
|
||||
updateAccount("follows", event.tags, event.pubkey);
|
||||
updateAccount("follows", follows, event.pubkey);
|
||||
break;
|
||||
}
|
||||
// chat
|
||||
case 4:
|
||||
if (event.pubkey !== key.pubkey) {
|
||||
createChat(key.id, event.pubkey, event.created_at);
|
||||
}
|
||||
createChat(
|
||||
event.id,
|
||||
key.pubkey,
|
||||
event.pubkey,
|
||||
event.content,
|
||||
event.created_at,
|
||||
);
|
||||
break;
|
||||
// repost
|
||||
case 6:
|
||||
|
||||
@@ -25,7 +25,7 @@ export default function MultiAccounts() {
|
||||
{!activeAccount ? (
|
||||
<div className="group relative flex h-10 w-10 shrink animate-pulse items-center justify-center rounded-lg bg-zinc-900" />
|
||||
) : (
|
||||
<ActiveAccount user={activeAccount} />
|
||||
<ActiveAccount data={activeAccount} />
|
||||
)}
|
||||
</>
|
||||
<div>
|
||||
@@ -49,7 +49,7 @@ export default function MultiAccounts() {
|
||||
) : (
|
||||
accounts.map(
|
||||
(account: { is_active: number; pubkey: string }) => (
|
||||
<InactiveAccount key={account.pubkey} user={account} />
|
||||
<InactiveAccount key={account.pubkey} data={account} />
|
||||
),
|
||||
)
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FULL_RELAYS } from "@stores/constants";
|
||||
|
||||
import { RelayPool } from "nostr-relaypool";
|
||||
import { createContext } from "react";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user