Avoids concurrent exceptions

This commit is contained in:
Vitor Pamplona 2023-01-30 13:50:43 -03:00
parent a0ba313661
commit e59dfa7a76
3 changed files with 28 additions and 4 deletions

View File

@ -373,13 +373,13 @@ class Account(
fun isAcceptable(user: User): Boolean {
return user !in hiddenUsers() // if user hasn't hided this author
&& user.reports.firstOrNull { it.author == userProfile() } == null // if user has not reported this post
&& user.reports.filter { it.author in userProfile().follows }.size < 5
&& user.reportsBy( userProfile() ).isEmpty() // if user has not reported this post
&& user.reportsBy( userProfile().follows ).size < 5
}
fun isAcceptableDirect(note: Note): Boolean {
return note.reports.firstOrNull { it.author == userProfile() } == null // if user has not reported this post
&& note.reports.filter { it.author in userProfile().follows }.size < 5 // if it has 5 reports by reliable users
return note.reportsBy( userProfile() ).isEmpty() // if user has not reported this post
&& note.reportsBy( userProfile().follows ).size < 5 // if it has 5 reports by reliable users
}
fun isAcceptable(note: Note): Boolean {

View File

@ -107,6 +107,18 @@ class Note(val idHex: String) {
}
}
fun reportsBy(user: User): List<Note> {
return synchronized(reports) {
reports.filter { it.author == user }
}
}
fun reportsBy(users: Set<User>): List<Note> {
return synchronized(reports) {
reports.filter { it.author in users }
}
}
// Observers line up here.
val live: NoteLiveData = NoteLiveData(this)

View File

@ -93,6 +93,18 @@ class User(val pubkey: ByteArray) {
}
}
fun reportsBy(user: User): List<Note> {
return synchronized(reports) {
reports.filter { it.author == user }
}
}
fun reportsBy(users: Set<User>): List<Note> {
return synchronized(reports) {
reports.filter { it.author in users }
}
}
@Synchronized
fun getOrCreateChannel(user: User): MutableSet<Note> {
return messages[user] ?: run {