Simplifies if a chatroom sender intersects with the follow list.
This commit is contained in:
@@ -27,6 +27,7 @@ import com.vitorpamplona.quartz.utils.TimeUtils
|
|||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
class Chatroom() {
|
class Chatroom() {
|
||||||
|
var authors: Set<User> = setOf()
|
||||||
var roomMessages: Set<Note> = setOf()
|
var roomMessages: Set<Note> = setOf()
|
||||||
var subject: String? = null
|
var subject: String? = null
|
||||||
var subjectCreatedAt: Long? = null
|
var subjectCreatedAt: Long? = null
|
||||||
@@ -38,6 +39,12 @@ class Chatroom() {
|
|||||||
if (msg !in roomMessages) {
|
if (msg !in roomMessages) {
|
||||||
roomMessages = roomMessages + msg
|
roomMessages = roomMessages + msg
|
||||||
|
|
||||||
|
msg.author?.let { author ->
|
||||||
|
if (author !in authors) {
|
||||||
|
authors += author
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val newSubject = msg.event?.subject()
|
val newSubject = msg.event?.subject()
|
||||||
|
|
||||||
if (newSubject != null && (msg.createdAt() ?: 0) > (subjectCreatedAt ?: 0)) {
|
if (newSubject != null && (msg.createdAt() ?: 0) > (subjectCreatedAt ?: 0)) {
|
||||||
@@ -51,8 +58,8 @@ class Chatroom() {
|
|||||||
fun removeMessageSync(msg: Note) {
|
fun removeMessageSync(msg: Note) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
if (msg !in roomMessages) {
|
if (msg in roomMessages) {
|
||||||
roomMessages = roomMessages + msg
|
roomMessages = roomMessages - msg
|
||||||
|
|
||||||
roomMessages
|
roomMessages
|
||||||
.filter { it.event?.subject() != null }
|
.filter { it.event?.subject() != null }
|
||||||
@@ -66,7 +73,7 @@ class Chatroom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun senderIntersects(keySet: Set<HexKey>): Boolean {
|
fun senderIntersects(keySet: Set<HexKey>): Boolean {
|
||||||
return roomMessages.any { it.author?.pubkeyHex in keySet }
|
return authors.any { it.pubkeyHex in keySet }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pruneMessagesToTheLatestOnly(): Set<Note> {
|
fun pruneMessagesToTheLatestOnly(): Set<Note> {
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ class User(val pubkeyHex: String) {
|
|||||||
fun hasSentMessagesTo(key: ChatroomKey?): Boolean {
|
fun hasSentMessagesTo(key: ChatroomKey?): Boolean {
|
||||||
val messagesToUser = privateChatrooms[key] ?: return false
|
val messagesToUser = privateChatrooms[key] ?: return false
|
||||||
|
|
||||||
return messagesToUser.roomMessages.any { this.pubkeyHex == it.author?.pubkeyHex }
|
return messagesToUser.authors.any { this == it }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasReport(
|
fun hasReport(
|
||||||
|
|||||||
Reference in New Issue
Block a user