-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[arcade-chat] Update channel metadata via Nostr kind 41 (#30)
* Add channelmetadata NostrKind and sub to it * Initial useChannelMetadata * useChannelMetadata uses creation info if no updated metadata * ChannelScreen sets title based on metadata name * Pass channelMetadata to ChannelAvatar * initial updateDemoChannelMetadata * create updateDemoChannelMetadata * Sending update messge - just looking for tag * Cleanup * Set channelId to #e tag and fix tags typedef * Extract and fix isArrayInArray * Setting+filtering events for messages+metadata * Use most recent channel metadata event * shhh * clear textinput after submit * Add useDebounce * useChannelMessages w useDebounce * debounce useChannelMetadata * cleanup * Reconnect WS on close * better debounce for useChannelMetadata * Updating name+pic in metadata via modal
- Loading branch information
1 parent
75f8bfa
commit a33b06d
Showing
24 changed files
with
397 additions
and
100 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
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import { useChannelMetadata } from '@arcadecity/use-arcade' | ||
import { useEffect } from 'react' | ||
import { View } from 'react-native' | ||
import { MessageInput } from '../components/MessageInput' | ||
import { MessageList } from '../components/MessageList' | ||
import { RootStackScreenProps } from '../types' | ||
|
||
export const ChannelScreen = () => ( | ||
<View style={{ flex: 1, width: '100%' }}> | ||
<MessageList /> | ||
<MessageInput /> | ||
</View> | ||
) | ||
export const ChannelScreen = ({ navigation }: RootStackScreenProps<'channel'>) => { | ||
const metadata = useChannelMetadata() | ||
// console.log(metadata) | ||
useEffect(() => { | ||
navigation.setOptions({ title: metadata.name }) | ||
}, [metadata]) | ||
return ( | ||
<View style={{ flex: 1, width: '100%' }}> | ||
<MessageList /> | ||
<MessageInput /> | ||
</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 |
---|---|---|
@@ -1,35 +1,90 @@ | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { Platform, StyleSheet } from 'react-native'; | ||
|
||
import EditScreenInfo from '../components/EditScreenInfo'; | ||
import { Text, View } from '../components/Themed'; | ||
import { color } from '@arcadecity/ui' | ||
import { | ||
ArcadeContext, | ||
formatEvent, | ||
updateChannelMetadata, | ||
useChannelMetadata, | ||
} from '@arcadecity/use-arcade' | ||
import { useNavigation } from '@react-navigation/native' | ||
import { useContext, useRef, useState } from 'react' | ||
import { Button, StyleSheet, TextInput } from 'react-native' | ||
import { Text, View } from '../components/Themed' | ||
|
||
export default function ModalScreen() { | ||
const metadata = useChannelMetadata() | ||
const navigation = useNavigation() | ||
const [name, setName] = useState(metadata.name) | ||
const [picture, setPicture] = useState(metadata.picture) | ||
const inputBoxRef = useRef<TextInput | null>(null) | ||
const context = useContext(ArcadeContext) | ||
const updateMetadata = async () => { | ||
// TODO: get channelID properly now that we are storing channelId in tag not prop | ||
const event = await updateChannelMetadata(metadata.tags[0][1], { name, picture }) | ||
const formattedEvent = formatEvent(event) | ||
context.ws.send(formattedEvent) | ||
navigation.goBack() | ||
} | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.title}>Modal</Text> | ||
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> | ||
<EditScreenInfo path="/screens/ModalScreen.tsx" /> | ||
|
||
{/* Use a light status bar on iOS to account for the black space above the modal */} | ||
<StatusBar style={Platform.OS === 'ios' ? 'light' : 'auto'} /> | ||
<Text style={styles.title}>Name</Text> | ||
<View style={styles.inputContainer}> | ||
<TextInput | ||
autoCorrect={false} | ||
defaultValue={metadata.name} | ||
onChangeText={(text: string) => setName(text)} | ||
ref={inputBoxRef} | ||
spellCheck={false} | ||
style={styles.inputBox} | ||
/> | ||
</View> | ||
<View style={styles.inputContainer}> | ||
<TextInput | ||
autoCorrect={false} | ||
defaultValue={metadata.picture} | ||
onChangeText={(text: string) => setPicture(text)} | ||
ref={inputBoxRef} | ||
spellCheck={false} | ||
style={styles.inputBox} | ||
/> | ||
</View> | ||
<Button title='Update channel metadata' onPress={updateMetadata} /> | ||
</View> | ||
); | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: color.background, | ||
}, | ||
title: { | ||
fontSize: 20, | ||
fontWeight: 'bold', | ||
inputBox: { | ||
backgroundColor: color.field, | ||
color: color.text, | ||
flexGrow: 1, | ||
fontSize: 14, | ||
height: 40, | ||
borderRadius: 10, | ||
includeFontPadding: false, | ||
padding: 10, | ||
textAlignVertical: 'center', | ||
}, | ||
inputContainer: { | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
padding: 20, | ||
backgroundColor: color.background, | ||
}, | ||
separator: { | ||
marginVertical: 30, | ||
height: 1, | ||
width: '80%', | ||
}, | ||
}); | ||
title: { | ||
color: color.text, | ||
fontSize: 20, | ||
fontWeight: 'bold', | ||
}, | ||
}) |
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,44 @@ | ||
import { | ||
createNewAccount, | ||
getEventHash, | ||
NostrEvent, | ||
NostrEventToSerialize, | ||
NostrEventToSign, | ||
NostrKind, | ||
signEvent, | ||
} from '../nostr' | ||
import { ChannelMetadata } from '../store' | ||
|
||
export const updateDemoChannelMetadata = async (channelId: string) => { | ||
const { pubkey, privkey } = createNewAccount() | ||
const date = new Date() | ||
const dateTimeInSeconds = Math.floor(date.getTime() / 1000) | ||
const twohundy = Math.round(200 + Math.random() * 5) | ||
const photo = `https://placekitten.com/200/${twohundy.toString()}` | ||
const channelMetadata = { | ||
about: `test about metadadtatatata ${twohundy}`, | ||
channelId, | ||
name: `test name ${twohundy}`, | ||
picture: photo, | ||
type: 'public', // maybe 'public', 'private', 'geohash', 'geocoords' | ||
} | ||
const nostrEventToSerialize: NostrEventToSerialize = { | ||
created_at: dateTimeInSeconds, | ||
kind: NostrKind.channelmetadata, | ||
tags: [['#e', channelId]], | ||
content: JSON.stringify(channelMetadata), | ||
pubkey, | ||
} | ||
const id = getEventHash(nostrEventToSerialize) | ||
const nostrEventToSign: NostrEventToSign = { | ||
...nostrEventToSerialize, | ||
id, | ||
} | ||
const sig = await signEvent(nostrEventToSign, privkey) | ||
const nostrEvent: NostrEvent = { | ||
...nostrEventToSerialize, | ||
id, | ||
sig, | ||
} as ChannelMetadata | ||
return nostrEvent | ||
} |
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,3 +1,7 @@ | ||
export * from './useActiveChannelId' | ||
export * from './useArcadeRelay' | ||
export * from './useChannelMessages' | ||
export * from './useChannelMetadata' | ||
export * from './useChannelsCreated' | ||
export * from './useDebounce' | ||
export * from './useLastChannelMessage' |
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,7 @@ | ||
import { useSnapshot } from 'valtio' | ||
import { store } from '../store' | ||
|
||
export const useActiveChannelId: () => string | null = () => { | ||
const snapshot = useSnapshot(store) | ||
return snapshot.activeChannelId | ||
} |
Oops, something went wrong.
a33b06d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
map-web – ./
map-web.vercel.app
map.arcade.city
map-web-arcade-city.vercel.app
map-web-git-main-arcade-city.vercel.app