mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-30 04:31:50 +02:00
Speeding up userprofile, hidden user search and notification filter time
This commit is contained in:
parent
110c074993
commit
a2f14c3671
@ -61,9 +61,16 @@ class Account(
|
|||||||
var latestContactList: ContactListEvent? = null
|
var latestContactList: ContactListEvent? = null
|
||||||
) {
|
) {
|
||||||
var transientHiddenUsers: Set<String> = setOf()
|
var transientHiddenUsers: Set<String> = setOf()
|
||||||
|
@Transient
|
||||||
|
var userProfile: User? = null
|
||||||
|
|
||||||
fun userProfile(): User {
|
fun userProfile(): User {
|
||||||
return LocalCache.getOrCreateUser(loggedIn.pubKey.toHexKey())
|
userProfile?.let { return it }
|
||||||
|
|
||||||
|
val newUser = LocalCache.getOrCreateUser(loggedIn.pubKey.toHexKey())
|
||||||
|
userProfile = newUser
|
||||||
|
|
||||||
|
return newUser
|
||||||
}
|
}
|
||||||
|
|
||||||
fun followingChannels(): List<Channel> {
|
fun followingChannels(): List<Channel> {
|
||||||
@ -483,10 +490,10 @@ class Account(
|
|||||||
val liveLanguages: AccountLiveData = AccountLiveData(this)
|
val liveLanguages: AccountLiveData = AccountLiveData(this)
|
||||||
val saveable: AccountLiveData = AccountLiveData(this)
|
val saveable: AccountLiveData = AccountLiveData(this)
|
||||||
|
|
||||||
fun isHidden(user: User) = user in hiddenUsers()
|
fun isHidden(user: User) = user.pubkeyHex in hiddenUsers || user.pubkeyHex in transientHiddenUsers
|
||||||
|
|
||||||
fun isAcceptable(user: User): Boolean {
|
fun isAcceptable(user: User): Boolean {
|
||||||
return user !in hiddenUsers() // if user hasn't hided this author
|
return !isHidden(user) // if user hasn't hided this author
|
||||||
&& user.reportsBy( userProfile() ).isEmpty() // if user has not reported this post
|
&& user.reportsBy( userProfile() ).isEmpty() // if user has not reported this post
|
||||||
&& user.reportAuthorsBy( userProfile().follows ).size < 5
|
&& user.reportAuthorsBy( userProfile().follows ).size < 5
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.dal
|
package com.vitorpamplona.amethyst.ui.dal
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
@ -10,8 +11,14 @@ import kotlinx.coroutines.Job
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
abstract class FeedFilter<T>() {
|
abstract class FeedFilter<T>() {
|
||||||
|
@OptIn(ExperimentalTime::class)
|
||||||
fun loadTop(): List<T> {
|
fun loadTop(): List<T> {
|
||||||
return feed().take(1000)
|
val (feed, elapsed) = measureTimedValue {
|
||||||
|
feed().take(1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("Time","${this.javaClass.simpleName} Feed in ${elapsed}")
|
||||||
|
return feed
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun feed(): List<T>
|
abstract fun feed(): List<T>
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.dal
|
package com.vitorpamplona.amethyst.ui.dal
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import nostr.postr.JsonFilter
|
|
||||||
import nostr.postr.events.TextNoteEvent
|
|
||||||
|
|
||||||
object HiddenAccountsFeedFilter: FeedFilter<User>() {
|
object HiddenAccountsFeedFilter: FeedFilter<User>() {
|
||||||
lateinit var account: Account
|
lateinit var account: Account
|
||||||
|
@ -109,7 +109,7 @@ private fun homeHasNewItems(account: Account, cache: NotificationCache, context:
|
|||||||
|
|
||||||
HomeNewThreadFeedFilter.account = account
|
HomeNewThreadFeedFilter.account = account
|
||||||
|
|
||||||
return HomeNewThreadFeedFilter.feed().any {(it.event?.createdAt ?: 0) > lastTime }
|
return (HomeNewThreadFeedFilter.feed().firstOrNull { it.event?.createdAt != null }?.event?.createdAt ?: 0) > lastTime
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notificationHasNewItems(account: Account, cache: NotificationCache, context: Context): Boolean {
|
private fun notificationHasNewItems(account: Account, cache: NotificationCache, context: Context): Boolean {
|
||||||
@ -117,19 +117,17 @@ private fun notificationHasNewItems(account: Account, cache: NotificationCache,
|
|||||||
|
|
||||||
NotificationFeedFilter.account = account
|
NotificationFeedFilter.account = account
|
||||||
|
|
||||||
return NotificationFeedFilter.feed().any {(it.event?.createdAt ?: 0) > lastTime }
|
return (NotificationFeedFilter.feed().firstOrNull { it.event?.createdAt != null }?.event?.createdAt ?: 0) > lastTime
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun messagesHasNewItems(account: Account, cache: NotificationCache, context: Context): Boolean {
|
private fun messagesHasNewItems(account: Account, cache: NotificationCache, context: Context): Boolean {
|
||||||
ChatroomListKnownFeedFilter.account = account
|
ChatroomListKnownFeedFilter.account = account
|
||||||
|
|
||||||
return ChatroomListKnownFeedFilter.feed().any {
|
val note = ChatroomListKnownFeedFilter.feed().firstOrNull {
|
||||||
if (it.channel == null && it.author != account.userProfile()) {
|
it.event?.createdAt != null && it.channel == null && it.author != account.userProfile()
|
||||||
val lastTime = cache.load("Room/${it.author?.pubkeyHex}", context)
|
} ?: return false
|
||||||
|
|
||||||
(it.event?.createdAt ?: 0) > lastTime
|
val lastTime = cache.load("Room/${note.author?.pubkeyHex}", context)
|
||||||
} else {
|
|
||||||
false
|
return (note.event?.createdAt ?: 0) > lastTime
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user