feat: eliminate channel loading screen

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-10-08 01:18:03 +02:00
parent 5de17c5dda
commit b07f36e3f9
2 changed files with 19 additions and 17 deletions

View File

@ -69,6 +69,8 @@ import chat.revolt.activities.RevoltTweenInt
import chat.revolt.api.RevoltAPI import chat.revolt.api.RevoltAPI
import chat.revolt.api.internals.ChannelUtils import chat.revolt.api.internals.ChannelUtils
import chat.revolt.api.routes.microservices.autumn.FileArgs import chat.revolt.api.routes.microservices.autumn.FileArgs
import chat.revolt.api.schemas.Channel
import chat.revolt.api.schemas.ChannelType
import chat.revolt.api.settings.FeatureFlag import chat.revolt.api.settings.FeatureFlag
import chat.revolt.api.settings.FeatureFlags import chat.revolt.api.settings.FeatureFlags
import chat.revolt.api.settings.FilePickerFeatureFlagVariates import chat.revolt.api.settings.FilePickerFeatureFlagVariates
@ -188,6 +190,7 @@ fun ChannelScreen(
} }
LaunchedEffect(channelId) { LaunchedEffect(channelId) {
viewModel.activeChannelId = channelId
viewModel.fetchChannel(channelId) viewModel.fetchChannel(channelId)
coroutineScope.launch { coroutineScope.launch {
@ -236,18 +239,17 @@ fun ChannelScreen(
} }
} }
if (channel?.channelType == null) {
CircularProgressIndicator()
return
}
Column( Column(
modifier = Modifier modifier = Modifier
.imePadding() .imePadding()
.safeDrawingPadding() .safeDrawingPadding()
) { ) {
ChannelHeader( ChannelHeader(
channel = channel, channel = channel ?: Channel(
id = channelId,
name = stringResource(R.string.loading),
channelType = ChannelType.TextChannel
),
onChannelClick = { onChannelClick = {
channelInfoSheetShown = true channelInfoSheetShown = true
}, },
@ -338,7 +340,7 @@ fun ChannelScreen(
ch.value.name ?: ch.value.id ?: "#DeletedChannel" ch.value.name ?: ch.value.id ?: "#DeletedChannel"
}, },
emojiMap = RevoltAPI.emojiCache, emojiMap = RevoltAPI.emojiCache,
serverId = channel.server ?: "", serverId = channel?.server ?: "",
// check if message consists solely of one *or more* custom emotes // check if message consists solely of one *or more* custom emotes
useLargeEmojis = it.content?.matches( useLargeEmojis = it.content?.matches(
Regex("(:([0-9A-Z]{26}):)+") Regex("(:([0-9A-Z]{26}):)+")
@ -352,7 +354,7 @@ fun ChannelScreen(
}, },
onAvatarClick = { onAvatarClick = {
message.author?.let { author -> message.author?.let { author ->
onUserSheetOpenFor(author, channel.server) onUserSheetOpenFor(author, channel?.server)
} }
}, },
canReply = true, canReply = true,
@ -514,11 +516,12 @@ fun ChannelScreen(
viewModel.currentBottomPane = BottomPane.EmojiPicker viewModel.currentBottomPane = BottomPane.EmojiPicker
} }
}, },
channelType = channel.channelType, channelType = channel?.channelType ?: ChannelType.TextChannel,
channelName = channel.name ?: ChannelUtils.resolveDMName(channel) channelName = channel?.name
?: stringResource( ?: channel?.let { ChannelUtils.resolveDMName(it) }
R.string.unknown ?: stringResource(
), R.string.unknown
),
forceSendButton = viewModel.pendingAttachments.isNotEmpty(), forceSendButton = viewModel.pendingAttachments.isNotEmpty(),
disabled = viewModel.pendingAttachments.isNotEmpty() && viewModel.isSendingMessage, disabled = viewModel.pendingAttachments.isNotEmpty() && viewModel.isSendingMessage,
editMode = viewModel.editingMessage != null, editMode = viewModel.editingMessage != null,

View File

@ -65,6 +65,7 @@ sealed class BottomPane {
class ChannelScreenViewModel : ViewModel() { class ChannelScreenViewModel : ViewModel() {
var activeChannel by mutableStateOf<Channel?>(null) var activeChannel by mutableStateOf<Channel?>(null)
var activeChannelId by mutableStateOf<String?>(null)
var renderableMessages = mutableStateListOf<Message>() var renderableMessages = mutableStateListOf<Message>()
var typingUsers = mutableStateListOf<String>() var typingUsers = mutableStateListOf<String>()
@ -116,15 +117,13 @@ class ChannelScreenViewModel : ViewModel() {
} }
fun fetchOlderMessages() { fun fetchOlderMessages() {
if (activeChannel == null) { if (activeChannelId == null) return
return
}
viewModelScope.launch { viewModelScope.launch {
val messages = arrayListOf<Message>() val messages = arrayListOf<Message>()
fetchMessagesFromChannel( fetchMessagesFromChannel(
activeChannel!!.id!!, activeChannelId!!,
limit = 50, limit = 50,
includeUsers = true, includeUsers = true,
before = if (renderableMessages.isNotEmpty()) { before = if (renderableMessages.isNotEmpty()) {