From 1b46bf12f4f95a6e57e0a048e8a8df70e4088f31 Mon Sep 17 00:00:00 2001 From: Avently <7953703+avently@users.noreply.github.com> Date: Fri, 10 Jan 2025 17:53:06 +0700 Subject: [PATCH] groupInfo button and closing when needed --- .../simplex/common/views/chat/ChatView.kt | 16 ++------------ .../views/chat/group/GroupChatInfoView.kt | 21 ++++++++++++++++++- .../views/chat/group/GroupReportsView.kt | 20 +++++++++++++++++- .../commonMain/resources/MR/base/strings.xml | 1 + 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index 7c2b38c73c..23b0249f39 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -297,7 +297,7 @@ fun ChatView( link = chatModel.controller.apiGetGroupLink(chatRh, chatInfo.groupInfo.groupId) preloadedLink = link } - GroupChatInfoView(chatModel, chatRh, chatInfo.id, link?.first, link?.second, { + GroupChatInfoView(chatModel, chatRh, chatInfo.id, link?.first, link?.second, scrollToItemId, { link = it preloadedLink = it }, close, { showSearch.value = true }) @@ -317,19 +317,7 @@ fun ChatView( } hideKeyboard(view) scope.launch { - openChat(chatModel.remoteHostId(), info, ContentFilter(MsgContentTag.Report, false)) - ModalManager.end.showCustomModal(true, id = ModalViewId.GROUP_REPORTS) { close -> - ModalView({}, showAppBar = false) { - val chatInfo = remember { activeChatInfo }.value - if (chatInfo is ChatInfo.Group) { - GroupReportsView(staleChatId, scrollToItemId) - } else { - LaunchedEffect(Unit) { - close() - } - } - } - } + showGroupReportsView(staleChatId, scrollToItemId, info) } }, showMemberInfo = { groupInfo: GroupInfo, member: GroupMember -> diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt index 0689c382f3..50d25b037d 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupChatInfoView.kt @@ -46,7 +46,7 @@ import kotlinx.coroutines.* const val SMALL_GROUPS_RCPS_MEM_LIMIT: Int = 20 @Composable -fun ModalData.GroupChatInfoView(chatModel: ChatModel, rhId: Long?, chatId: String, groupLink: String?, groupLinkMemberRole: GroupMemberRole?, onGroupLinkUpdated: (Pair?) -> Unit, close: () -> Unit, onSearchClicked: () -> Unit) { +fun ModalData.GroupChatInfoView(chatModel: ChatModel, rhId: Long?, chatId: String, groupLink: String?, groupLinkMemberRole: GroupMemberRole?, scrollToItemId: MutableState, onGroupLinkUpdated: (Pair?) -> Unit, close: () -> Unit, onSearchClicked: () -> Unit) { BackHandler(onBack = close) // TODO derivedStateOf? val chat = chatModel.chats.value.firstOrNull { ch -> ch.id == chatId && ch.remoteHostId == rhId } @@ -71,6 +71,7 @@ fun ModalData.GroupChatInfoView(chatModel: ChatModel, rhId: Long?, chatId: Strin .sortedByDescending { it.memberRole }, developerTools, groupLink, + scrollToItemId, addMembers = { scope.launch(Dispatchers.Default) { setGroupMembers(rhId, groupInfo, chatModel) @@ -286,6 +287,7 @@ fun ModalData.GroupChatInfoLayout( members: List, developerTools: Boolean, groupLink: String?, + scrollToItemId: MutableState, addMembers: () -> Unit, showMemberInfo: (GroupMember) -> Unit, editGroupProfile: () -> Unit, @@ -362,6 +364,13 @@ fun ModalData.GroupChatInfoLayout( } val prefsTitleId = if (groupInfo.businessChat == null) MR.strings.group_preferences else MR.strings.chat_preferences GroupPreferencesButton(prefsTitleId, openPreferences) + if (chat.chatStats.reportsCount > 0 || chat.chatStats.archivedReportsCount > 0) { + GroupReportsButton(chat.chatStats) { + scope.launch { + showGroupReportsView(chatModel.chatId, scrollToItemId, chat.chatInfo) + } + } + } if (members.filter { it.memberCurrent }.size <= SMALL_GROUPS_RCPS_MEM_LIMIT) { SendReceiptsOption(currentUser, sendReceipts, setSendReceipts) } else { @@ -491,6 +500,15 @@ private fun GroupPreferencesButton(titleId: StringResource, onClick: () -> Unit) ) } +@Composable +private fun GroupReportsButton(chatStats: Chat.ChatStats, onClick: () -> Unit) { + SettingsActionItem( + painterResource(MR.images.ic_flag), + stringResource(if (chatStats.reportsCount > 0) MR.strings.group_reports_member_reports else MR.strings.group_reports_archived_member_reports), + click = onClick + ) +} + @Composable private fun SendReceiptsOption(currentUser: User, state: State, onSelected: (SendReceipts) -> Unit) { val values = remember { @@ -741,6 +759,7 @@ fun PreviewGroupChatInfoLayout() { members = listOf(GroupMember.sampleData, GroupMember.sampleData, GroupMember.sampleData), developerTools = false, groupLink = null, + scrollToItemId = remember { mutableStateOf(null) }, addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, addOrEditWelcomeMessage = {}, openPreferences = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {}, manageGroupLink = {}, onSearchClicked = {}, ) } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupReportsView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupReportsView.kt index bb3482d47a..23907d9570 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupReportsView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/group/GroupReportsView.kt @@ -39,7 +39,7 @@ data class GroupReports( } @Composable -fun GroupReportsView(staleChatId: State, scrollToItemId: MutableState) { +private fun GroupReportsView(staleChatId: State, scrollToItemId: MutableState) { ChatView(staleChatId, reportsView = true, scrollToItemId, onComposed = {}) } @@ -140,6 +140,24 @@ private fun ItemsReload(groupReports: State) { } } } + +suspend fun showGroupReportsView(staleChatId: State, scrollToItemId: MutableState, chatInfo: ChatInfo) { + openChat(chatModel.remoteHostId(), chatInfo, ContentFilter(MsgContentTag.Report, false)) + ModalManager.end.showCustomModal(true, id = ModalViewId.GROUP_REPORTS) { close -> + ModalView({}, showAppBar = false) { + val chatInfo = remember { derivedStateOf { chatModel.chats.value.firstOrNull { it.id == chatModel.chatId.value }?.chatInfo } }.value + val chatStats = remember { derivedStateOf { chatModel.chats.value.firstOrNull { it.id == chatModel.chatId.value }?.chatStats } }.value + if (chatInfo is ChatInfo.Group && chatStats != null && (chatStats.reportsCount > 0 || chatStats.archivedReportsCount > 0)) { + GroupReportsView(staleChatId, scrollToItemId) + } else { + LaunchedEffect(Unit) { + close() + } + } + } + } +} + private suspend fun reloadItems(chat: Chat, groupReports: State) { val contentFilter = groupReports.value.toContentFilter() if (chat.chatStats.reportsCount > 0 || contentFilter?.deleted == true) { diff --git a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml index bec9103bc1..2451114af4 100644 --- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml +++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml @@ -447,6 +447,7 @@ 1 report %d reports Member reports + Archived member reports Show archived Show active