Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Sep 4, 2024
1 parent 2b5797c commit 68ca992
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class MessagesPresenter @AssistedInject constructor(
}

return MessagesState(
isDebugBuild = buildMeta.isDebuggable,
isDebugBuild = buildMeta.isDebuggable,
roomId = room.roomId,
roomName = roomName,
roomAvatar = roomAvatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import io.element.android.features.messages.impl.voicemessages.composer.VoiceMes
import io.element.android.features.messages.impl.voicemessages.composer.VoiceMessageSendingFailedDialog
import io.element.android.features.networkmonitor.api.ui.ConnectivityIndicatorView
import io.element.android.libraries.androidutils.ui.hideKeyboard
import io.element.android.libraries.core.bool.orFalse
import io.element.android.libraries.designsystem.atomic.molecules.IconTitlePlaceholdersRowMolecule
import io.element.android.libraries.designsystem.components.ProgressDialog
import io.element.android.libraries.designsystem.components.ProgressDialogType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.features.messages.impl.MessagesState
import io.element.android.features.messages.impl.R
import io.element.android.libraries.designsystem.components.avatar.Avatar
import io.element.android.libraries.designsystem.components.avatar.AvatarData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private fun SheetContent(
SenderRow(
isDebugBuild = summary.isDebugBuild,
avatarData = user.getAvatarData(AvatarSize.UserListItem),
name = user.getBestName(), // TCHAP TODO should be applied in Element X
// TCHAP TODO should be applied in Element X
name = user.getBestName(),
userId = user.userId.value,
sentTime = sender.sentTime
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ private fun DmHeaderSection(
)
TitleAndSubtitle(
title = roomName,
subtitle = otherMember.userId.value.takeIf { isDebugBuild }, // TCHAP hide the Matrix Id in release mode
// TCHAP hide the Matrix Id in release mode
subtitle = otherMember.userId.value.takeIf { isDebugBuild },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ private fun RoomMemberActionsBottomSheet(
.align(Alignment.CenterHorizontally)
)
Text(
text = roomMember.getBestName(), // TCHAP display a value generated from userId if displayname does not exist
// TCHAP display a value generated from userId if displayname does not exist
text = roomMember.getBestName(),
style = ElementTheme.typography.fontHeadingLgBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
Expand All @@ -234,8 +235,7 @@ private fun RoomMemberActionsBottomSheet(
.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
.fillMaxWidth()
)
// TCHAP hide the Matrix Id in release mode
if (isDebugBuild) {
if (isDebugBuild) { // TCHAP hide the Matrix Id in release mode
Text(
text = roomMember.userId.toString(),
style = ElementTheme.typography.fontBodyLgRegular,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class InviteSender(
) {
@Composable
fun annotatedString(): AnnotatedString {
return stringResource(R.string.screen_invites_invited_you, displayName, userId.value).let { text -> // TCHAP TODO text should be changed to hide the user id
return stringResource(R.string.screen_invites_invited_you, displayName, userId.value).let { text -> // TCHAP TODO should be changed to hide the user id
val senderNameStart = LocalContext.current.getString(R.string.screen_invites_invited_you).indexOf("%1\$s")
AnnotatedString(
text = text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ object TchapPatterns {
* For example in case of "@jean-philippe.martin-modernisation.fr:matrix.test.org", this will return "matrix.test.org".
* in case of "!AAAAAAA:matrix.test.org", this will return "matrix.test.org".
*
* @param mxId the matrix identifier.
* @return the homeserver name, if any.
*/
fun String.toHomeserverName() = this.substringAfter(":", "")
Expand All @@ -46,7 +45,6 @@ object TchapPatterns {
* For example in case of "@jean-philippe.martin-modernisation.fr:name1.tchap.gouv.fr", this will return "Name1".
* in case of "@jean-philippe.martin-modernisation.fr:agent.name2.tchap.gouv.fr", this will return "Name2".
*
* @param mxId the matrix identifier.
* @return the Tchap display name of the homeserver.
*/
fun String.toHomeserverDisplayName(): String {
Expand All @@ -62,7 +60,6 @@ object TchapPatterns {
/**
* Tells whether a homeserver name corresponds to an external server or not.
*
* @param homeServerName the homeserver name to check.
* @return true if external.
*/
fun String.isExternalTchapServer() = this.isEmpty() || this.startsWith("e.") || this.startsWith("agent.externe.")
Expand All @@ -71,7 +68,6 @@ object TchapPatterns {
* Get name part of a display name by removing the domain part if any.
* For example in case of "Jean Martin `[Modernisation]`", this will return "Jean Martin".
*
* @param displayName the display name to compute.
* @return displayName without domain (or the display name itself if no domain has been found).
*/
fun String.getUserName() = this.substringBefore('[').trim()
Expand All @@ -80,7 +76,6 @@ object TchapPatterns {
* Get the potential domain name from a display name.
* For example in case of "Jean Martin `[Modernisation]`", this will return "Modernisation".
*
* @param displayName the display name to compute.
* @return displayName without name, empty string if no domain is available.
*/
fun String.getUserDomain() = this.substringBeforeLast(']', "").substringAfterLast('[', "").trim()
Expand Down Expand Up @@ -115,7 +110,7 @@ object TchapPatterns {
for (i in 0 until lastHyphenIndex) {
val char = identifier[i]
when {
(capitalizeNext && (char == '.' || char == '-')) -> continue
capitalizeNext && (char == '.' || char == '-') -> continue
char == '.' -> {
// Replace the dot character by space character
append(' ')
Expand All @@ -140,7 +135,6 @@ object TchapPatterns {
* Tells whether the provided tchap identifier corresponds to an extern user.
* Note: invalid tchap identifier will be considered as external.
*
* @param tchapUserId user identifier (ie. the matrix identifier).
* @return true if external.
*/
fun String.isExternalTchapUser() = this.toHomeserverName().isExternalTchapServer()
Expand All @@ -156,7 +150,7 @@ object TchapPatterns {
/**
* Create a room alias with a prefix.
*
* @param session the user's session.
* @param sessionId the user's id session.
* @param prefix the alias name prefix.
* @return the suggested alias.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ package fr.gouv.tchap.libraries.tchaputils

import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.getUserDomain
import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.getUserName
import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.toUserDisplayName
import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.toHomeserverDisplayName
import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.toUserDisplayName
import org.junit.Assert.assertEquals
import org.junit.Test

class TchapPatternsTest {

/**
* Test getting full name without domain.
*/

@Test
fun `given a displayName if it contains brackets then return its first element after split`() {
assertEquals( "Nom Prenom", "Nom Prenom [Modernisation]".getUserName())
assertEquals("Nom Prenom", "Nom Prenom [Modernisation]".getUserName())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class MarkdownTextEditorState(
}
is ResolvedSuggestion.Member -> {
val currentText = SpannableStringBuilder(text.value())
val text = resolvedSuggestion.roomMember.displayName?.prependIndent("@") ?: resolvedSuggestion.roomMember.userId.value // TCHAP TODO check needed about mxid displaying
val text = resolvedSuggestion.roomMember.displayName?.prependIndent("@")
?: resolvedSuggestion.roomMember.userId.value // TCHAP TODO check needed about mxid displaying
val link = permalinkBuilder.permalinkForUser(resolvedSuggestion.roomMember.userId).getOrNull() ?: return
val mentionPill = mentionSpanProvider.getMentionSpanFor(text, link)
currentText.replace(suggestion.start, suggestion.end, "@ ")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* MIT License
*
* Copyright (c) 2024. DINUM
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fr.gouv.tchap.android.tests.konsist

import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.verify.assertTrue
import org.junit.Test

class KonsistLicenseTest {
private val tchapLicense = """
/\*
\* MIT License
\*
\* Copyright \(c\) 20\d\d\. DINUM
\*
\* Permission is hereby granted, free of charge, to any person obtaining a copy
\* of this software and associated documentation files \(the "Software"\), to deal
\* in the Software without restriction, including without limitation the rights
\* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\* copies of the Software, and to permit persons to whom the Software is
\* furnished to do so, subject to the following conditions:
\*
\* The above copyright notice and this permission notice shall be included in all
\* copies or substantial portions of the Software\.
\*
\* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\.
\* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
\* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
\* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\* OR OTHER DEALINGS IN THE SOFTWARE\.
\*/
""".trimIndent().toRegex()

@Test
fun `assert that Tchap files have the correct license header`() {
Konsist
.scopeFromProject()
.files
.filter {
it.path.contains("/fr/gouv/tchap/")
}
.assertTrue {
tchapLicense.containsMatchIn(it.text)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,6 @@ import com.lemonappdev.konsist.api.verify.assertTrue
import org.junit.Test

class KonsistLicenseTest {
private val tchapLicense = """
/\*
\* MIT License
\*
\* Copyright \(c\) 20\d\d\. DINUM
\*
\* Permission is hereby granted, free of charge, to any person obtaining a copy
\* of this software and associated documentation files \(the "Software"\), to deal
\* in the Software without restriction, including without limitation the rights
\* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\* copies of the Software, and to permit persons to whom the Software is
\* furnished to do so, subject to the following conditions:
\*
\* The above copyright notice and this permission notice shall be included in all
\* copies or substantial portions of the Software\.
\*
\* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\.
\* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
\* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
\* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
\* OR OTHER DEALINGS IN THE SOFTWARE\.
\*/
""".trimIndent().toRegex()

private val publicLicense = """
/\*
(?:.*\n)* \* Copyright \(c\) 20\d\d New Vector Ltd
Expand Down Expand Up @@ -81,19 +55,6 @@ class KonsistLicenseTest {
\*/
""".trimIndent().toRegex()

@Test
fun `assert that Tchap files have the correct license header`() {
Konsist
.scopeFromProject()
.files
.filter {
it.path.contains("/fr/gouv/tchap/")
}
.assertTrue {
tchapLicense.containsMatchIn(it.text)
}
}

@Test
fun `assert that FOSS files have the correct license header`() {
Konsist
Expand Down

0 comments on commit 68ca992

Please sign in to comment.