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