Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/upgrade-pe…
Browse files Browse the repository at this point in the history
…rsonal-team-api-android
  • Loading branch information
ohassine committed Nov 21, 2024
2 parents eeb2daf + 7cd4bd6 commit d919871
Show file tree
Hide file tree
Showing 42 changed files with 946 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
groupName = conversationDetails.conversation.name.orEmpty(),
conversationId = conversationDetails.conversation.id,
mutedStatus = conversationDetails.conversation.mutedStatus,
isLegalHold = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
showLegalHoldIndicator = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
lastMessageContent = lastMessage.toUIPreview(unreadEventCount),
badgeEventType = parseConversationEventType(
mutedStatus = conversationDetails.conversation.mutedStatus,
Expand Down Expand Up @@ -83,7 +83,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
),
conversationId = conversationDetails.conversation.id,
mutedStatus = conversationDetails.conversation.mutedStatus,
isLegalHold = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
showLegalHoldIndicator = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
lastMessageContent = lastMessage.toUIPreview(unreadEventCount),
badgeEventType = parsePrivateConversationEventType(
conversationDetails.otherUser.connectionStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class MessageMapper @Inject constructor(
is SelfUser, null -> Membership.None
},
connectionState = getConnectionState(sender),
isLegalHold = sender?.isUnderLegalHold == true,
showLegalHoldIndicator = sender?.isUnderLegalHold == true,
messageTime = MessageTime(message.date),
messageStatus = getMessageStatus(message),
messageId = message.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ fun OngoingCallScreen(
clearVideoPreview = sharedCallingViewModel::clearVideoPreview,
onCollapse = onCollapse,
requestVideoStreams = ongoingCallViewModel::requestVideoStreams,
onSelectedParticipant = ongoingCallViewModel::onSelectedParticipant,
selectedParticipantForFullScreen = ongoingCallViewModel.selectedParticipant,
hideDoubleTapToast = ongoingCallViewModel::hideDoubleTapToast,
onCameraPermissionPermanentlyDenied = onCameraPermissionPermanentlyDenied,
participants = sharedCallingViewModel.participantsState,
Expand Down Expand Up @@ -289,6 +291,8 @@ private fun OngoingCallContent(
hideDoubleTapToast: () -> Unit,
onCameraPermissionPermanentlyDenied: () -> Unit,
requestVideoStreams: (participants: List<UICallParticipant>) -> Unit,
onSelectedParticipant: (selectedParticipant: SelectedParticipant) -> Unit,
selectedParticipantForFullScreen: SelectedParticipant,
participants: PersistentList<UICallParticipant>,
inPictureInPictureMode: Boolean,
currentUserId: UserId,
Expand All @@ -303,7 +307,6 @@ private fun OngoingCallContent(
)

var shouldOpenFullScreen by remember { mutableStateOf(false) }
var selectedParticipantForFullScreen by remember { mutableStateOf(SelectedParticipant()) }

WireBottomSheetScaffold(
sheetDragHandle = null,
Expand Down Expand Up @@ -391,11 +394,14 @@ private fun OngoingCallContent(
selectedParticipant = selectedParticipantForFullScreen,
height = this@BoxWithConstraints.maxHeight - dimensions().spacing4x,
closeFullScreen = {
onSelectedParticipant(SelectedParticipant())
shouldOpenFullScreen = !shouldOpenFullScreen
},
onBackButtonClicked = {
onSelectedParticipant(SelectedParticipant())
shouldOpenFullScreen = !shouldOpenFullScreen
},
requestVideoStreams = requestVideoStreams,
setVideoPreview = setVideoPreview,
clearVideoPreview = clearVideoPreview,
participants = participants
Expand All @@ -412,7 +418,7 @@ private fun OngoingCallContent(
requestVideoStreams = requestVideoStreams,
currentUserId = currentUserId,
onDoubleTap = { selectedParticipant ->
selectedParticipantForFullScreen = selectedParticipant
onSelectedParticipant(selectedParticipant)
shouldOpenFullScreen = !shouldOpenFullScreen
},
)
Expand Down Expand Up @@ -580,6 +586,8 @@ fun PreviewOngoingCallContent(participants: PersistentList<UICallParticipant>) {
participants = participants,
inPictureInPictureMode = false,
currentUserId = UserId("userId", "domain"),
onSelectedParticipant = {},
selectedParticipantForFullScreen = SelectedParticipant(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import com.wire.android.appLogger
import com.wire.android.datastore.GlobalDataStore
import com.wire.android.di.CurrentAccount
import com.wire.android.ui.calling.model.UICallParticipant
import com.wire.android.ui.calling.ongoing.fullscreen.SelectedParticipant
import com.wire.kalium.logic.data.call.Call
import com.wire.kalium.logic.data.call.CallClient
import com.wire.kalium.logic.data.call.CallQuality
import com.wire.kalium.logic.data.call.VideoState
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.UserId
Expand Down Expand Up @@ -63,6 +65,8 @@ class OngoingCallViewModel @AssistedInject constructor(

var state by mutableStateOf(OngoingCallState())
private set
var selectedParticipant by mutableStateOf(SelectedParticipant())
private set

init {
viewModelScope.launch {
Expand Down Expand Up @@ -124,20 +128,32 @@ class OngoingCallViewModel @AssistedInject constructor(
.also {
if (it.isNotEmpty()) {
val clients: List<CallClient> = it.map { uiParticipant ->
CallClient(uiParticipant.id.toString(), uiParticipant.clientId)
CallClient(
userId = uiParticipant.id.toString(),
clientId = uiParticipant.clientId,
quality = mapQualityStream(uiParticipant)
)
}
requestVideoStreams(conversationId, clients)
}
}
}
}

private fun mapQualityStream(uiParticipant: UICallParticipant): CallQuality {
return if (uiParticipant.clientId == selectedParticipant.clientId) {
CallQuality.HIGH
} else {
CallQuality.LOW
}
}

private fun startDoubleTapToastDisplayCountDown() {
doubleTapIndicatorCountDownTimer?.cancel()
doubleTapIndicatorCountDownTimer =
object : CountDownTimer(DOUBLE_TAP_TOAST_DISPLAY_TIME, COUNT_DOWN_INTERVAL) {
override fun onTick(p0: Long) {
appLogger.i("startDoubleTapToastDisplayCountDown: $p0")
appLogger.d("$TAG - startDoubleTapToastDisplayCountDown: $p0")
}

override fun onFinish() {
Expand Down Expand Up @@ -171,10 +187,16 @@ class OngoingCallViewModel @AssistedInject constructor(
}
}

fun onSelectedParticipant(selectedParticipant: SelectedParticipant) {
appLogger.d("$TAG - Selected participant: ${selectedParticipant.toLogString()}")
this.selectedParticipant = selectedParticipant
}

companion object {
const val DOUBLE_TAP_TOAST_DISPLAY_TIME = 7000L
const val COUNT_DOWN_INTERVAL = 1000L
const val DELAY_TO_SHOW_DOUBLE_TAP_TOAST = 500L
const val TAG = "OngoingCallViewModel"
}

@AssistedFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fun FullScreenTile(
closeFullScreen: (offset: Offset) -> Unit,
onBackButtonClicked: () -> Unit,
setVideoPreview: (View) -> Unit,
requestVideoStreams: (participants: List<UICallParticipant>) -> Unit,
clearVideoPreview: () -> Unit,
modifier: Modifier = Modifier,
contentPadding: Dp = dimensions().spacing4x,
Expand Down Expand Up @@ -119,6 +120,10 @@ fun FullScreenTile(
}
)
}

LaunchedEffect(selectedParticipant.userId) {
requestVideoStreams(listOf(it))
}
}
}

Expand All @@ -139,6 +144,7 @@ fun PreviewFullScreenTile() = WireTheme {
closeFullScreen = {},
onBackButtonClicked = {},
setVideoPreview = {},
requestVideoStreams = {},
clearVideoPreview = {},
participants = participants,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
*/
package com.wire.android.ui.calling.ongoing.fullscreen

import com.wire.kalium.logger.obfuscateId
import com.wire.kalium.logic.data.user.UserId

data class SelectedParticipant(
val userId: UserId = UserId("", ""),
val clientId: String = "",
val isSelfUser: Boolean = false
)
) {

fun toLogString(): String {
return "SelectedParticipant(userId=${userId.toLogString()}, clientId=${clientId.obfuscateId()}, isSelfUser=$isSelfUser)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = isLegalHold
isUnderLegalHold = showLegalHoldIndicator
)
}
}
Expand All @@ -102,7 +102,7 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = isLegalHold
isUnderLegalHold = showLegalHoldIndicator
)
}
}
Expand All @@ -122,7 +122,7 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = isLegalHold
isUnderLegalHold = showLegalHoldIndicator
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun CodeTextField(
maxHorizontalSpacing = maxHorizontalSpacing,
horizontalAlignment = horizontalAlignment,
modifier = modifier,
innerBasicTextField = { decorator, textFieldModifier ->
innerBasicTextField = { decorator, textFieldModifier, _ ->
BasicTextField(
state = textState,
textStyle = textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ internal fun CodeTextFieldLayout(
}
},
textFieldModifier = Modifier,
decorationBox = {}
)
val bottomText = when {
state is WireTextFieldState.Error && state.errorText != null -> state.errorText
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.textfield

import androidx.compose.ui.text.TextRange

object MentionDeletionHandler {
@Suppress("ReturnCount")
fun handle(
oldText: String,
newText: String,
oldSelection: TextRange,
mentions: List<String>
): String {
if (oldText == newText) {
// No change in text, only cursor movement, return as is
return oldText
}
for (mention in mentions) {
// Find the start position of the mention in the text
val mentionStart = oldText.indexOf(mention)

if (mentionStart == -1) continue

val mentionEnd = mentionStart + mention.length

// Check if the selection (i.e., user's cursor position) is inside the mention's range
if (oldSelection.start in mentionStart + 1..mentionEnd || oldSelection.end in mentionStart + 1..mentionEnd) {
// If the user is deleting inside the mention, remove the entire mention
return oldText.removeRange(mentionStart, mentionEnd)
}
}
return newText
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.textfield

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.withStyle
import com.wire.android.ui.home.conversations.model.UIMention

class MentionVisualTransformation(
val color: Color,
val mentions: List<UIMention>
) : VisualTransformation {
override fun filter(text: AnnotatedString): TransformedText {
val styledText = buildAnnotatedString {
var lastIndex = 0
text.takeIf { it.isNotEmpty() }?.let {
mentions.forEach { mention ->
// Append the text before the mention
append(text.subSequence(lastIndex, mention.start))
// Apply the style to the mention
withStyle(style = SpanStyle(color = color, fontWeight = FontWeight.Bold)) {
append(text.subSequence(mention.start, mention.start + mention.length))
}
lastIndex = mention.start + mention.length
}
}
// Append the remaining text after the last mention
append(text.subSequence(lastIndex, text.length))
}
return TransformedText(
text = styledText,
offsetMapping = object : OffsetMapping {
override fun originalToTransformed(offset: Int): Int = offset
override fun transformedToOriginal(offset: Int): Int = offset
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fun WirePasswordTextField(
modifier = modifier.then(autoFillModifier(autoFillType, textState::setTextAndPlaceCursorAtEnd)),
testTag = testTag,
onTap = onTap,
innerBasicTextField = { decorator, textFieldModifier ->
innerBasicTextField = { decorator, textFieldModifier, _ ->
BasicSecureTextField(
state = textState,
textStyle = textStyle.copy(color = colors.textColor(state = state).value, textDirection = TextDirection.ContentOrLtr),
Expand Down
Loading

0 comments on commit d919871

Please sign in to comment.