Allowing unloaded Notes to go into the feed and be loaded later

This commit is contained in:
Vitor Pamplona
2023-01-22 18:33:22 -03:00
parent 59305c9b15
commit 9f15b87d57

View File

@ -27,18 +27,18 @@ object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
fun createLoadEventsIfNotLoadedFilter(): JsonFilter? { fun createLoadEventsIfNotLoadedFilter(): JsonFilter? {
val directEventsToLoad = eventsToWatch val directEventsToLoad = eventsToWatch
.mapNotNull { LocalCache.notes[it] } .map { LocalCache.getOrCreateNote(it) }
.filter { it.event == null } .filter { it.event == null }
val threadingEventsToLoad = eventsToWatch val threadingEventsToLoad = eventsToWatch
.mapNotNull { LocalCache.notes[it] } .map { LocalCache.getOrCreateNote(it) }
.mapNotNull { it.replyTo } .mapNotNull { it.replyTo }
.flatten() .flatten()
.filter { it.event == null } .filter { it.event == null }
val interestedEvents = val interestedEvents =
(directEventsToLoad + threadingEventsToLoad) (directEventsToLoad + threadingEventsToLoad)
.map { it.idHex } .map { it.idHex }.toSet()
if (interestedEvents.isEmpty()) { if (interestedEvents.isEmpty()) {
return null return null
@ -47,7 +47,7 @@ object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
// downloads linked events to this event. // downloads linked events to this event.
return JsonFilter( return JsonFilter(
kinds = listOf(TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind), kinds = listOf(TextNoteEvent.kind, ReactionEvent.kind, RepostEvent.kind),
ids = interestedEvents ids = interestedEvents.toList()
) )
} }
@ -55,10 +55,12 @@ object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
val loadEventsChannel = requestNewChannel() val loadEventsChannel = requestNewChannel()
override fun feed(): List<Note> { override fun feed(): List<Note> {
return eventsToWatch.map { return synchronized(eventsToWatch) {
eventsToWatch.map {
LocalCache.notes[it] LocalCache.notes[it]
}.filterNotNull() }.filterNotNull()
} }
}
override fun updateChannelFilters() { override fun updateChannelFilters() {
val reactions = createRepliesAndReactionsFilter() val reactions = createRepliesAndReactionsFilter()