mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 20:06:37 +01:00
Better filter for People Lists
This commit is contained in:
@@ -45,6 +45,28 @@ fun kindEnd(kind: Int) = kindEnd(kind, END_KEY)
|
|||||||
|
|
||||||
val ACCEPT_ALL_FILTER = CacheCollectors.BiFilter<Address, AddressableNote> { key, note -> true }
|
val ACCEPT_ALL_FILTER = CacheCollectors.BiFilter<Address, AddressableNote> { key, note -> true }
|
||||||
|
|
||||||
|
fun LargeSoftCache<Address, AddressableNote>.filter(
|
||||||
|
kind: Int,
|
||||||
|
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
|
||||||
|
): List<AddressableNote> = filter(kindStart(kind), kindEnd(kind), consumer)
|
||||||
|
|
||||||
|
fun LargeSoftCache<Address, AddressableNote>.filter(
|
||||||
|
kinds: List<Int>,
|
||||||
|
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
|
||||||
|
): List<AddressableNote> {
|
||||||
|
val set = mutableSetOf<AddressableNote>()
|
||||||
|
kinds.forEach {
|
||||||
|
set.addAll(filter(kindStart(it), kindEnd(it), consumer))
|
||||||
|
}
|
||||||
|
return set.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun LargeSoftCache<Address, AddressableNote>.filter(
|
||||||
|
kind: Int,
|
||||||
|
pubKey: HexKey,
|
||||||
|
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
|
||||||
|
): List<AddressableNote> = filter(kindStart(kind, pubKey), kindEnd(kind, pubKey), consumer)
|
||||||
|
|
||||||
fun LargeSoftCache<Address, AddressableNote>.filterIntoSet(
|
fun LargeSoftCache<Address, AddressableNote>.filterIntoSet(
|
||||||
kind: Int,
|
kind: Int,
|
||||||
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
|
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
|
||||||
|
|||||||
@@ -2126,18 +2126,7 @@ object LocalCache : ILocalCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFollowSetNotesFor(user: User): List<AddressableNote> {
|
fun getPeopleListNotesFor(user: User): List<AddressableNote> = addressables.filter(PeopleListEvent.KIND, user.pubkeyHex)
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
return addressables
|
|
||||||
.filter { _, note ->
|
|
||||||
val listEvent = note.event
|
|
||||||
(
|
|
||||||
listEvent is PeopleListEvent &&
|
|
||||||
user.pubkeyHex == listEvent.pubKey
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun findStatusesForUser(user: User): ImmutableList<AddressableNote> {
|
fun findStatusesForUser(user: User): ImmutableList<AddressableNote> {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class FollowSetState(
|
|||||||
|
|
||||||
suspend fun getFollowSetNotes() =
|
suspend fun getFollowSetNotes() =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val followSetNotes = LocalCache.getFollowSetNotesFor(user)
|
val followSetNotes = cache.getPeopleListNotesFor(user)
|
||||||
return@withContext followSetNotes
|
return@withContext followSetNotes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user