From f41c0311fa7069c0e4ee8fded0ceb011d25e59ac Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 3 Jul 2019 11:58:50 +0200 Subject: [PATCH] Fix done TODO --- build.gradle | 2 -- matrix-sdk-android/build.gradle | 2 -- .../matrix/android/api/auth/Authenticator.kt | 11 ++------ .../pushrules/ContainsDisplayNameCondition.kt | 15 +++++----- .../android/internal/crypto/CryptoModule.kt | 2 +- .../crypto/IncomingRoomKeyRequestManager.kt | 2 +- .../crypto/OutgoingRoomKeyRequestManager.kt | 7 +++-- .../crypto/actions/MessageEncrypter.kt | 3 -- .../algorithms/megolm/MXMegolmDecryption.kt | 3 +- .../megolm/MXMegolmEncryptionFactory.kt | 4 --- .../crypto/store/db/RealmCryptoStore.kt | 4 +-- .../src/test/java/ModuleTest.kt | 28 ------------------- .../api/pushrules/PushrulesConditionTest.kt | 23 +++++++-------- tools/check/check_code_quality.sh | 3 +- .../detail/timeline/item/MessageTextItem.kt | 1 - .../main/res/menu/home_bottom_navigation.xml | 1 - 16 files changed, 32 insertions(+), 79 deletions(-) delete mode 100644 matrix-sdk-android/src/test/java/ModuleTest.kt diff --git a/build.gradle b/build.gradle index 605bccbb..961fa588 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,6 @@ buildscript { ext.kotlin_version = '1.3.21' - ext.koin_version = '1.0.2' - // TODO ext.koin_version = '2.0.0-GA' repositories { google() jcenter() diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 1bcd4fb3..ff4eaa36 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -148,13 +148,11 @@ dependencies { testImplementation 'junit:junit:4.12' testImplementation 'org.robolectric:robolectric:4.0.2' - testImplementation "org.koin:koin-test:$koin_version" //testImplementation 'org.robolectric:shadows-support-v4:3.0' testImplementation "io.mockk:mockk:1.8.13.kotlin13" testImplementation 'org.amshove.kluent:kluent-android:1.44' testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" - androidTestImplementation "org.koin:koin-test:$koin_version" androidTestImplementation 'androidx.test:core:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:rules:1.2.0' diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt index 2ca6d0a2..932ffbea 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt @@ -36,17 +36,15 @@ interface Authenticator { */ fun authenticate(homeServerConnectionConfig: HomeServerConnectionConfig, login: String, password: String, callback: MatrixCallback): Cancelable - //TODO remove this method. Shouldn't be managed like that. /** - * Check if there is an active [Session]. + * Check if there is an authenticated [Session]. * @return true if there is at least one active session. */ fun hasAuthenticatedSessions(): Boolean - //TODO remove this method. Shouldn't be managed like that. /** - * Get the last active [Session], if there is an active session. - * @return the lastActive session if any, or null + * Get the last authenticated [Session], if there is an active session. + * @return the last active session if any, or null */ fun getLastAuthenticatedSession(): Session? @@ -58,7 +56,4 @@ interface Authenticator { * @return the associated session if any, or null */ fun getSession(sessionParams: SessionParams): Session? - - - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/ContainsDisplayNameCondition.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/ContainsDisplayNameCondition.kt index ce9f88e3..37bc75ad 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/ContainsDisplayNameCondition.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/ContainsDisplayNameCondition.kt @@ -20,7 +20,6 @@ import im.vector.matrix.android.api.session.events.model.Event 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.message.MessageContent -import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import timber.log.Timber import java.util.regex.Pattern @@ -35,16 +34,16 @@ class ContainsDisplayNameCondition : Condition(Kind.contains_display_name) { } fun isSatisfied(event: Event, displayName: String): Boolean { - //TODO the spec says: - // Matches any message whose content is unencrypted and contains the user's current display name var message = when (event.type) { - EventType.MESSAGE -> { + EventType.MESSAGE -> { event.content.toModel() } -// EventType.ENCRYPTED -> { -// event.root.getClearContent()?.toModel() -// } - else -> null + //TODO the spec says: + // Matches any message whose content is unencrypted and contains the user's current display name + // EventType.ENCRYPTED -> { + // event.root.getClearContent()?.toModel() + // } + else -> null } ?: return false return caseInsensitiveFind(displayName, message.body) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt index 32a5b3d2..9025d7b0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/CryptoModule.kt @@ -76,7 +76,7 @@ internal abstract class CryptoModule { @Provides fun providesCryptoStore(@CryptoDatabase realmConfiguration: RealmConfiguration, credentials: Credentials): IMXCryptoStore { - return RealmCryptoStore(false /* TODO*/, + return RealmCryptoStore( realmConfiguration, credentials) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt index 7901ca1a..86f78130 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt @@ -84,7 +84,7 @@ internal class IncomingRoomKeyRequestManager @Inject constructor( Timber.e("## processReceivedRoomKeyRequests() : Ignoring room key request from other user for now") return } - // todo: should we queue up requests we don't yet have keys for, in case they turn up later? + // TODO: should we queue up requests we don't yet have keys for, in case they turn up later? // if we don't have a decryptor for this room/alg, we don't have // the keys for the requested events, and can drop the requests. val decryptor = roomDecryptorProvider.getRoomDecryptor(roomId, alg) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt index a07b136c..f8407e8c 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/OutgoingRoomKeyRequestManager.kt @@ -121,8 +121,8 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor( */ private fun cancelRoomKeyRequest(requestBody: RoomKeyRequestBody, andResend: Boolean) { val req = cryptoStore.getOutgoingRoomKeyRequest(requestBody) - ?: // no request was made for this key - return + ?: // no request was made for this key + return Timber.v("cancelRoomKeyRequest: requestId: " + req.requestId + " state: " + req.state + " andResend: " + andResend) @@ -285,7 +285,8 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor( val contentMap = MXUsersDevicesMap() for (recipient in recipients) { - contentMap.setObject(message, recipient["userId"], recipient["deviceId"]) // TODO Change this two hard coded key to something better + // TODO Change this two hard coded key to something better + contentMap.setObject(message, recipient["userId"], recipient["deviceId"]) } sendToDeviceTask.configureWith(SendToDeviceTask.Params(EventType.ROOM_KEY_REQUEST, contentMap, transactionId)) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt index 4703237e..336a5a0f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/actions/MessageEncrypter.kt @@ -81,9 +81,6 @@ internal class MessageEncrypter @Inject constructor(private val credentials: Cre recipientsKeysMap["ed25519"] = deviceInfo.fingerprint()!! payloadJson["recipient_keys"] = recipientsKeysMap - // FIXME We have to canonicalize the JSON - //JsonUtility.canonicalize(JsonUtility.getGson(false).toJsonTree(payloadJson)).toString() - val payloadString = convertToUTF8(MoshiProvider.getCanonicalJson(Map::class.java, payloadJson)) ciphertext[deviceKey] = olmDevice.encryptMessage(deviceKey, sessionId!!, payloadString!!)!! } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt index 69992df6..bfe2e94c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt @@ -139,7 +139,8 @@ internal class MXMegolmDecryption(private val credentials: Credentials, val recipients = ArrayList>() val selfMap = HashMap() - selfMap["userId"] = credentials.userId // TODO Replace this hard coded keys (see OutgoingRoomKeyRequestManager) + // TODO Replace this hard coded keys (see OutgoingRoomKeyRequestManager) + selfMap["userId"] = credentials.userId selfMap["deviceId"] = "*" recipients.add(selfMap) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt index 2807863e..682a3c11 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmEncryptionFactory.kt @@ -25,8 +25,6 @@ import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup import im.vector.matrix.android.internal.crypto.repository.WarnOnUnknownDeviceRepository import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask -import im.vector.matrix.android.internal.session.SessionScope -import im.vector.matrix.android.internal.task.TaskExecutor import javax.inject.Inject internal class MXMegolmEncryptionFactory @Inject constructor( @@ -37,8 +35,6 @@ internal class MXMegolmEncryptionFactory @Inject constructor( private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction, private val credentials: Credentials, private val sendToDeviceTask: SendToDeviceTask, - // FIXME Why taskExecutor is not used? - private val taskExecutor: TaskExecutor, private val messageEncrypter: MessageEncrypter, private val warnOnUnknownDevicesRepository: WarnOnUnknownDeviceRepository) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt index fa944465..7c3bfabf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt @@ -39,10 +39,8 @@ import org.matrix.olm.OlmException import timber.log.Timber import kotlin.collections.set -// enableFileEncryption is used to migrate the previous store @SessionScope -internal class RealmCryptoStore(private val enableFileEncryption: Boolean = false, - private val realmConfiguration: RealmConfiguration, +internal class RealmCryptoStore(private val realmConfiguration: RealmConfiguration, private val credentials: Credentials) : IMXCryptoStore { /* ========================================================================================== diff --git a/matrix-sdk-android/src/test/java/ModuleTest.kt b/matrix-sdk-android/src/test/java/ModuleTest.kt deleted file mode 100644 index 11735fd3..00000000 --- a/matrix-sdk-android/src/test/java/ModuleTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -// TODO When upgrading to koin 2.0 -/* -class ModuleTest : KoinTest { - - @Test - fun checkModules() { - startKoin { - listOf(CryptoModule().definition) - }.checkModules() - } -} - */ \ No newline at end of file diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt index 0f9e88f9..6c1ef646 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt @@ -166,6 +166,7 @@ class PushrulesConditionTest { class MockRoomService() : RoomService { + override fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback) { } @@ -178,24 +179,28 @@ class PushrulesConditionTest { } } - override fun liveRoomSummaries(): LiveData> { + override fun liveRoomSummaries(fetchLastEvents: Boolean): LiveData> { return MutableLiveData() } - } class MockRoom(override val roomId: String, val _numberOfJoinedMembers: Int) : Room { + override fun liveTimeLineEvent(eventId: String): LiveData { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } override fun getNumberOfJoinedMembers(): Int { return _numberOfJoinedMembers } - override val liveRoomSummary: LiveData - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + override fun liveRoomSummary(fetchLastEvent: Boolean): LiveData { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } - override val roomSummary: RoomSummary? - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + override fun roomSummary(fetchLastEvent: Boolean): RoomSummary? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } override fun createTimeline(eventId: String?, allowedTypes: List?): Timeline { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. @@ -277,10 +282,6 @@ class PushrulesConditionTest { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun updateQuickReaction(reaction: String, oppositeReaction: String, targetEventId: String, myUserId: String) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - override fun editTextMessage(targetEventId: String, newBodyText: String, newBodyAutoMarkdown: Boolean, compatibilityBodyText: String): Cancelable { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } @@ -289,7 +290,7 @@ class PushrulesConditionTest { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun getEventSummaryLive(eventId: String): LiveData> { + override fun getEventSummaryLive(eventId: String): LiveData { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } diff --git a/tools/check/check_code_quality.sh b/tools/check/check_code_quality.sh index 75a02357..55d782da 100755 --- a/tools/check/check_code_quality.sh +++ b/tools/check/check_code_quality.sh @@ -105,8 +105,7 @@ fi echo echo "Search for long files..." -# TODO Reduce this once VectorSettingsPreferencesFragment.kt has been reworked -${checkLongFilesScript} 3500 \ +${checkLongFilesScript} 2000 \ ./vector/src/main/java \ ./vector/src/main/res/layout \ ./vector/src/main/res/values \ diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt index ad69d104..3ab428e0 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -45,7 +45,6 @@ abstract class MessageTextItem : AbsMessageItem() { @EpoxyAttribute var urlClickCallback: TimelineEventController.UrlClickCallback? = null - // TODO Move this instantiation somewhere else? private val mvmtMethod = BetterLinkMovementMethod.newInstance().also { it.setOnLinkClickListener { _, url -> //Return false to let android manage the click on the link, or true if the link is handled by the application diff --git a/vector/src/main/res/menu/home_bottom_navigation.xml b/vector/src/main/res/menu/home_bottom_navigation.xml index 4f8a4cf9..ea516607 100644 --- a/vector/src/main/res/menu/home_bottom_navigation.xml +++ b/vector/src/main/res/menu/home_bottom_navigation.xml @@ -1,7 +1,6 @@ -