mirror of
https://github.com/KoalaSat/nostros.git
synced 2024-09-29 06:30:47 +00:00
reconnect contacts relays (#433)
This commit is contained in:
commit
fbd914cccf
@ -110,7 +110,7 @@ export const LnPayment: React.FC<LnPaymentProps> = ({ open, setOpen, note, user
|
||||
|
||||
const renderZapperItem: ListRenderItem<Zap> = ({ item }) => {
|
||||
const zapDescription = item.tags?.find((tag) => tag[0] === 'description')
|
||||
const content = zapDescription ? JSON.parse(zapDescription[1])?.content : ''
|
||||
const content = zapDescription ? JSON.parse(zapDescription[1])?.content : undefined
|
||||
return (
|
||||
<TouchableRipple onPress={() => setDisplayUserDrawer(item.user_id)}>
|
||||
<View key={item.id} style={styles.zapperRow}>
|
||||
|
@ -96,7 +96,7 @@ export const RelayPoolContextProvider = ({
|
||||
const event: Event = {
|
||||
content: '',
|
||||
created_at: getUnixTime(new Date()),
|
||||
kind: 1002,
|
||||
kind: 10002,
|
||||
pubkey: publicKey,
|
||||
tags: results.map((relay) => ['r', relay.url, relay.mode ?? '']),
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export const getContactsRelays: (
|
||||
relayMetadada.forEach((metadata) => {
|
||||
pubKeys.push(metadata.pubkey)
|
||||
let rTags: string[][] = getRTags(metadata)
|
||||
rTags = rTags.filter(tag => tag.length < 3 || tag[2] !== 'read')
|
||||
rTags = rTags.filter((tag) => tag.length < 3 || tag[2] !== 'read')
|
||||
const urls = rTags.map((tags) => tags[1])
|
||||
urls.forEach((url) => {
|
||||
if (!localhostRegExp.test(url)) {
|
||||
|
@ -152,6 +152,7 @@
|
||||
"zap": "Zap"
|
||||
},
|
||||
"notificationsFeed": {
|
||||
"connectContactRelays": "Reconnect to contacts' relays",
|
||||
"reposted": "Reposted",
|
||||
"zap": "Zapped {{amount}}",
|
||||
"like": "Like",
|
||||
|
@ -274,6 +274,7 @@
|
||||
"relaysPage": {
|
||||
"pushListTitle": "Push relay list to the network",
|
||||
"pushListDescription": "Only relays on \"My relays\" list will be pushed.",
|
||||
"connectContactRelays": "Reconnect to contacts' relays",
|
||||
"pushList": "Push list",
|
||||
"contactsList": "Contact's relays",
|
||||
"freeAccess": "Free access",
|
||||
|
@ -176,6 +176,7 @@
|
||||
"reposted": "Reposteado",
|
||||
"zap": "Zap {{amount}}",
|
||||
"like": "Le ha gustado",
|
||||
"connectContactRelays": "Reconnectar a los relays de mis contactos",
|
||||
"Dislike": "No le ha gustado",
|
||||
"replied": "Respuesta",
|
||||
"emptyTitle": "No tienes notificationes.",
|
||||
|
@ -312,6 +312,7 @@
|
||||
}
|
||||
},
|
||||
"relaysPage": {
|
||||
"connectContactRelays": "Reconnect to contacts' relays",
|
||||
"pushListTitle": "Push relay list to the network",
|
||||
"pushListDescription": "Only relays on \"My relays\" list will be pushed.",
|
||||
"pushList": "Push list",
|
||||
|
@ -307,6 +307,7 @@
|
||||
}
|
||||
},
|
||||
"relaysPage": {
|
||||
"connectContactRelays": "Reconnect to contacts' relays",
|
||||
"pushListTitle": "Push relay list to the network",
|
||||
"pushListDescription": "Only relays on \"My relays\" list will be pushed.",
|
||||
"pushList": "Push list",
|
||||
|
@ -283,6 +283,7 @@
|
||||
"newMessages": "有{{newNotesCount}}条新的 Notes,下拉刷新"
|
||||
},
|
||||
"relaysPage": {
|
||||
"connectContactRelays": "Reconnect to contacts' relays",
|
||||
"pushListTitle": "Push relay list to the network",
|
||||
"pushListDescription": "Only relays on \"My relays\" list will be pushed.",
|
||||
"pushList": "Push list",
|
||||
|
@ -77,7 +77,8 @@ export const NotificationsFeed: React.FC = () => {
|
||||
}, [pushedTab])
|
||||
|
||||
useEffect(() => {
|
||||
if (pubKeys.length > 0) {
|
||||
if (database && pubKeys.length > 0) {
|
||||
getUsers(database, { includeIds: pubKeys }).then(setUsers)
|
||||
relayPool?.subscribe('notification-users', [
|
||||
{
|
||||
kinds: [Kind.Metadata],
|
||||
@ -132,7 +133,6 @@ export const NotificationsFeed: React.FC = () => {
|
||||
|
||||
const loadNotes: () => void = async () => {
|
||||
if (database && publicKey) {
|
||||
getUsers(database, { includeIds: pubKeys }).then(setUsers)
|
||||
getReactions(database, { reactedUser: publicKey, limitDate }).then((results) => {
|
||||
setPubKeys((prev) => [...prev, ...results.map((res) => res.pubkey)])
|
||||
setReaction(results)
|
||||
|
@ -30,6 +30,10 @@ import { useFocusEffect } from '@react-navigation/native'
|
||||
import { UserContext } from '../../Contexts/UserContext'
|
||||
import { type Event } from '../../lib/nostr/Events'
|
||||
import { getUnixTime } from 'date-fns'
|
||||
import { getAllRelayMetadata } from '../../Functions/DatabaseFunctions/RelayMetadatas'
|
||||
import { getContactsRelays } from '../../Functions/RelayFunctions/Metadata'
|
||||
import { AppContext } from '../../Contexts/AppContext'
|
||||
import { getUsers, User } from '../../Functions/DatabaseFunctions/Users'
|
||||
|
||||
export const RelaysPage: React.FC = () => {
|
||||
const defaultRelayInput = React.useMemo(() => 'wss://', [])
|
||||
@ -42,31 +46,40 @@ export const RelaysPage: React.FC = () => {
|
||||
relays,
|
||||
lastEventId,
|
||||
loadRelays,
|
||||
removeRelayItem,
|
||||
} = useContext(RelayPoolContext)
|
||||
const { publicKey } = useContext(UserContext)
|
||||
const { database } = useContext(AppContext)
|
||||
const { t } = useTranslation('common')
|
||||
const theme = useTheme()
|
||||
const bottomSheetAddRef = React.useRef<RBSheet>(null)
|
||||
const bottomSheetPushRef = React.useRef<RBSheet>(null)
|
||||
const bottomSheetContactsRef = React.useRef<RBSheet>(null)
|
||||
const [addRelayInput, setAddRelayInput] = useState<string>(defaultRelayInput)
|
||||
const [addRelayPaid, setAddRelayPaid] = useState<boolean>(false)
|
||||
const [showNotification, setShowNotification] = useState<string>()
|
||||
const [asignation, setAsignation] = useState<string[]>()
|
||||
const [showPaidRelays, setShowPaidRelays] = useState<boolean>(true)
|
||||
const [showFreeRelays, setShowFreeRelays] = useState<boolean>(true)
|
||||
|
||||
useFocusEffect(
|
||||
React.useCallback(() => {
|
||||
relayPool?.unsubscribeAll()
|
||||
if (publicKey) {
|
||||
relayPool?.subscribe('relays', [
|
||||
{
|
||||
kinds: [1002],
|
||||
authors: [publicKey],
|
||||
},
|
||||
])
|
||||
if (publicKey && database) {
|
||||
getUsers(database, {}).then((results) => {
|
||||
if (results.length > 0) {
|
||||
const authors = [...results.map((user: User) => user.id), publicKey]
|
||||
relayPool?.subscribe('relays-contacts', [
|
||||
{
|
||||
kinds: [10002],
|
||||
authors,
|
||||
},
|
||||
])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return () => relayPool?.unsubscribe(['relays'])
|
||||
return () => relayPool?.unsubscribe(['relays-contacts'])
|
||||
}, []),
|
||||
)
|
||||
|
||||
@ -172,6 +185,14 @@ export const RelaysPage: React.FC = () => {
|
||||
return 0
|
||||
})
|
||||
|
||||
const calculateContactsRelays: () => void = () => {
|
||||
if (database) {
|
||||
getAllRelayMetadata(database).then((relayMetadata) => {
|
||||
getContactsRelays(relays, relayMetadata).then(setAsignation)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const renderItem: ListRenderItem<Relay> = ({ item, index }) => {
|
||||
return (
|
||||
<View style={styles.relayItem}>
|
||||
@ -230,12 +251,42 @@ export const RelaysPage: React.FC = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const renderContactRelayItem: ListRenderItem<string> = ({ item, index }) => {
|
||||
return (
|
||||
<View style={styles.relayItem}>
|
||||
<List.Item
|
||||
key={index}
|
||||
title={item.replace('wss://', '').replace('ws://', '')}
|
||||
left={() => (
|
||||
<MaterialCommunityIcons
|
||||
style={styles.relayColor}
|
||||
name='circle'
|
||||
color={relayToColor(item)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const pasteUrl: () => void = () => {
|
||||
Clipboard.getString().then((value) => {
|
||||
setAddRelayInput(value ?? '')
|
||||
})
|
||||
}
|
||||
|
||||
const onPressAddContactRelay: () => void = () => {
|
||||
relays
|
||||
.filter((relay) => relay.resilient && relay.resilient > 0)
|
||||
.forEach((relay) => {
|
||||
removeRelayItem(relay)
|
||||
})
|
||||
if (asignation) {
|
||||
asignation.forEach(async (url) => await addRelayItem({ url, resilient: 1, global_feed: 0 }))
|
||||
}
|
||||
bottomSheetContactsRef.current?.close()
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<View style={styles.relayFilters}>
|
||||
@ -297,6 +348,18 @@ export const RelaysPage: React.FC = () => {
|
||||
ItemSeparatorComponent={Divider}
|
||||
/>
|
||||
</ScrollView>
|
||||
<AnimatedFAB
|
||||
style={styles.fabContacts}
|
||||
icon='cached'
|
||||
label='push'
|
||||
onPress={() => {
|
||||
calculateContactsRelays()
|
||||
bottomSheetContactsRef.current?.open()
|
||||
}}
|
||||
animateFrom='right'
|
||||
iconMode='static'
|
||||
extended={false}
|
||||
/>
|
||||
<AnimatedFAB
|
||||
style={styles.fabPush}
|
||||
icon='upload-multiple'
|
||||
@ -347,6 +410,27 @@ export const RelaysPage: React.FC = () => {
|
||||
</Button>
|
||||
</View>
|
||||
</RBSheet>
|
||||
<RBSheet
|
||||
ref={bottomSheetContactsRef}
|
||||
closeOnDragDown={true}
|
||||
customStyles={rbSheetCustomStyles}
|
||||
>
|
||||
<FlatList
|
||||
showsVerticalScrollIndicator={false}
|
||||
data={asignation}
|
||||
renderItem={renderContactRelayItem}
|
||||
ItemSeparatorComponent={Divider}
|
||||
style={styles.conteactRelaysList}
|
||||
/>
|
||||
<View style={styles.bottomDrawerButton}>
|
||||
<Button mode='contained' onPress={onPressAddContactRelay}>
|
||||
{t('relaysPage.connectContactRelays')}
|
||||
</Button>
|
||||
</View>
|
||||
<Button mode='outlined' onPress={() => bottomSheetContactsRef.current?.close()}>
|
||||
{t('relaysPage.cancel')}
|
||||
</Button>
|
||||
</RBSheet>
|
||||
<RBSheet ref={bottomSheetAddRef} closeOnDragDown={true} customStyles={rbSheetCustomStyles}>
|
||||
<View style={styles.addRelay}>
|
||||
<View style={styles.bottomDrawerButton}>
|
||||
@ -410,12 +494,16 @@ const styles = StyleSheet.create({
|
||||
marginBottom: -10,
|
||||
},
|
||||
bottomDrawerButton: {
|
||||
paddingTop: 16,
|
||||
paddingBottom: 16,
|
||||
},
|
||||
relayOptionButton: {
|
||||
margin: 0,
|
||||
marginRight: 10,
|
||||
},
|
||||
conteactRelaysList: {
|
||||
maxHeight: 400,
|
||||
},
|
||||
container: {
|
||||
padding: 0,
|
||||
},
|
||||
@ -434,7 +522,12 @@ const styles = StyleSheet.create({
|
||||
marginLeft: 32,
|
||||
},
|
||||
relayList: {
|
||||
paddingBottom: 200,
|
||||
paddingBottom: 260,
|
||||
},
|
||||
fabContacts: {
|
||||
bottom: 212,
|
||||
right: 16,
|
||||
position: 'absolute',
|
||||
},
|
||||
fabPush: {
|
||||
bottom: 142,
|
||||
|
Loading…
Reference in New Issue
Block a user