Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 9f3599e

Browse files
author
KoalaSat
authored
Better Landing (#73)
2 parents e81aebc + 12acf14 commit 9f3599e

16 files changed

Lines changed: 229 additions & 109 deletions

File tree

android/app/src/main/java/com/nostros/classes/Event.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,20 @@ protected void saveDirectMessage(SQLiteDatabase database) throws JSONException {
202202

203203
protected void saveUserMeta(SQLiteDatabase database) throws JSONException {
204204
JSONObject userContent = new JSONObject(content);
205-
String query = "SELECT * FROM nostros_users WHERE id = ?";
205+
String query = "SELECT created_at FROM nostros_users WHERE id = ?";
206206
@SuppressLint("Recycle") Cursor cursor = database.rawQuery(query, new String[] {pubkey});
207207

208208
ContentValues values = new ContentValues();
209209
values.put("name", userContent.optString("name"));
210210
values.put("picture", userContent.optString("picture"));
211211
values.put("about", userContent.optString("about"));
212-
values.put("lnurl", userContent.optString("lnurl"));
212+
values.put("lnurl", userContent.optString("lud06"));
213213
values.put("main_relay", userContent.optString("main_relay"));
214+
values.put("created_at", created_at);
214215
if (cursor.getCount() == 0) {
215216
values.put("id", pubkey);
216217
database.insert("nostros_users", null, values);
217-
} else {
218+
} else if (cursor.moveToFirst() && created_at > cursor.getInt(0)) {
218219
String whereClause = "id = ?";
219220
String[] whereArgs = new String[] {
220221
this.pubkey
@@ -233,7 +234,7 @@ protected void savePets(SQLiteDatabase database) throws JSONException {
233234
ContentValues values = new ContentValues();
234235
values.put("id", petId);
235236
values.put("name", tag.getString(3));
236-
values.put("contact", true);
237+
values.put("contact", true);
237238
database.insert("nostros_users", null, values);
238239
}
239240
}

android/app/src/main/java/com/nostros/modules/DatabaseModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class DatabaseModule {
6565
try {
6666
database.execSQL("ALTER TABLE nostros_users ADD COLUMN lnurl TEXT;");
6767
} catch (SQLException e) { }
68+
try {
69+
database.execSQL("ALTER TABLE nostros_users ADD COLUMN created_at INT DEFAULT 0;");
70+
} catch (SQLException e) { }
6871
}
6972

7073
public void saveEvent(JSONObject data, String userPubKey) throws JSONException {

android/app/src/main/java/com/nostros/modules/RelayPoolModule.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.IOException;
1313
import java.util.List;
14+
import java.util.ListIterator;
1415

1516
public class RelayPoolModule extends ReactContextBaseJavaModule {
1617
protected List<Relay> relays;
@@ -48,13 +49,16 @@ public void add(String url) {
4849

4950
@ReactMethod
5051
public void remove(String url, Callback callback) {
51-
for (Relay relay : relays) {
52-
if (relay.url.equals(url)) {
52+
ListIterator<Relay> iterator = relays.listIterator();
53+
while(iterator.hasNext()){
54+
Relay relay = iterator.next();
55+
if(url.equals(relay.url)){
5356
relay.disconnect();
54-
relays.remove(relay);
57+
iterator.remove();
5558
database.destroyRelay(relay);
5659
}
5760
}
61+
5862
callback.invoke();
5963
}
6064

@@ -64,6 +68,7 @@ public void connect(String pubKey, Callback callback) {
6468
relays = database.getRelays(context);
6569
if (relays.isEmpty()) {
6670
add("wss://relay.damus.io");
71+
add("wss://nostr-relay.wlvs.space");
6772
}
6873
for (Relay relay : relays) {
6974
try {

frontend/Components/ConfigPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const ConfigPage: React.FC = () => {
6666
name,
6767
about,
6868
picture,
69-
lnurl,
69+
lud06: lnurl,
7070
}),
7171
created_at: moment().unix(),
7272
kind: EventKind.meta,

frontend/Components/HomePage/index.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Card, Layout, Text, useTheme } from '@ui-kitten/components'
1+
import { Button, Card, Layout, Text, useTheme } from '@ui-kitten/components'
22
import React, { useCallback, useContext, useEffect, useState } from 'react'
33
import { t } from 'i18next'
44
import {
@@ -46,7 +46,7 @@ export const HomePage: React.FC = () => {
4646

4747
const message: RelayFilters = {
4848
kinds: [EventKind.textNote, EventKind.recommendServer],
49-
authors: users.map((user) => user.id)
49+
authors: [...users.map((user) => user.id), publicKey],
5050
}
5151

5252
if (lastNote && lastNotes.length > 0 && !past) {
@@ -65,7 +65,7 @@ export const HomePage: React.FC = () => {
6565
setRefreshing(false)
6666
relayPool?.subscribe('main-channel', {
6767
kinds: [EventKind.meta],
68-
authors: notes.map((note) => note.pubkey)
68+
authors: notes.map((note) => note.pubkey),
6969
})
7070
})
7171
}
@@ -132,6 +132,11 @@ export const HomePage: React.FC = () => {
132132
height: 32,
133133
},
134134
empty: {
135+
height: 128,
136+
justifyContent: 'center',
137+
alignItems: 'center',
138+
},
139+
noContacts: {
135140
height: 64,
136141
justifyContent: 'center',
137142
alignItems: 'center',
@@ -142,12 +147,27 @@ export const HomePage: React.FC = () => {
142147
<>
143148
<Layout style={styles.container} level='3'>
144149
{notes.length > 0 ? (
145-
<ScrollView onScroll={onScroll} horizontal={false} refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}>
150+
<ScrollView
151+
onScroll={onScroll}
152+
horizontal={false}
153+
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}
154+
>
146155
{notes.map((note) => itemCard(note))}
147156
</ScrollView>
148157
) : (
149158
<Layout style={styles.empty} level='3'>
150-
<Text>{t('homePage.noContacts')}</Text>
159+
<Layout style={styles.noContacts} level='3'>
160+
<Text>{t('homePage.noContacts')}</Text>
161+
</Layout>
162+
<Button
163+
onPress={() => goToPage('config')}
164+
status='warning'
165+
accessoryLeft={
166+
<Icon name='address-book' size={16} color={theme['text-basic-color']} solid />
167+
}
168+
>
169+
{t('homePage.addContacts')}
170+
</Button>
151171
</Layout>
152172
)}
153173
</Layout>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useContext, useEffect, useState } from 'react'
2+
import { Button, Layout, Text, useTheme } from '@ui-kitten/components'
3+
import { StyleSheet } from 'react-native'
4+
import { RelayPoolContext } from '../../../Contexts/RelayPoolContext'
5+
import { EventKind } from '../../../lib/nostr/Events'
6+
import { AppContext } from '../../../Contexts/AppContext'
7+
import { getUser, getUsers, User } from '../../../Functions/DatabaseFunctions/Users'
8+
import Icon from 'react-native-vector-icons/FontAwesome5'
9+
import { useTranslation } from 'react-i18next'
10+
11+
export const Loader: React.FC = () => {
12+
const { goToPage, loadingDb, database } = useContext(AppContext)
13+
const { publicKey, relayPool, lastEventId, loadingRelayPool } = useContext(RelayPoolContext)
14+
const theme = useTheme()
15+
const { t } = useTranslation('common')
16+
const [profileFound, setProfileFound] = useState<boolean>(false)
17+
const [contactsCount, setContactsCount] = useState<number>()
18+
19+
useEffect(() => {
20+
if (!loadingRelayPool && !loadingDb && publicKey) {
21+
relayPool?.subscribe('main-channel', {
22+
kinds: [EventKind.petNames, EventKind.meta, EventKind.directMessage],
23+
authors: [publicKey],
24+
})
25+
}
26+
}, [loadingRelayPool, publicKey, loadingDb])
27+
28+
useEffect(() => {
29+
loadPets()
30+
loadProfile()
31+
}, [lastEventId])
32+
33+
const loadPets: () => void = () => {
34+
if (database) {
35+
getUsers(database, { contacts: true }).then((results) => {
36+
setContactsCount(results.length)
37+
if (results && results.length > 0) {
38+
relayPool?.subscribe('main-channel', {
39+
kinds: [EventKind.meta],
40+
authors: results.map((user: User) => user.id),
41+
})
42+
}
43+
})
44+
}
45+
}
46+
47+
const loadProfile: () => void = () => {
48+
if (database && publicKey) {
49+
getUser(publicKey, database).then((result) => {
50+
if (result) {
51+
setProfileFound(true)
52+
}
53+
})
54+
}
55+
}
56+
57+
const styles = StyleSheet.create({
58+
container: {
59+
padding: 32,
60+
},
61+
text: {
62+
marginVertical: 10,
63+
padding: 32,
64+
alignItems: 'center',
65+
justifyContent: 'center',
66+
},
67+
action: {
68+
backgroundColor: 'transparent',
69+
marginTop: 12,
70+
},
71+
})
72+
73+
return (
74+
<>
75+
<Layout style={styles.text}>
76+
<Text>{profileFound ? t('loader.profileFound') : t('loader.searchingProfile')}</Text>
77+
<Text>{`${t('loader.searchingContacts')} ${contactsCount}`}</Text>
78+
</Layout>
79+
<Layout>
80+
<Text>{t('loader.help1')}</Text>
81+
<Text>{t('loader.help2')}</Text>
82+
</Layout>
83+
<Layout style={styles.action}>
84+
<Button
85+
onPress={() => goToPage('relays')}
86+
status='warning'
87+
accessoryLeft={<Icon name='server' size={16} color={theme['text-basic-color']} solid />}
88+
>
89+
{t('loader.relays')}
90+
</Button>
91+
</Layout>
92+
<Layout style={styles.action}>
93+
<Button
94+
onPress={() => goToPage('home')}
95+
accessoryLeft={<Icon name='home' size={16} color={theme['text-basic-color']} solid />}
96+
>
97+
{t('loader.home')}
98+
</Button>
99+
</Layout>
100+
</>
101+
)
102+
}
103+
104+
export default Loader

frontend/Components/LandingPage/Logger/index.tsx

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,27 @@
1-
import React, { useContext, useEffect, useState } from 'react'
1+
import React, { useContext, useState } from 'react'
22
import { Button, Input, Layout, useTheme } from '@ui-kitten/components'
33
import { Clipboard, StyleSheet } from 'react-native'
44
import { RelayPoolContext } from '../../../Contexts/RelayPoolContext'
55
import { useTranslation } from 'react-i18next'
6-
import { EventKind } from '../../../lib/nostr/Events'
7-
import { AppContext } from '../../../Contexts/AppContext'
8-
import SInfo from 'react-native-sensitive-info'
96
import Icon from 'react-native-vector-icons/FontAwesome5'
10-
import { generateRandomKey, getPublickey } from '../../../lib/nostr/Bip'
7+
import { generateRandomKey } from '../../../lib/nostr/Bip'
118
import { showMessage } from 'react-native-flash-message'
12-
import { getUsers, User } from '../../../Functions/DatabaseFunctions/Users'
139

1410
export const Logger: React.FC = () => {
15-
const { goToPage, loadingDb, database } = useContext(AppContext)
16-
const { privateKey, publicKey, relayPool, loadingRelayPool, setPrivateKey, setPublicKey } =
17-
useContext(RelayPoolContext)
11+
const { publicKey, setPrivateKey, setPublicKey } = useContext(RelayPoolContext)
1812
const { t } = useTranslation('common')
1913
const theme = useTheme()
20-
const [loading, setLoading] = useState<boolean>(false)
21-
const [status, setStatus] = useState<number>(0)
2214
const [isPrivate, setIsPrivate] = useState<boolean>(true)
2315
const [inputValue, setInputValue] = useState<string>('')
2416

25-
useEffect(() => {
26-
if (loading) {
27-
setStatus(1)
17+
const onPress: () => void = () => {
18+
if (inputValue && inputValue !== '') {
2819
if (isPrivate) {
2920
setPrivateKey(inputValue)
30-
const publicKey: string = getPublickey(inputValue)
31-
setPublicKey(publicKey)
32-
SInfo.setItem('privateKey', inputValue, {})
33-
SInfo.setItem('publicKey', publicKey, {})
3421
} else {
3522
setPublicKey(inputValue)
36-
SInfo.setItem('publicKey', inputValue, {})
3723
}
3824
}
39-
}, [loading])
40-
41-
useEffect(() => {
42-
if (!loadingRelayPool && !loadingDb && publicKey) {
43-
relayPool?.subscribe('main-channel', {
44-
kinds: [EventKind.petNames, EventKind.meta],
45-
authors: [publicKey],
46-
})
47-
setTimeout(loadPets, 4000)
48-
}
49-
}, [loadingRelayPool, publicKey, loadingDb])
50-
51-
const onPress: () => void = () => {
52-
if (inputValue && inputValue !== '') {
53-
setLoading(true)
54-
}
55-
}
56-
57-
const loadPets: () => void = () => {
58-
if (database) {
59-
getUsers(database, { contacts: true }).then((results) => {
60-
if (results && results.length > 0) {
61-
relayPool?.subscribe('main-channel', {
62-
kinds: [EventKind.textNote, EventKind.recommendServer, EventKind.meta],
63-
authors: results.map((user: User) => user.id),
64-
})
65-
}
66-
setTimeout(() => goToPage('home', true), 5000)
67-
})
68-
}
6925
}
7026

7127
const randomKeyGenerator: () => JSX.Element = () => {
@@ -95,11 +51,6 @@ export const Logger: React.FC = () => {
9551
)
9652
}
9753

98-
const statusName: { [status: number]: string } = {
99-
0: t('landing.connect'),
100-
1: t('landing.connecting'),
101-
2: t('landing.ready'),
102-
}
10354
const styles = StyleSheet.create({
10455
inputsContainer: {
10556
flexDirection: 'row',
@@ -130,7 +81,7 @@ export const Logger: React.FC = () => {
13081

13182
const label: string = isPrivate ? t('landing.privateKey') : t('landing.publicKey')
13283

133-
return !privateKey || !publicKey || status !== 0 ? (
84+
return (
13485
<>
13586
<Layout style={styles.inputsContainer}>
13687
<Layout style={styles.input}>
@@ -139,7 +90,7 @@ export const Logger: React.FC = () => {
13990
label={label}
14091
onChangeText={setInputValue}
14192
value={inputValue}
142-
disabled={loading}
93+
disabled={publicKey !== undefined}
14394
accessoryRight={randomKeyGenerator}
14495
/>
14596
</Layout>
@@ -151,20 +102,18 @@ export const Logger: React.FC = () => {
151102
setIsPrivate(!isPrivate)
152103
setInputValue('')
153104
}}
154-
disabled={loading}
105+
disabled={publicKey !== undefined}
155106
accessoryLeft={keyButton}
156107
status={isPrivate ? 'warning' : 'default'}
157108
/>
158109
</Layout>
159110
<Layout style={styles.buttonRight}>
160-
<Button onPress={onPress} disabled={loading}>
161-
{statusName[status]}
111+
<Button onPress={onPress} disabled={publicKey !== undefined}>
112+
{t('landing.connect')}
162113
</Button>
163114
</Layout>
164115
</Layout>
165116
</>
166-
) : (
167-
<></>
168117
)
169118
}
170119

0 commit comments

Comments
 (0)