Group notifications better, prefer followed users when mentioning people

This commit is contained in:
Jonathan Staab 2023-05-31 09:24:33 -07:00
parent 6e686c61af
commit c22ac18380
4 changed files with 54 additions and 34 deletions

View File

@ -1,5 +1,9 @@
# Changelog
# 0.2.30
- [x] Prefer followed users when mentioning people
# 0.2.29
- [x] Register url handler for web+nostr and use that for sharing

View File

@ -32,48 +32,51 @@
const notifications = watch("notifications", t => {
updateLastChecked()
// Sort by rounded timestamp so we can group reactions to the same parent
// Sort by hour so we can group clustered reactions to the same parent
return reverse(
sortBy(
e => formatTimestampAsLocalISODate(e.created_at) + findReplyId(e),
e => formatTimestampAsLocalISODate(e.created_at).slice(0, 13) + findReplyId(e),
user.applyMutes(t.all())
)
)
})
// Group notifications so we're only showing the parent once per chunk
$: events = $notifications
.slice(0, limit)
.map(e => [e, userEvents.get(findReplyId(e))])
.filter(([e, ref]) => {
if (ref && ref.kind !== 1) {
return false
}
$: events = sortBy(
({notifications}) => -notifications.reduce((a, b) => Math.max(a, b.created_at), 0),
$notifications
.slice(0, limit)
.map(e => [e, userEvents.get(findReplyId(e))])
.filter(([e, ref]) => {
if (ref && ref.kind !== 1) {
return false
}
if (activeTab === tabs[0]) {
return [1].includes(e.kind)
} else {
return [7, 9735].includes(e.kind) && ref
}
})
.reduce((r, [e, ref]) => {
const prev = last(r)
const prevTimestamp = pluck("created_at", prev?.notifications || []).reduce(max, 0)
if (activeTab === tabs[0]) {
return [1].includes(e.kind)
} else {
return [7, 9735].includes(e.kind) && ref
}
})
.reduce((r, [e, ref]) => {
const prev = last(r)
const prevTimestamp = pluck("created_at", prev?.notifications || []).reduce(max, 0)
if (ref && prev?.ref === ref) {
prev.notifications.push(e)
} else {
r = r.concat({
ref,
key: e.id,
notifications: [e],
dateDisplay: formatTimestampAsDate(e.created_at),
showLine: e.created_at < prevChecked && prevTimestamp >= prevChecked,
})
}
if (ref && prev?.ref === ref) {
prev.notifications.push(e)
} else {
r = r.concat({
ref,
key: e.id,
notifications: [e],
dateDisplay: formatTimestampAsDate(e.created_at),
showLine: e.created_at < prevChecked && prevTimestamp >= prevChecked,
})
}
return r
}, [])
return r
}, [])
)
const setActiveTab = tab => navigate(`/notifications/${tab}`)

View File

@ -1,17 +1,20 @@
<script lang="ts">
import {nip19} from "nostr-tools"
import {last, pluck, propEq} from "ramda"
import {last, partition, pluck, propEq} from "ramda"
import {displayPerson} from "src/util/nostr"
import PersonBadge from "src/app/shared/PersonBadge.svelte"
import ContentEditable from "src/partials/ContentEditable.svelte"
import Suggestions from "src/partials/Suggestions.svelte"
import {searchPeople} from "src/agent/db"
import user from "src/agent/user"
import {getPubkeyWriteRelays} from "src/agent/relays"
export let onSubmit
let contenteditable, suggestions
const {petnamePubkeys} = user
const pubkeyEncoder = {
encode: pubkey => {
const relays = pluck("url", getPubkeyWriteRelays(pubkey))
@ -26,7 +29,17 @@
}
const applySearch = word => {
suggestions.setData(word.startsWith("@") ? $searchPeople(word.slice(1)).slice(0, 5) : [])
let results = []
if (word.startsWith("@")) {
const [followed, notFollowed] = partition(
p => $petnamePubkeys.includes(p.pubkey),
$searchPeople(word.slice(1))
)
results = followed.concat(notFollowed)
}
suggestions.setData(results.slice(0, 5))
}
const getInfo = () => {

View File

@ -114,7 +114,7 @@ export const formatTimestampAsLocalISODate = ts => {
const offset = date.getTimezoneOffset() * 60000
const datetime = new Date(date.getTime() - offset).toISOString()
return datetime.slice(0, 10)
return datetime
}
export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))