Skip to content

Commit

Permalink
fix: improve detekt score and threshold
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Aug 17, 2024
1 parent 69ed820 commit 9d62a6f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,12 @@ class OfflineFirstChatRepository @Inject constructor(
chatBlock.newestMessageId
).first()

if (connectedChatBlocks.size == 1) {
return if (connectedChatBlocks.size == 1) {
Log.d(TAG, "This chatBlock is not connected to others")
val chatBlockFromDb = connectedChatBlocks[0]
Log.d(TAG, "chatBlockFromDb.oldestMessageId: " + chatBlockFromDb.oldestMessageId)
Log.d(TAG, "chatBlockFromDb.newestMessageId: " + chatBlockFromDb.newestMessageId)
return chatBlockFromDb
chatBlockFromDb
} else if (connectedChatBlocks.size > 1) {
Log.d(TAG, "Found " + connectedChatBlocks.size + " chat blocks that are connected")
val oldestIdFromDbChatBlocks =
Expand All @@ -536,10 +536,10 @@ class OfflineFirstChatRepository @Inject constructor(
Log.d(TAG, "A new chat block was created that covers all the range of the found chatblocks")
Log.d(TAG, "new chatBlock - oldest MessageId: $oldestIdFromDbChatBlocks")
Log.d(TAG, "new chatBlock - newest MessageId: $newestIdFromDbChatBlocks")
return newChatBlock
newChatBlock
} else {
Log.d(TAG, "No chat block found ....")
return null
null
}
}

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ object DisplayUtils {
private const val TWITTER_HANDLE_PREFIX = "@"
private const val HTTP_PROTOCOL = "http://"
private const val HTTPS_PROTOCOL = "https://"
private const val HTTP_MIN_LENGTH: Int = 7
private const val HTTPS_MIN_LENGTH: Int = 7
private const val DATE_TIME_PARTS_SIZE = 2
fun isDarkModeOn(context: Context): Boolean {
val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
Expand Down Expand Up @@ -394,10 +396,14 @@ object DisplayUtils {
if (TextUtils.isEmpty(url)) {
return ""
}
if (url!!.length >= 7 && HTTP_PROTOCOL.equals(url.substring(0, 7), ignoreCase = true)) {
if (url!!.length >= HTTP_MIN_LENGTH &&
HTTP_PROTOCOL.equals(url.substring(0, HTTP_MIN_LENGTH), ignoreCase = true)
) {
return url.substring(HTTP_PROTOCOL.length).trim { it <= ' ' }
}
return if (url.length >= 8 && HTTPS_PROTOCOL.equals(url.substring(0, 8), ignoreCase = true)) {
return if (url.length >= HTTPS_MIN_LENGTH &&
HTTPS_PROTOCOL.equals(url.substring(0, HTTPS_MIN_LENGTH), ignoreCase = true)
) {
url.substring(HTTPS_PROTOCOL.length).trim { it <= ' ' }
} else {
url.trim { it <= ' ' }
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/nextcloud/talk/utils/PushUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,26 @@ class PushUtils {
var keyGen: KeyPairGenerator? = null
try {
keyGen = KeyPairGenerator.getInstance("RSA")
keyGen.initialize(2048)
keyGen.initialize(RSA_KEY_SIZE)
val pair = keyGen.generateKeyPair()
val statusPrivate = saveKeyToFile(pair.private, privateKeyFile.absolutePath)
val statusPublic = saveKeyToFile(pair.public, publicKeyFile.absolutePath)
return if (statusPrivate == 0 && statusPublic == 0) {
// all went well
0
RETURN_CODE_KEY_GENERATION_SUCCESSFUL
} else {
-2
RETURN_CODE_KEY_GENERATION_FAILED
}
} catch (e: NoSuchAlgorithmException) {
Log.d(TAG, "RSA algorithm not supported")
}
} else {
// We already have the key
return -1
return RETURN_CODE_KEY_ALREADY_EXISTS
}

// we failed to generate the key
return -2
return RETURN_CODE_KEY_GENERATION_FAILED
}

fun pushRegistrationToServer(ncApi: NcApi) {
Expand Down Expand Up @@ -399,6 +399,10 @@ class PushUtils {

companion object {
private const val TAG = "PushUtils"
private const val RSA_KEY_SIZE: Int = 2048
private const val RETURN_CODE_KEY_GENERATION_SUCCESSFUL: Int = 0
private const val RETURN_CODE_KEY_ALREADY_EXISTS: Int = -1
private const val RETURN_CODE_KEY_GENERATION_FAILED: Int = -2
const val LATEST_PUSH_REGISTRATION_AT_SERVER: String = "LATEST_PUSH_REGISTRATION_AT_SERVER"
const val LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY: String = "LATEST_PUSH_REGISTRATION_AT_PUSH_PROXY"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
for (msgStr in queueStr.split("]")) {
try {
val msgArray = msgStr.replace("[", "").split(",")
val message = msgArray[0]
val replyTo = msgArray[1].toInt()
val displayName = msgArray[2]
val silent = msgArray[3].toBoolean()
val message = msgArray[MESSAGE_INDEX]
val replyTo = msgArray[REPLY_TO_INDEX].toInt()
val displayName = msgArray[DISPLY_NAME_INDEX]
val silent = msgArray[SILENT_INDEX].toBoolean()

val qMsg = MessageInputViewModel.QueuedMessage(message, displayName, replyTo, silent)
queue.add(qMsg)
Expand Down Expand Up @@ -570,6 +570,10 @@ class AppPreferencesImpl(val context: Context) : AppPreferences {
@Suppress("UnusedPrivateProperty")
private val TAG = AppPreferencesImpl::class.simpleName
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
private const val MESSAGE_INDEX: Int = 0
private const val REPLY_TO_INDEX: Int = 1
private const val DISPLY_NAME_INDEX: Int = 2
private const val SILENT_INDEX: Int = 3
const val PROXY_TYPE = "proxy_type"
const val PROXY_SERVER = "proxy_server"
const val PROXY_HOST = "proxy_host"
Expand Down
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: GPL-3.0-or-later
build:
maxIssues: 138
maxIssues: 166
weights:
# complexity: 2
# LongParameterList: 1
Expand Down

0 comments on commit 9d62a6f

Please sign in to comment.