Don't use since when loading messages, group notifications by hour

This commit is contained in:
Jonathan Staab 2023-03-29 13:56:58 -05:00
parent 681d36d443
commit 0f032ee05b
5 changed files with 30 additions and 16 deletions

View File

@ -1,6 +1,13 @@
# Current
- [ ] Fix reactions and replies
- [ ] Fix relays notification when multiplexing
- [ ] Disable self-zap
- [ ] Move blog to nostr
- [ ] Improve note rendering
- [ ] Fix reactions and replies showing up
- [ ] Show all images in preview as slideshow or something
- [ ] Extract nostr: links and bech32 entities, hover
- [ ] Linkify topics
- [ ] Multiplexer
- [ ] Announce multiplextr, paravel, coracle update w/url
- [ ] Write NIP to support proxies. Update COUNT NIP to mention how proxies are a good use case for COUNT

View File

@ -3,7 +3,7 @@
import {fly} from "svelte/transition"
import {navigate} from "svelte-routing"
import {prop, path as getPath, reverse, pluck, uniqBy, sortBy, last} from "ramda"
import {sleep, timedelta, createScroller, Cursor} from "src/util/misc"
import {sleep, createScroller, Cursor} from "src/util/misc"
import Spinner from "src/partials/Spinner.svelte"
import user from "src/agent/user"
import {getPersonWithFallback} from "src/agent/tables"
@ -18,9 +18,7 @@
let loading = sleep(30_000)
let annotatedMessages = []
let showNewMessages = false
let cursor = new Cursor({
delta: timedelta(7, "days"),
})
let cursor = new Cursor()
$: {
// Group messages so we're only showing the person once per chunk

View File

@ -1,8 +1,8 @@
<script>
import {pluck, max, last, sortBy, assoc} from "ramda"
import {pluck, reverse, max, last, sortBy, assoc} from "ramda"
import {onMount} from "svelte"
import {fly} from "svelte/transition"
import {now, createScroller} from "src/util/misc"
import {now, timedelta, createScroller} from "src/util/misc"
import {findReplyId} from "src/util/nostr"
import Spinner from "src/partials/Spinner.svelte"
import Content from "src/partials/Content.svelte"
@ -19,7 +19,13 @@
const notifications = watch("notifications", t => {
lastChecked.update(assoc("notifications", now()))
return sortBy(e => -e.created_at, user.applyMutes(t.all()))
// Sort by rounded timestamp so we can group reactions to the same parent
return reverse(
sortBy(
e => Math.round(e.created_at / timedelta(1, "hour")).toString() + findReplyId(e),
user.applyMutes(t.all())
)
)
})
// Group notifications so we're only showing the parent once per chunk

View File

@ -6,6 +6,7 @@ import {
reject,
mergeDeepRight,
aperture,
filter,
path as getPath,
allPass,
pipe,
@ -164,24 +165,24 @@ export const createScroller = (loadMore, {reverse = false} = {}) => {
export const randomChoice = xs => xs[Math.floor(Math.random() * xs.length)]
export class Cursor {
delta: number
since: number
delta?: number
since?: number
until: number
limit: number
count: number
constructor({limit = 50, delta = timedelta(6, "hours")}) {
constructor({limit = 50, delta = undefined} = {}) {
this.delta = delta
this.since = now() - delta
this.since = delta ? now() - delta : undefined
this.until = now()
this.limit = limit
this.count = 0
}
getFilter() {
return {
return filter(identity, {
since: this.since,
until: this.until,
limit: this.limit,
}
})
}
// Remove events that are significantly older than the average
prune(events) {
@ -214,7 +215,9 @@ export class Cursor {
this.until -= Math.round(gap * scale * this.limit)
}
this.since = Math.min(this.since, this.until) - this.delta
if (this.since) {
this.since = Math.min(this.since, this.until) - this.delta
}
}
}

View File

@ -31,7 +31,7 @@
const submit = async event => {
event?.preventDefault()
publishWithToast(getUserWriteRelays(), cmd.updateUser(values))
navigate(routes.person(user.getPubkey(), "profile"))
navigate(routes.person(user.getPubkey(), "notes"))
}
document.title = "Profile"