BugFix: Chat List updating immediately when new messages arrive.

This commit is contained in:
Vitor Pamplona
2023-08-11 20:04:37 -04:00
parent f97a0468cc
commit d262b48f31
2 changed files with 27 additions and 12 deletions

View File

@@ -68,26 +68,36 @@ class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter<Not
var myNewList = oldList var myNewList = oldList
newRelevantPublicMessages.forEach { newNotePair -> newRelevantPublicMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote -> oldList.forEach { oldNote ->
if ( if (newNotePair.key == oldNote.channelHex()) {
(newNotePair.key == oldNote.channelHex()) && (newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0) hasUpdated = true
) { if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value) myNewList = myNewList.updated(oldNote, newNotePair.value)
} }
} }
} }
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
newRelevantPrivateMessages.forEach { newNotePair -> newRelevantPrivateMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote -> oldList.forEach { oldNote ->
val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex) val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
if ( if (newNotePair.key == oldRoom) {
(newNotePair.key == oldRoom) && (newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0) hasUpdated = true
) { if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value) myNewList = myNewList.updated(oldNote, newNotePair.value)
} }
} }
} }
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
sort(myNewList.toSet()).take(1000) sort(myNewList.toSet()).take(1000)
} }

View File

@@ -53,16 +53,21 @@ class ChatroomListNewFeedFilter(val account: Account) : AdditiveFeedFilter<Note>
var myNewList = oldList var myNewList = oldList
newRelevantPrivateMessages.forEach { newNotePair -> newRelevantPrivateMessages.forEach { newNotePair ->
var hasUpdated = false
oldList.forEach { oldNote -> oldList.forEach { oldNote ->
val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex) val oldRoom = (oldNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
if ( if (newNotePair.key == oldRoom) {
(newNotePair.key == oldRoom) && (newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0) hasUpdated = true
) { if ((newNotePair.value.createdAt() ?: 0) > (oldNote.createdAt() ?: 0)) {
myNewList = myNewList.updated(oldNote, newNotePair.value) myNewList = myNewList.updated(oldNote, newNotePair.value)
} }
} }
} }
if (!hasUpdated) {
myNewList = myNewList.plus(newNotePair.value)
}
}
sort(myNewList.toSet()).take(1000) sort(myNewList.toSet()).take(1000)
} }