mirror of
https://github.com/dergigi/boris.git
synced 2025-12-26 19:14:52 +01:00
- 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
35 lines
924 B
TypeScript
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))
|
|
}
|
|
|