fix: a bunch of crashes
This commit is contained in:
parent
07fe9869d6
commit
2de7a5aa11
|
|
@ -142,7 +142,7 @@ fun Message(
|
||||||
if (message.content.isBlank()) return@let // if only an attachment is sent
|
if (message.content.isBlank()) return@let // if only an attachment is sent
|
||||||
|
|
||||||
AndroidView(factory = { ctx ->
|
AndroidView(factory = { ctx ->
|
||||||
androidx.appcompat.widget.AppCompatTextView(ctx).apply {
|
android.widget.TextView(ctx).apply {
|
||||||
text = parse(message)
|
text = parse(message)
|
||||||
maxLines = if (truncate) 1 else Int.MAX_VALUE
|
maxLines = if (truncate) 1 else Int.MAX_VALUE
|
||||||
ellipsize = TextUtils.TruncateAt.END
|
ellipsize = TextUtils.TruncateAt.END
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ fun UIMarkdown(
|
||||||
|
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = {
|
factory = {
|
||||||
androidx.appcompat.widget.AppCompatTextView(it).apply {
|
android.widget.TextView(it).apply {
|
||||||
ellipsize = TextUtils.TruncateAt.END
|
ellipsize = TextUtils.TruncateAt.END
|
||||||
typeface = ResourcesCompat.getFont(it, R.font.inter)
|
typeface = ResourcesCompat.getFont(it, R.font.inter)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ import chat.revolt.internals.markdown.createInlineCodeRule
|
||||||
import com.discord.simpleast.core.simple.SimpleMarkdownRules
|
import com.discord.simpleast.core.simple.SimpleMarkdownRules
|
||||||
import com.discord.simpleast.core.simple.SimpleRenderer
|
import com.discord.simpleast.core.simple.SimpleRenderer
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
|
import io.sentry.Sentry
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
|
@ -213,6 +214,11 @@ class ChannelScreenViewModel : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun registerCallbacks() {
|
private fun registerCallbacks() {
|
||||||
|
if (channel?.id == null) {
|
||||||
|
Sentry.captureException(IllegalStateException("Channel ID is null while trying to register callbacks"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
_channelCallback.value = ChannelScreenCallback()
|
_channelCallback.value = ChannelScreenCallback()
|
||||||
RealtimeSocket.registerChannelCallback(channel!!.id!!, channelCallback!!)
|
RealtimeSocket.registerChannelCallback(channel!!.id!!, channelCallback!!)
|
||||||
|
|
||||||
|
|
@ -344,7 +350,7 @@ class ChannelScreenViewModel : ViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun regroupMessages(newMessages: List<MessageSchema> = renderableMessages) {
|
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
|
// 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.
|
// 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
|
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
|
private var debouncedChannelAck: Job? = null
|
||||||
|
|
@ -448,6 +456,12 @@ fun ChannelScreen(
|
||||||
viewModel.fetchChannel(channelId)
|
viewModel.fetchChannel(channelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(viewModel.channel) {
|
||||||
|
if (viewModel.channel?.id != channelId) {
|
||||||
|
viewModel.fetchChannel(channelId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DisposableEffect(channelId) {
|
DisposableEffect(channelId) {
|
||||||
onDispose {
|
onDispose {
|
||||||
RealtimeSocket.unregisterChannelCallback(channelId)
|
RealtimeSocket.unregisterChannelCallback(channelId)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue