mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Fix Quote from within a thread
This commit is contained in:
parent
6503412928
commit
1b41a72e72
4 changed files with 37 additions and 43 deletions
|
@ -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 {
|
||||
|
|
|
@ -242,7 +242,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
handleJoinToAnotherRoomSlashCommand(slashCommandResult)
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.PartRoom -> {
|
||||
is ParsedCommand.PartRoom -> {
|
||||
handlePartSlashCommand(slashCommandResult)
|
||||
}
|
||||
is ParsedCommand.SendEmote -> {
|
||||
|
@ -325,7 +325,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
is ParsedCommand.ChangeAvatarForRoom -> {
|
||||
handleChangeAvatarForRoomSlashCommand(slashCommandResult)
|
||||
}
|
||||
is ParsedCommand.ShowUser -> {
|
||||
is ParsedCommand.ShowUser -> {
|
||||
_viewEvents.post(MessageComposerViewEvents.SlashCommandResultOk())
|
||||
handleWhoisSlashCommand(slashCommandResult)
|
||||
popDraft()
|
||||
|
@ -343,7 +343,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
}
|
||||
is ParsedCommand.CreateSpace -> {
|
||||
is ParsedCommand.CreateSpace -> {
|
||||
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
|
@ -367,7 +367,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
}
|
||||
Unit
|
||||
}
|
||||
is ParsedCommand.AddToSpace -> {
|
||||
is ParsedCommand.AddToSpace -> {
|
||||
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
|
@ -386,7 +386,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
}
|
||||
Unit
|
||||
}
|
||||
is ParsedCommand.JoinSpace -> {
|
||||
is ParsedCommand.JoinSpace -> {
|
||||
_viewEvents.post(MessageComposerViewEvents.SlashCommandLoading)
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
|
@ -399,7 +399,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
}
|
||||
Unit
|
||||
}
|
||||
is ParsedCommand.LeaveRoom -> {
|
||||
is ParsedCommand.LeaveRoom -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
session.getRoom(slashCommandResult.roomId)?.leave(null)
|
||||
|
@ -411,7 +411,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
}
|
||||
Unit
|
||||
}
|
||||
is ParsedCommand.UpgradeRoom -> {
|
||||
is ParsedCommand.UpgradeRoom -> {
|
||||
_viewEvents.post(
|
||||
MessageComposerViewEvents.ShowRoomUpgradeDialog(
|
||||
slashCommandResult.newVersion,
|
||||
|
@ -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…
Reference in a new issue