mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-20 14:01:22 +02:00
Fix crashing when changing users.
This commit is contained in:
@@ -11,6 +11,7 @@ import com.vitorpamplona.amethyst.NotificationCache
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.dal.ChatroomListKnownFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.ChatroomListKnownFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.dal.HomeNewThreadFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.HomeNewThreadFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.dal.NotificationFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.NotificationFeedFilter
|
||||||
@@ -109,9 +110,29 @@ fun currentRoute(navController: NavHostController): String? {
|
|||||||
return navBackStackEntry?.destination?.route
|
return navBackStackEntry?.destination?.route
|
||||||
}
|
}
|
||||||
|
|
||||||
object HomeLatestItem {
|
open class LatestItem {
|
||||||
private var newestItem: Note? = null
|
var newestItemPerAccount: Map<String, Note?> = mapOf()
|
||||||
|
|
||||||
|
fun updateNewestItem(newNotes: Set<Note>, account: Account, filter: AdditiveFeedFilter<Note>): Note? {
|
||||||
|
val newestItem = newestItemPerAccount[account.userProfile().pubkeyHex]
|
||||||
|
|
||||||
|
if (newestItem == null) {
|
||||||
|
newestItemPerAccount = newestItemPerAccount + Pair(
|
||||||
|
account.userProfile().pubkeyHex,
|
||||||
|
filter.feed().firstOrNull { it.createdAt() != null }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
newestItemPerAccount = newestItemPerAccount + Pair(
|
||||||
|
account.userProfile().pubkeyHex,
|
||||||
|
filter.sort(filter.applyFilter(newNotes) + newestItem).first()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newestItemPerAccount[account.userProfile().pubkeyHex]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object HomeLatestItem : LatestItem() {
|
||||||
fun hasNewItems(
|
fun hasNewItems(
|
||||||
account: Account,
|
account: Account,
|
||||||
cache: NotificationCache,
|
cache: NotificationCache,
|
||||||
@@ -120,22 +141,13 @@ object HomeLatestItem {
|
|||||||
val lastTime = cache.load("HomeFollows")
|
val lastTime = cache.load("HomeFollows")
|
||||||
HomeNewThreadFeedFilter.account = account
|
HomeNewThreadFeedFilter.account = account
|
||||||
|
|
||||||
if (newestItem == null) {
|
val newestItem = updateNewestItem(newNotes, account, HomeNewThreadFeedFilter)
|
||||||
newestItem = HomeNewThreadFeedFilter.feed().firstOrNull { it.createdAt() != null }
|
|
||||||
} else {
|
|
||||||
newestItem =
|
|
||||||
HomeNewThreadFeedFilter.sort(
|
|
||||||
HomeNewThreadFeedFilter.applyFilter(newNotes + newestItem!!)
|
|
||||||
).first()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (newestItem?.createdAt() ?: 0) > lastTime
|
return (newestItem?.createdAt() ?: 0) > lastTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object NotificationLatestItem {
|
object NotificationLatestItem : LatestItem() {
|
||||||
private var newestItem: Note? = null
|
|
||||||
|
|
||||||
fun hasNewItems(
|
fun hasNewItems(
|
||||||
account: Account,
|
account: Account,
|
||||||
cache: NotificationCache,
|
cache: NotificationCache,
|
||||||
@@ -144,21 +156,13 @@ object NotificationLatestItem {
|
|||||||
val lastTime = cache.load("Notification")
|
val lastTime = cache.load("Notification")
|
||||||
NotificationFeedFilter.account = account
|
NotificationFeedFilter.account = account
|
||||||
|
|
||||||
if (newestItem == null) {
|
val newestItem = updateNewestItem(newNotes, account, NotificationFeedFilter)
|
||||||
newestItem = NotificationFeedFilter.feed().firstOrNull { it.createdAt() != null }
|
|
||||||
} else {
|
|
||||||
newestItem = HomeNewThreadFeedFilter.sort(
|
|
||||||
NotificationFeedFilter.applyFilter(newNotes) + newestItem!!
|
|
||||||
).first()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (newestItem?.createdAt() ?: 0) > lastTime
|
return (newestItem?.createdAt() ?: 0) > lastTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object MessagesLatestItem {
|
object MessagesLatestItem {
|
||||||
private var newestItem: Note? = null
|
|
||||||
|
|
||||||
fun hasNewItems(
|
fun hasNewItems(
|
||||||
account: Account,
|
account: Account,
|
||||||
cache: NotificationCache,
|
cache: NotificationCache,
|
||||||
|
Reference in New Issue
Block a user