import type { Session } from "../Session" import type { UserRecordActor } from "./UserRecordActor" export function sessionMessageAuthorPubkeys(session: Session): string[] { const authors = new Set() if (session.state.theirCurrentNostrPublicKey) { authors.add(session.state.theirCurrentNostrPublicKey) } if (session.state.theirNextNostrPublicKey) { authors.add(session.state.theirNextNostrPublicKey) } for (const author of Object.keys(session.state.skippedKeys || {})) { authors.add(author) } return [...authors].sort() } export function collectMessagePushAuthorPubkeys( userRecord?: UserRecordActor, ): string[] { if (!userRecord) { return [] } const authors = new Set() for (const device of userRecord.devices.values()) { const sessions = [ ...(device.activeSession ? [device.activeSession] : []), ...device.inactiveSessions, ] for (const session of sessions) { for (const author of sessionMessageAuthorPubkeys(session)) { authors.add(author) } } } return [...authors].sort() } export function collectAllMessagePushAuthorPubkeys( userRecords: Iterable, ): string[] { const authors = new Set() for (const userRecord of userRecords) { for (const author of collectMessagePushAuthorPubkeys(userRecord)) { authors.add(author) } } return [...authors].sort() }