Skip to content

Commit

Permalink
Merge branch 'develop' into chore/adr-and-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored Aug 6, 2024
2 parents bff9043 + 59c23d9 commit 9632b4a
Show file tree
Hide file tree
Showing 29 changed files with 501 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-run-ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
cache: gradle

- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v3
uses: gradle/actions/wrapper-validation@v4

- name: AVD cache
uses: buildjet/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
distribution: 'temurin'
cache: gradle
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v3
uses: gradle/actions/wrapper-validation@v4

- name: Test Build Logic
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.sync.SyncState
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import dagger.Lazy
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
Expand All @@ -48,8 +49,7 @@ import javax.inject.Inject
@HiltViewModel
class CommonTopAppBarViewModel @Inject constructor(
private val currentScreenManager: CurrentScreenManager,
@KaliumCoreLogic
private val coreLogic: CoreLogic,
@KaliumCoreLogic private val coreLogic: Lazy<CoreLogic>,
) : ViewModel() {

var state by mutableStateOf(CommonTopAppBarState())
Expand All @@ -59,7 +59,7 @@ class CommonTopAppBarViewModel @Inject constructor(
currentScreenManager.observeCurrentScreen(viewModelScope)

private fun connectivityFlow(userId: UserId): Flow<Connectivity> =
coreLogic.sessionScope(userId) {
coreLogic.get().sessionScope(userId) {
observeSyncState().map {
when (it) {
is SyncState.Failed, SyncState.Waiting -> Connectivity.WAITING_CONNECTION
Expand All @@ -71,7 +71,7 @@ class CommonTopAppBarViewModel @Inject constructor(

@VisibleForTesting
internal suspend fun activeCallFlow(userId: UserId): Flow<Call?> =
coreLogic.sessionScope(userId) {
coreLogic.get().sessionScope(userId) {
combine(
calls.establishedCall(),
calls.getIncomingCalls(),
Expand All @@ -85,7 +85,7 @@ class CommonTopAppBarViewModel @Inject constructor(

init {
viewModelScope.launch {
coreLogic.globalScope {
coreLogic.get().globalScope {
session.currentSessionFlow().flatMapLatest {
when (it) {
is CurrentSessionResult.Failure.Generic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fun WireTopAppBarTitle(
// This workaround is based on this: https://stackoverflow.com/a/69947555, but instead of using SubcomposeLayout, we just measure text.
BoxWithConstraints(
modifier = modifier
.padding(horizontal = dimensions().spacing6x)
) {
val textMeasurer = rememberTextMeasurer()
val textLayoutResult: TextLayoutResult = textMeasurer.measure(
Expand All @@ -148,7 +149,6 @@ fun WireTopAppBarTitle(
}
Text(
modifier = Modifier
.padding(horizontal = dimensions().spacing6x)
.width(width),
text = title,
style = style,
Expand All @@ -174,7 +174,7 @@ fun PreviewWireCenterAlignedTopAppBarWithDefaultTitle() = WireTheme {
fun PreviewWireCenterAlignedTopAppBarWithDefaultTwoLinesTitle() = WireTheme {
Box(modifier = Modifier.width(400.dp)) {
WireCenterAlignedTopAppBar(
title = "This is title is very long this_is_a_very_long_word",
title = "This title is a quite long title another_line",
titleStyle = MaterialTheme.wireTypography.title01
)
}
Expand All @@ -185,7 +185,7 @@ fun PreviewWireCenterAlignedTopAppBarWithDefaultTwoLinesTitle() = WireTheme {
fun PreviewWireCenterAlignedTopAppBarWithDefaultTwoLinesTooLongTitle() = WireTheme {
Box(modifier = Modifier.width(400.dp)) {
WireCenterAlignedTopAppBar(
title = "This is title is even longer than previous one this_is_a_very_long_word",
title = "This title is even longer than one before another_line",
titleStyle = MaterialTheme.wireTypography.title01
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ import kotlinx.serialization.Serializable
data class ConversationNavArgs(
val conversationId: ConversationId,
val searchedMessageId: String? = null,
val pendingBundles: ArrayList<AssetBundle>? = null
val pendingBundles: ArrayList<AssetBundle>? = null,
val pendingTextBundle: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class ObserveParticipantsForConversationUseCase @Inject constructor(

ConversationParticipantsData(
admins = visibleAdminsWithoutServices
.map { uiParticipantMapper.toUIParticipant(it.user, mlsVerificationMap[it.user.id].let { false }) },
.map { uiParticipantMapper.toUIParticipant(it.user, mlsVerificationMap[it.user.id] ?: false) },
participants = visibleParticipants
.map { uiParticipantMapper.toUIParticipant(it.user, mlsVerificationMap[it.user.id].let { false }) },
.map { uiParticipantMapper.toUIParticipant(it.user, mlsVerificationMap[it.user.id] ?: false) },
allAdminsCount = allAdminsWithoutServices.size,
allParticipantsCount = allParticipants.size,
isSelfAnAdmin = allAdminsWithoutServices.any { it.user is SelfUser },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ data class AssetBundle(
*/
data class UriAsset(
val uri: Uri,
val saveToDeviceIfInvalid: Boolean = false
val saveToDeviceIfInvalid: Boolean = false,
val mimeType: String? = null
)

private object PathAsStringSerializer : KSerializer<Path> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.wire.android.ui.home.messagecomposer.model.MessageBundle
import com.wire.android.ui.home.messagecomposer.model.Ping
import com.wire.android.ui.navArgs
import com.wire.android.ui.sharing.SendMessagesSnackbarMessages
import com.wire.android.util.SUPPORTED_AUDIO_MIME_TYPE
import com.wire.android.util.ImageUtil
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.android.util.getAudioLengthInMs
Expand Down Expand Up @@ -114,6 +113,9 @@ class SendMessageViewModel @Inject constructor(
)

init {
conversationNavArgs.pendingTextBundle?.let { text ->
trySendPendingMessageBundle(text)
}
conversationNavArgs.pendingBundles?.let { assetBundles ->
trySendMessages(
assetBundles.map { assetBundle ->
Expand All @@ -136,6 +138,12 @@ class SendMessageViewModel @Inject constructor(
private suspend fun shouldInformAboutUnderLegalHoldBeforeSendingMessage(conversationId: ConversationId) =
observeConversationUnderLegalHoldNotified(conversationId).first().let { !it }

private fun trySendPendingMessageBundle(pendingMessage: String) {
viewModelScope.launch {
sendMessage(ComposableMessageBundle.SendTextMessageBundle(conversationId, pendingMessage, emptyList()))
}
}

fun trySendMessage(messageBundle: MessageBundle) {
trySendMessages(listOf(messageBundle))
}
Expand Down Expand Up @@ -208,8 +216,7 @@ class SendMessageViewModel @Inject constructor(
is ComposableMessageBundle.AudioMessageBundle -> {
handleAssetMessageBundle(
attachmentUri = messageBundle.attachmentUri,
conversationId = messageBundle.conversationId,
specifiedMimeType = SUPPORTED_AUDIO_MIME_TYPE,
conversationId = messageBundle.conversationId
)
}

Expand Down Expand Up @@ -244,13 +251,12 @@ class SendMessageViewModel @Inject constructor(

private suspend fun handleAssetMessageBundle(
conversationId: ConversationId,
attachmentUri: UriAsset,
specifiedMimeType: String? = null, // specify a particular mimetype, otherwise it will be taken from the uri / file extension
attachmentUri: UriAsset
) {
when (val result = handleUriAsset.invoke(
uri = attachmentUri.uri,
saveToDeviceIfInvalid = attachmentUri.saveToDeviceIfInvalid,
specifiedMimeType = specifiedMimeType
specifiedMimeType = attachmentUri.mimeType
)) {
is HandleUriAssetUseCase.Result.Failure.AssetTooLarge -> {
assetTooLargeDialogState = AssetTooLargeDialogState.Visible(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import com.wire.android.ui.home.conversationslist.model.ConversationFolder
import com.wire.android.ui.home.conversationslist.model.ConversationItem
import com.wire.android.util.extension.folderWithElements
Expand Down Expand Up @@ -57,19 +55,6 @@ fun ConversationList(
state = lazyListState,
modifier = modifier.fillMaxSize()
) {
/*
* When the list is scrolled to top and new items (e.g. new activity section) should appear on top of the list, it appears above
* all current items, scroll is preserved so the list still shows the same item as the first one on list so it scrolls
* automatically to that item and the newly added section on top is hidden above this previously top item, so for such situation
* when the list is scrolled to the top and we want the new section to appear at the top we need a dummy top item which will make
* it so it wants to keep this dummy top item as the first one on list and show all other items below it.
*/
item("empty-top-header") {
HorizontalDivider(
thickness = Dp.Hairline,
color = Color.Transparent
)
}
conversationListItems.forEach { (conversationFolder, conversationList) ->
folderWithElements(
header = when (conversationFolder) {
Expand All @@ -96,4 +81,21 @@ fun ConversationList(
}
}
}

/**
* When the list is scrolled to top and new items (e.g. new activity section) should appear on top of the list, it appears above
* all current items, scroll is preserved so the list still shows the same item as the first one on list so it scrolls
* automatically to that item and the newly added section on top is hidden above this previously top item, so for such situation
* when the list is scrolled to the top and we want the new section to appear at the top we request to scroll to item at the top.
* Implemented according to the templates from compose lazy list test cases - LazyListRequestScrollTest.kt.
* https://android.googlesource.com/platform/frameworks/support/+/refs/changes/93/2987293/35/compose/foundation/foundation/integration-tests/lazy-tests/src/androidTest/kotlin/androidx/compose/foundation/lazy/list/LazyListRequestScrollTest.kt
*/
SideEffect {
if (lazyListState.firstVisibleItemIndex == 0 && lazyListState.firstVisibleItemScrollOffset == 0) {
lazyListState.requestScrollToItem(
index = lazyListState.firstVisibleItemIndex,
scrollOffset = lazyListState.firstVisibleItemScrollOffset
)
}
}
}
Loading

0 comments on commit 9632b4a

Please sign in to comment.