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

View File

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