mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-18 19:23:40 +00:00
Fix table listener
This commit is contained in:
parent
2d45928e8c
commit
ffa32fc0c4
@ -1,10 +1,5 @@
|
||||
# Current
|
||||
|
||||
- [ ] Fix memory usage
|
||||
- [x] Add table of user events, derive profile from this using `watch`.
|
||||
- [x] Make zapper info more compact
|
||||
- [ ] Person search doesn't find people on first load
|
||||
- [ ] Fix re-connects
|
||||
- [ ] Show loading/success on zap invoice screen
|
||||
- [ ] Fix iOS/safari/firefox
|
||||
- [ ] Update https://nostr.com/clients/coracle
|
||||
|
@ -121,8 +121,6 @@ export class Table {
|
||||
this._persist()
|
||||
}
|
||||
subscribe(cb) {
|
||||
cb = throttle(100, cb)
|
||||
|
||||
this.listeners.push(cb)
|
||||
|
||||
cb(this)
|
||||
@ -142,7 +140,7 @@ export class Table {
|
||||
this.cache.set(k, item)
|
||||
}
|
||||
|
||||
this._persist()
|
||||
this._notify()
|
||||
}
|
||||
put(item) {
|
||||
this.bulkPut([item])
|
||||
@ -158,7 +156,7 @@ export class Table {
|
||||
this.cache.set(k, {...this.cache.get(k), ...item})
|
||||
}
|
||||
|
||||
this._persist()
|
||||
this._notify()
|
||||
}
|
||||
patch(item) {
|
||||
this.bulkPatch([item])
|
||||
@ -168,7 +166,7 @@ export class Table {
|
||||
this.cache.delete(k)
|
||||
}
|
||||
|
||||
this._persist()
|
||||
this._notify()
|
||||
}
|
||||
remove(k) {
|
||||
this.bulkRemove([k])
|
||||
@ -207,14 +205,15 @@ export class Table {
|
||||
}
|
||||
}
|
||||
|
||||
const listener = (() => {
|
||||
export const listener = (() => {
|
||||
let listeners = []
|
||||
|
||||
for (const table of Object.values(registry) as Array<Table>) {
|
||||
table.subscribe(() => listeners.forEach(f => f(table.name)))
|
||||
}
|
||||
|
||||
return {
|
||||
connect: () => {
|
||||
for (const table of Object.values(registry) as Array<Table>) {
|
||||
table.subscribe(() => listeners.forEach(f => f(table.name)))
|
||||
}
|
||||
},
|
||||
subscribe: f => {
|
||||
listeners.push(f)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {pluck, all, identity} from "ramda"
|
||||
import {derived} from "svelte/store"
|
||||
import {Table, registry} from "src/agent/storage"
|
||||
import {Table, listener, registry} from "src/agent/storage"
|
||||
|
||||
export const userEvents = new Table("userEvents", "id")
|
||||
export const people = new Table("people", "pubkey")
|
||||
@ -10,6 +10,8 @@ export const alerts = new Table("alerts", "id")
|
||||
export const relays = new Table("relays", "url")
|
||||
export const routes = new Table("routes", "id")
|
||||
|
||||
listener.connect()
|
||||
|
||||
export const getPersonWithFallback = pubkey => people.get(pubkey) || {pubkey}
|
||||
|
||||
const ready = derived(pluck("ready", Object.values(registry)), all(identity))
|
||||
|
@ -162,7 +162,7 @@ const processChats = async (pubkey, events) => {
|
||||
|
||||
const listen = async pubkey => {
|
||||
// Include an offset so we don't miss alerts on one relay but not another
|
||||
const since = now() - timedelta(7, "days")
|
||||
const since = now() - timedelta(30, "days")
|
||||
const roomIds = pluck("id", rooms.all({joined: true}))
|
||||
|
||||
if (listener) {
|
||||
|
@ -7,6 +7,11 @@
|
||||
import {watch} from "src/agent/storage"
|
||||
|
||||
let activeTab = "messages"
|
||||
let contacts = []
|
||||
|
||||
const getContacts = tab => sortBy(c => -c.lastMessage, tab === "messages" ? $accepted : $requests)
|
||||
|
||||
$: contacts = getContacts(activeTab)
|
||||
|
||||
const setActiveTab = tab => {
|
||||
activeTab = tab
|
||||
@ -15,8 +20,6 @@
|
||||
const accepted = watch("contacts", t => t.all({accepted: true}))
|
||||
const requests = watch("contacts", t => t.all({"accepted:!eq": true}))
|
||||
|
||||
const getContacts = tab => sortBy(c => -c.lastMessage, tab === "messages" ? $accepted : $requests)
|
||||
|
||||
const getDisplay = tab => ({
|
||||
title: toTitle(tab),
|
||||
badge: getContacts(tab).length,
|
||||
|
Loading…
Reference in New Issue
Block a user