Fix notifications

This commit is contained in:
Jonathan Staab 2023-01-21 13:47:17 -08:00
parent 23160dff4b
commit 53cf666af5
7 changed files with 32 additions and 20 deletions

View File

@ -1,6 +1,7 @@
import {pluck} from 'ramda'
import {pluck, reject} from 'ramda'
import {get} from 'svelte/store'
import {synced, now, timedelta, batch} from 'src/util/misc'
import {listen as _listen} from 'src/agent'
import {listen as _listen, db, user} from 'src/agent'
import loaders from 'src/app/loaders'
let listener
@ -19,12 +20,22 @@ const listen = async (relays, pubkey) => {
[{kinds: [4], authors: [pubkey], since},
{kinds: [4], '#p': [pubkey], since}],
batch(300, async events => {
if (events.length > 0) {
await loaders.loadPeople(relays, pluck('pubkey', events))
const $user = get(user)
// Reload annotated messages, don't alert about messages to self
const messages = reject(
e => e.pubkey === e.recipient,
await db.messages.toArray()
)
if (messages.length > 0) {
await loaders.loadPeople(relays, pluck('pubkey', messages))
mostRecentByPubkey.update(o => {
for (const {pubkey, created_at} of events) {
o[pubkey] = Math.max(created_at, o[pubkey] || 0)
for (const {pubkey, recipient, created_at} of messages) {
const k = pubkey === $user.pubkey ? recipient : pubkey
o[k] = Math.max(created_at, o[k] || 0)
}
return o

View File

@ -27,7 +27,7 @@
<div
class="py-2 px-3 flex flex-col gap-2 text-white cursor-pointer transition-all
border border-solid border-black hover:border-medium hover:bg-dark"
on:click={() => modal.set({type: 'note', note})}>
on:click={() => modal.set({type: 'note/detail', note})}>
<div class="flex gap-2 items-center justify-between relative">
<span class="cursor-pointer" on:click={openPopover}>
{quantify(note.people.length, 'person', 'people')} liked your note.

View File

@ -45,7 +45,7 @@
const onClick = e => {
if (!['I'].includes(e.target.tagName) && !e.target.closest('a')) {
modal.set({type: 'note', note, relays})
modal.set({type: 'note/detail', note, relays})
}
}
@ -53,7 +53,7 @@
const [id, url] = findReply(note).slice(1)
const relays = getEventRelays(note).concat({url})
modal.set({type: 'note', note: {id}, relays})
modal.set({type: 'note/detail', note: {id}, relays})
}
const react = async content => {

View File

@ -51,7 +51,7 @@
<h2 class="text-lg">{room.name}</h2>
{/if}
</div>
{#if joined}
{#if room.type === 'npub'}
{#if hasNewMessages}
<div class="relative">
<i class="fa fa-bell" />

View File

@ -1,9 +1,8 @@
<script>
import {without, uniq, sortBy, pluck} from 'ramda'
import {without, assoc, uniq, sortBy, pluck} from 'ramda'
import {onMount} from "svelte"
import {nip19} from 'nostr-tools'
import {navigate} from "svelte-routing"
import {liveQuery} from 'dexie'
import {fuzzy} from "src/util/misc"
import {getRelays, user, lq, getPerson, listen, db} from 'src/agent'
import {modal, messages} from 'src/app'
@ -22,8 +21,7 @@
const rooms = lq(async () => {
const rooms = await db.rooms.where('joined').equals(1).toArray()
const messages = await db.messages.toArray()
const pubkeys = without([$user.pubkey], uniq(pluck('pubkey', messages)))
const pubkeys = without([$user.pubkey], uniq(messages.flatMap(m => [m.pubkey, m.recipient])))
await loaders.loadPeople(getRelays(), pubkeys)
@ -32,12 +30,12 @@
.concat(rooms.map(room => ({type: 'note', ...room})))
})
const search = liveQuery(async () => {
const search = lq(async () => {
const rooms = await db.rooms.where('joined').equals(0).toArray()
roomsCount = rooms.length
return fuzzy(rooms, {keys: ["name", "about"]})
return fuzzy(rooms.map(assoc('type', 'note')), {keys: ["name", "about"]})
})
const setRoom = ({type, id}) => {

View File

@ -10,7 +10,12 @@
confirmed = true
localStorage.clear()
await db.delete()
try {
await db.delete()
} catch (e) {
// pass
}
// do a hard refresh so everything gets totally cleared.
// Give them a moment to see the state transition. Dexie

View File

@ -1,8 +1,6 @@
<script>
import {navigate} from 'svelte-routing'
import Input from "src/partials/Input.svelte"
import Content from 'src/partials/Content.svelte'
import Tabs from 'src/partials/Tabs.svelte'
import SearchPeople from 'src/views/SearchPeople.svelte'
import SearchNotes from 'src/views/SearchNotes.svelte'
@ -10,7 +8,7 @@
let q = ''
const setActiveTab = tab => navigate(`/search/${tab}`)
// const setActiveTab = tab => navigate(`/search/${tab}`)
</script>
<Content>