fix: a bunch of crashes

This commit is contained in:
Infi 2023-03-14 00:56:48 +01:00
parent 07fe9869d6
commit 2de7a5aa11
3 changed files with 19 additions and 5 deletions

View File

@ -142,7 +142,7 @@ fun Message(
if (message.content.isBlank()) return@let // if only an attachment is sent
AndroidView(factory = { ctx ->
androidx.appcompat.widget.AppCompatTextView(ctx).apply {
android.widget.TextView(ctx).apply {
text = parse(message)
maxLines = if (truncate) 1 else Int.MAX_VALUE
ellipsize = TextUtils.TruncateAt.END

View File

@ -89,7 +89,7 @@ fun UIMarkdown(
AndroidView(
factory = {
androidx.appcompat.widget.AppCompatTextView(it).apply {
android.widget.TextView(it).apply {
ellipsize = TextUtils.TruncateAt.END
typeface = ResourcesCompat.getFont(it, R.font.inter)

View File

@ -67,6 +67,7 @@ import chat.revolt.internals.markdown.createInlineCodeRule
import com.discord.simpleast.core.simple.SimpleMarkdownRules
import com.discord.simpleast.core.simple.SimpleRenderer
import io.ktor.http.*
import io.sentry.Sentry
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.distinctUntilChanged
@ -213,6 +214,11 @@ class ChannelScreenViewModel : ViewModel() {
}
private fun registerCallbacks() {
if (channel?.id == null) {
Sentry.captureException(IllegalStateException("Channel ID is null while trying to register callbacks"))
return
}
_channelCallback.value = ChannelScreenCallback()
RealtimeSocket.registerChannelCallback(channel!!.id!!, channelCallback!!)
@ -344,7 +350,7 @@ class ChannelScreenViewModel : ViewModel() {
}
private fun regroupMessages(newMessages: List<MessageSchema> = renderableMessages) {
val groupedMessages = arrayListOf<MessageSchema>()
val groupedMessages = mutableMapOf<String, MessageSchema>()
// Verbatim implementation of https://wiki.rvlt.gg/index.php/Text_Channel_(UI)#Message_Grouping_Algorithm
// The exception is the date variable being pushed into cache, we don't need that here.
@ -372,10 +378,12 @@ class ChannelScreenViewModel : ViewModel() {
tail = false
}
groupedMessages.add(message.copy(tail = tail))
if (groupedMessages.containsKey(message.id!!)) return@forEach
groupedMessages[message.id] = message.copy(tail = tail)
}
setRenderableMessages(groupedMessages)
setRenderableMessages(groupedMessages.values.toList())
}
private var debouncedChannelAck: Job? = null
@ -448,6 +456,12 @@ fun ChannelScreen(
viewModel.fetchChannel(channelId)
}
LaunchedEffect(viewModel.channel) {
if (viewModel.channel?.id != channelId) {
viewModel.fetchChannel(channelId)
}
}
DisposableEffect(channelId) {
onDispose {
RealtimeSocket.unregisterChannelCallback(channelId)