From dbc61971df6f5bab1e44f5d9af7dbd4a30fe3cbd Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 19 Sep 2022 17:32:36 +0200 Subject: [PATCH] Reduce duplicated code --- .../room/send/LocalEchoEventFactory.kt | 44 +++++-------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt index 4d5e574592..afff51a4a5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt @@ -403,14 +403,7 @@ internal class LocalEchoEventFactory @Inject constructor( size = attachment.size ), url = attachment.queryUri.toString(), - relatesTo = rootThreadEventId?.let { - RelationDefaultContent( - type = RelationType.THREAD, - eventId = it, - isFallingBack = true, - inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) - ) - } + relatesTo = rootThreadEventId?.let { generateThreadRelationContent(it) } ) return createMessageEvent(roomId, content) } @@ -447,14 +440,7 @@ internal class LocalEchoEventFactory @Inject constructor( thumbnailInfo = thumbnailInfo ), url = attachment.queryUri.toString(), - relatesTo = rootThreadEventId?.let { - RelationDefaultContent( - type = RelationType.THREAD, - eventId = it, - isFallingBack = true, - inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) - ) - } + relatesTo = rootThreadEventId?.let { generateThreadRelationContent(it) } ) return createMessageEvent(roomId, content) } @@ -479,14 +465,7 @@ internal class LocalEchoEventFactory @Inject constructor( waveform = waveformSanitizer.sanitize(attachment.waveform) ), voiceMessageIndicator = if (!isVoiceMessage) null else emptyMap(), - relatesTo = rootThreadEventId?.let { - RelationDefaultContent( - type = RelationType.THREAD, - eventId = it, - isFallingBack = true, - inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) - ) - } + relatesTo = rootThreadEventId?.let { generateThreadRelationContent(it) } ) return createMessageEvent(roomId, content) } @@ -500,14 +479,7 @@ internal class LocalEchoEventFactory @Inject constructor( size = attachment.size ), url = attachment.queryUri.toString(), - relatesTo = rootThreadEventId?.let { - RelationDefaultContent( - type = RelationType.THREAD, - eventId = it, - isFallingBack = true, - inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it)) - ) - } + relatesTo = rootThreadEventId?.let { generateThreadRelationContent(it) } ) return createMessageEvent(roomId, content) } @@ -629,6 +601,14 @@ internal class LocalEchoEventFactory @Inject constructor( return createMessageEvent(roomId, content) } + private fun generateThreadRelationContent(rootThreadEventId: String) = + RelationDefaultContent( + type = RelationType.THREAD, + eventId = rootThreadEventId, + isFallingBack = true, + inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(rootThreadEventId)) + ) + /** * Generates the appropriate relatesTo object for a reply event. * It can either be a regular reply or a reply within a thread