mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 04:12:56 +02:00
Renames chatroom and message fields
This commit is contained in:
@@ -317,7 +317,7 @@ class Account(
|
||||
val privateZapsDecryptionCache = PrivateZapCache(signer)
|
||||
val draftsDecryptionCache = DraftEventCache(signer)
|
||||
|
||||
val chatroomList = LocalCache.getOrCreateChatroomList(signer.pubKey)
|
||||
val chatroomList = cache.getOrCreateChatroomList(signer.pubKey)
|
||||
|
||||
val privacyState = PrivacyState(settings)
|
||||
val torRelayState = TorRelayState(trustedRelays, dmRelayList, settings, scope)
|
||||
|
@@ -389,8 +389,6 @@ object LocalCache : ILocalCache {
|
||||
idHex: String,
|
||||
note: Note,
|
||||
): Note {
|
||||
checkNotInMainThread()
|
||||
|
||||
require(isValidHex(idHex)) { "$idHex is not a valid hex" }
|
||||
|
||||
return notes.getOrCreate(idHex) {
|
||||
@@ -399,8 +397,6 @@ object LocalCache : ILocalCache {
|
||||
}
|
||||
|
||||
fun getOrCreateNote(idHex: String): Note {
|
||||
checkNotInMainThread()
|
||||
|
||||
require(isValidHex(idHex)) { "$idHex is not a valid hex" }
|
||||
|
||||
return notes.getOrCreate(idHex) {
|
||||
@@ -2313,7 +2309,7 @@ object LocalCache : ILocalCache {
|
||||
}
|
||||
|
||||
chatroomList.forEach { userHex, room ->
|
||||
room.chatrooms.map { key, chatroom ->
|
||||
room.rooms.map { key, chatroom ->
|
||||
val toBeRemoved = chatroom.pruneMessagesToTheLatestOnly()
|
||||
|
||||
val childrenToBeRemoved = mutableListOf<Note>()
|
||||
@@ -2330,7 +2326,7 @@ object LocalCache : ILocalCache {
|
||||
|
||||
if (toBeRemoved.size > 1) {
|
||||
println(
|
||||
"PRUNE: ${toBeRemoved.size} private messages from $userHex to ${key.users.joinToString()} removed. ${chatroom.roomMessages.size} kept",
|
||||
"PRUNE: ${toBeRemoved.size} private messages from $userHex to ${key.users.joinToString()} removed. ${chatroom.messages.size} kept",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@Stable
|
||||
class Chatroom {
|
||||
var activeSenders: Set<User> = setOf()
|
||||
var roomMessages: Set<Note> = setOf()
|
||||
var messages: Set<Note> = setOf()
|
||||
var subject = MutableStateFlow<String?>(null)
|
||||
var subjectCreatedAt: Long? = null
|
||||
var ownerSentMessage: Boolean = false
|
||||
@@ -42,8 +42,8 @@ class Chatroom {
|
||||
|
||||
@Synchronized
|
||||
fun addMessageSync(msg: Note) {
|
||||
if (msg !in roomMessages) {
|
||||
roomMessages = roomMessages + msg
|
||||
if (msg !in messages) {
|
||||
messages = messages + msg
|
||||
|
||||
msg.author?.let { author ->
|
||||
if (author !in activeSenders) {
|
||||
@@ -69,10 +69,10 @@ class Chatroom {
|
||||
fun removeMessageSync(msg: Note) {
|
||||
checkNotInMainThread()
|
||||
|
||||
if (msg in roomMessages) {
|
||||
roomMessages = roomMessages - msg
|
||||
if (msg in messages) {
|
||||
messages = messages - msg
|
||||
|
||||
roomMessages
|
||||
messages
|
||||
.filter { it.event?.subject() != null }
|
||||
.sortedBy { it.createdAt() }
|
||||
.lastOrNull()
|
||||
@@ -86,7 +86,7 @@ class Chatroom {
|
||||
fun senderIntersects(keySet: Set<HexKey>): Boolean = activeSenders.any { it.pubkeyHex in keySet }
|
||||
|
||||
fun pruneMessagesToTheLatestOnly(): Set<Note> {
|
||||
val sorted = roomMessages.sortedWith(DefaultFeedOrder)
|
||||
val sorted = messages.sortedWith(DefaultFeedOrder)
|
||||
|
||||
val toKeep =
|
||||
if ((sorted.firstOrNull()?.createdAt() ?: 0) > TimeUtils.oneWeekAgo()) {
|
||||
@@ -97,8 +97,8 @@ class Chatroom {
|
||||
sorted.take(1).toSet()
|
||||
} + sorted.filter { it.flowSet?.isInUse() ?: false } + sorted.filter { it.event !is PrivateDmEvent }
|
||||
|
||||
val toRemove = roomMessages.minus(toKeep)
|
||||
roomMessages = toKeep
|
||||
val toRemove = messages.minus(toKeep)
|
||||
messages = toKeep
|
||||
return toRemove
|
||||
}
|
||||
}
|
||||
|
@@ -30,10 +30,10 @@ import kotlinx.collections.immutable.persistentSetOf
|
||||
class ChatroomList(
|
||||
val ownerPubKey: HexKey,
|
||||
) {
|
||||
var chatrooms = LargeCache<ChatroomKey, Chatroom>()
|
||||
var rooms = LargeCache<ChatroomKey, Chatroom>()
|
||||
private set
|
||||
|
||||
private fun getOrCreatePrivateChatroomSync(key: ChatroomKey): Chatroom = chatrooms.getOrCreate(key) { Chatroom() }
|
||||
private fun getOrCreatePrivateChatroomSync(key: ChatroomKey): Chatroom = rooms.getOrCreate(key) { Chatroom() }
|
||||
|
||||
fun getOrCreatePrivateChatroom(user: User): Chatroom {
|
||||
val key = ChatroomKey(persistentSetOf(user.pubkeyHex))
|
||||
@@ -47,7 +47,7 @@ class ChatroomList(
|
||||
msg: Note,
|
||||
) {
|
||||
val privateChatroom = getOrCreatePrivateChatroom(room)
|
||||
if (msg !in privateChatroom.roomMessages) {
|
||||
if (msg !in privateChatroom.messages) {
|
||||
privateChatroom.addMessageSync(msg)
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class ChatroomList(
|
||||
msg: Note,
|
||||
) {
|
||||
val privateChatroom = getOrCreatePrivateChatroom(user)
|
||||
if (msg !in privateChatroom.roomMessages) {
|
||||
if (msg !in privateChatroom.messages) {
|
||||
privateChatroom.addMessageSync(msg)
|
||||
if (msg.author?.pubkeyHex == ownerPubKey) {
|
||||
privateChatroom.ownerSentMessage = true
|
||||
@@ -70,7 +70,7 @@ class ChatroomList(
|
||||
msg: Note,
|
||||
) {
|
||||
val privateChatroom = getOrCreatePrivateChatroom(user)
|
||||
if (msg in privateChatroom.roomMessages) {
|
||||
if (msg in privateChatroom.messages) {
|
||||
privateChatroom.removeMessageSync(msg)
|
||||
}
|
||||
}
|
||||
@@ -80,13 +80,13 @@ class ChatroomList(
|
||||
msg: Note,
|
||||
) {
|
||||
val privateChatroom = getOrCreatePrivateChatroom(room)
|
||||
if (msg in privateChatroom.roomMessages) {
|
||||
if (msg in privateChatroom.messages) {
|
||||
privateChatroom.removeMessageSync(msg)
|
||||
}
|
||||
}
|
||||
|
||||
fun hasSentMessagesTo(key: ChatroomKey?): Boolean {
|
||||
if (key == null) return false
|
||||
return chatrooms.get(key)?.ownerSentMessage == true
|
||||
return rooms.get(key)?.ownerSentMessage == true
|
||||
}
|
||||
}
|
||||
|
@@ -203,7 +203,7 @@ class EventNotificationConsumer(
|
||||
|
||||
val isKnownRoom =
|
||||
(
|
||||
chatroomList.chatrooms.get(chatRoom)?.senderIntersects(followingKeySet) == true || chatroomList.hasSentMessagesTo(chatRoom)
|
||||
chatroomList.rooms.get(chatRoom)?.senderIntersects(followingKeySet) == true || chatroomList.hasSentMessagesTo(chatRoom)
|
||||
)
|
||||
|
||||
if (isKnownRoom) {
|
||||
@@ -246,7 +246,7 @@ class EventNotificationConsumer(
|
||||
|
||||
val followingKeySet = acc.backupContactList?.unverifiedFollowKeySet()?.toSet() ?: return
|
||||
|
||||
val isKnownRoom = chatroomList.chatrooms.get(chatRoom)?.senderIntersects(followingKeySet) == true || chatroomList.hasSentMessagesTo(chatRoom)
|
||||
val isKnownRoom = chatroomList.rooms.get(chatRoom)?.senderIntersects(followingKeySet) == true || chatroomList.hasSentMessagesTo(chatRoom)
|
||||
|
||||
if (isKnownRoom) {
|
||||
val content = chatNote.event?.content ?: ""
|
||||
@@ -284,7 +284,7 @@ class EventNotificationConsumer(
|
||||
|
||||
val chatRoom = event.chatroomKey(signer.pubKey)
|
||||
|
||||
val isKnownRoom = chatroomList.chatrooms.get(chatRoom)?.senderIntersects(followingKeySet) == true || chatroomList.hasSentMessagesTo(chatRoom)
|
||||
val isKnownRoom = chatroomList.rooms.get(chatRoom)?.senderIntersects(followingKeySet) == true || chatroomList.hasSentMessagesTo(chatRoom)
|
||||
|
||||
if (isKnownRoom) {
|
||||
note.author?.let {
|
||||
|
@@ -34,18 +34,18 @@ class ChatroomFeedFilter(
|
||||
override fun feedKey(): String = withUser.hashCode().toString()
|
||||
|
||||
override fun feed(): List<Note> {
|
||||
val messages = account.chatroomList.getOrCreatePrivateChatroom(withUser)
|
||||
val chatroom = account.chatroomList.getOrCreatePrivateChatroom(withUser)
|
||||
|
||||
return messages.roomMessages
|
||||
return chatroom.messages
|
||||
.filter { account.isAcceptable(it) }
|
||||
.sortedWith(compareBy({ it.createdAt() }, { it.idHex }))
|
||||
.reversed()
|
||||
}
|
||||
|
||||
override fun applyFilter(collection: Set<Note>): Set<Note> {
|
||||
val messages = account.chatroomList.getOrCreatePrivateChatroom(withUser)
|
||||
val chatroom = account.chatroomList.getOrCreatePrivateChatroom(withUser)
|
||||
|
||||
return collection.filter { it in messages.roomMessages && account.isAcceptable(it) }.toSet()
|
||||
return collection.filter { it in chatroom.messages && account.isAcceptable(it) }.toSet()
|
||||
}
|
||||
|
||||
override fun sort(collection: Set<Note>): List<Note> = collection.sortedWith(DefaultFeedOrder)
|
||||
|
@@ -74,7 +74,7 @@ fun NewChatroomSubjectDialog(
|
||||
val groupName =
|
||||
remember {
|
||||
mutableStateOf<String>(
|
||||
accountViewModel.account.chatroomList.chatrooms
|
||||
accountViewModel.account.chatroomList.rooms
|
||||
.get(room)
|
||||
?.subject
|
||||
?.value ?: "",
|
||||
|
@@ -43,7 +43,7 @@ class ChatroomListKnownFeedFilter(
|
||||
val followingKeySet = account.followingKeySet()
|
||||
|
||||
val privateMessages =
|
||||
chatList.chatrooms.mapNotNull { key, chatroom ->
|
||||
chatList.rooms.mapNotNull { key, chatroom ->
|
||||
if ((chatroom.senderIntersects(followingKeySet) || chatList.hasSentMessagesTo(key)) &&
|
||||
!account.isAllHidden(key.users)
|
||||
) {
|
||||
@@ -229,7 +229,7 @@ class ChatroomListKnownFeedFilter(
|
||||
.forEach { newNote ->
|
||||
val roomKey = (newNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
|
||||
if (roomKey != null) {
|
||||
val room = account.chatroomList.chatrooms.get(roomKey)
|
||||
val room = account.chatroomList.rooms.get(roomKey)
|
||||
if (room != null) {
|
||||
if (
|
||||
(
|
||||
|
@@ -39,7 +39,7 @@ class ChatroomListNewFeedFilter(
|
||||
val followingKeySet = account.followingKeySet()
|
||||
|
||||
val privateMessages =
|
||||
chatList.chatrooms.mapNotNull { key, chatroom ->
|
||||
chatList.rooms.mapNotNull { key, chatroom ->
|
||||
if (!chatroom.senderIntersects(followingKeySet) && !chatList.hasSentMessagesTo(key) && !account.isAllHidden(key.users)) {
|
||||
chatroom.lastMessage
|
||||
} else {
|
||||
@@ -108,7 +108,7 @@ class ChatroomListNewFeedFilter(
|
||||
val noteEvent = newNote.event
|
||||
if (noteEvent is ChatroomKeyable) {
|
||||
val roomKey = noteEvent.chatroomKey(me.pubkeyHex)
|
||||
val room = account.chatroomList.chatrooms.get(roomKey)
|
||||
val room = account.chatroomList.rooms.get(roomKey)
|
||||
|
||||
if (room != null &&
|
||||
(
|
||||
|
Reference in New Issue
Block a user