mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 12:19:54 +00:00
ui: drop filter when no such tags exist (#5662)
* ui: drop filter when no such tags exist * ios * android/desktop * change * change * ios * change * change * ios * android * ios
This commit is contained in:
parent
b96b6c70d2
commit
c972298dd2
3 changed files with 31 additions and 19 deletions
|
@ -123,11 +123,9 @@ class ChatTagsModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
if case let .presetTag(tag) = tm.activeFilter, (newPresetTags[tag] ?? 0) == 0 {
|
||||
activeFilter = nil
|
||||
}
|
||||
presetTags = newPresetTags
|
||||
unreadTags = newUnreadTags
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
|
||||
func updateChatFavorite(favorite: Bool, wasFavorite: Bool) {
|
||||
|
@ -136,9 +134,7 @@ class ChatTagsModel: ObservableObject {
|
|||
presetTags[.favorites] = (count ?? 0) + 1
|
||||
} else if !favorite && wasFavorite, let count {
|
||||
presetTags[.favorites] = max(0, count - 1)
|
||||
if case .presetTag(.favorites) = activeFilter, (presetTags[.favorites] ?? 0) == 0 {
|
||||
activeFilter = nil
|
||||
}
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,6 +158,7 @@ class ChatTagsModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
|
||||
func markChatTagRead(_ chat: Chat) -> Void {
|
||||
|
@ -192,7 +189,17 @@ class ChatTagsModel: ObservableObject {
|
|||
|
||||
func changeGroupReportsTag(_ by: Int = 0) {
|
||||
if by == 0 { return }
|
||||
presetTags[.groupReports] = (presetTags[.groupReports] ?? 0) + by
|
||||
presetTags[.groupReports] = max(0, (presetTags[.groupReports] ?? 0) + by)
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
|
||||
func clearActiveChatFilterIfNeeded() {
|
||||
let clear = switch activeFilter {
|
||||
case let .presetTag(tag): (presetTags[tag] ?? 0) == 0
|
||||
case let .userTag(tag): !userTags.contains(tag)
|
||||
case .unread, nil: false
|
||||
}
|
||||
if clear { activeFilter = nil }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -247,15 +247,12 @@ object ChatModel {
|
|||
}
|
||||
}
|
||||
|
||||
if (activeChatTagFilter.value is ActiveFilter.PresetTag &&
|
||||
(newPresetTags[(activeChatTagFilter.value as ActiveFilter.PresetTag).tag] ?: 0) == 0) {
|
||||
activeChatTagFilter.value = null
|
||||
}
|
||||
|
||||
presetTags.clear()
|
||||
presetTags.putAll(newPresetTags)
|
||||
unreadTags.clear()
|
||||
unreadTags.putAll(newUnreadTags)
|
||||
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
|
||||
fun updateChatFavorite(favorite: Boolean, wasFavorite: Boolean) {
|
||||
|
@ -265,9 +262,7 @@ object ChatModel {
|
|||
presetTags[PresetTagKind.FAVORITES] = (count ?: 0) + 1
|
||||
} else if (!favorite && wasFavorite && count != null) {
|
||||
presetTags[PresetTagKind.FAVORITES] = maxOf(0, count - 1)
|
||||
if (activeChatTagFilter.value == ActiveFilter.PresetTag(PresetTagKind.FAVORITES) && (presetTags[PresetTagKind.FAVORITES] ?: 0) == 0) {
|
||||
activeChatTagFilter.value = null
|
||||
}
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,6 +283,7 @@ object ChatModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
|
||||
fun moveChatTagUnread(chat: Chat, oldTags: List<Long>?, newTags: List<Long>) {
|
||||
|
@ -875,10 +871,20 @@ object ChatModel {
|
|||
|
||||
private fun changeGroupReportsTagNoContentTag(by: Int = 0) {
|
||||
if (by == 0 || contentTag != null) return
|
||||
presetTags[PresetTagKind.GROUP_REPORTS] = (presetTags[PresetTagKind.GROUP_REPORTS] ?: 0) + by
|
||||
presetTags[PresetTagKind.GROUP_REPORTS] = kotlin.math.max(0, (presetTags[PresetTagKind.GROUP_REPORTS] ?: 0) + by)
|
||||
clearActiveChatFilterIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
fun clearActiveChatFilterIfNeeded() {
|
||||
val clear = when(val f = activeChatTagFilter.value) {
|
||||
is ActiveFilter.PresetTag -> (presetTags[f.tag] ?: 0) == 0
|
||||
is ActiveFilter.UserTag -> userTags.value.none { it.chatTagId == f.tag.chatTagId }
|
||||
is ActiveFilter.Unread, null -> false
|
||||
}
|
||||
if (clear) activeChatTagFilter.value = null
|
||||
}
|
||||
|
||||
fun updateCurrentUser(rhId: Long?, newProfile: Profile, preferences: FullChatPreferences? = null) {
|
||||
val current = currentUser.value ?: return
|
||||
val updated = current.copy(
|
||||
|
|
|
@ -31,6 +31,7 @@ import chat.simplex.common.model.*
|
|||
import chat.simplex.common.model.ChatController.apiDeleteChatTag
|
||||
import chat.simplex.common.model.ChatController.apiSetChatTags
|
||||
import chat.simplex.common.model.ChatController.appPrefs
|
||||
import chat.simplex.common.model.ChatModel.clearActiveChatFilterIfNeeded
|
||||
import chat.simplex.common.model.ChatModel.withChats
|
||||
import chat.simplex.common.model.ChatModel.withReportsChatsIfOpen
|
||||
import chat.simplex.common.platform.*
|
||||
|
@ -447,9 +448,7 @@ private fun deleteTag(rhId: Long?, tag: ChatTag, saving: MutableState<Boolean>)
|
|||
val tagId = tag.chatTagId
|
||||
if (apiDeleteChatTag(rhId, tagId)) {
|
||||
chatModel.userTags.value = chatModel.userTags.value.filter { it.chatTagId != tagId }
|
||||
if (chatModel.activeChatTagFilter.value == ActiveFilter.UserTag(tag)) {
|
||||
chatModel.activeChatTagFilter.value = null
|
||||
}
|
||||
clearActiveChatFilterIfNeeded()
|
||||
chatModel.chats.value.forEach { c ->
|
||||
when (val cInfo = c.chatInfo) {
|
||||
is ChatInfo.Direct -> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue