groupInfo button and closing when needed

This commit is contained in:
Avently
2025-01-10 17:53:06 +07:00
parent 473fdedf23
commit 1b46bf12f4
4 changed files with 42 additions and 16 deletions
@@ -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 ->
@@ -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<String, GroupMemberRole>?) -> Unit, close: () -> Unit, onSearchClicked: () -> Unit) {
fun ModalData.GroupChatInfoView(chatModel: ChatModel, rhId: Long?, chatId: String, groupLink: String?, groupLinkMemberRole: GroupMemberRole?, scrollToItemId: MutableState<Long?>, onGroupLinkUpdated: (Pair<String, GroupMemberRole>?) -> 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<GroupMember>,
developerTools: Boolean,
groupLink: String?,
scrollToItemId: MutableState<Long?>,
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<SendReceipts>, 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 = {},
)
}
@@ -39,7 +39,7 @@ data class GroupReports(
}
@Composable
fun GroupReportsView(staleChatId: State<String?>, scrollToItemId: MutableState<Long?>) {
private fun GroupReportsView(staleChatId: State<String?>, scrollToItemId: MutableState<Long?>) {
ChatView(staleChatId, reportsView = true, scrollToItemId, onComposed = {})
}
@@ -140,6 +140,24 @@ private fun ItemsReload(groupReports: State<GroupReports>) {
}
}
}
suspend fun showGroupReportsView(staleChatId: State<String?>, scrollToItemId: MutableState<Long?>, 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<GroupReports>) {
val contentFilter = groupReports.value.toContentFilter()
if (chat.chatStats.reportsCount > 0 || contentFilter?.deleted == true) {
@@ -447,6 +447,7 @@
<string name="group_reports_active_one">1 report</string>
<string name="group_reports_active">%d reports</string>
<string name="group_reports_member_reports">Member reports</string>
<string name="group_reports_archived_member_reports">Archived member reports</string>
<string name="group_reports_show_archived">Show archived</string>
<string name="group_reports_show_active">Show active</string>