Merge branch 'develop' into feature/fga/safer_callback_flows

This commit is contained in:
ganfra
2023-07-31 11:36:59 +02:00
122 changed files with 682 additions and 267 deletions

View File

@@ -183,7 +183,7 @@ fun Context.startInstallFromSourceIntent(
noActivityFoundMessage: String = getString(R.string.error_no_compatible_app_found),
) {
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
.setData(Uri.parse(String.format("package:%s", packageName)))
.setData(Uri.parse("package:$packageName"))
try {
activityResultLauncher.launch(intent)
} catch (activityNotFoundException: ActivityNotFoundException) {

View File

@@ -23,5 +23,5 @@ import com.bumble.appyx.core.plugin.plugins
interface NodeInputs : Plugin
inline fun <reified I : NodeInputs> Node.inputs(): I {
return plugins<I>().firstOrNull() ?: throw RuntimeException("Make sure to actually pass NodeInputs plugin to your node")
return requireNotNull(plugins<I>().firstOrNull()) { "Make sure to actually pass NodeInputs plugin to your node" }
}

View File

@@ -72,7 +72,3 @@ fun String.ellipsize(length: Int): String {
return "${this.take(length)}"
}
inline fun <reified R> Any?.takeAs(): R? {
return takeIf { it is R } as R?
}

View File

@@ -101,7 +101,7 @@ class DefaultLastMessageTimestampFormatterTest {
* Create DefaultLastMessageFormatter and set current time to the provided date.
*/
private fun createFormatter(@Suppress("SameParameterValue") currentDate: String): LastMessageTimestampFormatter {
val clock = FakeClock().also { it.givenInstant(Instant.parse(currentDate)) }
val clock = FakeClock().apply { givenInstant(Instant.parse(currentDate)) }
val localDateTimeProvider = LocalDateTimeProvider(clock, TimeZone.UTC)
val dateFormatters = DateFormatters(Locale.US, clock, TimeZone.UTC)
return DefaultLastMessageTimestampFormatter(localDateTimeProvider, dateFormatters)

View File

@@ -70,7 +70,7 @@ fun InfoListItemMolecule(
@DayNightPreviews
@Composable
fun InfoListItemMoleculePreview() {
internal fun InfoListItemMoleculePreview() {
ElementPreview {
val color = if (isSystemInDarkTheme()) Color.DarkGray else Color.LightGray
Column(

View File

@@ -68,11 +68,11 @@ fun LabelledTextField(
@Preview
@Composable
fun LabelledTextFieldLightPreview() = ElementPreviewLight { ContentToPreview() }
internal fun LabelledTextFieldLightPreview() = ElementPreviewLight { ContentToPreview() }
@Preview
@Composable
fun LabelledTextFieldDarkPreview() = ElementPreviewDark { ContentToPreview() }
internal fun LabelledTextFieldDarkPreview() = ElementPreviewDark { ContentToPreview() }
@Composable
private fun ContentToPreview() {

View File

@@ -51,6 +51,6 @@ fun PinIcon(
@DayNightPreviews
@Composable
fun PinIconPreview() = ElementPreview {
internal fun PinIconPreview() = ElementPreview {
PinIcon()
}

View File

@@ -102,7 +102,7 @@ private fun InitialsAvatar(
@Preview(group = PreviewGroup.Avatars)
@Composable
fun AvatarPreview(@PreviewParameter(AvatarDataProvider::class) avatarData: AvatarData) =
internal fun AvatarPreview(@PreviewParameter(AvatarDataProvider::class) avatarData: AvatarData) =
ElementThemedPreview {
Row(
verticalAlignment = Alignment.CenterVertically,

View File

@@ -20,19 +20,16 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
open class AvatarDataProvider : PreviewParameterProvider<AvatarData> {
override val values: Sequence<AvatarData>
get() {
AvatarSize.values()
.also { it.sortBy { item -> item.name } }
.asSequence()
return AvatarSize.values().asSequence().map {
get() = AvatarSize.values()
.asSequence()
.map {
sequenceOf(
anAvatarData(size = it),
anAvatarData(size = it).copy(name = null),
anAvatarData(size = it).copy(url = "aUrl"),
)
}
.flatten()
}
.flatten()
}
fun anAvatarData(

View File

@@ -42,6 +42,13 @@ const val DAY_MODE_NAME = "D"
*
* NB: Content should be wrapped into [ElementPreview] to apply proper theming.
*/
@Preview(name = DAY_MODE_NAME)
@Preview(name = NIGHT_MODE_NAME, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(
name = DAY_MODE_NAME,
fontScale = 1f,
)
@Preview(
name = NIGHT_MODE_NAME,
uiMode = Configuration.UI_MODE_NIGHT_YES,
fontScale = 1f,
)
annotation class DayNightPreviews

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 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 io.element.android.libraries.designsystem.preview
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
/**
* Showkase does not take into account the `fontScale` parameter of the Preview annotation, so alter the
* LocalDensity in the CompositionLocalProvider.
*/
@Composable
fun WithFontScale(fontScale: Float, content: @Composable () -> Unit) {
CompositionLocalProvider(
LocalDensity provides Density(
density = LocalDensity.current.density,
fontScale = fontScale
)
) {
content()
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) 2023 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 io.element.android.libraries.designsystem.text
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
import io.element.android.libraries.designsystem.preview.WithFontScale
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.theme.ElementTheme
/**
* Return the maximum value between the receiver value and the value with fontScale applied.
* So if fontScale is >= 1f, the same value is returned, and if fontScale is < 1f, so returned value
* will be smaller.
*/
@Composable
fun Dp.applyScaleDown(): Dp = with(LocalDensity.current) {
return this@applyScaleDown * fontScale.coerceAtMost(1f)
}
/**
* Return the minimum value between the receiver value and the value with fontScale applied.
* So if fontScale is <= 1f, the same value is returned, and if fontScale is > 1f, so returned value
* will be bigger.
*/
@Composable
fun Dp.applyScaleUp(): Dp = with(LocalDensity.current) {
return this@applyScaleUp * fontScale.coerceAtLeast(1f)
}
@Preview
@Composable
fun DpScalePreview_0_75f() = WithFontScale(0.75f) {
ElementPreviewLight {
val fontSizeInDp = 16.dp
Column(
modifier = Modifier.padding(4.dp),
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(
text = "Text with size of 16.sp",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.toSp())
)
Text(
text = "Text with the same size (applyScaleUp)",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.applyScaleUp().toSp())
)
Text(
text = "Text with a smaller size (applyScaleDown)",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.applyScaleDown().toSp())
)
}
}
}
@Preview
@Composable
fun DpScalePreview_1_0f() = WithFontScale(1f) {
ElementPreviewLight {
val fontSizeInDp = 16.dp
Column(
modifier = Modifier.padding(4.dp),
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(
text = "Text with size of 16.sp",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.toSp())
)
Text(
text = "Text with the same size (applyScaleUp)",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.applyScaleUp().toSp())
)
Text(
text = "Text with the same size (applyScaleDown)",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.applyScaleDown().toSp())
)
}
}
}
@Preview
@Composable
fun DpScalePreview_1_5f() = WithFontScale(1.5f) {
ElementPreviewLight {
val fontSizeInDp = 16.dp
Column(
modifier = Modifier.padding(4.dp),
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(
text = "Text with size of 16.sp",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.toSp())
)
Text(
text = "Text with a bigger size (applyScaleUp)",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.applyScaleUp().toSp())
)
Text(
text = "Text with the same size (applyScaleDown)",
style = ElementTheme.typography.fontBodyLgRegular.copy(fontSize = fontSizeInDp.applyScaleDown().toSp())
)
}
}
}

View File

@@ -44,7 +44,7 @@ internal fun DatePickerPreviewDark() {
@Composable
private fun ContentToPreview() {
val state = rememberDatePickerState(
initialSelectedDateMillis = 1672578000000L,
initialSelectedDateMillis = 1_672_578_000_000L,
)
AlertDialogContent(
buttons = { /*TODO*/ },

View File

@@ -28,10 +28,12 @@ import timber.log.Timber
@Composable
fun LogCompositions(tag: String, msg: String) {
if (BuildConfig.DEBUG) {
val ref = remember { Ref(0) }
val ref = remember { Ref() }
SideEffect { ref.value++ }
Timber.tag(tag).d("Compositions: $msg ${ref.value}")
}
}
class Ref(var value: Int)
private class Ref {
var value: Int = 0
}

View File

@@ -236,7 +236,7 @@ private fun MapView.lifecycleObserver(previousState: MutableState<Lifecycle.Even
Lifecycle.Event.ON_DESTROY -> {
//handled in onDispose
}
else -> throw IllegalStateException()
Lifecycle.Event.ON_ANY -> error("ON_ANY should never be used")
}
previousState.value = event
}

View File

@@ -95,9 +95,9 @@ object PermalinkParser {
return if (signUrl.isNullOrEmpty().not() && email.isNullOrEmpty().not()) {
try {
val signValidUri = Uri.parse(signUrl)
val identityServerHost = signValidUri.authority ?: throw IllegalArgumentException()
val token = signValidUri.getQueryParameter("token") ?: throw IllegalArgumentException()
val privateKey = signValidUri.getQueryParameter("private_key") ?: throw IllegalArgumentException()
val identityServerHost = signValidUri.authority ?: throw IllegalArgumentException("missing `authority`")
val token = signValidUri.getQueryParameter("token") ?: throw IllegalArgumentException("missing `token`")
val privateKey = signValidUri.getQueryParameter("private_key") ?: throw IllegalArgumentException("missing `private_key`")
PermalinkData.RoomEmailInviteLink(
roomId = identifier,
email = email!!,
@@ -137,7 +137,8 @@ object PermalinkParser {
.parameterList
.filter {
it.mParameter == "via"
}.map {
}
.map {
URLDecoder.decode(it.mValue, "UTF-8")
}
}

View File

@@ -105,6 +105,8 @@ interface MatrixRoom : Closeable {
suspend fun canUserInvite(userId: UserId): Result<Boolean>
suspend fun canUserRedact(userId: UserId): Result<Boolean>
suspend fun canUserSendState(userId: UserId, type: StateEventType): Result<Boolean>
suspend fun canUserSendMessage(userId: UserId, type: MessageEventType): Result<Boolean>

View File

@@ -34,3 +34,9 @@ suspend fun MatrixRoom.canSendState(type: StateEventType): Result<Boolean> = can
* Shortcut for calling [MatrixRoom.canUserSendMessage] with our own user.
*/
suspend fun MatrixRoom.canSendMessage(type: MessageEventType): Result<Boolean> = canUserSendMessage(sessionId, type)
/**
* Shortcut for calling [MatrixRoom.canUserRedact] with our own user.
*/
suspend fun MatrixRoom.canRedact(): Result<Boolean> = canUserRedact(sessionId)

View File

@@ -147,7 +147,8 @@ class RustMatrixClient constructor(
if (syncState == SyncState.Running) {
onSlidingSyncUpdate()
}
}.launchIn(sessionCoroutineScope)
}
.launchIn(sessionCoroutineScope)
}
override suspend fun getRoom(roomId: RoomId): MatrixRoom? = withContext(sessionDispatcher) {
@@ -227,7 +228,8 @@ class RustMatrixClient constructor(
roomSummaryDataSource.allRooms()
.filter { roomSummaries ->
roomSummaries.map { it.identifier() }.contains(roomId.value)
}.first()
}
.first()
}
roomId
}

View File

@@ -93,7 +93,7 @@ class RustMatrixAuthenticationService @Inject constructor(
client.restoreSession(sessionData.toSession())
createMatrixClient(client)
} else {
throw IllegalStateException("No session to restore with id $sessionId")
error("No session to restore with id $sessionId")
}
}.mapFailure { failure ->
failure.mapClientException()

View File

@@ -250,6 +250,12 @@ class RustMatrixRoom(
}
}
override suspend fun canUserRedact(userId: UserId): Result<Boolean> {
return runCatching {
innerRoom.canUserRedact(userId.value)
}
}
override suspend fun canUserSendState(userId: UserId, type: StateEventType): Result<Boolean> {
return runCatching {
innerRoom.canUserSendState(userId.value, type.map())

View File

@@ -64,7 +64,8 @@ internal class RustRoomSummaryDataSource(
.map { it.toRoomSummaryDataSourceLoadingState() }
.onEach {
allRoomsLoadingState.value = it
}.launchIn(this)
}
.launchIn(this)
launch {
// Wait until running, as invites is only available after that

View File

@@ -118,7 +118,8 @@ class RustMatrixTimeline(
innerRoom.backPaginationStatusFlow()
.onEach {
postPaginationStatus(it)
}.launchIn(this)
}
.launchIn(this)
taskHandleBag += fetchMembers().getOrNull()
}.invokeOnCompletion {

View File

@@ -27,7 +27,7 @@ import java.util.Date
class TimelineEncryptedHistoryPostProcessorTest {
private val defaultLastLoginTimestamp = Date(1689061264L)
private val defaultLastLoginTimestamp = Date(1_689_061_264L)
@Test
fun `given an unencrypted room, nothing is done`() {

View File

@@ -56,6 +56,7 @@ class FakeMatrixRoom(
override val joinedMemberCount: Long = 123L,
override val activeMemberCount: Long = 234L,
private val matrixTimeline: MatrixTimeline = FakeMatrixTimeline(),
canRedact: Boolean = false,
) : MatrixRoom {
private var ignoreResult: Result<Unit> = Result.success(Unit)
@@ -66,6 +67,7 @@ class FakeMatrixRoom(
private var joinRoomResult = Result.success(Unit)
private var inviteUserResult = Result.success(Unit)
private var canInviteResult = Result.success(true)
private var canRedactResult = Result.success(canRedact)
private val canSendStateResults = mutableMapOf<StateEventType, Result<Boolean>>()
private val canSendEventResults = mutableMapOf<MessageEventType, Result<Boolean>>()
private var sendMediaResult = Result.success(Unit)
@@ -207,6 +209,10 @@ class FakeMatrixRoom(
return canInviteResult
}
override suspend fun canUserRedact(userId: UserId): Result<Boolean> {
return canRedactResult
}
override suspend fun canUserSendState(userId: UserId, type: StateEventType): Result<Boolean> {
return canSendStateResults[type] ?: Result.failure(IllegalStateException("No fake answer"))
}

View File

@@ -111,12 +111,12 @@ private fun AvatarActionBottomSheetContent(
@Preview
@Composable
fun AvatarActionBottomSheetLightPreview() =
internal fun AvatarActionBottomSheetLightPreview() =
ElementPreviewLight { ContentToPreview() }
@Preview
@Composable
fun AvatarActionBottomSheetDarkPreview() =
internal fun AvatarActionBottomSheetDarkPreview() =
ElementPreviewDark { ContentToPreview() }
@Composable

View File

@@ -103,12 +103,12 @@ private fun MatrixUserHeaderContent(
@Preview
@Composable
fun MatrixUserHeaderLightPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
internal fun MatrixUserHeaderLightPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
ElementPreviewLight { ContentToPreview(matrixUser) }
@Preview
@Composable
fun MatrixUserHeaderDarkPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
internal fun MatrixUserHeaderDarkPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
ElementPreviewDark { ContentToPreview(matrixUser) }
@Composable

View File

@@ -68,12 +68,12 @@ fun MatrixUserHeaderPlaceholder(
@Preview
@Composable
fun MatrixUserHeaderPlaceholderLightPreview() =
internal fun MatrixUserHeaderPlaceholderLightPreview() =
ElementPreviewLight { ContentToPreview() }
@Preview
@Composable
fun MatrixUserHeaderPlaceholderDarkPreview() =
internal fun MatrixUserHeaderPlaceholderDarkPreview() =
ElementPreviewDark { ContentToPreview() }
@Composable

View File

@@ -85,11 +85,11 @@ fun UnsavedAvatar(
@Preview
@Composable
fun UnsavedAvatarLightPreview() = ElementPreviewLight { ContentToPreview() }
internal fun UnsavedAvatarLightPreview() = ElementPreviewLight { ContentToPreview() }
@Preview
@Composable
fun UnsavedAvatarDarkPreview() = ElementPreviewDark { ContentToPreview() }
internal fun UnsavedAvatarDarkPreview() = ElementPreviewDark { ContentToPreview() }
@Composable
private fun ContentToPreview() {

View File

@@ -57,14 +57,9 @@ fun MatrixRoom.getDirectRoomMember(roomMembersState: MatrixRoomMembersState): St
val roomMembers = roomMembersState.roomMembers()
return remember(roomMembersState) {
derivedStateOf {
if (roomMembers == null) {
null
} else if (roomMembers.size == 2 && isDirect && isEncrypted) {
roomMembers.find { it.userId != this.sessionId }
} else {
null
}
roomMembers
?.takeIf { it.size == 2 && isDirect && isEncrypted }
?.find { it.userId != sessionId }
}
}
}

View File

@@ -21,6 +21,7 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.produceState
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.MessageEventType
import io.element.android.libraries.matrix.api.room.powerlevels.canRedact
import io.element.android.libraries.matrix.api.room.powerlevels.canSendMessage
@Composable
@@ -30,3 +31,10 @@ fun MatrixRoom.canSendMessageAsState(type: MessageEventType, updateKey: Long): S
}
}
@Composable
fun MatrixRoom.canRedactAsState(updateKey: Long): State<Boolean> {
return produceState(initialValue = false, key1 = updateKey) {
value = canRedact().getOrElse { false }
}
}

View File

@@ -83,12 +83,12 @@ fun PermissionsView(
@Preview
@Composable
fun PermissionsViewLightPreview(@PreviewParameter(PermissionsViewStateProvider::class) state: PermissionsState) =
internal fun PermissionsViewLightPreview(@PreviewParameter(PermissionsViewStateProvider::class) state: PermissionsState) =
ElementPreviewLight { ContentToPreview(state) }
@Preview
@Composable
fun PermissionsViewDarkPreview(@PreviewParameter(PermissionsViewStateProvider::class) state: PermissionsState) =
internal fun PermissionsViewDarkPreview(@PreviewParameter(PermissionsViewStateProvider::class) state: PermissionsState) =
ElementPreviewDark { ContentToPreview(state) }
@Composable

View File

@@ -23,17 +23,15 @@ import io.element.android.libraries.matrix.api.core.SessionId
* Data class to hold information about a group of notifications for a room.
*/
data class RoomEventGroupInfo(
val sessionId: SessionId,
val roomId: RoomId,
val roomDisplayName: String,
val isDirect: Boolean = false
) {
val sessionId: SessionId,
val roomId: RoomId,
val roomDisplayName: String,
val isDirect: Boolean = false,
// An event in the list has not yet been display
var hasNewEvent: Boolean = false
val hasNewEvent: Boolean = false,
// true if at least one on the not yet displayed event is noisy
var shouldBing: Boolean = false
var customSound: String? = null
var hasSmartReplyError: Boolean = false
var isUpdated: Boolean = false
}
val shouldBing: Boolean = false,
val customSound: String? = null,
val hasSmartReplyError: Boolean = false,
val isUpdated: Boolean = false,
)

View File

@@ -85,12 +85,11 @@ class RoomGroupMessageCreator @Inject constructor(
roomId = roomId,
roomDisplayName = roomName,
isDirect = !roomIsGroup,
).also {
it.hasSmartReplyError = smartReplyErrors.isNotEmpty()
it.shouldBing = meta.shouldBing
it.customSound = events.last().soundName
it.isUpdated = events.last().isUpdated
},
hasSmartReplyError = smartReplyErrors.isNotEmpty(),
shouldBing = meta.shouldBing,
customSound = events.last().soundName,
isUpdated = events.last().isUpdated,
),
threadId = lastKnownRoomEvent.threadId,
largeIcon = largeBitmap,
lastMessageTimestamp,

View File

@@ -30,7 +30,7 @@ data class SimpleNotifiableEvent(
val type: String?,
val timestamp: Long,
val soundName: String?,
override var canBeReplaced: Boolean,
override val canBeReplaced: Boolean,
override val isRedacted: Boolean = false,
override val isUpdated: Boolean = false
) : NotifiableEvent

View File

@@ -100,15 +100,15 @@ class DefaultPushHandler @Inject constructor(
}
val clientSecret = pushData.clientSecret
val userId = if (clientSecret == null) {
// Should not happen. In this case, restore default session
null
} else {
// Get userId from client secret
pushClientSecret.getUserIdFromSecret(clientSecret)
} ?: run {
matrixAuthenticationService.getLatestSessionId()
}
// clientSecret should not be null. If this happens, restore default session
val userId = clientSecret
?.let {
// Get userId from client secret
pushClientSecret.getUserIdFromSecret(clientSecret)
}
?: run {
matrixAuthenticationService.getLatestSessionId()
}
if (userId == null) {
Timber.w("Unable to get a session")

View File

@@ -25,7 +25,7 @@ class NotificationIdProviderTest {
@Test
fun `test notification id provider`() {
val sut = NotificationIdProvider()
val offsetForASessionId = 305410
val offsetForASessionId = 305_410
assertThat(sut.getSummaryNotificationId(A_SESSION_ID)).isEqualTo(offsetForASessionId + 0)
assertThat(sut.getRoomMessagesNotificationId(A_SESSION_ID)).isEqualTo(offsetForASessionId + 1)
assertThat(sut.getRoomEventNotificationId(A_SESSION_ID)).isEqualTo(offsetForASessionId + 2)

View File

@@ -36,7 +36,7 @@ import io.element.android.libraries.pushproviders.api.PushData
data class PushDataFirebase(
val eventId: String?,
val roomId: String?,
var unread: Int?,
val unread: Int?,
val clientSecret: String?
)

View File

@@ -47,7 +47,7 @@ data class PushDataUnifiedPush(
data class PushDataUnifiedPushNotification(
@SerialName("event_id") val eventId: String? = null,
@SerialName("room_id") val roomId: String? = null,
@SerialName("counts") var counts: PushDataUnifiedPushCounts? = null,
@SerialName("counts") val counts: PushDataUnifiedPushCounts? = null,
)
@Serializable

View File

@@ -75,6 +75,7 @@ import io.element.android.libraries.designsystem.VectorIcons
import io.element.android.libraries.designsystem.modifiers.applyIf
import io.element.android.libraries.designsystem.preview.DayNightPreviews
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.text.applyScaleUp
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.Surface
import io.element.android.libraries.designsystem.theme.components.Text
@@ -111,12 +112,15 @@ fun TextComposer(
) {
AttachmentButton(onClick = onAddAttachment, modifier = Modifier.padding(vertical = 6.dp))
Spacer(modifier = Modifier.width(12.dp))
val roundCornerSmall = 20.dp.applyScaleUp()
val roundCornerLarge = 28.dp.applyScaleUp()
var lineCount by remember { mutableStateOf(0) }
val roundedCornerSize = remember(lineCount, composerMode) {
if (lineCount > 1 || composerMode is MessageComposerMode.Special) {
20.dp
roundCornerSmall
} else {
28.dp
roundCornerLarge
}
}
val roundedCornerSizeState = animateDpAsState(
@@ -126,7 +130,7 @@ fun TextComposer(
)
)
val roundedCorners = RoundedCornerShape(roundedCornerSizeState.value)
val minHeight = 42.dp
val minHeight = 42.dp.applyScaleUp()
val bgColor = ElementTheme.colors.bgSubtleSecondary
// Change border color depending on focus
var hasFocus by remember { mutableStateOf(false) }
@@ -170,7 +174,12 @@ fun TextComposer(
singleLine = false,
visualTransformation = VisualTransformation.None,
shape = roundedCorners,
contentPadding = PaddingValues(top = 10.dp, bottom = 10.dp, start = 12.dp, end = 42.dp),
contentPadding = PaddingValues(
top = 10.dp.applyScaleUp(),
bottom = 10.dp.applyScaleUp(),
start = 12.dp.applyScaleUp(),
end = 42.dp.applyScaleUp(),
),
interactionSource = remember { MutableInteractionSource() },
placeholder = {
Text(stringResource(CommonStrings.common_message), style = defaultTypography)
@@ -198,7 +207,7 @@ fun TextComposer(
canSendMessage = composerCanSendMessage,
onSendMessage = onSendMessage,
composerMode = composerMode,
modifier = Modifier.padding(end = 6.dp, bottom = 6.dp)
modifier = Modifier.padding(end = 6.dp.applyScaleUp(), bottom = 6.dp.applyScaleUp())
)
}
}
@@ -258,7 +267,7 @@ private fun EditingModeView(
tint = ElementTheme.materialColors.secondary,
modifier = Modifier
.padding(vertical = 8.dp)
.size(16.dp),
.size(16.dp.applyScaleUp()),
)
Text(
stringResource(CommonStrings.common_editing),
@@ -275,7 +284,7 @@ private fun EditingModeView(
tint = ElementTheme.materialColors.secondary,
modifier = Modifier
.padding(top = 8.dp, bottom = 8.dp, start = 16.dp, end = 12.dp)
.size(16.dp)
.size(16.dp.applyScaleUp())
.clickable(
enabled = true,
onClick = onResetComposerMode,
@@ -338,7 +347,7 @@ private fun ReplyToModeView(
tint = MaterialTheme.colorScheme.secondary,
modifier = Modifier
.padding(end = 4.dp, top = 4.dp, start = 16.dp, bottom = 16.dp)
.size(16.dp)
.size(16.dp.applyScaleUp())
.clickable(
enabled = true,
onClick = onResetComposerMode,
@@ -356,13 +365,13 @@ private fun AttachmentButton(
) {
Surface(
modifier
.size(30.dp)
.size(30.dp.applyScaleUp())
.clickable(onClick = onClick),
shape = CircleShape,
color = ElementTheme.colors.iconPrimary
) {
Image(
modifier = Modifier.size(12.5f.dp),
modifier = Modifier.size(12.5f.dp.applyScaleUp()),
painter = painterResource(R.drawable.ic_add_attachment),
contentDescription = stringResource(R.string.rich_text_editor_a11y_add_attachment),
contentScale = ContentScale.Inside,
@@ -386,10 +395,10 @@ private fun BoxScope.SendButton(
modifier = modifier
.clip(CircleShape)
.background(if (canSendMessage) ElementTheme.colors.iconAccentTertiary else Color.Transparent)
.size(30.dp)
.size(30.dp.applyScaleUp())
.align(Alignment.BottomEnd)
.applyIf(composerMode !is MessageComposerMode.Edit, ifTrue = {
padding(start = 1.dp) // Center the arrow in the circle
padding(start = 1.dp.applyScaleUp()) // Center the arrow in the circle
})
.clickable(
enabled = canSendMessage,
@@ -409,7 +418,7 @@ private fun BoxScope.SendButton(
else -> stringResource(CommonStrings.action_send)
}
Icon(
modifier = Modifier.size(16.dp),
modifier = Modifier.size(16.dp.applyScaleUp()),
resourceId = iconId,
contentDescription = contentDescription,
// Exception here, we use Color.White instead of ElementTheme.colors.iconOnSolidPrimary
@@ -420,7 +429,7 @@ private fun BoxScope.SendButton(
@DayNightPreviews
@Composable
fun TextComposerSimplePreview() = ElementPreview {
internal fun TextComposerSimplePreview() = ElementPreview {
Column {
TextComposer(
onSendMessage = {},
@@ -451,7 +460,7 @@ fun TextComposerSimplePreview() = ElementPreview {
@DayNightPreviews
@Composable
fun TextComposerEditPreview() = ElementPreview {
internal fun TextComposerEditPreview() = ElementPreview {
TextComposer(
onSendMessage = {},
onComposerTextChange = {},
@@ -464,7 +473,7 @@ fun TextComposerEditPreview() = ElementPreview {
@DayNightPreviews
@Composable
fun TextComposerReplyPreview() = ElementPreview {
internal fun TextComposerReplyPreview() = ElementPreview {
Column {
TextComposer(
onSendMessage = {},

View File

@@ -91,7 +91,7 @@ internal val materialColorSchemeDark = darkColorScheme(
@Preview
@Composable
fun ColorsSchemePreviewLight() = ColorsSchemePreview(
internal fun ColorsSchemePreviewLight() = ColorsSchemePreview(
Color.Black,
Color.White,
materialColorSchemeLight,
@@ -99,7 +99,7 @@ fun ColorsSchemePreviewLight() = ColorsSchemePreview(
@Preview
@Composable
fun ColorsSchemePreviewDark() = ColorsSchemePreview(
internal fun ColorsSchemePreviewDark() = ColorsSchemePreview(
Color.White,
Color.Black,
materialColorSchemeDark,