BugFix for marking chat as read

This commit is contained in:
Vitor Pamplona
2023-08-12 13:50:40 -04:00
parent c8172265dd
commit cb7b51e8d1
2 changed files with 6 additions and 26 deletions
@@ -198,7 +198,7 @@ private fun ChannelRoomCompose(
channelIdHex = chanHex, channelIdHex = chanHex,
channelPicture = channelPicture, channelPicture = channelPicture,
channelTitle = { modifier -> channelTitle = { modifier ->
ChannelTitleWithBoostInfo(channelName, modifier) ChannelTitleWithLabelInfo(channelName, modifier)
}, },
channelLastTime = remember(note) { note.createdAt() }, channelLastTime = remember(note) { note.createdAt() },
channelLastContent = remember(note) { "$authorName: $description" }, channelLastContent = remember(note) { "$authorName: $description" },
@@ -208,10 +208,10 @@ private fun ChannelRoomCompose(
} }
@Composable @Composable
private fun ChannelTitleWithBoostInfo(channelName: String, modifier: Modifier) { private fun ChannelTitleWithLabelInfo(channelName: String, modifier: Modifier) {
val boosted = stringResource(id = R.string.public_chat) val label = stringResource(id = R.string.public_chat)
val placeHolderColor = MaterialTheme.colors.placeholderText val placeHolderColor = MaterialTheme.colors.placeholderText
val channelNameAndBoostInfo = remember { val channelNameAndBoostInfo = remember(channelName) {
buildAnnotatedString { buildAnnotatedString {
withStyle( withStyle(
SpanStyle( SpanStyle(
@@ -227,7 +227,7 @@ private fun ChannelTitleWithBoostInfo(channelName: String, modifier: Modifier) {
fontWeight = FontWeight.Normal fontWeight = FontWeight.Normal
) )
) { ) {
append(" $boosted") append(" $label")
} }
} }
} }
@@ -17,12 +17,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.service.model.ChatroomKeyable import com.vitorpamplona.amethyst.service.model.ChatroomKeyable
import com.vitorpamplona.amethyst.service.model.GiftWrapEvent
import com.vitorpamplona.amethyst.service.model.SealedGossipEvent
import com.vitorpamplona.amethyst.ui.note.ChatroomHeaderCompose import com.vitorpamplona.amethyst.ui.note.ChatroomHeaderCompose
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
import kotlin.time.measureTimedValue import kotlin.time.measureTimedValue
@@ -88,28 +84,12 @@ private fun FeedLoaded(
LaunchedEffect(key1 = markAsRead.value) { LaunchedEffect(key1 = markAsRead.value) {
if (markAsRead.value) { if (markAsRead.value) {
for (note in state.feed.value) { for (note in state.feed.value) {
var myEvent = if (note.event is GiftWrapEvent) { note.event?.let { noteEvent ->
val unwrapped = accountViewModel.unwrap(note.event as GiftWrapEvent)
if (unwrapped is SealedGossipEvent) {
accountViewModel.unseal(unwrapped)
} else {
unwrapped
}
} else {
note.event
}
myEvent?.let { noteEvent ->
val channelHex = note.channelHex() val channelHex = note.channelHex()
val route = if (channelHex != null) { val route = if (channelHex != null) {
"Channel/$channelHex" "Channel/$channelHex"
} else if (note.event is ChatroomKeyable) { } else if (note.event is ChatroomKeyable) {
val withKey = (note.event as ChatroomKeyable).chatroomKey(accountViewModel.userProfile().pubkeyHex) val withKey = (note.event as ChatroomKeyable).chatroomKey(accountViewModel.userProfile().pubkeyHex)
withContext(Dispatchers.IO) {
accountViewModel.userProfile().createChatroom(withKey)
}
"Room/${withKey.hashCode()}" "Room/${withKey.hashCode()}"
} else { } else {
null null