Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reply markdown [WPB-3558] #2904

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -62,7 +63,12 @@ import com.wire.android.ui.common.typography
import com.wire.android.ui.home.conversations.messages.QuotedMessageStyle.COMPLETE
import com.wire.android.ui.home.conversations.messages.QuotedMessageStyle.PREVIEW
import com.wire.android.ui.home.conversations.model.UIQuotedMessage
import com.wire.android.ui.markdown.MarkdownInline
import com.wire.android.ui.markdown.NodeData
import com.wire.android.ui.markdown.getFirstInlines
import com.wire.android.ui.markdown.toMarkdownDocument
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.ui.UIText

private const val TEXT_QUOTE_MAX_LINES = 7
Expand Down Expand Up @@ -338,14 +344,16 @@ private fun QuotedText(
modifier = modifier,
startContent = {
startContent()
}, centerContent = {
},
centerContent = {
editedTimeDescription?.let {
if (style == COMPLETE) {
StatusBox(it.asString())
}
}
MainContentText(text)
}, footerContent = {
MainMarkdownText(text)
},
footerContent = {
QuotedMessageOriginalDate(originalDateTimeDescription)
},
clickable = clickable
Expand Down Expand Up @@ -515,6 +523,33 @@ fun QuotedAudioMessage(
)
}

@Composable
private fun MainMarkdownText(text: String, fontStyle: FontStyle = FontStyle.Normal) {
val nodeData = NodeData(
color = colorsScheme().onSurfaceVariant,
style = MaterialTheme.wireTypography.subline01.copy(fontStyle = fontStyle),
colorScheme = MaterialTheme.wireColorScheme,
typography = MaterialTheme.wireTypography,
searchQuery = "",
mentions = listOf(),
disableLinks = true,
)

val markdownPreview = remember(text) {
text.toMarkdownDocument().getFirstInlines()
}

if (markdownPreview != null) {
MarkdownInline(
inlines = markdownPreview.children,
maxLines = TEXT_QUOTE_MAX_LINES,
nodeData = nodeData
)
} else {
MainContentText(text, fontStyle)
}
}

@Composable
private fun MainContentText(text: String, fontStyle: FontStyle = FontStyle.Normal) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ internal fun MessageBody(
)
)

text?.also {
val markdownDocument = remember(text) {
text?.toMarkdownDocument()
}

markdownDocument?.also {
MarkdownDocument(
it.toMarkdownDocument(),
it,
nodeData,
clickable
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.wire.android.ui.home.conversationslist.common
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.text.style.TextOverflow
import com.wire.android.ui.markdown.MarkdownConstants
import com.wire.android.ui.markdown.MarkdownInline
Expand Down Expand Up @@ -59,8 +60,13 @@ private fun LastMessageMarkdown(text: String, leadingText: String = "") {
disableLinks = true
)

val markdownPreview = text.toMarkdownDocument().getFirstInlines()
val leadingInlines = leadingText.toMarkdownDocument().getFirstInlines()?.children ?: persistentListOf()
val markdownPreview = remember(text) {
text.toMarkdownDocument().getFirstInlines()
}

val leadingInlines = remember(leadingText) {
leadingText.toMarkdownDocument().getFirstInlines()?.children ?: persistentListOf()
}

if (markdownPreview != null) {
MarkdownInline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.text.style.TextOverflow
@Composable
fun MarkdownInline(
inlines: List<MarkdownNode.Inline>,
maxLines: Int = 1,
nodeData: NodeData
) {
val annotatedString = buildAnnotatedString {
Expand All @@ -36,7 +37,7 @@ fun MarkdownInline(
style = nodeData.style,
color = nodeData.color,
clickable = false,
maxLines = 1,
maxLines = maxLines,
overflow = TextOverflow.Ellipsis
)
}
Loading