mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-18 19:23:40 +00:00
Group notifications better, prefer followed users when mentioning people
This commit is contained in:
parent
6e686c61af
commit
c22ac18380
@ -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
|
||||
|
@ -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}`)
|
||||
|
||||
|
@ -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 = () => {
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user