Fix Quote from within a thread
This commit is contained in:
parent
6503412928
commit
1b41a72e72
@ -63,7 +63,7 @@ interface SendService {
|
||||
* @param autoMarkdown If true, the SDK will generate a formatted HTML message from the body text if markdown syntax is present
|
||||
* @return a [Cancelable]
|
||||
*/
|
||||
fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean): Cancelable
|
||||
fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean, rootThreadEventId: String? = null): Cancelable
|
||||
|
||||
/**
|
||||
* Method to send a media asynchronously.
|
||||
|
@ -97,8 +97,14 @@ internal class DefaultSendService @AssistedInject constructor(
|
||||
.let { sendEvent(it) }
|
||||
}
|
||||
|
||||
override fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean): Cancelable {
|
||||
return localEchoEventFactory.createQuotedTextEvent(roomId, quotedEvent, text, autoMarkdown)
|
||||
override fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean, rootThreadEventId: String?): Cancelable {
|
||||
return localEchoEventFactory.createQuotedTextEvent(
|
||||
roomId = roomId,
|
||||
quotedEvent = quotedEvent,
|
||||
text = text,
|
||||
autoMarkdown = autoMarkdown,
|
||||
rootThreadEventId = rootThreadEventId
|
||||
)
|
||||
.also { createLocalEcho(it) }
|
||||
.let { sendEvent(it) }
|
||||
}
|
||||
|
@ -476,6 +476,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||
newBodyFormatted
|
||||
)
|
||||
}
|
||||
|
||||
private fun buildReplyFallback(body: TextContent, originalSenderId: String?, newBodyText: String): String {
|
||||
return buildString {
|
||||
append("> <")
|
||||
@ -564,11 +565,25 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||
quotedEvent: TimelineEvent,
|
||||
text: String,
|
||||
autoMarkdown: Boolean,
|
||||
rootThreadEventId: String?
|
||||
): Event {
|
||||
val messageContent = quotedEvent.getLastMessageContent()
|
||||
val textMsg = messageContent?.body
|
||||
val quoteText = legacyRiotQuoteText(textMsg, text)
|
||||
return createFormattedTextEvent(roomId, markdownParser.parse(quoteText, force = true, advanced = autoMarkdown), MessageType.MSGTYPE_TEXT)
|
||||
|
||||
return if (rootThreadEventId != null) {
|
||||
createMessageEvent(
|
||||
roomId,
|
||||
markdownParser
|
||||
.parse(quoteText, force = true, advanced = autoMarkdown)
|
||||
.toThreadTextContent(rootThreadEventId, MessageType.MSGTYPE_TEXT)
|
||||
)
|
||||
} else {
|
||||
createFormattedTextEvent(
|
||||
roomId,
|
||||
markdownParser.parse(quoteText, force = true, advanced = autoMarkdown),
|
||||
MessageType.MSGTYPE_TEXT)
|
||||
}
|
||||
}
|
||||
|
||||
private fun legacyRiotQuoteText(quotedText: String?, myText: String): String {
|
||||
|
@ -446,39 +446,12 @@ class MessageComposerViewModel @AssistedInject constructor(
|
||||
_viewEvents.post(MessageComposerViewEvents.MessageSent)
|
||||
popDraft()
|
||||
}
|
||||
// is SendMode.Quote -> {
|
||||
// val messageContent = state.sendMode.timelineEvent.getLastMessageContent()
|
||||
// val textMsg = messageContent?.body
|
||||
//
|
||||
// val finalText = legacyRiotQuoteText(textMsg, action.text.toString())
|
||||
//
|
||||
// // TODO check for pills?
|
||||
//
|
||||
// // TODO Refactor this, just temporary for quotes
|
||||
// val parser = Parser.builder().build()
|
||||
// val document = parser.parse(finalText)
|
||||
// val renderer = HtmlRenderer.builder().build()
|
||||
// val htmlText = renderer.render(document)
|
||||
//
|
||||
// if (finalText == htmlText) {
|
||||
// state.rootThreadEventId?.let {
|
||||
// room.replyInThread(
|
||||
// rootThreadEventId = it,
|
||||
// replyInThreadText = finalText)
|
||||
// } ?: room.sendTextMessage(finalText)
|
||||
// } else {
|
||||
// state.rootThreadEventId?.let {
|
||||
// room.replyInThread(
|
||||
// rootThreadEventId = it,
|
||||
// replyInThreadText = finalText,
|
||||
// formattedText = htmlText)
|
||||
// } ?: room.sendFormattedTextMessage(finalText, htmlText)
|
||||
// }
|
||||
// _viewEvents.post(MessageComposerViewEvents.MessageSent)
|
||||
// popDraft()
|
||||
// }
|
||||
is SendMode.Quote -> {
|
||||
room.sendQuotedTextMessage(state.sendMode.timelineEvent, action.text.toString(), action.autoMarkdown)
|
||||
room.sendQuotedTextMessage(
|
||||
quotedEvent = state.sendMode.timelineEvent,
|
||||
text = action.text.toString(),
|
||||
autoMarkdown = action.autoMarkdown,
|
||||
rootThreadEventId = state.rootThreadEventId)
|
||||
_viewEvents.post(MessageComposerViewEvents.MessageSent)
|
||||
popDraft()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user