parent
add6f6d557
commit
75c7ec95a4
|
|
@ -223,7 +223,7 @@ fun ChannelScreen(
|
|||
.collect {
|
||||
if (it) {
|
||||
coroutineScope.launch {
|
||||
if (viewModel.noMoreMessages) return@launch
|
||||
if (viewModel.hasNoMoreMessages) return@launch
|
||||
viewModel.fetchOlderMessages()
|
||||
}
|
||||
}
|
||||
|
|
@ -284,7 +284,7 @@ fun ChannelScreen(
|
|||
},
|
||||
canReply = true,
|
||||
onReply = {
|
||||
if (viewModel.replies.size >= 5) {
|
||||
if (viewModel.pendingReplies.size >= 5) {
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.too_many_replies, 5),
|
||||
|
|
@ -298,7 +298,7 @@ fun ChannelScreen(
|
|||
}
|
||||
|
||||
item {
|
||||
if (viewModel.noMoreMessages) {
|
||||
if (viewModel.hasNoMoreMessages) {
|
||||
Text(
|
||||
text = stringResource(R.string.start_of_conversation),
|
||||
modifier = Modifier
|
||||
|
|
@ -373,10 +373,10 @@ fun ChannelScreen(
|
|||
)
|
||||
.clip(MaterialTheme.shapes.medium)
|
||||
) {
|
||||
AnimatedVisibility(visible = viewModel.replies.isNotEmpty()) {
|
||||
AnimatedVisibility(visible = viewModel.pendingReplies.isNotEmpty()) {
|
||||
ReplyManager(
|
||||
replies = viewModel.replies,
|
||||
onRemove = { viewModel.replies.remove(it) },
|
||||
replies = viewModel.pendingReplies,
|
||||
onRemove = { viewModel.pendingReplies.remove(it) },
|
||||
onToggleMention = viewModel::toggleReplyMentionFor
|
||||
)
|
||||
}
|
||||
|
|
@ -384,15 +384,15 @@ fun ChannelScreen(
|
|||
AnimatedVisibility(visible = viewModel.pendingAttachments.isNotEmpty()) {
|
||||
AttachmentManager(
|
||||
attachments = viewModel.pendingAttachments,
|
||||
uploading = viewModel.sendingMessage,
|
||||
uploading = viewModel.isSendingMessage,
|
||||
onRemove = { viewModel.pendingAttachments.remove(it) }
|
||||
)
|
||||
}
|
||||
|
||||
MessageField(
|
||||
messageContent = viewModel.messageContent,
|
||||
messageContent = viewModel.pendingMessageContent,
|
||||
onMessageContentChange = {
|
||||
viewModel.messageContent = it
|
||||
viewModel.pendingMessageContent = it
|
||||
},
|
||||
onSendMessage = viewModel::sendPendingMessage,
|
||||
onAddAttachment = {
|
||||
|
|
@ -403,7 +403,7 @@ fun ChannelScreen(
|
|||
R.string.unknown
|
||||
),
|
||||
forceSendButton = viewModel.pendingAttachments.isNotEmpty(),
|
||||
disabled = viewModel.pendingAttachments.isNotEmpty() && viewModel.sendingMessage
|
||||
disabled = viewModel.pendingAttachments.isNotEmpty() && viewModel.isSendingMessage
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,16 +46,13 @@ class ChannelScreenViewModel : ViewModel() {
|
|||
var activeChannel by mutableStateOf<Channel?>(null)
|
||||
|
||||
var renderableMessages = mutableStateListOf<Message>()
|
||||
|
||||
private fun setRenderableMessages(messages: List<Message>) {
|
||||
renderableMessages.clear()
|
||||
renderableMessages.addAll(messages)
|
||||
}
|
||||
|
||||
var typingUsers = mutableStateListOf<String>()
|
||||
|
||||
var messageContent by mutableStateOf("")
|
||||
var isSendingMessage by mutableStateOf(false)
|
||||
var hasNoMoreMessages by mutableStateOf(false)
|
||||
|
||||
var pendingMessageContent by mutableStateOf("")
|
||||
var pendingReplies = mutableStateListOf<SendMessageReply>()
|
||||
var pendingAttachments = mutableStateListOf<FileArgs>()
|
||||
|
||||
private fun popAttachmentBatch() {
|
||||
|
|
@ -63,31 +60,30 @@ class ChannelScreenViewModel : ViewModel() {
|
|||
pendingAttachments.drop(MAX_ATTACHMENTS_PER_MESSAGE) as SnapshotStateList<FileArgs>
|
||||
}
|
||||
|
||||
var sendingMessage by mutableStateOf(false)
|
||||
|
||||
var replies = mutableStateListOf<SendMessageReply>()
|
||||
private fun setRenderableMessages(messages: List<Message>) {
|
||||
renderableMessages.clear()
|
||||
renderableMessages.addAll(messages)
|
||||
}
|
||||
|
||||
private fun addReply(reply: SendMessageReply) {
|
||||
if (replies.any { it.id == reply.id }) return
|
||||
replies.add(reply)
|
||||
if (pendingReplies.any { it.id == reply.id }) return
|
||||
pendingReplies.add(reply)
|
||||
}
|
||||
|
||||
fun toggleReplyMentionFor(reply: SendMessageReply) {
|
||||
val index = replies.indexOf(reply)
|
||||
val index = pendingReplies.indexOf(reply)
|
||||
val newReply = SendMessageReply(
|
||||
reply.id,
|
||||
!reply.mention
|
||||
)
|
||||
|
||||
replies[index] = newReply
|
||||
pendingReplies[index] = newReply
|
||||
}
|
||||
|
||||
private fun clearInReplyTo() {
|
||||
replies.clear()
|
||||
pendingReplies.clear()
|
||||
}
|
||||
|
||||
var noMoreMessages by mutableStateOf(false)
|
||||
|
||||
fun fetchOlderMessages() {
|
||||
if (activeChannel == null) {
|
||||
return
|
||||
|
|
@ -107,7 +103,7 @@ class ChannelScreenViewModel : ViewModel() {
|
|||
}
|
||||
).let {
|
||||
if (it.messages.isNullOrEmpty() || it.messages.size < 50) {
|
||||
noMoreMessages = true
|
||||
hasNoMoreMessages = true
|
||||
}
|
||||
|
||||
it.messages?.forEach { message ->
|
||||
|
|
@ -142,7 +138,7 @@ class ChannelScreenViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
fun sendPendingMessage() {
|
||||
sendingMessage = true
|
||||
isSendingMessage = true
|
||||
|
||||
viewModelScope.launch {
|
||||
val attachmentIds = arrayListOf<String>()
|
||||
|
|
@ -165,13 +161,13 @@ class ChannelScreenViewModel : ViewModel() {
|
|||
|
||||
sendMessage(
|
||||
activeChannel!!.id!!,
|
||||
messageContent.trimIndent(),
|
||||
pendingMessageContent.trimIndent(),
|
||||
attachments = if (attachmentIds.isEmpty()) null else attachmentIds,
|
||||
replies = replies
|
||||
replies = pendingReplies
|
||||
)
|
||||
|
||||
messageContent = ""
|
||||
noMoreMessages = false
|
||||
pendingMessageContent = ""
|
||||
hasNoMoreMessages = false
|
||||
popAttachmentBatch()
|
||||
clearInReplyTo()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue