fully support nip05
This commit is contained in:
@@ -20,7 +20,7 @@ export function ChatMessageForm({
|
||||
const tags = [["p", receiverPubkey]];
|
||||
|
||||
// publish message
|
||||
publish({ content: message, kind: 4, tags });
|
||||
await publish({ content: message, kind: 4, tags });
|
||||
|
||||
// reset state
|
||||
setValue("");
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
import { User } from "@app/auth/components/user";
|
||||
import { Dialog, Transition } from "@headlessui/react";
|
||||
import { getPlebs } from "@libs/storage";
|
||||
import { CancelIcon, PlusIcon } from "@shared/icons";
|
||||
import { DEFAULT_AVATAR } from "@stores/constants";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { useAccount } from "@utils/hooks/useAccount";
|
||||
import { Fragment, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
export function NewMessageModal() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { status, data }: any = useQuery(["plebs"], async () => {
|
||||
return await getPlebs();
|
||||
});
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const { status, account } = useAccount();
|
||||
const follows = account ? JSON.parse(account.follows) : [];
|
||||
|
||||
const closeModal = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
@@ -24,8 +20,7 @@ export function NewMessageModal() {
|
||||
setIsOpen(true);
|
||||
};
|
||||
|
||||
const openChat = (npub: string) => {
|
||||
const pubkey = nip19.decode(npub).data;
|
||||
const openChat = (pubkey: string) => {
|
||||
closeModal();
|
||||
navigate(`/app/chat/${pubkey}`);
|
||||
};
|
||||
@@ -99,31 +94,16 @@ export function NewMessageModal() {
|
||||
{status === "loading" ? (
|
||||
<p>Loading...</p>
|
||||
) : (
|
||||
data.map((pleb) => (
|
||||
follows.map((follow) => (
|
||||
<div
|
||||
key={pleb.npub}
|
||||
key={follow}
|
||||
className="group flex items-center justify-between px-4 py-3 hover:bg-zinc-800"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<img
|
||||
alt={pleb.npub}
|
||||
src={pleb.image || DEFAULT_AVATAR}
|
||||
className="w-9 h-9 shrink-0 object-cover rounded"
|
||||
/>
|
||||
<div className="inline-flex flex-col gap-1">
|
||||
<h3 className="leading-none max-w-[15rem] line-clamp-1 font-medium text-zinc-100">
|
||||
{pleb.displayName || pleb.name}
|
||||
</h3>
|
||||
<span className="leading-none max-w-[10rem] line-clamp-1 text-sm text-zinc-400">
|
||||
{pleb.nip05 ||
|
||||
pleb.npub.substring(0, 16).concat("...")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<User pubkey={follow} />
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openChat(pleb.npub)}
|
||||
onClick={() => openChat(follow)}
|
||||
className="inline-flex text-sm w-max px-3 py-1.5 rounded border-t border-zinc-600/50 bg-zinc-700 hover:bg-fuchsia-500 transform translate-x-20 group-hover:translate-x-0 transition-transform ease-in-out duration-150"
|
||||
>
|
||||
Chat
|
||||
|
||||
@@ -2,18 +2,11 @@ import { Image } from "@shared/image";
|
||||
import { DEFAULT_AVATAR } from "@stores/constants";
|
||||
import { useProfile } from "@utils/hooks/useProfile";
|
||||
import { shortenKey } from "@utils/shortenKey";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
export function ChatSidebar({ pubkey }: { pubkey: string }) {
|
||||
const navigate = useNavigate();
|
||||
const { user } = useProfile(pubkey);
|
||||
|
||||
const viewProfile = () => {
|
||||
const pubkey = nip19.decode(user.npub).data;
|
||||
navigate(`/app/user/${pubkey}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="px-3 py-2">
|
||||
<div className="flex flex-col gap-3">
|
||||
@@ -36,13 +29,12 @@ export function ChatSidebar({ pubkey }: { pubkey: string }) {
|
||||
</div>
|
||||
<div>
|
||||
<p className="leading-tight">{user?.bio || user?.about}</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => viewProfile()}
|
||||
<Link
|
||||
to={`/app/user/${pubkey}`}
|
||||
className="mt-3 inline-flex w-full h-10 items-center justify-center rounded-md bg-zinc-900 hover:bg-zinc-800 text-sm text-zinc-300 hover:text-zinc-100 font-medium"
|
||||
>
|
||||
View full profile
|
||||
</button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
createNote,
|
||||
getChannels,
|
||||
getLastLogin,
|
||||
updateLastLogin,
|
||||
} from "@libs/storage";
|
||||
import { NDKFilter } from "@nostr-dev-kit/ndk";
|
||||
import { LoaderIcon, LumeIcon } from "@shared/icons";
|
||||
@@ -142,6 +143,7 @@ export function Root() {
|
||||
const chats = await fetchChats();
|
||||
// const channels = await fetchChannelMessages();
|
||||
if (chats) {
|
||||
await updateLastLogin(dateToUnix());
|
||||
navigate("/app/space", { replace: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import { useVirtualizer } from "@tanstack/react-virtual";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const ITEM_PER_PAGE = 10;
|
||||
const TIME = Math.floor(Date.now() / 1000);
|
||||
|
||||
export function FeedBlock({ params }: { params: any }) {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -21,7 +20,6 @@ export function FeedBlock({ params }: { params: any }) {
|
||||
queryFn: async ({ pageParam = 0 }) => {
|
||||
return await getNotesByAuthors(
|
||||
params.content,
|
||||
TIME,
|
||||
ITEM_PER_PAGE,
|
||||
pageParam,
|
||||
);
|
||||
|
||||
@@ -9,7 +9,6 @@ import { useVirtualizer } from "@tanstack/react-virtual";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const ITEM_PER_PAGE = 10;
|
||||
const TIME = Math.floor(Date.now() / 1000);
|
||||
|
||||
export function FollowingBlock({ block }: { block: number }) {
|
||||
// subscribe for live update
|
||||
@@ -29,7 +28,7 @@ export function FollowingBlock({ block }: { block: number }) {
|
||||
}: any = useInfiniteQuery({
|
||||
queryKey: ["newsfeed-circle"],
|
||||
queryFn: async ({ pageParam = 0 }) => {
|
||||
return await getNotes(TIME, ITEM_PER_PAGE, pageParam);
|
||||
return await getNotes(ITEM_PER_PAGE, pageParam);
|
||||
},
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
});
|
||||
@@ -64,7 +63,7 @@ export function FollowingBlock({ block }: { block: number }) {
|
||||
|
||||
const refreshFirstPage = () => {
|
||||
// refetch
|
||||
refetch({ refetchPage: (page, index) => index === 0 });
|
||||
refetch({ refetchPage: (_, index: number) => index === 0 });
|
||||
// scroll to top
|
||||
rowVirtualizer.scrollToIndex(1);
|
||||
// stop notify
|
||||
|
||||
Reference in New Issue
Block a user