Skip to content

Commit 9d62a6f

Browse files
fix: improve detekt score and threshold
Signed-off-by: Andy Scherzinger <[email protected]>
1 parent 69ed820 commit 9d62a6f

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,12 @@ class OfflineFirstChatRepository @Inject constructor(
504504
chatBlock.newestMessageId
505505
).first()
506506

507-
if (connectedChatBlocks.size == 1) {
507+
return if (connectedChatBlocks.size == 1) {
508508
Log.d(TAG, "This chatBlock is not connected to others")
509509
val chatBlockFromDb = connectedChatBlocks[0]
510510
Log.d(TAG, "chatBlockFromDb.oldestMessageId: " + chatBlockFromDb.oldestMessageId)
511511
Log.d(TAG, "chatBlockFromDb.newestMessageId: " + chatBlockFromDb.newestMessageId)
512-
return chatBlockFromDb
512+
chatBlockFromDb
513513
} else if (connectedChatBlocks.size > 1) {
514514
Log.d(TAG, "Found " + connectedChatBlocks.size + " chat blocks that are connected")
515515
val oldestIdFromDbChatBlocks =
@@ -536,10 +536,10 @@ class OfflineFirstChatRepository @Inject constructor(
536536
Log.d(TAG, "A new chat block was created that covers all the range of the found chatblocks")
537537
Log.d(TAG, "new chatBlock - oldest MessageId: $oldestIdFromDbChatBlocks")
538538
Log.d(TAG, "new chatBlock - newest MessageId: $newestIdFromDbChatBlocks")
539-
return newChatBlock
539+
newChatBlock
540540
} else {
541541
Log.d(TAG, "No chat block found ....")
542-
return null
542+
null
543543
}
544544
}
545545

app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ object DisplayUtils {
7777
private const val TWITTER_HANDLE_PREFIX = "@"
7878
private const val HTTP_PROTOCOL = "http://"
7979
private const val HTTPS_PROTOCOL = "https://"
80+
private const val HTTP_MIN_LENGTH: Int = 7
81+
private const val HTTPS_MIN_LENGTH: Int = 7
8082
private const val DATE_TIME_PARTS_SIZE = 2
8183
fun isDarkModeOn(context: Context): Boolean {
8284
val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
@@ -394,10 +396,14 @@ object DisplayUtils {
394396
if (TextUtils.isEmpty(url)) {
395397
return ""
396398
}
397-
if (url!!.length >= 7 && HTTP_PROTOCOL.equals(url.substring(0, 7), ignoreCase = true)) {
399+
if (url!!.length >= HTTP_MIN_LENGTH &&
400+
HTTP_PROTOCOL.equals(url.substring(0, HTTP_MIN_LENGTH), ignoreCase = true)
401+
) {
398402
return url.substring(HTTP_PROTOCOL.length).trim { it <= ' ' }
399403
}
400-
return if (url.length >= 8 && HTTPS_PROTOCOL.equals(url.substring(0, 8), ignoreCase = true)) {
404+
return if (url.length >= HTTPS_MIN_LENGTH &&
405+
HTTPS_PROTOCOL.equals(url.substring(0, HTTPS_MIN_LENGTH), ignoreCase = true)
406+
) {
401407
url.substring(HTTPS_PROTOCOL.length).trim { it <= ' ' }
402408
} else {
403409
url.trim { it <= ' ' }

app/src/main/java/com/nextcloud/talk/utils/PushUtils.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,26 @@ class PushUtils {
162162
var keyGen: KeyPairGenerator? = null
163163
try {
164164
keyGen = KeyPairGenerator.getInstance("RSA")
165-
keyGen.initialize(2048)
165+
keyGen.initialize(RSA_KEY_SIZE)
166166
val pair = keyGen.generateKeyPair()
167167
val statusPrivate = saveKeyToFile(pair.private, privateKeyFile.absolutePath)
168168
val statusPublic = saveKeyToFile(pair.public, publicKeyFile.absolutePath)
169169
return if (statusPrivate == 0 && statusPublic == 0) {
170170
// all went well
171-
0
171+
RETURN_CODE_KEY_GENERATION_SUCCESSFUL
172172
} else {
173-
-2
173+
RETURN_CODE_KEY_GENERATION_FAILED
174174
}
175175
} catch (e: NoSuchAlgorithmException) {
176176
Log.d(TAG, "RSA algorithm not supported")
177177
}
178178
} else {
179179
// We already have the key
180-
return -1
180+
return RETURN_CODE_KEY_ALREADY_EXISTS
181181
}
182182

183183
// we failed to generate the key
184-
return -2
184+
return RETURN_CODE_KEY_GENERATION_FAILED
185185
}
186186

187187
fun pushRegistrationToServer(ncApi: NcApi) {
@@ -399,6 +399,10 @@ class PushUtils {
399399

400400
companion object {
401401
private const val TAG = "PushUtils"
402+
private const val RSA_KEY_SIZE: Int = 2048
403+
private const val RETURN_CODE_KEY_GENERATION_SUCCESSFUL: Int = 0
404+
private const val RETURN_CODE_KEY_ALREADY_EXISTS: Int = -1
405+
private const val RETURN_CODE_KEY_GENERATION_FAILED: Int = -2
402406
const val LATEST_PUSH_REGISTRATION_AT_SERVER: String = "LATEST_PUSH_REGISTRATION_AT_SERVER"
403407
const val LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY: String = "LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY"
404408
}

app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
503503
for (msgStr in queueStr.split("]")) {
504504
try {
505505
val msgArray = msgStr.replace("[", "").split(",")
506-
val message = msgArray[0]
507-
val replyTo = msgArray[1].toInt()
508-
val displayName = msgArray[2]
509-
val silent = msgArray[3].toBoolean()
506+
val message = msgArray[MESSAGE_INDEX]
507+
val replyTo = msgArray[REPLY_TO_INDEX].toInt()
508+
val displayName = msgArray[DISPLY_NAME_INDEX]
509+
val silent = msgArray[SILENT_INDEX].toBoolean()
510510

511511
val qMsg = MessageInputViewModel.QueuedMessage(message, displayName, replyTo, silent)
512512
queue.add(qMsg)
@@ -570,6 +570,10 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
570570
@Suppress("UnusedPrivateProperty")
571571
private val TAG = AppPreferencesImpl::class.simpleName
572572
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
573+
private const val MESSAGE_INDEX: Int = 0
574+
private const val REPLY_TO_INDEX: Int = 1
575+
private const val DISPLY_NAME_INDEX: Int = 2
576+
private const val SILENT_INDEX: Int = 3
573577
const val PROXY_TYPE = "proxy_type"
574578
const val PROXY_SERVER = "proxy_server"
575579
const val PROXY_HOST = "proxy_host"

detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
22
# SPDX-License-Identifier: GPL-3.0-or-later
33
build:
4-
maxIssues: 138
4+
maxIssues: 166
55
weights:
66
# complexity: 2
77
# LongParameterList: 1

0 commit comments

Comments
 (0)