Skip to content

Commit

Permalink
Merge branch 'develop' into fix/disable-view-tracking-countly-cherry-…
Browse files Browse the repository at this point in the history
…pick
  • Loading branch information
yamilmedina authored Dec 13, 2024
2 parents ea04edd + 375b8ca commit d847bca
Show file tree
Hide file tree
Showing 19 changed files with 451 additions and 58 deletions.
8 changes: 8 additions & 0 deletions app/src/main/kotlin/com/wire/android/WireApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import co.touchlab.kermit.platformLogWriter
import com.wire.android.analytics.ObserveCurrentSessionAnalyticsUseCase
import com.wire.android.datastore.GlobalDataStore
import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.debug.DatabaseProfilingManager
import com.wire.android.di.ApplicationScope
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.feature.analytics.AnonymousAnalyticsManagerImpl
Expand Down Expand Up @@ -89,6 +90,9 @@ class WireApplication : BaseApp() {
@Inject
lateinit var currentScreenManager: CurrentScreenManager

@Inject
lateinit var databaseProfilingManager: DatabaseProfilingManager

override val workManagerConfiguration: Configuration
get() = Configuration.Builder()
.setWorkerFactory(wireWorkerFactory.get())
Expand Down Expand Up @@ -183,6 +187,10 @@ class WireApplication : BaseApp() {
logDeviceInformation()
// 5. Verify if we can initialize Anonymous Analytics
initializeAnonymousAnalytics()
// 6. Observe and update profiling when needed
globalAppScope.launch {
databaseProfilingManager.observeAndUpdateProfiling()
}
}

private fun initializeAnonymousAnalytics() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.debug

import com.wire.android.datastore.GlobalDataStore
import com.wire.android.di.KaliumCoreLogic
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.functional.mapToRightOr
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.scan
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class DatabaseProfilingManager @Inject constructor(
@KaliumCoreLogic private val coreLogic: CoreLogic,
private val globalDataStore: GlobalDataStore,
) {

suspend fun observeAndUpdateProfiling() {
globalDataStore.isLoggingEnabled()
.flatMapLatest { isLoggingEnabled ->
coreLogic.getGlobalScope().sessionRepository.allValidSessionsFlow()
.mapToRightOr(emptyList())
.map { it.map { it.userId } }
.scan(emptyList<UserId>()) { previousList, currentList -> currentList - previousList.toSet() }
.map { userIds -> isLoggingEnabled to userIds }
}
.filter { (_, userIds) -> userIds.isNotEmpty() }
.distinctUntilChanged()
.collect { (isLoggingEnabled, userIds) ->
userIds.forEach { userId ->
coreLogic.getSessionScope(userId).debug.changeProfiling(isLoggingEnabled)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
),
userId = conversationDetails.otherUser.id,
blockingState = conversationDetails.otherUser.BlockState,
isUserDeleted = conversationDetails.otherUser.deleted,
teamId = conversationDetails.otherUser.teamId,
isArchived = conversationDetails.conversation.archived,
mlsVerificationStatus = conversationDetails.conversation.mlsVerificationStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ sealed class ConversationTypeDetail {
data class Private(
val avatarAsset: UserAvatarAsset?,
val userId: UserId,
val blockingState: BlockingState
val blockingState: BlockingState,
val isUserDeleted: Boolean
) : ConversationTypeDetail()

data class Connection(val avatarAsset: UserAvatarAsset?) : ConversationTypeDetail()
Expand Down Expand Up @@ -131,7 +132,8 @@ data class ConversationSheetContent(

fun canEditNotifications(): Boolean = isSelfUserMember
&& ((conversationTypeDetail is ConversationTypeDetail.Private
&& (conversationTypeDetail.blockingState != BlockingState.BLOCKED))
&& (conversationTypeDetail.blockingState != BlockingState.BLOCKED)
&& !conversationTypeDetail.isUserDeleted)
|| conversationTypeDetail is ConversationTypeDetail.Group)

fun canDeleteGroup(): Boolean {
Expand All @@ -142,8 +144,11 @@ data class ConversationSheetContent(

fun canLeaveTheGroup(): Boolean = conversationTypeDetail is ConversationTypeDetail.Group && isSelfUserMember

fun canBlockUser(): Boolean =
conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState == BlockingState.NOT_BLOCKED
fun canBlockUser(): Boolean {
return conversationTypeDetail is ConversationTypeDetail.Private
&& conversationTypeDetail.blockingState == BlockingState.NOT_BLOCKED
&& !conversationTypeDetail.isUserDeleted
}

fun canUnblockUser(): Boolean =
conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState == BlockingState.BLOCKED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ fun rememberConversationSheetState(
} else conversationInfo.name,
mutingConversationState = mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Private(
userAvatarData.asset,
userId,
blockingState
avatarAsset = userAvatarData.asset,
userId = userId,
blockingState = blockingState,
isUserDeleted = isUserDeleted
),
isTeamConversation = isTeamConversation,
selfRole = Conversation.Member.Role.Member,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import androidx.paging.insertSeparators
import androidx.paging.map
import com.wire.android.BuildConfig
Expand Down Expand Up @@ -211,10 +212,11 @@ class ConversationListViewModelImpl @AssistedInject constructor(
}
}
.flowOn(dispatcher.io())
.cachedIn(viewModelScope)

private var notPaginatedConversationListState by mutableStateOf(ConversationListState.NotPaginated())
override val conversationListState: ConversationListState
get() = if (usePagination) {
override val conversationListState: ConversationListState =
if (usePagination) {
ConversationListState.Paginated(
conversations = conversationsPaginatedFlow,
domain = currentAccount.domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ fun PreviewPrivateConversationItemWithBlockedBadge() = WireTheme {
isArchived = false,
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
isFavorite = false
isFavorite = false,
isUserDeleted = false
),
modifier = Modifier,
isSelectableItem = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ fun previewConversationList(count: Int, startIndex: Int = 0, unread: Boolean = f
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
searchQuery = searchQuery,
isFavorite = false
isFavorite = false,
isUserDeleted = false
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ sealed class ConversationItem : ConversationFolderItem {
val conversationInfo: ConversationInfo,
val userId: UserId,
val blockingState: BlockingState,
val isUserDeleted: Boolean,
override val conversationId: ConversationId,
override val mutedStatus: MutedConversationStatus,
override val showLegalHoldIndicator: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ fun rememberMessageComposerStateHolder(

val messageTextFieldValue = remember { mutableStateOf(TextFieldValue()) }

LaunchedEffect(draftMessageComposition.draftText) {
if (draftMessageComposition.draftText.isNotBlank()) {
messageTextFieldValue.value = messageTextFieldValue.value.copy(
text = draftMessageComposition.draftText,
selection = TextRange(draftMessageComposition.draftText.length) // Place cursor at the end of the new text
)
}
}

val messageCompositionHolder = remember {
mutableStateOf(
MessageCompositionHolder(
Expand All @@ -77,6 +68,23 @@ fun rememberMessageComposerStateHolder(
)
)
}

LaunchedEffect(draftMessageComposition.draftText) {
if (draftMessageComposition.draftText.isNotBlank()) {
messageTextFieldValue.value = messageTextFieldValue.value.copy(
text = draftMessageComposition.draftText,
selection = TextRange(draftMessageComposition.draftText.length) // Place cursor at the end of the new text
)
}

if (draftMessageComposition.selectedMentions.isNotEmpty()) {
messageCompositionHolder.value.setMentions(
draftMessageComposition.draftText,
draftMessageComposition.selectedMentions.map { it.intoMessageMention() }
)
}
}

LaunchedEffect(Unit) {
messageCompositionHolder.value.handleMessageTextUpdates()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,20 @@ class MessageCompositionHolder(
)
messageComposition.update {
it.copy(
selectedMentions = mentions.mapNotNull { it.toUiMention(editMessageText) },
selectedMentions = mentions.mapNotNull { mention -> mention.toUiMention(editMessageText) },
editMessageId = messageId
)
}
onSaveDraft(messageComposition.value.toDraft(editMessageText))
}

fun setMentions(editMessageText: String, mentions: List<MessageMention>) {
messageComposition.update {
it.copy(selectedMentions = mentions.mapNotNull { mention -> mention.toUiMention(editMessageText) })
}
onSaveDraft(messageComposition.value.toDraft(editMessageText))
}

fun addOrRemoveMessageMarkdown(
markdown: RichTextMarkdown,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ fun ContentFooter(
exit = fadeOut(),
) {
// TODO show open conversation button for service bots after AR-2135
if (!state.isMetadataEmpty() && state.membership != Membership.Service && !state.isTemporaryUser()) {
val isNotTemporaryAndNotDeleted = !state.isTemporaryUser() && !state.isDeletedUser
if (!state.isMetadataEmpty() && state.membership != Membership.Service && isNotTemporaryAndNotDeleted) {
Surface(
shadowElevation = dimensions().bottomNavigationShadowElevation,
color = MaterialTheme.wireColorScheme.background
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,17 @@ class OtherUserProfileScreenViewModel @Inject constructor(
isUnderLegalHold = otherUser.isUnderLegalHold,
expiresAt = otherUser.expiresAt,
accentId = otherUser.accentId,
isDeletedUser = otherUser.deleted,
conversationSheetContent = conversation?.let {
ConversationSheetContent(
title = otherUser.name.orEmpty(),
conversationId = conversation.id,
mutingConversationState = conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Private(
userAvatarAsset,
userId,
otherUser.BlockState
avatarAsset = userAvatarAsset,
userId = userId,
blockingState = otherUser.BlockState,
isUserDeleted = otherUser.deleted
),
isTeamConversation = conversation.isTeamGroup(),
selfRole = Conversation.Member.Role.Member,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ data class OtherUserProfileState(
val isConversationStarted: Boolean = false,
val expiresAt: Instant? = null,
val accentId: Int = -1,
val errorLoadingUser: ErrorLoadingUser? = null
val errorLoadingUser: ErrorLoadingUser? = null,
val isDeletedUser: Boolean = false
) {
fun updateMuteStatus(status: MutedConversationStatus): OtherUserProfileState {
return conversationSheetContent?.let {
Expand Down
Loading

0 comments on commit d847bca

Please sign in to comment.