mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-05 02:20:18 +02:00
Faster way to count reports.
This commit is contained in:
parent
308a79a305
commit
c0bdb40c7d
app/src/main/java/com/vitorpamplona/amethyst/model
@ -479,19 +479,19 @@ class Account(
|
||||
fun isAcceptable(user: User): Boolean {
|
||||
return !isHidden(user) // if user hasn't hided this author
|
||||
&& user.reportsBy( userProfile() ).isEmpty() // if user has not reported this post
|
||||
&& user.reportAuthorsBy( userProfile().follows ).size < 5
|
||||
&& user.countReportAuthorsBy( userProfile().follows ) < 5
|
||||
}
|
||||
|
||||
fun isAcceptableDirect(note: Note): Boolean {
|
||||
return note.reportsBy( userProfile() ).isEmpty() // if user has not reported this post
|
||||
&& note.reportAuthorsBy( userProfile().follows ).size < 5 // if it has 5 reports by reliable users
|
||||
&& note.countReportAuthorsBy( userProfile().follows ) < 5 // if it has 5 reports by reliable users
|
||||
}
|
||||
|
||||
fun isAcceptable(note: Note): Boolean {
|
||||
return note.author?.let { isAcceptable(it) } ?: true // if user hasn't hided this author
|
||||
&& isAcceptableDirect(note)
|
||||
&& (note.event !is RepostEvent
|
||||
|| (note.event is RepostEvent && note.replyTo?.firstOrNull { isAcceptableDirect(it) } != null)
|
||||
|| (note.event is RepostEvent && note.replyTo?.firstOrNull { isAcceptableDirect(it) } != null)
|
||||
) // is not a reaction about a blocked post
|
||||
}
|
||||
|
||||
|
@ -229,6 +229,10 @@ open class Note(val idHex: String) {
|
||||
return reports.keys.filter { it in users }
|
||||
}
|
||||
|
||||
fun countReportAuthorsBy(users: Set<User>): Int {
|
||||
return reports.keys.count { it in users }
|
||||
}
|
||||
|
||||
fun reportsBy(users: Set<User>): List<Note> {
|
||||
return reportAuthorsBy(users).mapNotNull {
|
||||
reports[it]
|
||||
|
@ -201,6 +201,10 @@ class User(val pubkeyHex: String) {
|
||||
return reports.keys.filter { it in users }
|
||||
}
|
||||
|
||||
fun countReportAuthorsBy(users: Set<User>): Int {
|
||||
return reports.keys.count { it in users }
|
||||
}
|
||||
|
||||
fun reportsBy(users: Set<User>): List<Note> {
|
||||
return reportAuthorsBy(users).mapNotNull {
|
||||
reports[it]
|
||||
|
Loading…
x
Reference in New Issue
Block a user