Moves the filter for no subscriptions to the DAL

This commit is contained in:
Vitor Pamplona
2024-06-01 15:31:43 -04:00
parent f26fa71e49
commit f1834af506
2 changed files with 31 additions and 28 deletions
@@ -52,8 +52,7 @@ open class DiscoverNIP89FeedFilter(
val notes =
LocalCache.addressables.filterIntoSet { _, it ->
val noteEvent = it.event
noteEvent is AppDefinitionEvent && filterParams.match(noteEvent) && noteEvent.includeKind("5300") && noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent)
acceptDVM(it)
}
return sort(notes)
@@ -72,12 +71,26 @@ open class DiscoverNIP89FeedFilter(
)
}
protected open fun innerApplyFilter(collection: Collection<Note>): Set<Note> {
val filterParams = buildFilterParams(account)
fun acceptDVM(note: Note): Boolean {
val noteEvent = note.event
return if (noteEvent is AppDefinitionEvent) {
acceptDVM(noteEvent)
} else {
false
}
}
fun acceptDVM(noteEvent: AppDefinitionEvent): Boolean {
val filterParams = buildFilterParams(account)
return noteEvent.appMetaData()?.subscription != true &&
filterParams.match(noteEvent) &&
noteEvent.includeKind("5300") &&
noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent)
}
protected open fun innerApplyFilter(collection: Collection<Note>): Set<Note> {
return collection.filterTo(HashSet()) {
val noteEvent = it.event
noteEvent is AppDefinitionEvent && filterParams.match(noteEvent) && noteEvent.includeKind("5300") && noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent)
acceptDVM(it)
}
}
@@ -359,30 +359,20 @@ private fun DiscoverFeedLoaded(
itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item ->
val defaultModifier = remember { Modifier.fillMaxWidth().animateItemPlacement() }
// TODO For now we avoid subscription based DVMs, as we need logic for these first if a user is not subscribed already.
var avoid = false
if (item.event is AppDefinitionEvent) {
if ((item.event as AppDefinitionEvent).appMetaData()?.subscription == true) {
avoid = true
}
}
// TODO End
if (!avoid) {
Row(defaultModifier) {
ChannelCardCompose(
baseNote = item,
routeForLastRead = routeForLastRead,
modifier = Modifier.fillMaxWidth(),
forceEventKind = forceEventKind,
accountViewModel = accountViewModel,
nav = nav,
)
}
HorizontalDivider(
thickness = DividerThickness,
Row(defaultModifier) {
ChannelCardCompose(
baseNote = item,
routeForLastRead = routeForLastRead,
modifier = Modifier.fillMaxWidth(),
forceEventKind = forceEventKind,
accountViewModel = accountViewModel,
nav = nav,
)
}
HorizontalDivider(
thickness = DividerThickness,
)
}
}
}