code review

This commit is contained in:
Valere 2019-07-16 14:38:49 +02:00
parent d8092abc4e
commit c6fd625761
6 changed files with 18 additions and 7 deletions

View File

@ -25,4 +25,9 @@ interface MessageContent {
val body: String
val relatesTo: RelationDefaultContent?
val newContent: Content?
}


fun MessageContent?.isReply(): Boolean {
return this?.relatesTo?.inReplyTo != null
}

View File

@ -84,7 +84,9 @@ interface RelationService {
/**
* Edit a reply. This is a special case because replies contains fallback text as a prefix.
* This method will take the new body (stripped from fallbacks) and re-add them before sending.
* @param targetEventId The event to edit
* @param replyToEdit The event to edit
* @param originalSenderId the sender of the message that this reply (being edited) is relating to
* @param originalEventId the event id that this reply (being edited) is relating to
* @param newBodyText The edited body (stripped from in reply to content)
* @param compatibilityBodyText The text that will appear on clients that don't support yet edition
*/

View File

@ -21,8 +21,9 @@ import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.matrix.android.api.session.room.model.message.isReply
import im.vector.matrix.android.api.session.room.send.SendState
import im.vector.matrix.android.internal.session.room.send.extractUsefulTextFromReply
import im.vector.matrix.android.api.util.ContentUtils.extractUsefulTextFromReply

/**
* This data class is a wrapper around an Event. It allows to get useful data in the context of a timeline.
@ -93,7 +94,7 @@ fun TimelineEvent.getLastMessageContent(): MessageContent? = annotations?.editSu

fun TimelineEvent.getTextEditableContent(): String? {
val originalContent = root.getClearContent().toModel<MessageContent>() ?: return null
val isReply = originalContent.relatesTo?.inReplyTo != null
val isReply = originalContent.isReply()
val lastContent = getLastMessageContent()
return if (isReply) {
return extractUsefulTextFromReply(lastContent?.body ?: "")

View File

@ -38,7 +38,9 @@ object ContentUtils {

fun extractUsefulTextFromHtmlReply(repliedBody: String): String {
if (repliedBody.startsWith("<mx-reply>")) {
return repliedBody.substring(repliedBody.lastIndexOf("</mx-reply>") + "</mx-reply>".length).trim()
val closingTagIndex = repliedBody.lastIndexOf("</mx-reply>")
if (closingTagIndex != -1)
return repliedBody.substring(closingTagIndex + "</mx-reply>".length).trim()
}
return repliedBody
}

View File

@ -334,8 +334,8 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
formattedText = content.formattedBody
}
}
val isReply = content.relatesTo?.inReplyTo?.eventId != null ||
originalContent?.relatesTo?.inReplyTo?.eventId != null
val isReply = content.isReply() ||
originalContent.isReply()
return if (isReply)
TextContent(content.body, formattedText).removeInReplyFallbacks()
else

View File

@ -23,6 +23,7 @@ import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.matrix.android.api.session.room.model.message.isReply
import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.features.home.room.detail.timeline.helper.TimelineDateFormatter

@ -83,7 +84,7 @@ class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted
var originalIsReply = false
room.getTimeLineEvent(eventId)?.let {
withOriginal.add(it.root)
originalIsReply = it.root.getClearContent().toModel<MessageContent>()?.relatesTo?.inReplyTo?.eventId != null
originalIsReply = it.root.getClearContent().toModel<MessageContent>().isReply()
}
setState {
copy(