This commit is contained in:
Gabriel 2026-06-16 21:03:23 +01:00 committed by GitHub
commit af0b2b563a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 16 deletions

View File

@ -75,6 +75,10 @@ import java.time.ZoneId
class ChannelScreenViewModel(
private val kvStorage: KVStorage,
) : ViewModel() {
private companion object {
const val MAX_REPLY_TARGETS = 5
}
var items = mutableStateListOf<ChannelScreenItem>()
var typingUsers = mutableStateListOf<String>()
@ -353,7 +357,7 @@ class ChannelScreenViewModel(
}
suspend fun addReplyTo(messageId: String) {
if (draftReplyTo.size >= 5) return
if (draftReplyTo.size >= MAX_REPLY_TARGETS) return
if (draftReplyTo.any { it.id == messageId }) return
val shouldMention = kvStorage.getBoolean("mentionOnReply") ?: false
@ -412,7 +416,7 @@ class ChannelScreenViewModel(
// 2. if the user changes the content while the message is being sent we want to persist
// the original content
val content = MessageProcessor.processOutgoing(draftContent, channel?.server)
val replyTo = draftReplyTo.toList()
val replyTo = draftReplyTo.distinctBy { it.id }.take(MAX_REPLY_TARGETS)
// First we upload (the next 5) attachments...
viewModelScope.launch {
@ -818,13 +822,7 @@ class ChannelScreenViewModel(
m is ChannelScreenItem.RegularMessage && m.message.id == it.messageId
} as? ChannelScreenItem.RegularMessage ?: return@onEach
val shouldMention = kvStorage.getBoolean("mentionOnReply") ?: false
draftReplyTo.add(
SendMessageReply(
message.message.id ?: return@onEach,
shouldMention
)
)
addReplyTo(message.message.id ?: return@onEach)
}
is UiCallback.EditMessage -> {
@ -843,13 +841,7 @@ class ChannelScreenViewModel(
m is ChannelScreenItem.RegularMessage && m.message.id == it.messageId
} as? ChannelScreenItem.RegularMessage ?: return@onEach
val shouldMention = kvStorage.getBoolean("mentionOnReply") ?: false
draftReplyTo.add(
SendMessageReply(
message.message.id ?: return@onEach,
shouldMention
)
)
addReplyTo(message.message.id ?: return@onEach)
putDraftContent(it.content, true)
}
}