Fix Quote from within a thread

This commit is contained in:
ariskotsomitopoulos 2022-01-10 14:14:11 +02:00
parent 6503412928
commit 1b41a72e72
4 changed files with 37 additions and 43 deletions

View File

@ -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 * @param autoMarkdown If true, the SDK will generate a formatted HTML message from the body text if markdown syntax is present
* @return a [Cancelable] * @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. * Method to send a media asynchronously.

View File

@ -97,8 +97,14 @@ internal class DefaultSendService @AssistedInject constructor(
.let { sendEvent(it) } .let { sendEvent(it) }
} }
override fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean): Cancelable { override fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean, rootThreadEventId: String?): Cancelable {
return localEchoEventFactory.createQuotedTextEvent(roomId, quotedEvent, text, autoMarkdown) return localEchoEventFactory.createQuotedTextEvent(
roomId = roomId,
quotedEvent = quotedEvent,
text = text,
autoMarkdown = autoMarkdown,
rootThreadEventId = rootThreadEventId
)
.also { createLocalEcho(it) } .also { createLocalEcho(it) }
.let { sendEvent(it) } .let { sendEvent(it) }
} }

View File

@ -476,6 +476,7 @@ internal class LocalEchoEventFactory @Inject constructor(
newBodyFormatted newBodyFormatted
) )
} }
private fun buildReplyFallback(body: TextContent, originalSenderId: String?, newBodyText: String): String { private fun buildReplyFallback(body: TextContent, originalSenderId: String?, newBodyText: String): String {
return buildString { return buildString {
append("> <") append("> <")
@ -564,11 +565,25 @@ internal class LocalEchoEventFactory @Inject constructor(
quotedEvent: TimelineEvent, quotedEvent: TimelineEvent,
text: String, text: String,
autoMarkdown: Boolean, autoMarkdown: Boolean,
rootThreadEventId: String?
): Event { ): Event {
val messageContent = quotedEvent.getLastMessageContent() val messageContent = quotedEvent.getLastMessageContent()
val textMsg = messageContent?.body val textMsg = messageContent?.body
val quoteText = legacyRiotQuoteText(textMsg, text) 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 { private fun legacyRiotQuoteText(quotedText: String?, myText: String): String {

View File

@ -242,7 +242,7 @@ class MessageComposerViewModel @AssistedInject constructor(
handleJoinToAnotherRoomSlashCommand(slashCommandResult) handleJoinToAnotherRoomSlashCommand(slashCommandResult)
popDraft() popDraft()
} }
is ParsedCommand.PartRoom -> { is ParsedCommand.PartRoom -> {
handlePartSlashCommand(slashCommandResult) handlePartSlashCommand(slashCommandResult)
} }
is ParsedCommand.SendEmote -> { is ParsedCommand.SendEmote -> {
@ -325,7 +325,7 @@ class MessageComposerViewModel @AssistedInject constructor(
is ParsedCommand.ChangeAvatarForRoom -> { is ParsedCommand.ChangeAvatarForRoom -> {
handleChangeAvatarForRoomSlashCommand(slashCommandResult) handleChangeAvatarForRoomSlashCommand(slashCommandResult)
} }
is ParsedCommand.ShowUser -> { is ParsedCommand.ShowUser -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk()) _viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
handleWhoisSlashCommand(slashCommandResult) handleWhoisSlashCommand(slashCommandResult)
popDraft() popDraft()
@ -343,7 +343,7 @@ class MessageComposerViewModel @AssistedInject constructor(
) )
} }
} }
is ParsedCommand.CreateSpace -> { is ParsedCommand.CreateSpace -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading) _viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
@ -367,7 +367,7 @@ class MessageComposerViewModel @AssistedInject constructor(
} }
Unit Unit
} }
is ParsedCommand.AddToSpace -> { is ParsedCommand.AddToSpace -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading) _viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
@ -386,7 +386,7 @@ class MessageComposerViewModel @AssistedInject constructor(
} }
Unit Unit
} }
is ParsedCommand.JoinSpace -> { is ParsedCommand.JoinSpace -> {
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading) _viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
@ -399,7 +399,7 @@ class MessageComposerViewModel @AssistedInject constructor(
} }
Unit Unit
} }
is ParsedCommand.LeaveRoom -> { is ParsedCommand.LeaveRoom -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
try { try {
session.getRoom(slashCommandResult.roomId)?.leave(null) session.getRoom(slashCommandResult.roomId)?.leave(null)
@ -411,7 +411,7 @@ class MessageComposerViewModel @AssistedInject constructor(
} }
Unit Unit
} }
is ParsedCommand.UpgradeRoom -> { is ParsedCommand.UpgradeRoom -> {
_viewEvents.post( _viewEvents.post(
MessageComposerViewEvents.ShowRoomUpgradeDialog( MessageComposerViewEvents.ShowRoomUpgradeDialog(
slashCommandResult.newVersion, slashCommandResult.newVersion,
@ -446,39 +446,12 @@ class MessageComposerViewModel @AssistedInject constructor(
_viewEvents.post(MessageComposerViewEvents.MessageSent) _viewEvents.post(MessageComposerViewEvents.MessageSent)
popDraft() 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 -> { 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) _viewEvents.post(MessageComposerViewEvents.MessageSent)
popDraft() popDraft()
} }