Moves MarkAsRead write and read to IO context.
This commit is contained in:
@@ -40,7 +40,9 @@ import androidx.navigation.NavHostController
|
|||||||
import com.vitorpamplona.amethyst.NotificationCache
|
import com.vitorpamplona.amethyst.NotificationCache
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
val bottomNavigationItems = listOf(
|
val bottomNavigationItems = listOf(
|
||||||
Route.Home,
|
Route.Home,
|
||||||
@@ -157,11 +159,15 @@ private fun NotifiableIcon(item: Route, currentRoute: String?, accountViewModel:
|
|||||||
val context = LocalContext.current.applicationContext
|
val context = LocalContext.current.applicationContext
|
||||||
|
|
||||||
LaunchedEffect(key1 = notif) {
|
LaunchedEffect(key1 = notif) {
|
||||||
hasNewItems = item.hasNewItems(account, notif.cache, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
hasNewItems = item.hasNewItems(account, notif.cache, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(key1 = db) {
|
LaunchedEffect(key1 = db) {
|
||||||
hasNewItems = item.hasNewItems(account, notif.cache, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
hasNewItems = item.hasNewItems(account, notif.cache, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNewItems) {
|
if (hasNewItems) {
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import com.vitorpamplona.amethyst.R
|
|||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.BadgeCard
|
import com.vitorpamplona.amethyst.ui.screen.BadgeCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -56,9 +58,11 @@ fun BadgeCompose(likeSetCard: BadgeCard, modifier: Modifier = Modifier, isInnerN
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = likeSetCard) {
|
LaunchedEffect(key1 = likeSetCard) {
|
||||||
isNew = likeSetCard.createdAt() > NotificationCache.load(routeForLastRead, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
isNew = likeSetCard.createdAt() > NotificationCache.load(routeForLastRead, context)
|
||||||
|
|
||||||
NotificationCache.markAsRead(routeForLastRead, likeSetCard.createdAt(), context)
|
NotificationCache.markAsRead(routeForLastRead, likeSetCard.createdAt(), context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor = if (isNew) {
|
var backgroundColor = if (isNew) {
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import com.vitorpamplona.amethyst.R
|
|||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.BoostSetCard
|
import com.vitorpamplona.amethyst.ui.screen.BoostSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -53,9 +55,11 @@ fun BoostSetCompose(boostSetCard: BoostSetCard, isInnerNote: Boolean = false, ro
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = boostSetCard) {
|
LaunchedEffect(key1 = boostSetCard) {
|
||||||
isNew = boostSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
isNew = boostSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
||||||
|
|
||||||
NotificationCache.markAsRead(routeForLastRead, boostSetCard.createdAt, context)
|
NotificationCache.markAsRead(routeForLastRead, boostSetCard.createdAt, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor = if (isNew) {
|
var backgroundColor = if (isNew) {
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
|
|||||||
import com.vitorpamplona.amethyst.ui.components.AsyncImageProxy
|
import com.vitorpamplona.amethyst.ui.components.AsyncImageProxy
|
||||||
import com.vitorpamplona.amethyst.ui.components.ResizeImage
|
import com.vitorpamplona.amethyst.ui.components.ResizeImage
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatroomCompose(
|
fun ChatroomCompose(
|
||||||
@@ -90,9 +92,11 @@ fun ChatroomCompose(
|
|||||||
var hasNewMessages by remember { mutableStateOf<Boolean>(false) }
|
var hasNewMessages by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = notificationCache, key2 = note) {
|
LaunchedEffect(key1 = notificationCache, key2 = note) {
|
||||||
note.createdAt()?.let {
|
withContext(Dispatchers.IO) {
|
||||||
hasNewMessages =
|
note.createdAt()?.let {
|
||||||
it > notificationCache.cache.load("Channel/${channel.idHex}", context)
|
hasNewMessages =
|
||||||
|
it > notificationCache.cache.load("Channel/${channel.idHex}", context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,11 +156,13 @@ fun ChatroomCompose(
|
|||||||
var hasNewMessages by remember { mutableStateOf<Boolean>(false) }
|
var hasNewMessages by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = notificationCache, key2 = note) {
|
LaunchedEffect(key1 = notificationCache, key2 = note) {
|
||||||
noteEvent?.let {
|
withContext(Dispatchers.IO) {
|
||||||
hasNewMessages = it.createdAt() > notificationCache.cache.load(
|
noteEvent?.let {
|
||||||
"Room/${userToComposeOn.pubkeyHex}",
|
hasNewMessages = it.createdAt() > notificationCache.cache.load(
|
||||||
context
|
"Room/${userToComposeOn.pubkeyHex}",
|
||||||
)
|
context
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ import com.vitorpamplona.amethyst.ui.components.AsyncImageProxy
|
|||||||
import com.vitorpamplona.amethyst.ui.components.ResizeImage
|
import com.vitorpamplona.amethyst.ui.components.ResizeImage
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslateableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslateableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
val ChatBubbleShapeMe = RoundedCornerShape(15.dp, 15.dp, 3.dp, 15.dp)
|
val ChatBubbleShapeMe = RoundedCornerShape(15.dp, 15.dp, 3.dp, 15.dp)
|
||||||
val ChatBubbleShapeThem = RoundedCornerShape(3.dp, 15.dp, 15.dp, 15.dp)
|
val ChatBubbleShapeThem = RoundedCornerShape(3.dp, 15.dp, 15.dp, 15.dp)
|
||||||
@@ -131,12 +133,14 @@ fun ChatroomMessageCompose(
|
|||||||
|
|
||||||
LaunchedEffect(key1 = routeForLastRead) {
|
LaunchedEffect(key1 = routeForLastRead) {
|
||||||
routeForLastRead?.let {
|
routeForLastRead?.let {
|
||||||
val lastTime = NotificationCache.load(it, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
val lastTime = NotificationCache.load(it, context)
|
||||||
|
|
||||||
val createdAt = note.createdAt()
|
val createdAt = note.createdAt()
|
||||||
if (createdAt != null) {
|
if (createdAt != null) {
|
||||||
NotificationCache.markAsRead(it, createdAt, context)
|
NotificationCache.markAsRead(it, createdAt, context)
|
||||||
isNew = createdAt > lastTime
|
isNew = createdAt > lastTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import com.vitorpamplona.amethyst.R
|
|||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.LikeSetCard
|
import com.vitorpamplona.amethyst.ui.screen.LikeSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -53,9 +55,11 @@ fun LikeSetCompose(likeSetCard: LikeSetCard, modifier: Modifier = Modifier, isIn
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = likeSetCard) {
|
LaunchedEffect(key1 = likeSetCard) {
|
||||||
isNew = likeSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
isNew = likeSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
||||||
|
|
||||||
NotificationCache.markAsRead(routeForLastRead, likeSetCard.createdAt, context)
|
NotificationCache.markAsRead(routeForLastRead, likeSetCard.createdAt, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor = if (isNew) {
|
var backgroundColor = if (isNew) {
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import com.vitorpamplona.amethyst.R
|
|||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.MessageSetCard
|
import com.vitorpamplona.amethyst.ui.screen.MessageSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -51,9 +53,12 @@ fun MessageSetCompose(messageSetCard: MessageSetCard, isInnerNote: Boolean = fal
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = messageSetCard) {
|
LaunchedEffect(key1 = messageSetCard) {
|
||||||
isNew = messageSetCard.createdAt() > NotificationCache.load(routeForLastRead, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
isNew =
|
||||||
|
messageSetCard.createdAt() > NotificationCache.load(routeForLastRead, context)
|
||||||
|
|
||||||
NotificationCache.markAsRead(routeForLastRead, messageSetCard.createdAt(), context)
|
NotificationCache.markAsRead(routeForLastRead, messageSetCard.createdAt(), context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor = if (isNew) {
|
var backgroundColor = if (isNew) {
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -57,9 +59,11 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, modifier: Modifier = Modifier, r
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = multiSetCard) {
|
LaunchedEffect(key1 = multiSetCard) {
|
||||||
isNew = multiSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
isNew = multiSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
||||||
|
|
||||||
NotificationCache.markAsRead(routeForLastRead, multiSetCard.createdAt, context)
|
NotificationCache.markAsRead(routeForLastRead, multiSetCard.createdAt, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor = if (isNew) {
|
var backgroundColor = if (isNew) {
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ import com.vitorpamplona.amethyst.ui.components.TranslateableRichTextViewer
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Following
|
import com.vitorpamplona.amethyst.ui.theme.Following
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -120,13 +122,15 @@ fun NoteCompose(
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = routeForLastRead) {
|
LaunchedEffect(key1 = routeForLastRead) {
|
||||||
routeForLastRead?.let {
|
withContext(Dispatchers.IO) {
|
||||||
val lastTime = NotificationCache.load(it, context)
|
routeForLastRead?.let {
|
||||||
|
val lastTime = NotificationCache.load(it, context)
|
||||||
|
|
||||||
val createdAt = note.createdAt()
|
val createdAt = note.createdAt()
|
||||||
if (createdAt != null) {
|
if (createdAt != null) {
|
||||||
NotificationCache.markAsRead(it, createdAt, context)
|
NotificationCache.markAsRead(it, createdAt, context)
|
||||||
isNew = createdAt > lastTime
|
isNew = createdAt > lastTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.ZapSetCard
|
import com.vitorpamplona.amethyst.ui.screen.ZapSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -55,9 +57,11 @@ fun ZapSetCompose(zapSetCard: ZapSetCard, modifier: Modifier = Modifier, isInner
|
|||||||
var isNew by remember { mutableStateOf<Boolean>(false) }
|
var isNew by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = zapSetCard) {
|
LaunchedEffect(key1 = zapSetCard) {
|
||||||
isNew = zapSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
withContext(Dispatchers.IO) {
|
||||||
|
isNew = zapSetCard.createdAt > NotificationCache.load(routeForLastRead, context)
|
||||||
|
|
||||||
NotificationCache.markAsRead(routeForLastRead, zapSetCard.createdAt, context)
|
NotificationCache.markAsRead(routeForLastRead, zapSetCard.createdAt, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor = if (isNew) {
|
var backgroundColor = if (isNew) {
|
||||||
|
|||||||
Reference in New Issue
Block a user