support for articles; ui & ux & logic fixes for 2fa and captcha screens; fix mentions;

This commit is contained in:
2024-07-13 01:37:24 +03:00
parent 25acc6505b
commit ce1867c22c
38 changed files with 449 additions and 218 deletions
@@ -222,7 +222,7 @@ class ConversationsViewModelImpl(
private fun loadConversations(
offset: Int = currentOffset.value
) {
conversationsUseCase.getConversations(count = 30, offset = offset).listenValue { state ->
conversationsUseCase.getConversations(count = LOAD_COUNT, offset = offset).listenValue { state ->
state.processState(
error = { error ->
when (error) {
@@ -247,7 +247,7 @@ class ConversationsViewModelImpl(
}
},
success = { response ->
val itemsCountSufficient = response.size == 30
val itemsCountSufficient = response.size == LOAD_COUNT
canPaginate.setValue { itemsCountSufficient }
val paginationExhausted = !itemsCountSufficient &&
@@ -621,5 +621,9 @@ class ConversationsViewModelImpl(
old.copy(conversations = uiConversations)
}
}
companion object {
const val LOAD_COUNT = 30
}
}
@@ -47,6 +47,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@@ -299,7 +300,35 @@ fun ConversationItem(
LocalContentAlpha(alpha = ContentAlpha.medium) {
Text(
modifier = Modifier.weight(1f),
text = conversation.message,
text = kotlin.run {
val builder =
AnnotatedString.Builder(conversation.message.text)
conversation.message.spanStyles.map { spanStyleRange ->
val updatedSpanStyle =
if (spanStyleRange.item.color == Color.Red) {
spanStyleRange.item.copy(color = MaterialTheme.colorScheme.primary)
} else {
spanStyleRange.item
}
builder.addStyle(
style = updatedSpanStyle,
start = spanStyleRange.start,
end = spanStyleRange.end
)
}
conversation.message.paragraphStyles.forEach { style ->
builder.addStyle(
style = style.item,
start = style.start,
end = style.end
)
}
builder.toAnnotatedString()
},
minLines = 1,
maxLines = maxLines,
style = MaterialTheme.typography.bodyLarge,
@@ -611,6 +611,7 @@ private fun getAttachmentIconByType(attachmentType: AttachmentType): UiImage? {
AttachmentType.AUDIO_PLAYLIST -> null
AttachmentType.PODCAST -> null
AttachmentType.NARRATIVE -> null
AttachmentType.ARTICLE -> null
}?.let(UiImage::Resource)
}
@@ -660,18 +661,14 @@ private fun getTextWithVisualizedMentions(
var currentIndex = 0
val replacements = mutableListOf<Pair<IntRange, String>>()
// TODO: 25/04/2024, Danil Nikolaev: check why not working ([id279494346|@iworld2rist] да убери ты Елену Шлипс от меня)
val result = regex.replace(originalText) { matchResult ->
val idPrefix = matchResult.groups[1]?.value.orEmpty()
val startIndex = matchResult.range.first
val endIndex = matchResult.range.last
val id = matchResult.groups[2]?.value ?: ""
val text = matchResult.groups[3]?.value ?: ""
val replaced =
text.substring(startIndex, endIndex + 1)
.replace("[$idPrefix$id|$text]", text)
val replaced = matchResult.groups[3]?.value.orEmpty()
val indexRange =
(startIndex + currentIndex)..startIndex + currentIndex + replaced.length
@@ -757,6 +754,7 @@ private fun getAttachmentUiText(
AttachmentType.AUDIO_PLAYLIST -> UiR.string.message_attachments_audio_playlist
AttachmentType.PODCAST -> UiR.string.message_attachments_podcast
AttachmentType.NARRATIVE -> UiR.string.message_attachments_narrative
AttachmentType.ARTICLE -> UiR.string.message_attachments_article
}.let(UiText::Resource)
}