Global feed relay fix

This commit is contained in:
KoalaSat 2023-02-03 16:21:01 +01:00
parent 8392773923
commit b9cbc7cc94
No known key found for this signature in database
GPG Key ID: 2F7F61C6146AB157
7 changed files with 43 additions and 44 deletions

View File

@ -42,33 +42,27 @@ public class Event {
}
public void save(SQLiteDatabase database, String userPubKey, String relayUrl) {
if (isValid()) {
try {
if (kind.equals("0")) {
saveUserMeta(database);
} else if (kind.equals("1") || kind.equals("2")) {
saveNote(database, userPubKey, relayUrl);
} else if (kind.equals("3")) {
if (pubkey.equals(userPubKey)) {
savePets(database);
} else {
saveFollower(database, userPubKey);
}
} else if (kind.equals("4")) {
saveDirectMessage(database);
} else if (kind.equals("7")) {
saveReaction(database);
try {
if (kind.equals("0")) {
saveUserMeta(database);
} else if (kind.equals("1") || kind.equals("2")) {
saveNote(database, userPubKey, relayUrl);
} else if (kind.equals("3")) {
if (pubkey.equals(userPubKey)) {
savePets(database);
} else {
saveFollower(database, userPubKey);
}
} catch (JSONException e) {
e.printStackTrace();
} else if (kind.equals("4")) {
saveDirectMessage(database);
} else if (kind.equals("7")) {
saveReaction(database);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
protected boolean isValid() {
return !id.isEmpty() && !sig.isEmpty() && created_at <= System.currentTimeMillis() / 1000L;
}
protected String getMainEventId() {
JSONArray eTags = filterTags("e");
String mainEventId = null;

View File

@ -120,8 +120,8 @@ public class DatabaseModule {
database.execSQL("CREATE INDEX nostros_reactions_created_at_reacted_event_id_index ON nostros_reactions(created_at, reacted_event_id); ");
database.execSQL("CREATE INDEX nostros_users_contact_index ON nostros_users(contact, follower); ");
database.execSQL("CREATE INDEX nostros_users_contact_index ON nostros_users(id, name); ");
database.execSQL("CREATE INDEX nostros_users_contact_follower_index ON nostros_users(contact, follower); ");
database.execSQL("CREATE INDEX nostros_users_id_name_index ON nostros_users(id, name); ");
} catch (SQLException e) { }
try {
database.execSQL("DROP TABLE IF EXISTS nostros_config;");

View File

@ -1,6 +1,7 @@
export const defaultRelays = [
'wss://brb.io',
'wss://damus.io',
'wss://nostr-pub.wellorder.net',
'wss://nostr.swiss-enigma.ch',
'wss://nostr.onsats.org',
'wss://nostr-pub.semisol.dev',
@ -9,7 +10,6 @@ export const defaultRelays = [
'wss://nostr.oxtr.dev',
'wss://nostr.ono.re',
'wss://relay.grunch.dev',
'wss://nostr-pub.wellorder.net',
'wss://nostr.developer.li',
]

View File

@ -53,7 +53,6 @@ export const getMainNotes: (
if (filters?.until) notesQuery += `nostros_notes.created_at <= ${filters?.until} AND `
notesQuery += `
nostros_users.blocked != 1 AND
nostros_notes.main_event_id IS NULL
ORDER BY created_at DESC
LIMIT ${limit}

View File

@ -4,6 +4,7 @@ import RelayPool from '../../../lib/nostr/RelayPool/intex'
import { getUser, getUsers, User } from '../../DatabaseFunctions/Users'
import { Event } from '../../../lib/nostr/Events'
import { getNpub } from '../../../lib/nostr/Nip19'
import { Kind } from 'nostr-tools'
export const usersToTags: (users: User[]) => string[][] = (users) => {
return users.map((user): string[] => {
@ -60,7 +61,7 @@ export const populatePets: (
const event: Event = {
content: '',
created_at: getUnixTime(new Date()),
kind: 3,
kind: Kind.Contacts,
pubkey: publicKey,
tags: usersToTags(results),
}
@ -84,7 +85,7 @@ export const populateProfile: (
const event: Event = {
content: JSON.stringify(profile),
created_at: getUnixTime(new Date()),
kind: 0,
kind: Kind.Metadata,
pubkey: publicKey,
tags: usersToTags([result]),
}

View File

@ -27,9 +27,14 @@ export const ProfileLoadPage: React.FC = () => {
debounce(() => {
loadMeta()
loadPets()
}, 500)
}, 1000)
return () => relayPool?.unsubscribe(['profile-load-notes', 'profile-load-meta-pets'])
return () =>
relayPool?.unsubscribe([
'profile-load-meta',
'profile-load-notes',
'profile-load-meta-pets',
])
}, []),
)
@ -49,11 +54,13 @@ export const ProfileLoadPage: React.FC = () => {
const loadMeta: () => void = () => {
if (publicKey && relayPoolReady) {
relayPool?.subscribe('profile-load-meta-pets', [
relayPool?.subscribe('profile-load-meta', [
{
kinds: [Kind.Contacts, Kind.Metadata],
kinds: [Kind.Text, Kind.Contacts, Kind.Metadata],
authors: [publicKey],
},
])
relayPool?.subscribe('profile-load-meta-pets', [
{
kinds: [Kind.Contacts],
'#p': [publicKey],
@ -70,18 +77,14 @@ export const ProfileLoadPage: React.FC = () => {
const authors = [...results.map((user: User) => user.id), publicKey]
relayPool?.subscribe('profile-load-notes', [
{
kinds: [Kind.Text],
authors: [publicKey],
kinds: [Kind.Metadata],
authors,
},
{
kinds: [Kind.Text],
authors,
since: getUnixTime(new Date()) - 43200,
},
{
kinds: [Kind.Metadata],
authors,
},
])
}
})

View File

@ -59,12 +59,14 @@ export const RelaysPage: React.FC = () => {
const desactiveRelay: (relay: Relay) => void = (relay) => {
relay.active = 0
relay.global_feed = 0
updateRelayItem(relay).then(() => {
setShowNotification('desactive')
})
}
const activeGlobalFeedRelay: (relay: Relay) => void = (relay) => {
relay.active = 1
relay.global_feed = 1
updateRelayItem(relay).then(() => {
setShowNotification('globalFeedActive')
@ -125,7 +127,7 @@ export const RelaysPage: React.FC = () => {
<Switch
value={item.global_feed !== undefined && item.global_feed > 0}
onValueChange={() =>
item.active ? desactiveGlobalFeedRelay(item) : activeGlobalFeedRelay(item)
item.global_feed ? desactiveGlobalFeedRelay(item) : activeGlobalFeedRelay(item)
}
/>
<Switch
@ -162,11 +164,11 @@ export const RelaysPage: React.FC = () => {
)}
/>
<ScrollView horizontal={false}>
<Text style={styles.title} variant='titleMedium'>
{t('relaysPage.myList')}
</Text>
{myRelays.length > 0 && (
<>
<Text style={styles.title} variant='titleMedium'>
{t('relaysPage.myList')}
</Text>
<FlatList
showsVerticalScrollIndicator={false}
data={myRelays}
@ -280,7 +282,7 @@ const styles = StyleSheet.create({
paddingLeft: 16,
},
list: {
paddingBottom: 80,
paddingBottom: 130,
},
snackbar: {
margin: 16,
@ -298,7 +300,7 @@ const styles = StyleSheet.create({
textAlign: 'center',
},
fab: {
bottom: 16,
bottom: 65,
right: 16,
position: 'absolute',
},