From 187e2a26db283cba01f337015d4a0a2b84886744 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 23 Oct 2019 17:26:02 +0200 Subject: [PATCH] Clean after Benoit's review --- .../api/session/events/model/LocalEcho.kt | 24 +++++++++++++++++-- .../room/send/LocalEchoEventFactory.kt | 10 +++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/LocalEcho.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/LocalEcho.kt index 0a8a4a3ec3..ca75871cda 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/LocalEcho.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/LocalEcho.kt @@ -1,8 +1,28 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package im.vector.matrix.android.api.session.events.model +import java.util.* + object LocalEcho { - const val PREFIX = "local." + private const val PREFIX = "local." - fun isLocalEchoId(eventId: String): Boolean = eventId.startsWith(PREFIX) + fun isLocalEchoId(eventId: String) = eventId.startsWith(PREFIX) + + fun createLocalEchoId() = "${PREFIX}${UUID.randomUUID()}" } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index 1d3f4def19..49c813ece6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -160,7 +160,7 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use reaction ) ) - val localId = dummyEventId() + val localId = LocalEcho.createLocalEchoId() return Event( roomId = roomId, originServerTs = dummyOriginServerTs(), @@ -264,7 +264,7 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use } private fun createEvent(roomId: String, content: Any? = null): Event { - val localID = dummyEventId() + val localID = LocalEcho.createLocalEchoId() return Event( roomId = roomId, originServerTs = dummyOriginServerTs(), @@ -280,10 +280,6 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use return System.currentTimeMillis() } - private fun dummyEventId(): String { - return "${LocalEcho.PREFIX}${UUID.randomUUID()}" - } - fun createReplyTextEvent(roomId: String, eventReplied: TimelineEvent, replyText: String, autoMarkdown: Boolean): Event? { // Fallbacks and event representation // TODO Add error/warning logs when any of this is null @@ -383,7 +379,7 @@ internal class LocalEchoEventFactory @Inject constructor(@UserId private val use } */ fun createRedactEvent(roomId: String, eventId: String, reason: String?): Event { - val localID = dummyEventId() + val localID = LocalEcho.createLocalEchoId() return Event( roomId = roomId, originServerTs = dummyOriginServerTs(),