Files
boris/src/utils/highlightClassification.ts
Gigi 5ef7d2c41c refactor: DRY up highlight classification and URL normalization
- Extract classifyHighlight and classifyHighlights utilities
- Remove duplicate highlight classification logic from 3 locations
- Use existing normalizeUrl from urlHelpers instead of duplicating
- Reduce code duplication while maintaining functionality
2025-10-07 21:58:17 +01:00

35 lines
924 B
TypeScript

import { Highlight } from '../types/highlights'
export type HighlightLevel = 'mine' | 'friends' | 'nostrverse'
/**
* Classify a highlight based on the current user and their followed pubkeys
*/
export function classifyHighlight(
highlight: Highlight,
currentUserPubkey?: string,
followedPubkeys: Set<string> = new Set()
): Highlight & { level: HighlightLevel } {
let level: HighlightLevel = 'nostrverse'
if (highlight.pubkey === currentUserPubkey) {
level = 'mine'
} else if (followedPubkeys.has(highlight.pubkey)) {
level = 'friends'
}
return { ...highlight, level }
}
/**
* Classify an array of highlights
*/
export function classifyHighlights(
highlights: Highlight[],
currentUserPubkey?: string,
followedPubkeys: Set<string> = new Set()
): Array<Highlight & { level: HighlightLevel }> {
return highlights.map(h => classifyHighlight(h, currentUserPubkey, followedPubkeys))
}