Skip to content

Commit

Permalink
Prepare v0.0.4 for release (#57)
Browse files Browse the repository at this point in the history
* 004 app.json

* clean up our websocket shaz

* showing nomessages message

* change test channel create msg

* channel type fix

* use prod api ur
  • Loading branch information
AtlantisPleb authored Mar 11, 2023
1 parent a525e2a commit b9fed2b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 42 deletions.
6 changes: 3 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "Arc",
"slug": "arc",
"version": "0.0.3",
"version": "0.0.4",
"sdkVersion": "48.0.0",
"jsEngine": "hermes",
"platforms": ["ios", "android"],
Expand All @@ -17,7 +17,7 @@
"ios": {
"supportsTablet": true,
"bundleIdentifier": "arcade.labs.arc",
"buildNumber": "2",
"buildNumber": "1",
"config": {
"usesNonExemptEncryption": false
}
Expand All @@ -27,7 +27,7 @@
"foregroundImage": "./src/assets/icons/adaptive-icon.png",
"backgroundColor": "#000000"
},
"versionCode": 11
"versionCode": 12
},
"extra": {
"eas": {
Expand Down
76 changes: 43 additions & 33 deletions src/lib/hooks/useChannelMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,52 @@ import { Channel, ChannelMessage } from 'stores/types'
export function useChannelMessages(channel: Channel) {
const [messages, setMessages] = useState<ChannelMessage[]>([])

const relay = relayInit(channel.relayurl)
relay.on('connect', () => {
console.log(`connected to ${relay.url}`)
})
relay.on('error', () => {
console.log(`failed to connect to ${relay.url}`)
})

const setupConnection = async () => {
await relay.connect()

// let's query for an event that exists
const sub = relay.sub([
{
kinds: [42],
'#e': [channel.eventid],
limit: 10,
},
])
sub.on('event', (event) => {
const channelMessage: ChannelMessage = {
id: event.id,
content: event.content,
created_at: event.created_at,
pubkey: event.pubkey,
}
setMessages((messages) => [...messages, channelMessage])
useEffect(() => {
let sub: any
const relay = relayInit(channel.relayurl)
relay.on('connect', () => {
console.log(`connected to ${relay.url}`)
})
relay.on('error', () => {
console.log(`failed to connect to ${relay.url}`)
})
// sub.on('eose', () => {
// sub.unsub()
// })
}

useEffect(() => {
const setupConnection = async () => {
await relay.connect()

sub = relay.sub([
{
kinds: [42],
'#e': [channel.eventid],
limit: 100,
since: Math.floor(Date.now() / 1000) - 60 * 60 * 24 * 14,
},
])
sub.on('event', (event: any) => {
const channelMessage: ChannelMessage = {
id: event.id,
content: event.content,
created_at: event.created_at,
pubkey: event.pubkey,
}
setMessages((messages) => [...messages, channelMessage])
})

return sub.unsub
}

const unsubscribe = async () => {
const unsub = await setupConnection()
unsub()
}

setupConnection()
}, [])

return () => {
unsubscribe()
relay.close()
}
}, [channel])

return messages
}
5 changes: 4 additions & 1 deletion src/views/chat/components/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { ChannelPreview } from './ChannelPreview'

export const ChannelList = ({ joined }) => {
const channels = useChannels(joined).filter(
(c: Channel) => c.relayurl !== 'wss://nostr.developer.li'
(c: Channel) =>
c.relayurl !== 'wss://nostr.developer.li' &&
// and name isn't channel name
c.title !== 'channel name'
) as Channel[]
const queryClient = useQueryClient()
const flashListRef = useRef<FlashList<Channel>>(null)
Expand Down
8 changes: 3 additions & 5 deletions src/views/chat/components/CreateChannelButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const CreateChannelButton = () => {
const mutation = useMutation({
mutationFn: async (channel: Partial<Channel>) => {
const { eventid, relayurl } = await saveNewChannel({
channel,
channel: channel as Channel,
publicKey,
privateKey,
})
Expand Down Expand Up @@ -56,11 +56,9 @@ export const CreateChannelButton = () => {
})

const clickedCreateChannel = () => {
console.log('clicked create channel')
mutation.mutate({
// id: '0',
about: 'New Channel Description',
title: `New Channel ${Math.random()}`,
about: 'Testing channel creation from Arc',
title: `Random Test Channel ${Math.floor(Math.random() * 10000)}`,
picture: generateRandomPlacekitten(),
})
}
Expand Down
8 changes: 8 additions & 0 deletions src/views/chat/components/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useChannelMessages } from 'lib/hooks'
import * as React from 'react'
import { FlatList, View } from 'react-native'
import { Channel } from 'stores/types'
import { Stack, Text } from 'tamagui'

import { Message } from './Message'

Expand All @@ -21,6 +22,13 @@ export const MessageList: React.FC<Props> = ({ channel }) => {
keyExtractor={(item) => item.id}
style={{ paddingHorizontal: 10 }}
ListFooterComponent={<View style={{ margin: 5 }} />}
ListEmptyComponent={() => (
<Stack mt="$4" f={1} jc="center" ai="center" h={500}>
<Text color="$color10" textAlign="center">
No messages found from last 14 days
</Text>
</Stack>
)}
/>
)
}

0 comments on commit b9fed2b

Please sign in to comment.