mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-22 21:52:28 +00:00
removed support of archived page and counter
This commit is contained in:
1 parent
8912c5dbc2
commit
b7b4059225
7 files changed
+24
-67
No files matched your search
+4
-4
@@ -811,14 +811,13 @@ object ChatModel {
|
||||
}
|
||||
}
|
||||
|
||||
fun decreaseGroupReportsCounter(rhId: Long?, chatId: ChatId, wasArchived: Boolean) {
|
||||
fun decreaseGroupReportsCounter(rhId: Long?, chatId: ChatId) {
|
||||
val i = getChatIndex(rhId, chatId)
|
||||
if (i >= 0) {
|
||||
val chat = chats.value[i]
|
||||
chats[i] = chat.copy(
|
||||
chatStats = chat.chatStats.copy(
|
||||
reportsCount = (chat.chatStats.reportsCount - 1).coerceAtLeast(0),
|
||||
archivedReportsCount = if (wasArchived) chat.chatStats.archivedReportsCount + 1 else chat.chatStats.archivedReportsCount
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1235,8 +1234,6 @@ data class Chat(
|
||||
val unreadCount: Int = 0,
|
||||
// actual only via getChats() and getChat(.initial), otherwise, zero
|
||||
val reportsCount: Int = 0,
|
||||
// actual only via getChat(.initial), otherwise, zero
|
||||
val archivedReportsCount: Int = 0,
|
||||
val minUnreadItemId: Long = 0,
|
||||
val unreadChat: Boolean = false
|
||||
)
|
||||
@@ -1759,6 +1756,9 @@ data class GroupInfo (
|
||||
val canAddMembers: Boolean
|
||||
get() = membership.memberRole >= GroupMemberRole.Admin && membership.memberActive
|
||||
|
||||
val canModerate: Boolean
|
||||
get() = membership.memberRole >= GroupMemberRole.Moderator && membership.memberActive
|
||||
|
||||
companion object {
|
||||
val sampleData = GroupInfo(
|
||||
groupId = 1,
|
||||
|
||||
+4
-6
@@ -2606,15 +2606,14 @@ object ChatController {
|
||||
generalGetString(MR.strings.marked_deleted_description)
|
||||
)
|
||||
}
|
||||
val wasModerated = r.member_ != null && (cItem.chatDir as CIDirection.GroupRcv?)?.groupMember != r.member_
|
||||
val deleted = if (wasModerated && r.member_ != null) {
|
||||
val deleted = if (r.member_ != null && (cItem.chatDir as CIDirection.GroupRcv?)?.groupMember != r.member_) {
|
||||
CIDeleted.Moderated(Clock.System.now(), r.member_)
|
||||
} else {
|
||||
CIDeleted.Deleted(Clock.System.now())
|
||||
}
|
||||
upsertChatItem(rhId, cInfo, cItem.copy(meta = cItem.meta.copy(itemDeleted = deleted)))
|
||||
if (cItem.isActiveReport) {
|
||||
decreaseGroupReportsCounter(rhId, cInfo.id, wasModerated)
|
||||
decreaseGroupReportsCounter(rhId, cInfo.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3491,7 +3490,7 @@ sealed class CC {
|
||||
val filter = if (contentFilter == null) {
|
||||
""
|
||||
} else {
|
||||
" content=${contentFilter.mcTag.name.lowercase()} deleted=${onOff(contentFilter.deleted ?: true)}"
|
||||
" content=${contentFilter.mcTag.name.lowercase()}"
|
||||
}
|
||||
"/_get chat ${chatRef(type, id)}$filter ${pagination.cmdString}" + (if (search == "") "" else " search=$search")
|
||||
}
|
||||
@@ -3832,8 +3831,7 @@ data class NewUser(
|
||||
)
|
||||
|
||||
data class ContentFilter(
|
||||
val mcTag: MsgContentTag,
|
||||
val deleted: Boolean?
|
||||
val mcTag: MsgContentTag
|
||||
)
|
||||
|
||||
sealed class ChatPagination {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ suspend fun apiLoadSingleMessage(
|
||||
itemId: Long,
|
||||
contentTag: MsgContentTag?,
|
||||
): ChatItem? = coroutineScope {
|
||||
val contentFilter = if (contentTag != null) ContentFilter(contentTag, true) else null
|
||||
val contentFilter = if (contentTag != null) ContentFilter(contentTag) else null
|
||||
val (chat, _) = chatModel.controller.apiGetChat(rhId, chatType, apiId, contentFilter, ChatPagination.Around(itemId, 0), "") ?: return@coroutineScope null
|
||||
chat.chatItems.firstOrNull()
|
||||
}
|
||||
|
||||
+5
-15
@@ -76,10 +76,9 @@ fun ChatView(
|
||||
ModalManager.end.closeModals()
|
||||
}
|
||||
} else {
|
||||
val showArchivedReports = remember { mutableStateOf(if (reportsView) reportsShowArchived else false) }
|
||||
val groupReports = remember { derivedStateOf {
|
||||
val reportsCount = if (activeChatInfo.value is ChatInfo.Group) activeChatStats.value?.reportsCount ?: 0 else 0
|
||||
GroupReports(reportsCount, reportsView, showArchivedReports.value) }
|
||||
GroupReports(reportsCount, reportsView) }
|
||||
}
|
||||
val reversedChatItems = remember { derivedStateOf { chatModel.chatItemsForContent(groupReports.value.contentTag).value.asReversed() } }
|
||||
val searchText = rememberSaveable { mutableStateOf("") }
|
||||
@@ -240,7 +239,6 @@ fun ChatView(
|
||||
}
|
||||
},
|
||||
groupReports,
|
||||
showArchivedReports,
|
||||
scrollToItemId,
|
||||
attachmentOption,
|
||||
attachmentBottomSheetState,
|
||||
@@ -387,7 +385,7 @@ fun ChatView(
|
||||
}
|
||||
val deletedItem = deleted.deletedChatItem.chatItem
|
||||
if (deletedItem.isActiveReport) {
|
||||
decreaseGroupReportsCounter(chatRh, chatInfo.id, toChatItem != null)
|
||||
decreaseGroupReportsCounter(chatRh, chatInfo.id)
|
||||
}
|
||||
}
|
||||
withReportsChatsIfOpen {
|
||||
@@ -667,7 +665,6 @@ fun ChatLayout(
|
||||
composeState: MutableState<ComposeState>,
|
||||
composeView: (@Composable () -> Unit),
|
||||
groupReports: State<GroupReports>,
|
||||
showArchivedReports: MutableState<Boolean>,
|
||||
scrollToItemId: MutableState<Long?>,
|
||||
attachmentOption: MutableState<AttachmentOption?>,
|
||||
attachmentBottomSheetState: ModalBottomSheetState,
|
||||
@@ -824,9 +821,7 @@ fun ChatLayout(
|
||||
Column(if (oneHandUI.value) Modifier.align(Alignment.BottomStart).imePadding() else Modifier) {
|
||||
Box {
|
||||
if (selectedChatItems.value == null) {
|
||||
GroupReportsAppBar(groupReports, { ModalManager.end.closeModal() }, showArchived = { showHide ->
|
||||
showArchivedReports.value = showHide
|
||||
}, onSearchValueChanged)
|
||||
GroupReportsAppBar(groupReports, { ModalManager.end.closeModal() }, onSearchValueChanged)
|
||||
} else {
|
||||
SelectedItemsTopToolbar(selectedChatItems, !oneHandUI.value)
|
||||
}
|
||||
@@ -1113,7 +1108,6 @@ private fun ContactVerifiedShield() {
|
||||
|
||||
/** Saves current scroll position when [GroupReports] are open and user opens [ChatItemInfoView], for example, and goes back */
|
||||
private var reportsListState: LazyListState? = null
|
||||
private var reportsShowArchived: Boolean = false
|
||||
|
||||
@Composable
|
||||
fun BoxScope.ChatItemsList(
|
||||
@@ -1165,12 +1159,11 @@ fun BoxScope.ChatItemsList(
|
||||
val maxHeightForList = rememberUpdatedState(
|
||||
with(LocalDensity.current) { LocalWindowHeight().roundToPx() - topPaddingToContentPx.value - (AppBarHeight * fontSizeSqrtMultiplier * 2).roundToPx() }
|
||||
)
|
||||
val listState = rememberUpdatedState(rememberSaveable(chatInfo.id, searchValueIsEmpty.value, groupReports.value.showArchived, saver = LazyListState.Saver) {
|
||||
val listState = rememberUpdatedState(rememberSaveable(chatInfo.id, searchValueIsEmpty.value, saver = LazyListState.Saver) {
|
||||
val index = mergedItems.value.items.indexOfLast { it.hasUnread() }
|
||||
val reportsState = reportsListState
|
||||
if (reportsState != null) {
|
||||
reportsListState = null
|
||||
reportsShowArchived = false
|
||||
reportsState
|
||||
} else if (index <= 0) {
|
||||
LazyListState(0, 0)
|
||||
@@ -1968,7 +1961,6 @@ private fun SaveReportsStateOnDispose(groupReports: State<GroupReports>, listSta
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
reportsListState = if (groupReports.value.reportsView && ModalManager.end.hasModalOpen(ModalViewId.GROUP_REPORTS)) listState.value else null
|
||||
reportsShowArchived = if (groupReports.value.reportsView && ModalManager.end.hasModalOpen(ModalViewId.GROUP_REPORTS)) groupReports.value.showArchived else false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2322,7 +2314,7 @@ private fun deleteMessages(chatRh: Long?, chatInfo: ChatInfo, itemIds: List<Long
|
||||
}
|
||||
val deletedItem = di.deletedChatItem.chatItem
|
||||
if (deletedItem.isActiveReport) {
|
||||
decreaseGroupReportsCounter(chatRh, chatInfo.id, toChatItem != null)
|
||||
decreaseGroupReportsCounter(chatRh, chatInfo.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2680,7 +2672,6 @@ fun PreviewChatLayout() {
|
||||
composeState = remember { mutableStateOf(ComposeState(useLinkPreviews = true)) },
|
||||
composeView = {},
|
||||
groupReports = remember { mutableStateOf(GroupReports(0, false)) },
|
||||
showArchivedReports = remember { mutableStateOf(false) },
|
||||
scrollToItemId = remember { mutableStateOf(null) },
|
||||
attachmentOption = remember { mutableStateOf<AttachmentOption?>(null) },
|
||||
attachmentBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden),
|
||||
@@ -2758,7 +2749,6 @@ fun PreviewGroupChatLayout() {
|
||||
composeState = remember { mutableStateOf(ComposeState(useLinkPreviews = true)) },
|
||||
composeView = {},
|
||||
groupReports = remember { mutableStateOf(GroupReports(0, false)) },
|
||||
showArchivedReports = remember { mutableStateOf(false) },
|
||||
scrollToItemId = remember { mutableStateOf(null) },
|
||||
attachmentOption = remember { mutableStateOf<AttachmentOption?>(null) },
|
||||
attachmentBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden),
|
||||
|
||||
+4
-4
@@ -364,8 +364,8 @@ 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) {
|
||||
if (groupInfo.canModerate) {
|
||||
GroupReportsButton {
|
||||
scope.launch {
|
||||
showGroupReportsView(chatModel.chatId, scrollToItemId, chat.chatInfo)
|
||||
}
|
||||
@@ -501,10 +501,10 @@ private fun GroupPreferencesButton(titleId: StringResource, onClick: () -> Unit)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GroupReportsButton(chatStats: Chat.ChatStats, onClick: () -> Unit) {
|
||||
private fun GroupReportsButton(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),
|
||||
stringResource(MR.strings.group_reports_member_reports),
|
||||
click = onClick
|
||||
)
|
||||
}
|
||||
|
||||
+6
-35
@@ -26,13 +26,12 @@ val LocalContentTag: ProvidableCompositionLocal<MsgContentTag?> = staticComposit
|
||||
data class GroupReports(
|
||||
val reportsCount: Int,
|
||||
val reportsView: Boolean,
|
||||
val showArchived: Boolean = false
|
||||
) {
|
||||
val showBar: Boolean = reportsCount > 0 && !reportsView
|
||||
|
||||
fun toContentFilter(): ContentFilter? {
|
||||
if (!reportsView) return null
|
||||
return ContentFilter(MsgContentTag.Report, deleted = showArchived)
|
||||
return ContentFilter(MsgContentTag.Report)
|
||||
}
|
||||
|
||||
val contentTag: MsgContentTag? = if (!reportsView) null else MsgContentTag.Report
|
||||
@@ -47,7 +46,6 @@ private fun GroupReportsView(staleChatId: State<String?>, scrollToItemId: Mutabl
|
||||
fun GroupReportsAppBar(
|
||||
groupReports: State<GroupReports>,
|
||||
close: () -> Unit,
|
||||
showArchived: (Boolean) -> Unit,
|
||||
onSearchValueChanged: (String) -> Unit
|
||||
) {
|
||||
val oneHandUI = remember { appPrefs.oneHandUI.state }
|
||||
@@ -97,28 +95,7 @@ fun GroupReportsAppBar(
|
||||
showSearch.value = true
|
||||
})
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ShowHideArchived() {
|
||||
ItemAction(
|
||||
if (groupReports.value.showArchived) stringResource(MR.strings.group_reports_show_active) else stringResource(MR.strings.group_reports_show_archived),
|
||||
painterResource(if (groupReports.value.showArchived) MR.images.ic_flag else MR.images.ic_inventory_2),
|
||||
onClick = {
|
||||
onClosedAction.value = {
|
||||
showArchived(!groupReports.value.showArchived)
|
||||
onClosedAction.value = {}
|
||||
}
|
||||
showMenu.value = false
|
||||
}
|
||||
)
|
||||
}
|
||||
if (oneHandUI.value) {
|
||||
ShowHideArchived()
|
||||
Search()
|
||||
} else {
|
||||
Search()
|
||||
ShowHideArchived()
|
||||
}
|
||||
Search()
|
||||
}
|
||||
}
|
||||
ItemsReload(groupReports)
|
||||
@@ -127,10 +104,9 @@ fun GroupReportsAppBar(
|
||||
@Composable
|
||||
private fun ItemsReload(groupReports: State<GroupReports>) {
|
||||
LaunchedEffect(Unit) {
|
||||
snapshotFlow { groupReports.value.showArchived to chatModel.chatId.value }
|
||||
snapshotFlow { chatModel.chatId.value }
|
||||
.distinctUntilChanged()
|
||||
.drop(1)
|
||||
.map { it.second }
|
||||
.filterNotNull()
|
||||
.map { chatModel.getChat(it) }
|
||||
.filterNotNull()
|
||||
@@ -142,12 +118,11 @@ 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))
|
||||
openChat(chatModel.remoteHostId(), chatInfo, ContentFilter(MsgContentTag.Report))
|
||||
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)) {
|
||||
if (chatInfo is ChatInfo.Group && chatInfo.groupInfo.canModerate) {
|
||||
GroupReportsView(staleChatId, scrollToItemId)
|
||||
} else {
|
||||
LaunchedEffect(Unit) {
|
||||
@@ -160,9 +135,5 @@ suspend fun showGroupReportsView(staleChatId: State<String?>, scrollToItemId: Mu
|
||||
|
||||
private suspend fun reloadItems(chat: Chat, groupReports: State<GroupReports>) {
|
||||
val contentFilter = groupReports.value.toContentFilter()
|
||||
if (chat.chatStats.reportsCount > 0 || contentFilter?.deleted == true) {
|
||||
apiLoadMessages(chat.remoteHostId, chat.chatInfo.chatType, chat.chatInfo.apiId, contentFilter, ChatPagination.Initial(ChatPagination.INITIAL_COUNT))
|
||||
} else {
|
||||
openLoadedChat(chat.copy(chatItems = emptyList()), contentTag = contentFilter?.mcTag)
|
||||
}
|
||||
apiLoadMessages(chat.remoteHostId, chat.chatInfo.chatType, chat.chatInfo.apiId, contentFilter, ChatPagination.Initial(ChatPagination.INITIAL_COUNT))
|
||||
}
|
||||
@@ -448,8 +448,6 @@
|
||||
<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>
|
||||
|
||||
<!-- ShareListView.kt -->
|
||||
<string name="share_message">Share message…</string>
|
||||
|
||||
Reference in new issue
Block a user