full markdown should work in replies, was hardcoded to simple irrespective of prefrence.
This commit is contained in:
parent
bc6ca2449e
commit
e7bb030d52
|
@ -104,9 +104,11 @@ interface RelationService {
|
||||||
* by the sdk into pills.
|
* by the sdk into pills.
|
||||||
* @param eventReplied the event referenced by the reply
|
* @param eventReplied the event referenced by the reply
|
||||||
* @param replyText the reply text
|
* @param replyText the reply text
|
||||||
|
* @param autoMarkdown If true, the SDK will generate a formatted HTML message from the body text if markdown syntax is present
|
||||||
*/
|
*/
|
||||||
fun replyToMessage(eventReplied: TimelineEvent,
|
fun replyToMessage(eventReplied: TimelineEvent,
|
||||||
replyText: CharSequence): Cancelable?
|
replyText: CharSequence,
|
||||||
|
autoMarkdown: Boolean = false): Cancelable?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current EventAnnotationsSummary
|
* Get the current EventAnnotationsSummary
|
||||||
|
|
|
@ -60,9 +60,10 @@ interface SendService {
|
||||||
* Method to quote an events content.
|
* Method to quote an events content.
|
||||||
* @param quotedEvent The event to which we will quote it's content.
|
* @param quotedEvent The event to which we will quote it's content.
|
||||||
* @param text the text message to send
|
* @param text the text message to send
|
||||||
|
* @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): Cancelable
|
fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean): Cancelable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to send a media asynchronously.
|
* Method to send a media asynchronously.
|
||||||
|
|
|
@ -131,8 +131,8 @@ internal class DefaultRelationService @AssistedInject constructor(
|
||||||
return fetchEditHistoryTask.execute(FetchEditHistoryTask.Params(roomId, eventId))
|
return fetchEditHistoryTask.execute(FetchEditHistoryTask.Params(roomId, eventId))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replyToMessage(eventReplied: TimelineEvent, replyText: CharSequence): Cancelable? {
|
override fun replyToMessage(eventReplied: TimelineEvent, replyText: CharSequence, autoMarkdown: Boolean): Cancelable? {
|
||||||
val event = eventFactory.createReplyTextEvent(roomId, eventReplied, replyText)
|
val event = eventFactory.createReplyTextEvent(roomId, eventReplied, replyText, autoMarkdown)
|
||||||
?.also { saveLocalEcho(it) }
|
?.also { saveLocalEcho(it) }
|
||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ internal class EventEditor @Inject constructor(private val eventSenderProcessor:
|
||||||
val roomId = replyToEdit.roomId
|
val roomId = replyToEdit.roomId
|
||||||
if (replyToEdit.root.sendState.hasFailed()) {
|
if (replyToEdit.root.sendState.hasFailed()) {
|
||||||
// We create a new in memory event for the EventSenderProcessor but we keep the eventId of the failed event.
|
// We create a new in memory event for the EventSenderProcessor but we keep the eventId of the failed event.
|
||||||
val editedEvent = eventFactory.createReplyTextEvent(roomId, originalTimelineEvent, newBodyText)?.copy(
|
val editedEvent = eventFactory.createReplyTextEvent(roomId, originalTimelineEvent, newBodyText, false)?.copy(
|
||||||
eventId = replyToEdit.eventId
|
eventId = replyToEdit.eventId
|
||||||
) ?: return NoOpCancellable
|
) ?: return NoOpCancellable
|
||||||
updateFailedEchoWithEvent(roomId, replyToEdit.eventId, editedEvent)
|
updateFailedEchoWithEvent(roomId, replyToEdit.eventId, editedEvent)
|
||||||
|
@ -78,6 +78,7 @@ internal class EventEditor @Inject constructor(private val eventSenderProcessor:
|
||||||
replyToEdit,
|
replyToEdit,
|
||||||
originalTimelineEvent,
|
originalTimelineEvent,
|
||||||
newBodyText,
|
newBodyText,
|
||||||
|
true,
|
||||||
MessageType.MSGTYPE_TEXT,
|
MessageType.MSGTYPE_TEXT,
|
||||||
compatibilityBodyText
|
compatibilityBodyText
|
||||||
)
|
)
|
||||||
|
|
|
@ -97,8 +97,8 @@ internal class DefaultSendService @AssistedInject constructor(
|
||||||
.let { sendEvent(it) }
|
.let { sendEvent(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String): Cancelable {
|
override fun sendQuotedTextMessage(quotedEvent: TimelineEvent, text: String, autoMarkdown: Boolean): Cancelable {
|
||||||
return localEchoEventFactory.createQuotedTextEvent(roomId, quotedEvent, text)
|
return localEchoEventFactory.createQuotedTextEvent(roomId, quotedEvent, text, autoMarkdown)
|
||||||
.also { createLocalEcho(it) }
|
.also { createLocalEcho(it) }
|
||||||
.let { sendEvent(it) }
|
.let { sendEvent(it) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
eventReplaced: TimelineEvent,
|
eventReplaced: TimelineEvent,
|
||||||
originalEvent: TimelineEvent,
|
originalEvent: TimelineEvent,
|
||||||
newBodyText: String,
|
newBodyText: String,
|
||||||
|
autoMarkdown: Boolean,
|
||||||
msgType: String,
|
msgType: String,
|
||||||
compatibilityText: String): Event {
|
compatibilityText: String): Event {
|
||||||
val permalink = permalinkFactory.createPermalink(roomId, originalEvent.root.eventId ?: "", false)
|
val permalink = permalinkFactory.createPermalink(roomId, originalEvent.root.eventId ?: "", false)
|
||||||
|
@ -205,9 +206,9 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
|
|
||||||
val body = bodyForReply(originalEvent.getLastMessageContent(), originalEvent.isReply())
|
val body = bodyForReply(originalEvent.getLastMessageContent(), originalEvent.isReply())
|
||||||
// As we always supply formatted body for replies we should force the MarkdownParser to produce html.
|
// As we always supply formatted body for replies we should force the MarkdownParser to produce html.
|
||||||
val newBodyFormatted = markdownParser.parse(newBodyText, force = true, advanced = false).takeFormatted()
|
val newBodyFormatted = markdownParser.parse(newBodyText, force = true, advanced = autoMarkdown).takeFormatted()
|
||||||
// Body of the original message may not have formatted version, so may also have to convert to html.
|
// Body of the original message may not have formatted version, so may also have to convert to html.
|
||||||
val bodyFormatted = body.formattedText ?: markdownParser.parse(newBodyText, force = true, advanced = false).takeFormatted()
|
val bodyFormatted = body.formattedText ?: markdownParser.parse(body.text, force = true, advanced = autoMarkdown).takeFormatted()
|
||||||
val replyFormatted = buildFormattedReply(
|
val replyFormatted = buildFormattedReply(
|
||||||
permalink,
|
permalink,
|
||||||
userLink,
|
userLink,
|
||||||
|
@ -384,7 +385,8 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
|
|
||||||
fun createReplyTextEvent(roomId: String,
|
fun createReplyTextEvent(roomId: String,
|
||||||
eventReplied: TimelineEvent,
|
eventReplied: TimelineEvent,
|
||||||
replyText: CharSequence): Event? {
|
replyText: CharSequence,
|
||||||
|
autoMarkdown: Boolean): Event? {
|
||||||
// Fallbacks and event representation
|
// Fallbacks and event representation
|
||||||
// TODO Add error/warning logs when any of this is null
|
// TODO Add error/warning logs when any of this is null
|
||||||
val permalink = permalinkFactory.createPermalink(eventReplied.root, false) ?: return null
|
val permalink = permalinkFactory.createPermalink(eventReplied.root, false) ?: return null
|
||||||
|
@ -394,9 +396,9 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
val body = bodyForReply(eventReplied.getLastMessageContent(), eventReplied.isReply())
|
val body = bodyForReply(eventReplied.getLastMessageContent(), eventReplied.isReply())
|
||||||
|
|
||||||
// As we always supply formatted body for replies we should force the MarkdownParser to produce html.
|
// As we always supply formatted body for replies we should force the MarkdownParser to produce html.
|
||||||
val replyTextFormatted = markdownParser.parse(replyText, force = true, advanced = false).takeFormatted()
|
val replyTextFormatted = markdownParser.parse(replyText, force = true, advanced = autoMarkdown).takeFormatted()
|
||||||
// Body of the original message may not have formatted version, so may also have to convert to html.
|
// Body of the original message may not have formatted version, so may also have to convert to html.
|
||||||
val bodyFormatted = body.formattedText ?: markdownParser.parse(replyText, force = true, advanced = false).takeFormatted()
|
val bodyFormatted = body.formattedText ?: markdownParser.parse(body.text, force = true, advanced = autoMarkdown).takeFormatted()
|
||||||
val replyFormatted = buildFormattedReply(
|
val replyFormatted = buildFormattedReply(
|
||||||
permalink,
|
permalink,
|
||||||
userLink,
|
userLink,
|
||||||
|
@ -517,11 +519,12 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
roomId: String,
|
roomId: String,
|
||||||
quotedEvent: TimelineEvent,
|
quotedEvent: TimelineEvent,
|
||||||
text: String,
|
text: String,
|
||||||
|
autoMarkdown: Boolean,
|
||||||
): 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 = false), MessageType.MSGTYPE_TEXT)
|
return 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 {
|
||||||
|
|
|
@ -406,13 +406,13 @@ class MessageComposerViewModel @AssistedInject constructor(
|
||||||
popDraft()
|
popDraft()
|
||||||
}
|
}
|
||||||
is SendMode.Quote -> {
|
is SendMode.Quote -> {
|
||||||
room.sendQuotedTextMessage(state.sendMode.timelineEvent, action.text.toString())
|
room.sendQuotedTextMessage(state.sendMode.timelineEvent, action.text.toString(), action.autoMarkdown)
|
||||||
_viewEvents.post(MessageComposerViewEvents.MessageSent)
|
_viewEvents.post(MessageComposerViewEvents.MessageSent)
|
||||||
popDraft()
|
popDraft()
|
||||||
}
|
}
|
||||||
is SendMode.Reply -> {
|
is SendMode.Reply -> {
|
||||||
state.sendMode.timelineEvent.let {
|
state.sendMode.timelineEvent.let {
|
||||||
room.replyToMessage(it, action.text.toString())
|
room.replyToMessage(it, action.text.toString(), action.autoMarkdown)
|
||||||
_viewEvents.post(MessageComposerViewEvents.MessageSent)
|
_viewEvents.post(MessageComposerViewEvents.MessageSent)
|
||||||
popDraft()
|
popDraft()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue