Skip to content

Commit

Permalink
Fix: follow & like & comment issues (#246)
Browse files Browse the repository at this point in the history
* fix: follow & like & comment

* fix: follow created_at
  • Loading branch information
ugur-eren authored Jul 23, 2024
1 parent 1875d32 commit e31f267
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useContacts = (options?: UseContactsOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['contacts', ndk, options?.authors, options?.search],
queryKey: ['contacts', options?.authors, options?.search, ndk],
queryFn: async () => {
const contacts = await ndk.fetchEvent({
kinds: [NDKKind.Contacts],
Expand Down
5 changes: 5 additions & 0 deletions JoyboyCommunity/src/hooks/nostr/useEditContacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ export const useEditContacts = () => {
contacts.tags = [];
}

// Resetting the id and created_at to avoid conflicts
contacts.id = undefined as any;
contacts.created_at = undefined;

if (data.type === 'add') {
contacts.tags.push(['p', data.pubkey, '', '']);
} else {
contacts.tags = contacts.tags.filter((tag) => tag[1] !== data.pubkey);
}

await contacts.sign();
return contacts.publish();
},
});
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useNote = (options: UseNoteOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['note', ndk, options.noteId],
queryKey: ['note', options.noteId, ndk],
queryFn: async () => {
const note = await ndk.fetchEvent({
kinds: [NDKKind.Text],
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useProfile = (options: UseProfileOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['profile', ndk, options.publicKey],
queryKey: ['profile', options.publicKey, ndk],
queryFn: async () => {
const user = ndk.getUser({pubkey: options.publicKey});

Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useReactions = (options?: UseReactionsOptions) => {
const {ndk} = useNostrContext();

return useQuery({
queryKey: ['reactions', ndk, options?.noteId, options?.authors, options?.search],
queryKey: ['reactions', options?.noteId, options?.authors, options?.search, ndk],
queryFn: async () => {
const notes = await ndk.fetchEvents({
kinds: [NDKKind.Reaction],
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useReplyNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useReplyNotes = (options?: UseReplyNotesOptions) => {

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['replyNotes', ndk, options?.noteId, options?.authors, options?.search],
queryKey: ['replyNotes', options?.noteId, options?.authors, options?.search, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useReposts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useReposts = (options?: UseRepostsOptions) => {

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['reposts', ndk, options?.authors, options?.search],
queryKey: ['reposts', options?.authors, options?.search, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/hooks/nostr/useRootNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useRootNotes = (options?: UseRootNotesOptions) => {

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['rootNotes', ndk, options?.authors, options?.search],
queryKey: ['rootNotes', options?.authors, options?.search, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

Expand Down
12 changes: 9 additions & 3 deletions JoyboyCommunity/src/screens/Profile/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Pressable, View} from 'react-native';
import {UserPlusIcon} from '../../../assets/icons';
import {Button, IconButton, Menu, Text} from '../../../components';
import {useContacts, useEditContacts, useProfile, useStyles, useTheme} from '../../../hooks';
import {useToast} from '../../../hooks/modals';
import {useAuth} from '../../../store/auth';
import {ProfileScreenProps} from '../../../types';
import {ProfileHead} from '../Head';
Expand All @@ -26,6 +27,7 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({publicKey: userPublicKe
const [menuOpen, setMenuOpen] = useState(false);
const publicKey = useAuth((state) => state.publicKey);

const {showToast} = useToast();
const queryClient = useQueryClient();
const userContacts = useContacts({authors: [userPublicKey]});
const contacts = useContacts({authors: [publicKey]});
Expand All @@ -40,12 +42,16 @@ export const ProfileInfo: React.FC<ProfileInfoProps> = ({publicKey: userPublicKe

const onConnectionPress = () => {
editContacts.mutateAsync(
{pubkey: publicKey, type: isConnected ? 'remove' : 'add'},
{pubkey: userPublicKey, type: isConnected ? 'remove' : 'add'},
{
onSuccess: () => {
queryClient.invalidateQueries({queryKey: ['contacts']});
userContacts.refetch();
contacts.refetch();
},
onError: () => {
showToast({
type: 'error',
title: isConnected ? 'Failed to unfollow user' : 'Failed to follow user',
});
},
},
);
Expand Down

0 comments on commit e31f267

Please sign in to comment.