mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-29 22:30:43 +00:00
Compare commits
3 Commits
73eadc4b8d
...
a522e919c6
Author | SHA1 | Date | |
---|---|---|---|
a522e919c6 | |||
452456927a | |||
77d48ae416 |
@ -21,9 +21,10 @@ class MyDexie extends Dexie {
|
||||
constructor() {
|
||||
super('iris');
|
||||
|
||||
this.version(5).stores({
|
||||
events: 'id, pubkey, kind, created_at, [pubkey+kind]',
|
||||
tags: 'id, eventId, [type+value]',
|
||||
this.version(6).stores({
|
||||
// TODO use events multientry index for *tags
|
||||
events: "++id, pubkey, kind, created_at, [pubkey+kind]",
|
||||
tags: "&[type+value+eventId], [type+value], eventId",
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -119,13 +120,13 @@ const IndexedDB = {
|
||||
.anyOf(authors)
|
||||
.limit(limit || 1000)
|
||||
.each(handleEvent);
|
||||
}, 1000),
|
||||
}, 100),
|
||||
|
||||
subscribeToEventIds: throttle(async function (this: typeof IndexedDB) {
|
||||
const ids = [...this.subscribedEventIds];
|
||||
this.subscribedEventIds.clear();
|
||||
await db.events.where('id').anyOf(ids).each(handleEvent);
|
||||
}, 1000),
|
||||
}, 100),
|
||||
|
||||
subscribeToTags: throttle(async function (this: typeof IndexedDB) {
|
||||
const tagPairs = [...this.subscribedTags].map((tag) => tag.split('|'));
|
||||
@ -136,7 +137,7 @@ const IndexedDB = {
|
||||
.each((tag) => this.subscribedEventIds.add(tag.eventId));
|
||||
|
||||
await this.subscribeToEventIds();
|
||||
}, 1000),
|
||||
}, 100),
|
||||
|
||||
async countEvents() {
|
||||
return await db.events.count();
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { sha256 } from '@noble/hashes/sha256';
|
||||
import throttle from 'lodash/throttle';
|
||||
import { Event, Filter, Sub } from 'nostr-tools';
|
||||
import { Event, Sub } from 'nostr-tools';
|
||||
|
||||
import EventDB from '@/nostr/EventDB';
|
||||
import relayPool from '@/nostr/relayPool.ts';
|
||||
@ -10,7 +9,6 @@ import Helpers from '../utils/Helpers';
|
||||
|
||||
import Events from './Events';
|
||||
import Key from './Key';
|
||||
import PubSub from './PubSub';
|
||||
|
||||
type SavedRelays = {
|
||||
[key: string]: {
|
||||
@ -245,58 +243,6 @@ const Relays = {
|
||||
};
|
||||
Events.publish(event);
|
||||
},
|
||||
updateLastSeen: throttle(
|
||||
(url) => {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
localState.get('relays').get(url).get('lastSeen').put(now);
|
||||
},
|
||||
5 * 1000,
|
||||
{ leading: true },
|
||||
),
|
||||
groupFilter(filter: Filter): { name: string; groupedFilter: Filter } {
|
||||
// if filter has authors, add to subscribedAuthors and group by authors
|
||||
if (filter.authors && filter.kinds?.length === 1 && filter.kinds[0] === 0) {
|
||||
filter.authors.forEach((a) => {
|
||||
this.subscribedProfiles.add(a);
|
||||
});
|
||||
return {
|
||||
name: 'profiles',
|
||||
groupedFilter: {
|
||||
authors: Array.from(this.subscribedProfiles.values()),
|
||||
kinds: [0],
|
||||
},
|
||||
};
|
||||
}
|
||||
if (filter.authors) {
|
||||
filter.authors = Array.from(this.subscribedProfiles.values());
|
||||
return {
|
||||
name: 'authors',
|
||||
groupedFilter: {
|
||||
authors: Array.from(this.subscribedProfiles.values()),
|
||||
},
|
||||
};
|
||||
}
|
||||
if (filter.ids) {
|
||||
return {
|
||||
name: 'ids',
|
||||
groupedFilter: { ids: Array.from(PubSub.subscribedEventIds.values()) },
|
||||
};
|
||||
}
|
||||
if (filter['#e']) {
|
||||
filter['#e'].forEach((e) => {
|
||||
this.subscribedEventTags.add(e);
|
||||
});
|
||||
return {
|
||||
name: 'eventsByTag',
|
||||
groupedFilter: { '#e': Array.from(this.subscribedEventTags.values()) },
|
||||
};
|
||||
}
|
||||
// do not bundle. TODO console.log, limit or sth
|
||||
return {
|
||||
name: JSON.stringify(filter),
|
||||
groupedFilter: filter,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default Relays;
|
||||
|
@ -17,7 +17,13 @@ export default class LocalStorageMemoryAdapter extends Adapter {
|
||||
private loadFromLocalStorage() {
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i) as string;
|
||||
const value = JSON.parse(localStorage.getItem(key) || '') as NodeValue;
|
||||
let value;
|
||||
try {
|
||||
value = localStorage.getItem(key) || '';
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
}
|
||||
this.storage.set(key, value);
|
||||
}
|
||||
this.isLoaded = true;
|
||||
|
Loading…
Reference in New Issue
Block a user