@ -324,7 +324,9 @@ const sortByCreatedAt = (evt1, evt2) => {
} ;
} ;
function renderFeed ( ) {
function renderFeed ( ) {
const sortedFeeds = textNoteList . sort ( sortByCreatedAt ) . reverse ( ) ;
const sortedFeeds = textNoteList
. filter ( note => ! fitlerDifficulty || note . tags . some ( ( [ tag , , commitment ] ) => tag === 'nonce' && commitment >= fitlerDifficulty ) )
. sort ( sortByCreatedAt ) . reverse ( ) ;
sortedFeeds . forEach ( ( evt , i ) => {
sortedFeeds . forEach ( ( evt , i ) => {
if ( feedDomMap [ evt . id ] ) {
if ( feedDomMap [ evt . id ] ) {
// TODO check eventRelayMap if event was published to different relays
// TODO check eventRelayMap if event was published to different relays
@ -340,6 +342,13 @@ function renderFeed() {
} ) ;
} ) ;
}
}
function rerenderFeed ( ) {
Object . keys ( feedDomMap ) . forEach ( key => delete feedDomMap [ key ] ) ;
Object . keys ( replyDomMap ) . forEach ( key => delete replyDomMap [ key ] ) ;
feedContainer . replaceChildren ( [ ] ) ;
renderFeed ( ) ;
}
setInterval ( ( ) => {
setInterval ( ( ) => {
document . querySelectorAll ( 'time[datetime]' ) . forEach ( timeElem => {
document . querySelectorAll ( 'time[datetime]' ) . forEach ( timeElem => {
timeElem . textContent = formatTime ( new Date ( timeElem . dateTime ) ) ;
timeElem . textContent = formatTime ( new Date ( timeElem . dateTime ) ) ;
@ -516,7 +525,9 @@ function handleRecommendServer(evt, relay) {
if ( textNoteList . length < 2 ) {
if ( textNoteList . length < 2 ) {
feedContainer . append ( art ) ;
feedContainer . append ( art ) ;
} else {
} else {
const closestTextNotes = textNoteList . sort ( sortEventCreatedAt ( evt . created _at ) ) ;
const closestTextNotes = textNoteList
. filter ( note => ! fitlerDifficulty || note . tags . some ( ( [ tag , , commitment ] ) => tag === 'nonce' && commitment >= fitlerDifficulty ) )
. sort ( sortEventCreatedAt ( evt . created _at ) ) ;
feedDomMap [ closestTextNotes [ 0 ] . id ] . after ( art ) ;
feedDomMap [ closestTextNotes [ 0 ] . id ] . after ( art ) ;
}
}
feedDomMap [ evt . id ] = art ;
feedDomMap [ evt . id ] = art ;
@ -758,6 +769,18 @@ function hideNewMessage(hide) {
newMessageDiv . hidden = hide ;
newMessageDiv . hidden = hide ;
}
}
let fitlerDifficulty = JSON . parse ( localStorage . getItem ( 'filter_difficulty' ) ) ? ? 0 ;
const filterDifficultyInput = document . querySelector ( '#filterDifficulty' ) ;
const filterDifficultyDisplay = document . querySelector ( '[data-display="filter_difficulty"]' ) ;
filterDifficultyInput . addEventListener ( 'input' , ( e ) => {
localStorage . setItem ( 'filter_difficulty' , filterDifficultyInput . valueAsNumber ) ;
fitlerDifficulty = filterDifficultyInput . valueAsNumber ;
filterDifficultyDisplay . textContent = filterDifficultyInput . value ;
rerenderFeed ( ) ;
} ) ;
filterDifficultyInput . value = fitlerDifficulty ;
filterDifficultyDisplay . textContent = filterDifficultyInput . value ;
// arbitrary difficulty default, still experimenting.
// arbitrary difficulty default, still experimenting.
let difficulty = JSON . parse ( localStorage . getItem ( 'mining_target' ) ) ? ? 16 ;
let difficulty = JSON . parse ( localStorage . getItem ( 'mining_target' ) ) ? ? 16 ;
const miningTargetInput = document . querySelector ( '#miningTarget' ) ;
const miningTargetInput = document . querySelector ( '#miningTarget' ) ;