mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
code review
This commit is contained in:
parent
d8092abc4e
commit
c6fd625761
6 changed files with 18 additions and 7 deletions
|
@ -26,3 +26,8 @@ interface MessageContent {
|
|||
val relatesTo: RelationDefaultContent?
|
||||
val newContent: Content?
|
||||
}
|
||||
|
||||
|
||||
fun MessageContent?.isReply(): Boolean {
|
||||
return this?.relatesTo?.inReplyTo != null
|
||||
}
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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 ?: "")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue