-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix hook + start reimpl conversation and chat * fix backend export + tsconfig * readd test relayer
- Loading branch information
Showing
17 changed files
with
251 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { Conversation as ConversationType } from '../../types/messages'; | ||
import { useStyles } from '../../hooks'; | ||
import { View, Image, Text } from 'react-native'; | ||
import { MessageInput } from '../PrivateMessageInput'; | ||
import { MessagesList } from '../PrivateMessages/MessagesList.tsx'; | ||
import stylesheet from './styles'; | ||
import { IconButton } from '../IconButton'; | ||
|
||
export type ChatProps = { | ||
conversation: ConversationType; | ||
handleGoBack: () => void; | ||
}; | ||
|
||
export const Chat: React.FC<ChatProps> = ({ conversation, handleGoBack }) => { | ||
|
||
const styles = useStyles(stylesheet); | ||
const user = conversation.user; | ||
const avatar = user.avatar ? {uri: user.avatar } : require('../../assets/pepe-logo.png'); | ||
|
||
const handleSendMessage = (message: string) => { | ||
//todo: integrate hook here | ||
//todo: encrypt message | ||
//todo: send message | ||
}; | ||
|
||
return ( | ||
<> | ||
<View style={styles.header}> | ||
<IconButton icon="ChevronLeftIcon" size={20} onPress={handleGoBack} style={styles.backButton} /> | ||
<View style={styles.headerContent}> | ||
<Image source={avatar} style={styles.avatar} /> | ||
<Text style={styles.name}>{user.name}</Text> | ||
</View> | ||
</View> | ||
<View style={styles.container}> | ||
<MessagesList messages={conversation.messages} /> | ||
<MessageInput onSend={handleSendMessage} /> | ||
</View> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { Conversation as ConversationType } from '../../types/messages'; | ||
import { useStyles } from '../../hooks'; | ||
import { View, Image, Text } from 'react-native'; | ||
import { MessageInput } from '../PrivateMessageInput'; | ||
import { MessagesList } from '../PrivateMessages/MessagesList.tsx'; | ||
import stylesheet from './styles'; | ||
import { IconButton } from '../IconButton'; | ||
|
||
export type ChatProps = { | ||
conversation: ConversationType; | ||
handleGoBack: () => void; | ||
}; | ||
|
||
export const Chat: React.FC<ChatProps> = ({ conversation, handleGoBack }) => { | ||
|
||
const styles = useStyles(stylesheet); | ||
const user = conversation.user; | ||
const avatar = user.avatar ? {uri: user.avatar } : require('../../assets/pepe-logo.png'); | ||
|
||
const handleSendMessage = (message: string) => { | ||
//todo: integrate hook here | ||
//todo: encrypt message | ||
//todo: send message | ||
}; | ||
|
||
return ( | ||
<> | ||
<View style={styles.header}> | ||
<IconButton icon="ChevronLeftIcon" size={20} onPress={handleGoBack} style={styles.backButton} /> | ||
<View style={styles.headerContent}> | ||
<Image source={avatar} style={styles.avatar} /> | ||
<Text style={styles.name}>{user.name}</Text> | ||
</View> | ||
</View> | ||
<View style={styles.container}> | ||
<MessagesList messages={conversation.messages} /> | ||
<MessageInput onSend={handleSendMessage} /> | ||
</View> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import { Conversation as ConversationType } from '../../types/messages'; | ||
import { useStyles } from '../../hooks'; | ||
import { View, Image, Text } from 'react-native'; | ||
import { MessageInput } from '../PrivateMessageInput'; | ||
import { MessagesList } from '../PrivateMessages/MessagesList.tsx'; | ||
import stylesheet from './styles'; | ||
import { IconButton } from '../IconButton'; | ||
import { useSendPrivateMessage } from 'afk_nostr_sdk'; | ||
import { NDKUser } from '@nostr-dev-kit/ndk'; | ||
import { useToast } from '../../hooks/modals'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { Input } from '../Input'; | ||
|
||
|
||
interface IFormPrivateMessage { | ||
publicKey?: string; | ||
user?: NDKUser; | ||
receiverPublicKeyProps?: string | ||
} | ||
export const FormPrivateMessageInput: React.FC<IFormPrivateMessage> = ({ user, publicKey, receiverPublicKeyProps }) => { | ||
const styles = useStyles(stylesheet); | ||
const avatar = user?.profile?.banner ?? require('../../assets/pepe-logo.png'); | ||
|
||
const [receiverPublicKey, setReceiverPublicKey] = React.useState(receiverPublicKeyProps) | ||
const [content, setContent] = React.useState<string | undefined>() | ||
const sendPrivateMessage = useSendPrivateMessage() | ||
const { showToast } = useToast() | ||
const queryClient = useQueryClient(); | ||
|
||
const handleSendMessage = async (message: string) => { | ||
|
||
if (!content) { | ||
showToast({ title: "Please add a content", type: "error" }) | ||
return; | ||
} | ||
|
||
if (!receiverPublicKey) { | ||
showToast({ title: "Please choose a Nostr public key", type: "error" }) | ||
return; | ||
} | ||
|
||
//todo: integrate hook here | ||
//todo: encrypt message | ||
//todo: send message | ||
await sendPrivateMessage.mutateAsync( | ||
{ receiverPublicKey: receiverPublicKey, content, }, | ||
{ | ||
onSuccess: () => { | ||
|
||
}, | ||
}, | ||
); | ||
|
||
}; | ||
|
||
return ( | ||
<> | ||
{/* <View style={styles.header}> | ||
<IconButton icon="ChevronLeftIcon" size={20} onPress={handleGoBack} style={styles.backButton} /> | ||
<View style={styles.headerContent}> | ||
<Image source={avatar} style={styles.avatar} /> | ||
<Text style={styles.name}>{user.name}</Text> | ||
</View> | ||
</View> */} | ||
<View style={styles.container}> | ||
<Input value={receiverPublicKey} onChangeText={setReceiverPublicKey} placeholder="Receiver" /> | ||
|
||
<MessageInput onSend={handleSendMessage} /> | ||
</View> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...src/components/MessagesList.tsx/index.tsx → ...rivateMessages/MessagesList.tsx/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/components/MessagesList.tsx/styles.ts → ...rivateMessages/MessagesList.tsx/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/afk_nostr_sdk/src/hooks/messages/useMyMessagesSent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {useInfiniteQuery} from '@tanstack/react-query'; | ||
import { useNostrContext } from '../../context'; | ||
import { useAuth } from '../../store'; | ||
|
||
export type UseRootProfilesOptions = { | ||
authors?: string[]; | ||
search?: string; | ||
}; | ||
|
||
export const useMyMessagesSent = (options?: UseRootProfilesOptions) => { | ||
const {ndk} = useNostrContext(); | ||
const {publicKey} = useAuth() | ||
return useInfiniteQuery({ | ||
initialPageParam: 0, | ||
queryKey: ['myMessagesSent', options?.authors, options?.search, ndk], | ||
getNextPageParam: (lastPage: any, allPages, lastPageParam) => { | ||
if (!lastPage?.length) return undefined; | ||
|
||
const pageParam = lastPage[lastPage.length - 1].created_at - 1; | ||
|
||
if (!pageParam || pageParam === lastPageParam) return undefined; | ||
return pageParam; | ||
}, | ||
queryFn: async ({pageParam}) => { | ||
const giftsWrap = await ndk.fetchEvents({ | ||
kinds: [1059 as number], | ||
authors: options?.authors, | ||
search: options?.search, | ||
// until: pageParam || Math.round(Date.now() / 1000), | ||
limit: 20, | ||
}); | ||
|
||
return [...giftsWrap]; | ||
}, | ||
placeholderData: {pages: [], pageParams: []}, | ||
}); | ||
}; |
Oops, something went wrong.