Merge branch 'main' into cron-minutely
This commit is contained in:
commit
29111e117c
1 changed files with 7 additions and 5 deletions
|
|
@ -25,7 +25,6 @@ import {
|
|||
getTagValue,
|
||||
} from '@welshman/util'
|
||||
import { Loader, AdapterContext, makeLoader, SocketAdapter } from '@welshman/net'
|
||||
import { Router, addMinimalFallbacks } from '@welshman/router'
|
||||
import { call } from '@welshman/lib'
|
||||
import { displayDuration, createElement } from './util.js'
|
||||
import type { Subscription } from './alert.js'
|
||||
|
|
@ -40,6 +39,7 @@ import {
|
|||
type DigestData = {
|
||||
events: TrustedEvent[]
|
||||
context: TrustedEvent[]
|
||||
relayByEventId: Map<string, string>
|
||||
}
|
||||
|
||||
export class Digest {
|
||||
|
|
@ -59,7 +59,7 @@ export class Digest {
|
|||
const parsed = truncate(parse(event), { minLength: 400, maxLength: 800, mediaLength: 50 })
|
||||
|
||||
return {
|
||||
Link: buildLink(event, handler),
|
||||
Link: buildLink(event, handler, data.relayByEventId.get(event.id)),
|
||||
Timestamp: formatter.format(secondsToDate(event.created_at)),
|
||||
Icon: profilesByPubkey.get().get(event.pubkey)?.picture,
|
||||
Name: displayProfileByPubkey(event.pubkey),
|
||||
|
|
@ -96,6 +96,7 @@ export class Digest {
|
|||
sendFromStoredEvents = async (storedEvents: { id: string; event: TrustedEvent; relay: string }[]) => {
|
||||
const events = storedEvents.map(se => se.event)
|
||||
const context = [...events] // For now, context == events (no reply loading)
|
||||
const relayByEventId = new Map(storedEvents.map(se => [se.event.id, se.relay]))
|
||||
|
||||
// Load profiles for event authors
|
||||
const pubkeys = new Set(events.map(e => e.pubkey))
|
||||
|
|
@ -108,7 +109,7 @@ export class Digest {
|
|||
}
|
||||
}
|
||||
|
||||
const data = { events, context } as DigestData
|
||||
const data = { events, context, relayByEventId } as DigestData
|
||||
|
||||
if (data.events.length > 0) {
|
||||
await sendDigest(this.sub, await this.buildParameters(data))
|
||||
|
|
@ -118,8 +119,9 @@ export class Digest {
|
|||
|
||||
// Utilities
|
||||
|
||||
const buildLink = (event: TrustedEvent, handler: string) => {
|
||||
const relays = Router.get().Event(event).getUrls()
|
||||
const buildLink = (event: TrustedEvent, handler: string, storedRelay?: string) => {
|
||||
const relays = storedRelay ? [storedRelay] : []
|
||||
|
||||
const groupId = getTagValue(["h"], event.tags)
|
||||
|
||||
if (groupId && relays.length > 0) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue