Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle guest 1:1 conversation when legal hold requested [WPB-5937] #2763

Merged
merged 10 commits into from
Mar 12, 2024
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/wire/android/di/ViewModelScoped.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun <R : ScopedArgs> scopedArgs(argsClass: KClass<R>, argsContainer: SavedStateH
@Suppress("BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER")
@Composable
inline fun <reified T, reified S, reified R : ScopedArgs> hiltViewModelScoped(arguments: R): S where T : ViewModel, T : S = when {
LocalInspectionMode.current -> ViewModelScopedPreviews.firstNotNullOf { it as S }
LocalInspectionMode.current -> ViewModelScopedPreviews.firstNotNullOf { it as? S }
else -> hiltViewModelScoped<T>(key = arguments.key, defaultArguments = Bundlizer.bundle(R::class.serializer(), arguments))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.common

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import com.wire.android.R
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.toSpanStyle

@Composable
fun TextWithLearnMore(
textAnnotatedString: AnnotatedString,
learnMoreLink: String,
onTextLayout: (TextLayoutResult) -> Unit = {},
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val learnMoreText = stringResource(id = R.string.label_learn_more).replace(" ", "\u00A0") // non-breaking space
val learnMoreAnnotatedString = buildAnnotatedString {
append(learnMoreText)
addStyle(
style = SpanStyle(
color = MaterialTheme.colorScheme.primary,
textDecoration = TextDecoration.Underline
),
start = 0,
end = learnMoreText.length
)
addStringAnnotation(
tag = TAG_LEARN_MORE,
annotation = learnMoreLink,
start = 0,
end = learnMoreText.length
)
}
val fullAnnotatedString = textAnnotatedString + AnnotatedString(" ") + learnMoreAnnotatedString
androidx.compose.foundation.text.ClickableText(
modifier = modifier,
text = fullAnnotatedString,
onTextLayout = onTextLayout,
onClick = { offset ->
fullAnnotatedString.getStringAnnotations(TAG_LEARN_MORE, offset, offset)
.firstOrNull()?.let { result -> CustomTabsHelper.launchUrl(context, result.item) }
},
)
}

private const val TAG_LEARN_MORE = "tag_learn_more"

@PreviewMultipleThemes
@Composable
fun PreviewTextWithLearnMore() = WireTheme {
TextWithLearnMore(
textAnnotatedString = buildAnnotatedString {
withStyle(toSpanStyle(typography().body01, colorsScheme().onBackground)) { append("This is text with a learn more link") }
},
learnMoreLink = "https://www.wire.com",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ private fun ConversationScreenContent(
onFailedMessageRetryClicked = onFailedMessageRetryClicked,
onLinkClick = onLinkClick,
selectedMessageId = selectedMessageId,
onNavigateToReplyOriginalMessage = onNavigateToReplyOriginalMessage
onNavigateToReplyOriginalMessage = onNavigateToReplyOriginalMessage,
interactionAvailability = messageComposerStateHolder.messageComposerViewState.value.interactionAvailability,
)
},
onChangeSelfDeletionClicked = onChangeSelfDeletionClicked,
Expand Down Expand Up @@ -891,7 +892,8 @@ fun MessageList(
onFailedMessageCancelClicked: (String) -> Unit,
onLinkClick: (String) -> Unit,
selectedMessageId: String?,
onNavigateToReplyOriginalMessage: (UIMessage) -> Unit
onNavigateToReplyOriginalMessage: (UIMessage) -> Unit,
interactionAvailability: InteractionAvailability,
) {
val prevItemCount = remember { mutableStateOf(lazyPagingMessages.itemCount) }
LaunchedEffect(lazyPagingMessages.itemCount) {
Expand Down Expand Up @@ -984,15 +986,17 @@ fun MessageList(
onNavigateToReplyOriginalMessage(message)
}
),
isSelectedMessage = (message.header.messageId == selectedMessageId)
isSelectedMessage = (message.header.messageId == selectedMessageId),
isInteractionAvailable = interactionAvailability == InteractionAvailability.ENABLED,
)
}

is UIMessage.System -> SystemMessageItem(
message = message,
onFailedMessageCancelClicked = onFailedMessageCancelClicked,
onFailedMessageRetryClicked = onFailedMessageRetryClicked,
onSelfDeletingMessageRead = onSelfDeletingMessageRead
onSelfDeletingMessageRead = onSelfDeletingMessageRead,
isInteractionAvailable = interactionAvailability == InteractionAvailability.ENABLED,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ fun MessageItem(
shouldDisplayMessageStatus: Boolean = true,
shouldDisplayFooter: Boolean = true,
onReplyClickable: Clickable? = null,
isSelectedMessage: Boolean = false
isSelectedMessage: Boolean = false,
isInteractionAvailable: Boolean = true,
) {
with(message) {
val selfDeletionTimerState = rememberSelfDeletionTimer(header.messageStatus.expirationStatus)
Expand Down Expand Up @@ -318,6 +319,7 @@ fun MessageItem(
if (message.sendingFailed) {
MessageSendFailureWarning(
messageStatus = header.messageStatus.flowStatus as MessageFlowStatus.Failure.Send,
isInteractionAvailable = isInteractionAvailable,
onRetryClick = remember { { onFailedMessageRetryClicked(header.messageId) } },
onCancelClick = remember { { onFailedMessageCancelClicked(header.messageId) } }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import kotlinx.collections.immutable.persistentMapOf
@Composable
internal fun MessageSendFailureWarning(
messageStatus: MessageFlowStatus.Failure.Send,
isInteractionAvailable: Boolean,
onRetryClick: () -> Unit,
onCancelClick: () -> Unit
) {
Expand All @@ -78,22 +79,24 @@ internal fun MessageSendFailureWarning(
if (messageStatus is MessageFlowStatus.Failure.Send.Remotely) {
OfflineBackendsLearnMoreLink()
}
Row {
WireSecondaryButton(
text = stringResource(R.string.label_retry),
onClick = onRetryClick,
minSize = dimensions().buttonSmallMinSize,
minClickableSize = dimensions().buttonMinClickableSize,
fillMaxWidth = false
)
HorizontalSpace.x8()
WireSecondaryButton(
text = stringResource(R.string.label_cancel),
onClick = onCancelClick,
minSize = dimensions().buttonSmallMinSize,
minClickableSize = dimensions().buttonMinClickableSize,
fillMaxWidth = false
)
if (isInteractionAvailable) {
Row {
WireSecondaryButton(
text = stringResource(R.string.label_retry),
onClick = onRetryClick,
minSize = dimensions().buttonSmallMinSize,
minClickableSize = dimensions().buttonMinClickableSize,
fillMaxWidth = false
)
HorizontalSpace.x8()
WireSecondaryButton(
text = stringResource(R.string.label_cancel),
onClick = onCancelClick,
minSize = dimensions().buttonSmallMinSize,
minClickableSize = dimensions().buttonMinClickableSize,
fillMaxWidth = false
)
}
}
}
}
Expand Down Expand Up @@ -299,7 +302,15 @@ internal fun OfflineBackendsLearnMoreLink(context: Context = LocalContext.curren
@Composable
fun PreviewMessageSendFailureWarning() {
WireTheme {
MessageSendFailureWarning(MessageFlowStatus.Failure.Send.Locally(false), {}, {})
MessageSendFailureWarning(MessageFlowStatus.Failure.Send.Locally(false), true, {}, {})
}
}

@PreviewMultipleThemes
@Composable
fun PreviewMessageSendFailureWarningWithInteractionDisabled() {
WireTheme {
MessageSendFailureWarning(MessageFlowStatus.Failure.Send.Locally(false), false, {}, {})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import kotlin.math.roundToInt
fun SystemMessageItem(
message: UIMessage.System,
initiallyExpanded: Boolean = false,
isInteractionAvailable: Boolean = true,
onFailedMessageRetryClicked: (String) -> Unit = {},
onFailedMessageCancelClicked: (String) -> Unit = {},
onSelfDeletingMessageRead: (UIMessage) -> Unit = {}
Expand Down Expand Up @@ -214,6 +215,7 @@ fun SystemMessageItem(
if (message.sendingFailed) {
MessageSendFailureWarning(
messageStatus = message.header.messageStatus.flowStatus as MessageFlowStatus.Failure.Send,
isInteractionAvailable = isInteractionAvailable,
onRetryClick = remember { { onFailedMessageRetryClicked(message.header.messageId) } },
onCancelClick = remember { { onFailedMessageCancelClicked(message.header.messageId) } }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.sebaslogen.resaca.hilt.hiltViewModelScoped
import com.wire.android.R
import com.wire.android.di.hiltViewModelScoped
import com.wire.android.model.UserAvatarData
import com.wire.android.ui.common.UserProfileAvatar
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.home.conversations.details.participants.model.UIParticipant
import com.wire.android.ui.home.conversations.typing.TypingIndicatorArgs
import com.wire.android.ui.home.conversations.typing.TypingIndicatorViewModel
import com.wire.android.ui.home.conversations.typing.TypingIndicatorViewModelImpl
import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.data.id.ConversationId
Expand All @@ -71,9 +74,11 @@ private const val ANIMATION_SPEED_MILLIS = 1_500
@Composable
fun UsersTypingIndicatorForConversation(
conversationId: ConversationId,
viewModel: TypingIndicatorViewModel = hiltViewModelScoped(conversationId),
viewModel: TypingIndicatorViewModel = hiltViewModelScoped<TypingIndicatorViewModelImpl, TypingIndicatorViewModel, TypingIndicatorArgs>(
TypingIndicatorArgs(conversationId)
)
) {
UsersTypingIndicator(usersTyping = viewModel.usersTypingViewState.usersTyping)
UsersTypingIndicator(usersTyping = viewModel.state().usersTyping)
}

@Composable
Expand Down Expand Up @@ -179,7 +184,7 @@ private fun HorizontalBouncingWritingPen(

@PreviewMultipleThemes
@Composable
fun PreviewUsersTypingOne() {
fun PreviewUsersTypingOne() = WireTheme {
Column(
modifier = Modifier
.background(color = colorsScheme().background)
Expand Down Expand Up @@ -210,7 +215,7 @@ fun PreviewUsersTypingOne() {

@PreviewMultipleThemes
@Composable
fun PreviewUsersTypingMoreThanOne() {
fun PreviewUsersTypingMoreThanOne() = WireTheme {
Column(
modifier = Modifier
.background(color = colorsScheme().background)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,31 @@
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wire.android.ui.home.conversations.ConversationNavArgs
import com.wire.android.di.ScopedArgs
import com.wire.android.di.ViewModelScopedPreview
import com.wire.android.di.scopedArgs
import com.wire.android.ui.home.conversations.usecase.ObserveUsersTypingInConversationUseCase
import com.wire.android.ui.navArgs
import com.wire.kalium.logic.data.id.QualifiedID
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import javax.inject.Inject

@ViewModelScopedPreview
interface TypingIndicatorViewModel {
fun state(): UsersTypingViewState = UsersTypingViewState()

Check warning on line 38 in app/src/main/kotlin/com/wire/android/ui/home/conversations/typing/TypingIndicatorViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/typing/TypingIndicatorViewModel.kt#L38

Added line #L38 was not covered by tests
}

@HiltViewModel
class TypingIndicatorViewModel @Inject constructor(
class TypingIndicatorViewModelImpl @Inject constructor(
private val observeUsersTypingInConversation: ObserveUsersTypingInConversationUseCase,
savedStateHandle: SavedStateHandle,
) : ViewModel() {

private val conversationNavArgs: ConversationNavArgs = savedStateHandle.navArgs()
val conversationId: QualifiedID = conversationNavArgs.conversationId
) : TypingIndicatorViewModel, ViewModel() {

var usersTypingViewState by mutableStateOf(UsersTypingViewState())
private set
private val args: TypingIndicatorArgs = savedStateHandle.scopedArgs()
val conversationId: QualifiedID = args.conversationId
private var usersTypingViewState by mutableStateOf(UsersTypingViewState())
override fun state(): UsersTypingViewState = usersTypingViewState

Check warning on line 50 in app/src/main/kotlin/com/wire/android/ui/home/conversations/typing/TypingIndicatorViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/typing/TypingIndicatorViewModel.kt#L50

Added line #L50 was not covered by tests

init {
observeUsersTypingState()
Expand All @@ -55,3 +61,9 @@
}
}
}

@Serializable
data class TypingIndicatorArgs(val conversationId: QualifiedID) : ScopedArgs {
override val key = "$ARGS_KEY:$conversationId"
companion object { const val ARGS_KEY = "TypingIndicatorArgsKey" }
}
Loading
Loading