Skip to content

Commit

Permalink
Merge branch 'develop' into feat/archived_conversations_tab_empty_state
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreferris committed Sep 26, 2023
2 parents 2dbfa26 + 596009f commit d42fc90
Show file tree
Hide file tree
Showing 23 changed files with 386 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/semantic-commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# Please look up the latest version from
# https://github.com/amannn/action-semantic-pull-request/releases
- name: Run Semantic Commint Linter
uses: amannn/action-semantic-pull-request@v5.2.0
uses: amannn/action-semantic-pull-request@v5.3.0
with:
# Configure which types are allowed.
# Default: https://github.com/commitizen/conventional-commit-types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.wire.kalium.logic.feature.conversation.RefreshConversationsWithoutMet
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.RenameConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationAccessRoleUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationReadDateUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationReceiptModeUseCase
Expand Down Expand Up @@ -216,4 +217,9 @@ class ConversationModule {
@Provides
fun provideClearConversationContentUseCase(conversationScope: ConversationScope): ClearConversationContentUseCase =
conversationScope.clearConversationContent

@ViewModelScoped
@Provides
fun provideUpdateConversationArchivedStatusUseCase(conversationScope: ConversationScope): UpdateConversationArchivedStatusUseCase =
conversationScope.updateConversationArchivedStatus
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun ConversationSheetContent(
onMutingConversationStatusChange: () -> Unit,
addConversationToFavourites: () -> Unit,
moveConversationToFolder: () -> Unit,
moveConversationToArchive: () -> Unit,
moveConversationToArchive: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUser: (BlockUserDialogState) -> Unit,
unblockUser: (UnblockUserDialogState) -> Unit,
Expand All @@ -61,7 +61,7 @@ fun ConversationSheetContent(
//
// addConversationToFavourites = addConversationToFavourites,
// moveConversationToFolder = moveConversationToFolder,
// moveConversationToArchive = moveConversationToArchive,
moveConversationToArchive = moveConversationToArchive,
clearConversationContent = clearConversationContent,
blockUserClick = blockUser,
unblockUserClick = unblockUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ import com.wire.kalium.logic.data.user.ConnectionState
internal fun ConversationMainSheetContent(
conversationSheetContent: ConversationSheetContent,
// TODO(profile): enable when implemented
//
// addConversationToFavourites: () -> Unit,
// moveConversationToFolder: () -> Unit,
// moveConversationToArchive: () -> Unit,
moveConversationToArchive: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUserClick: (BlockUserDialogState) -> Unit,
unblockUserClick: (UnblockUserDialogState) -> Unit,
Expand Down Expand Up @@ -135,18 +134,27 @@ internal fun ConversationMainSheetContent(
// onItemClick = moveConversationToFolder
// )
// }
// add {
// MenuBottomSheetItem(
// icon = {
// MenuItemIcon(
// id = R.drawable.ic_archive,
// contentDescription = stringResource(R.string.content_description_move_to_archive),
// )
// },
// title = stringResource(R.string.label_move_to_archive),
// onItemClick = moveConversationToArchive
// )
// }
add {
MenuBottomSheetItem(
icon = {
MenuItemIcon(
id = R.drawable.ic_archive,
contentDescription = stringResource(R.string.content_description_move_to_archive),
)
},
title = stringResource(R.string.label_move_to_archive),
onItemClick = {
with(conversationSheetContent) {
moveConversationToArchive(
DialogState(
conversationId,
title,
conversationTypeDetail
)
)
}
})
}
add {
MenuBottomSheetItem(
icon = {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ private fun handleSnackBarMessage(
is HomeSnackbarState.ClearConversationContentSuccess -> stringResource(
if (messageType.isGroup) R.string.group_content_deleted else R.string.conversation_content_deleted
)

HomeSnackbarState.ArchivingConversationError -> stringResource(id = R.string.error_archiving_conversation)
HomeSnackbarState.ArchivingConversationSuccess -> stringResource(id = R.string.success_archiving_conversation)
}

LaunchedEffect(messageType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ sealed class HomeSnackbarState {
object DeleteConversationGroupError : HomeSnackbarState()
object LeftConversationSuccess : HomeSnackbarState()
object LeaveConversationError : HomeSnackbarState()
object ArchivingConversationSuccess : HomeSnackbarState()
object ArchivingConversationError : HomeSnackbarState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,25 @@ private fun GroupConversationDetailsContent(
isBottomSheetVisible = getBottomSheetVisibility,
conversationSheetState = conversationSheetState,
onMutingConversationStatusChange = {
bottomSheetEventsHandler.onMutingConversationStatusChange(
conversationSheetState.conversationId,
conversationSheetState.conversationSheetContent!!.mutingConversationState,
closeBottomSheetAndShowSnackbarMessage
)
conversationSheetContent?.let {
bottomSheetEventsHandler.onMutingConversationStatusChange(
conversationSheetState.conversationId,
it.mutingConversationState,
closeBottomSheetAndShowSnackbarMessage
)
}
},
addConversationToFavourites = bottomSheetEventsHandler::onAddConversationToFavourites,
moveConversationToFolder = bottomSheetEventsHandler::onMoveConversationToFolder,
moveConversationToArchive = bottomSheetEventsHandler::onMoveConversationToArchive,
moveConversationToArchive = {
conversationSheetContent?.let {
bottomSheetEventsHandler.onMoveConversationToArchive(
conversationId = it.conversationId,
shouldArchive = true,
onMessage = closeBottomSheetAndShowSnackbarMessage
)
}
},
clearConversationContent = clearConversationDialogState::show,
blockUser = {},
unblockUser = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.feature.conversation.ArchiveStatusUpdateResult
import com.wire.kalium.logic.feature.conversation.ClearConversationContentUseCase
import com.wire.kalium.logic.feature.conversation.ConversationUpdateReceiptModeResult
import com.wire.kalium.logic.feature.conversation.ConversationUpdateStatusResult
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationAccessRoleUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationReceiptModeUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
Expand Down Expand Up @@ -91,6 +93,7 @@ class GroupConversationDetailsViewModel @Inject constructor(
private val clearConversationContent: ClearConversationContentUseCase,
private val updateConversationReceiptMode: UpdateConversationReceiptModeUseCase,
private val observeSelfDeletionTimerSettingsForConversation: ObserveSelfDeletionTimerSettingsForConversationUseCase,
private val updateConversationArchivedStatus: UpdateConversationArchivedStatusUseCase,
override val savedStateHandle: SavedStateHandle,
private val isMLSEnabled: IsMLSEnabledUseCase,
refreshUsersWithoutMetadata: RefreshUsersWithoutMetadataUseCase,
Expand Down Expand Up @@ -375,8 +378,22 @@ class GroupConversationDetailsViewModel @Inject constructor(
override fun onMoveConversationToFolder(conversationId: ConversationId?) {
}

@Suppress("EmptyFunctionBlock")
override fun onMoveConversationToArchive(conversationId: ConversationId?) {
override fun onMoveConversationToArchive(
conversationId: ConversationId,
shouldArchive: Boolean,
timestamp: Long,
onMessage: (UIText) -> Unit
) {
viewModelScope.launch {
requestInProgress = true
val result =
withContext(dispatcher.io()) { updateConversationArchivedStatus(conversationId, shouldArchive, timestamp) }
requestInProgress = false
when (result) {
ArchiveStatusUpdateResult.Failure -> onMessage(UIText.StringResource(R.string.error_archiving_conversation))
ArchiveStatusUpdateResult.Success -> onMessage(UIText.StringResource(R.string.success_archiving_conversation))
}
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ import com.wire.android.ui.home.conversationslist.model.DialogState
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.util.DateTimeUtil

@Suppress("TooManyFunctions")
interface GroupConversationDetailsBottomSheetEventsHandler {
fun onMutingConversationStatusChange(conversationId: ConversationId?, status: MutedConversationStatus, onMessage: (UIText) -> Unit)
fun onAddConversationToFavourites(conversationId: ConversationId? = null)
fun onMoveConversationToFolder(conversationId: ConversationId? = null)
fun onMoveConversationToArchive(conversationId: ConversationId? = null)
fun onMoveConversationToArchive(
conversationId: ConversationId,
shouldArchive: Boolean,
timestamp: Long = DateTimeUtil.currentInstant().toEpochMilliseconds(),
onMessage: (UIText) -> Unit
)

fun onClearConversationContent(dialogState: DialogState, onMessage: (UIText) -> Unit)

companion object {
Expand All @@ -40,10 +47,19 @@ interface GroupConversationDetailsBottomSheetEventsHandler {
conversationId: ConversationId?,
status: MutedConversationStatus,
onMessage: (UIText) -> Unit
) {}
) {
}

override fun onAddConversationToFavourites(conversationId: ConversationId?) {}
override fun onMoveConversationToFolder(conversationId: ConversationId?) {}
override fun onMoveConversationToArchive(conversationId: ConversationId?) {}
override fun onMoveConversationToArchive(
conversationId: ConversationId,
shouldArchive: Boolean,
timestamp: Long,
onMessage: (UIText) -> Unit
) {
}

override fun onClearConversationContent(dialogState: DialogState, onMessage: (UIText) -> Unit) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,23 @@ internal fun MessageGenericAsset(
* @param resources: Resources - To be able to get String out of UIText message
* @return Pair<List<DisplayMention>, String>
*/
private fun mapToDisplayMentions(uiText: UIText, resources: Resources): Pair<List<DisplayMention>, String> {
fun mapToDisplayMentions(uiText: UIText, resources: Resources): Pair<List<DisplayMention>, String> {
return if (uiText is UIText.DynamicString) {
val stringBuilder: StringBuilder = StringBuilder(uiText.value)
val mentions = uiText.mentions.sortedBy { it.start }.reversed()
val mentionList = mentions.mapNotNull {
val mentions = uiText.mentions
.filter { it.start >= 0 && it.length > 0 }
.sortedBy { it.start }
.reversed()
val mentionList = mentions.mapNotNull { mention ->
// secured crash for mentions caused by web when text without mentions contains mention data
if (it.start + it.length <= uiText.value.length && uiText.value.elementAt(it.start) == '@') {
val mentionName = uiText.value.substring(it.start, it.start + it.length)
stringBuilder.insert(it.start + it.length, MENTION_MARK)
stringBuilder.insert(it.start, MENTION_MARK)
if (mention.start + mention.length <= uiText.value.length && uiText.value.elementAt(mention.start) == '@') {
val mentionName = uiText.value.substring(mention.start, mention.start + mention.length)
stringBuilder.insert(mention.start + mention.length, MENTION_MARK)
stringBuilder.insert(mention.start, MENTION_MARK)
DisplayMention(
it.userId,
it.length,
it.isSelfMention,
mention.userId,
mention.length,
mention.isSelfMention,
mentionName
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ import com.wire.kalium.logic.feature.connection.BlockUserResult
import com.wire.kalium.logic.feature.connection.BlockUserUseCase
import com.wire.kalium.logic.feature.connection.UnblockUserResult
import com.wire.kalium.logic.feature.connection.UnblockUserUseCase
import com.wire.kalium.logic.feature.conversation.ArchiveStatusUpdateResult
import com.wire.kalium.logic.feature.conversation.ClearConversationContentUseCase
import com.wire.kalium.logic.feature.conversation.ConversationUpdateStatusResult
import com.wire.kalium.logic.feature.conversation.LeaveConversationUseCase
import com.wire.kalium.logic.feature.conversation.ObserveConversationListDetailsUseCase
import com.wire.kalium.logic.feature.conversation.RefreshConversationsWithoutMetadataUseCase
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
import com.wire.kalium.logic.feature.team.DeleteTeamConversationUseCase
import com.wire.kalium.logic.feature.team.Result
import com.wire.kalium.logic.functional.combine
import com.wire.kalium.util.DateTimeUtil
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -108,7 +111,8 @@ class ConversationListViewModel @Inject constructor(
private val userTypeMapper: UserTypeMapper,
private val endCall: EndCallUseCase,
private val refreshUsersWithoutMetadata: RefreshUsersWithoutMetadataUseCase,
private val refreshConversationsWithoutMetadata: RefreshConversationsWithoutMetadataUseCase
private val refreshConversationsWithoutMetadata: RefreshConversationsWithoutMetadataUseCase,
private val updateConversationArchivedStatus: UpdateConversationArchivedStatusUseCase,
) : ViewModel() {

var conversationListState by mutableStateOf(ConversationListState())
Expand Down Expand Up @@ -148,7 +152,7 @@ class ConversationListViewModel @Inject constructor(
}
viewModelScope.launch {
searchQueryFlow.combine(
observeConversationListDetails()
observeConversationListDetails(includeArchived = false)
.map {
it.map { conversationDetails ->
conversationDetails.toConversationItem(
Expand Down Expand Up @@ -417,9 +421,25 @@ class ConversationListViewModel @Inject constructor(
fun moveConversationToFolder(id: String = "") {
}

// TODO: needs to be implemented
@Suppress("EmptyFunctionBlock")
fun moveConversationToArchive(id: String = "") {
fun moveConversationToArchive(
conversationId: ConversationId,
isArchiving: Boolean,
timestamp: Long = DateTimeUtil.currentInstant().toEpochMilliseconds()
) {
viewModelScope.launch {
requestInProgress = true
val result = withContext(dispatcher.io()) { updateConversationArchivedStatus(conversationId, isArchiving, timestamp) }
requestInProgress = false
when (result) {
is ArchiveStatusUpdateResult.Failure -> {
homeSnackBarState.emit(HomeSnackbarState.ArchivingConversationError)
}

is ArchiveStatusUpdateResult.Success -> {
homeSnackBarState.emit(HomeSnackbarState.ArchivingConversationSuccess)
}
}
}
}

fun clearConversationContent(dialogState: DialogState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ fun ConversationRouterHomeBridge(
},
addConversationToFavourites = viewModel::addConversationToFavourites,
moveConversationToFolder = viewModel::moveConversationToFolder,
moveConversationToArchive = viewModel::moveConversationToArchive,
moveConversationToArchive = {
viewModel.moveConversationToArchive(
conversationId = it.conversationId,
isArchiving = true // All conversations at this point are not archived
)
onCloseBottomSheet()
},
clearConversationContent = clearContentDialogState::show,
blockUser = blockUserDialogState::show,
unblockUser = unblockUserDialogState::show,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
@OptIn(ExperimentalCoroutinesApi::class)
private suspend fun observeConversationWithSearch() = viewModelScope.launch {
searchQueryFlow.mapLatest { searchQuery ->
val conversations = observeConversationListDetails().first()
val conversations = observeConversationListDetails(includeArchived = false).first()
.mapNotNull { conversationDetails ->
conversationDetails.toConversationItem(
wireSessionImageLoader,
Expand Down
Loading

0 comments on commit d42fc90

Please sign in to comment.