- Removing user reports flow
- Integrates LocalCache.consume report into the consumeRegularEvent practice
This commit is contained in:
@@ -798,9 +798,6 @@ object LocalCache : ILocalCache {
|
||||
is ReactionEvent ->
|
||||
event.originalPost().mapNotNull { checkGetOrCreateNote(it) } +
|
||||
event.taggedAddresses().map { getOrCreateAddressableNote(it) }
|
||||
is ReportEvent ->
|
||||
event.reportedPost().mapNotNull { checkGetOrCreateNote(it.eventId) } +
|
||||
event.reportedAddresses().map { getOrCreateAddressableNote(it.address) }
|
||||
is ChannelMessageEvent ->
|
||||
event
|
||||
.tagsWithoutCitations()
|
||||
@@ -1511,40 +1508,23 @@ object LocalCache : ILocalCache {
|
||||
wasVerified: Boolean,
|
||||
): Boolean {
|
||||
val note = getOrCreateNote(event.id)
|
||||
val author = getOrCreateUser(event.pubKey)
|
||||
|
||||
if (relay != null) {
|
||||
author.addRelayBeingUsed(relay, event.createdAt)
|
||||
note.addRelay(relay)
|
||||
}
|
||||
val new = consumeRegularEvent(event, relay, wasVerified)
|
||||
|
||||
// Already processed this event.
|
||||
if (note.event != null) return false
|
||||
|
||||
if (wasVerified || justVerify(event)) {
|
||||
if (new) {
|
||||
val authorsReported = event.reportedAuthor().mapNotNull { checkGetOrCreateUser(it.pubkey) }
|
||||
val repliesTo = computeReplyTo(event)
|
||||
val eventsReported =
|
||||
event.reportedPost().mapNotNull { checkGetOrCreateNote(it.eventId) } +
|
||||
event.reportedAddresses().map { getOrCreateAddressableNote(it.address) }
|
||||
|
||||
note.loadEvent(event, author, repliesTo)
|
||||
|
||||
// Log.d("RP", "New Report ${event.content} by ${note.author?.toBestDisplayName()}
|
||||
// ${formattedDateTime(event.createdAt)}")
|
||||
// Adds notifications to users.
|
||||
if (repliesTo.isEmpty()) {
|
||||
if (eventsReported.isEmpty()) {
|
||||
authorsReported.forEach { author ->
|
||||
author.reports().addReport(note)
|
||||
}
|
||||
} else {
|
||||
repliesTo.forEach { it.addReport(note) }
|
||||
|
||||
authorsReported.forEach {
|
||||
// doesn't add to reports, but triggers recounts
|
||||
it.flowSet?.reports?.invalidateData()
|
||||
}
|
||||
eventsReported.forEach { it.addReport(note) }
|
||||
}
|
||||
|
||||
refreshNewNoteObservers(note)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -2472,9 +2452,16 @@ object LocalCache : ILocalCache {
|
||||
}
|
||||
}
|
||||
if (noteEvent is ReportEvent) {
|
||||
noteEvent.reportedAuthor().mapNotNull {
|
||||
val author = getUserIfExists(it.pubkey)
|
||||
author?.reportsOrNull()?.removeReport(note)
|
||||
noteEvent.reportedAuthor().forEach {
|
||||
getUserIfExists(it.pubkey)?.reportsOrNull()?.removeReport(note)
|
||||
}
|
||||
|
||||
noteEvent.reportedPost().forEach {
|
||||
getNoteIfExists(it.eventId)?.removeReport(note)
|
||||
}
|
||||
|
||||
noteEvent.reportedAddresses().forEach {
|
||||
getAddressableNoteIfExists(it.address)?.removeReport(note)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +298,6 @@ class UserFlowSet(
|
||||
val metadata = UserBundledRefresherFlow(u)
|
||||
val follows = UserBundledRefresherFlow(u)
|
||||
val followers = UserBundledRefresherFlow(u)
|
||||
val reports = UserBundledRefresherFlow(u)
|
||||
val usedRelays = UserBundledRefresherFlow(u)
|
||||
val zaps = UserBundledRefresherFlow(u)
|
||||
val statuses = UserBundledRefresherFlow(u)
|
||||
@@ -307,7 +306,6 @@ class UserFlowSet(
|
||||
metadata.hasObservers() ||
|
||||
follows.hasObservers() ||
|
||||
followers.hasObservers() ||
|
||||
reports.hasObservers() ||
|
||||
usedRelays.hasObservers() ||
|
||||
zaps.hasObservers() ||
|
||||
statuses.hasObservers()
|
||||
|
||||
+6
@@ -28,6 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip56Reports.ReportEvent
|
||||
import com.vitorpamplona.quartz.nip56Reports.ReportType
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
class UserReportCache : UserDependencies {
|
||||
@@ -84,6 +85,11 @@ class UserReportCache : UserDependencies {
|
||||
|
||||
fun count() = receivedReportsByAuthor.value.values.sumOf { it.size }
|
||||
|
||||
fun countFlow() =
|
||||
receivedReportsByAuthor.map { reportPerAuthor ->
|
||||
reportPerAuthor.values.sumOf { it.size }
|
||||
}
|
||||
|
||||
fun countReportAuthorsBy(users: Set<HexKey>): Int = receivedReportsByAuthor.value.count { it.key.pubkeyHex in users }
|
||||
|
||||
fun all() = receivedReportsByAuthor.value.values.flatten()
|
||||
|
||||
+2
-11
@@ -44,6 +44,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@@ -596,17 +597,7 @@ fun observeUserReportCount(
|
||||
UserFinderFilterAssemblerSubscription(user, accountViewModel)
|
||||
|
||||
// Subscribe in the LocalCache for changes that arrive in the device
|
||||
val flow =
|
||||
remember(user) {
|
||||
user
|
||||
.flow()
|
||||
.reports
|
||||
.stateFlow
|
||||
.sample(1000)
|
||||
.mapLatest { userState ->
|
||||
userState.user.reportsOrNull()?.count() ?: 0
|
||||
}.distinctUntilChanged()
|
||||
}
|
||||
val flow = remember(user) { user.reports().countFlow() }
|
||||
|
||||
return flow.collectAsStateWithLifecycle(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user