update dependencies & clean up
This commit is contained in:
@@ -4,30 +4,23 @@ import { ChatsListItem } from '@app/chat/components/item';
|
||||
import { NewMessageModal } from '@app/chat/components/modal';
|
||||
import { ChatsListSelfItem } from '@app/chat/components/self';
|
||||
|
||||
import { getChatsByPubkey } from '@libs/storage';
|
||||
import { getChats } from '@libs/storage';
|
||||
|
||||
import { useAccount } from '@utils/hooks/useAccount';
|
||||
|
||||
export function ChatsList() {
|
||||
const { account } = useAccount();
|
||||
|
||||
const {
|
||||
status,
|
||||
data: chats,
|
||||
isFetching,
|
||||
} = useQuery(
|
||||
['chats'],
|
||||
async () => {
|
||||
const chats = await getChatsByPubkey(account.pubkey);
|
||||
const sorted = chats.sort(
|
||||
(a, b) => parseInt(a.new_messages) - parseInt(b.new_messages)
|
||||
);
|
||||
return sorted;
|
||||
},
|
||||
{
|
||||
enabled: account ? true : false,
|
||||
}
|
||||
);
|
||||
} = useQuery(['chats'], async () => {
|
||||
const chats = await getChats();
|
||||
const sorted = chats.sort(
|
||||
(a, b) => parseInt(a.new_messages) - parseInt(b.new_messages)
|
||||
);
|
||||
return sorted;
|
||||
});
|
||||
|
||||
if (status === 'loading') {
|
||||
return (
|
||||
|
||||
@@ -66,6 +66,33 @@ export function Root() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchUsersProfile() {
|
||||
const authors = [];
|
||||
|
||||
users.forEach((user) => {
|
||||
if (user.sender_pubkey) {
|
||||
authors.push(user.sender_pubkey);
|
||||
} else {
|
||||
authors.push(user.pubkey);
|
||||
}
|
||||
});
|
||||
|
||||
const filter: NDKFilter = {
|
||||
authors: authors,
|
||||
kinds: [0],
|
||||
};
|
||||
|
||||
const events = await ndk.fetchEvents(filter);
|
||||
|
||||
events.forEach((event: NDKEvent) => {
|
||||
const profile = JSON.parse(event.content);
|
||||
profile['image'] = profile.picture;
|
||||
queryClient.setQueryData(['user', event.pubkey], profile);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async function fetchChats() {
|
||||
try {
|
||||
const sendFilter: NDKFilter = {
|
||||
@@ -101,34 +128,6 @@ export function Root() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchUsersProfile() {
|
||||
const authors = [];
|
||||
|
||||
users.forEach((user) => {
|
||||
if (user.sender_pubkey) {
|
||||
authors.push(user.sender_pubkey);
|
||||
} else {
|
||||
authors.push(user.pubkey);
|
||||
}
|
||||
});
|
||||
|
||||
const filter: NDKFilter = {
|
||||
authors: authors,
|
||||
kinds: [0],
|
||||
};
|
||||
|
||||
const events = await ndk.fetchEvents(filter);
|
||||
console.log('authors', events);
|
||||
|
||||
events.forEach((event: NDKEvent) => {
|
||||
const profile = JSON.parse(event.content);
|
||||
profile['image'] = profile.picture;
|
||||
queryClient.setQueryData(['user', event.pubkey], profile);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
async function fetchChannelMessages() {
|
||||
try {
|
||||
@@ -172,15 +171,12 @@ export function Root() {
|
||||
useEffect(() => {
|
||||
async function prefetch() {
|
||||
const notes = await fetchNotes();
|
||||
if (notes) {
|
||||
const chats = await fetchChats();
|
||||
const users = await fetchUsersProfile();
|
||||
// const channels = await fetchChannelMessages();
|
||||
if (chats && users) {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
await updateLastLogin(now);
|
||||
navigate('/app/space', { replace: true });
|
||||
}
|
||||
const chats = await fetchChats();
|
||||
const users = await fetchUsersProfile();
|
||||
if (notes && users && chats) {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
await updateLastLogin(now);
|
||||
navigate('/app/space', { replace: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user