添加更多消息clear时间区间

This commit is contained in:
Fin 2025-01-08 12:02:51 +08:00
parent d9da712af3
commit 5bcfd1ba3c
7 changed files with 421 additions and 99 deletions

View File

@ -100,6 +100,7 @@
066890082D1946D500E106F2 /* MessageItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066890072D1946D500E106F2 /* MessageItemView.swift */; };
0668900B2D19525400E106F2 /* ShowLessAndClearView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0668900A2D19525400E106F2 /* ShowLessAndClearView.swift */; };
0668900D2D19582400E106F2 /* MessageGroupHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0668900C2D19582400E106F2 /* MessageGroupHeaderView.swift */; };
066DF4822D2D31A60092B04E /* MessageDeleteTimeRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */; };
066E0C8C2BB6AC9A00873838 /* AddSoundCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */; };
0672CB06256903F700570C9D /* MessageListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0672CB05256903F700570C9D /* MessageListViewModel.swift */; };
06787C392A710568008ABDD7 /* GesturePassTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06787C382A710568008ABDD7 /* GesturePassTextView.swift */; };
@ -112,6 +113,7 @@
0687F2AA2CCB7FA500B2A52F /* UIFont+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */; };
06885EB6247FB9880004A303 /* MessageSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */; };
0689CF4C2C7484A7007203A6 /* BarkTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */; };
068A4B962D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */; };
068EC15827ED99C900D5D11E /* ServerListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15727ED99C900D5D11E /* ServerListViewController.swift */; };
068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15927ED99E700D5D11E /* ServerListViewModel.swift */; };
068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068F66B2247BD84C00DAD25A /* MessageListViewController.swift */; };
@ -343,6 +345,7 @@
066890072D1946D500E106F2 /* MessageItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageItemView.swift; sourceTree = "<group>"; };
0668900A2D19525400E106F2 /* ShowLessAndClearView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowLessAndClearView.swift; sourceTree = "<group>"; };
0668900C2D19582400E106F2 /* MessageGroupHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageGroupHeaderView.swift; sourceTree = "<group>"; };
066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDeleteTimeRange.swift; sourceTree = "<group>"; };
066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddSoundCell.swift; sourceTree = "<group>"; };
0672CB05256903F700570C9D /* MessageListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewModel.swift; sourceTree = "<group>"; };
06787C382A710568008ABDD7 /* GesturePassTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturePassTextView.swift; sourceTree = "<group>"; };
@ -355,6 +358,7 @@
0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extension.swift"; sourceTree = "<group>"; };
06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSettingsViewController.swift; sourceTree = "<group>"; };
0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkTabBarController.swift; sourceTree = "<group>"; };
068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDeleteTimeRangeTest.swift; sourceTree = "<group>"; };
068EC15727ED99C900D5D11E /* ServerListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewController.swift; sourceTree = "<group>"; };
068EC15927ED99E700D5D11E /* ServerListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewModel.swift; sourceTree = "<group>"; };
068F66B2247BD84C00DAD25A /* MessageListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewController.swift; sourceTree = "<group>"; };
@ -538,6 +542,7 @@
0604F7DD20620D3800B32F09 /* Model */ = {
isa = PBXGroup;
children = (
066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */,
06B1158E247BB1FB006D91FB /* Message.swift */,
067B2EB425693E38008B6BE1 /* MessageSection.swift */,
061E35852D1E5028009A2D6F /* MessageItemModel.swift */,
@ -728,6 +733,7 @@
06EE1FD226843E9300586708 /* BarkTests.swift */,
06EE1FD426843E9300586708 /* Info.plist */,
063B909A272149BF00431EC2 /* HomeViewModelTests.swift */,
068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */,
);
path = BarkTests;
sourceTree = "<group>";
@ -1256,6 +1262,7 @@
065BE4502563D939002A8CA4 /* SoundCellViewModel.swift in Sources */,
06F08EA729B1DDFE006AB9CA /* Error+Extension.swift in Sources */,
0687F2A82CCB791A00B2A52F /* UIFont+Extension.swift in Sources */,
066DF4822D2D31A60092B04E /* MessageDeleteTimeRange.swift in Sources */,
06B1158F247BB1FB006D91FB /* Message.swift in Sources */,
06BCAE562CDB19260092867A /* GroupMuteSettingManager.swift in Sources */,
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */,
@ -1353,6 +1360,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
068A4B962D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift in Sources */,
06EE1FD326843E9300586708 /* BarkTests.swift in Sources */,
063B909B272149BF00431EC2 /* HomeViewModelTests.swift in Sources */,
);

View File

@ -369,6 +369,98 @@
}
}
},
"beforeAMonth" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Before a month"
}
},
"tr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Bir Ay Önce"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "一个月之前"
}
}
}
},
"beforeAnHour" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Before an hour"
}
},
"tr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Bir Saat Önce"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "一小时之前"
}
}
}
},
"beforeToday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Before today"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Bugünden Önce"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "今天之前"
}
}
}
},
"beforeYesterday" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Before yesterday"
}
},
"tr" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Dünden Önce"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "昨天之前"
}
}
}
},
"buildDesc" : {
"extractionState" : "manual",
"localizations" : {
@ -1835,7 +1927,30 @@
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "过去一小时"
"value" : "最近一小时"
}
}
}
},
"lastMonth" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "The last month"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Son Ay"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "最近一个月"
}
}
}
@ -1886,6 +2001,29 @@
}
}
},
"more" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "More"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Daha"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "更多"
}
}
}
},
"MoreActions" : {
"extractionState" : "manual",
"localizations" : {

View File

@ -0,0 +1,69 @@
//
// MessageDeleteTimeRangeTest.swift
// BarkTests
//
// Created by huangfeng on 1/8/25.
// Copyright © 2025 Fin. All rights reserved.
//
@testable import Bark
import Testing
struct MessageDeleteTimeRangeTest {
@Test("检查时间范围区间是否正确", arguments: [
MessageDeleteTimeRange.lastHour,
MessageDeleteTimeRange.today,
MessageDeleteTimeRange.todayAndYesterday,
MessageDeleteTimeRange.lastMonth,
MessageDeleteTimeRange.allTime,
MessageDeleteTimeRange.beforeOneHour,
MessageDeleteTimeRange.beforeToday,
MessageDeleteTimeRange.beforeYesterday,
MessageDeleteTimeRange.beforeOneMonth
])
func testRange(range: MessageDeleteTimeRange) async throws {
let now = Date()
let lastHour = Calendar.current.date(byAdding: .hour, value: -1, to: now)!
let today = now.startOfDay
let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: today)!.startOfDay
let lastMonth = Calendar.current.date(byAdding: .month, value: -1, to: now)!
switch range {
case .lastHour:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == lastHour.timeInterval && endDate.timeInterval == now.timeInterval)
case .today:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == today.timeInterval && endDate.timeInterval == now.timeInterval)
case .todayAndYesterday:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == yesterday.timeInterval && endDate.timeInterval == now.timeInterval)
case .lastMonth:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == lastMonth.timeInterval && endDate.timeInterval == now.timeInterval)
case .allTime:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == 0 && endDate.timeInterval == now.timeInterval)
case .beforeOneHour:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == 0 && endDate.timeInterval == lastHour.timeInterval)
case .beforeToday:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == 0 && endDate.timeInterval == today.timeInterval)
case .beforeYesterday:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == 0 && endDate.timeInterval == yesterday.timeInterval)
case .beforeOneMonth:
let startDate = range.startDate
let endDate = range.endDate
#expect(startDate.timeInterval == 0 && endDate.timeInterval == lastMonth.timeInterval)
}
}
}

View File

@ -45,26 +45,38 @@ extension Date {
}
extension Date {
static var yesterday: Date { return Date().dayBefore }
static var tomorrow: Date { return Date().dayAfter }
static var lastHour: Date { return Calendar.current.date(byAdding: .hour, value: -1, to: Date())! }
var dayBefore: Date {
return Calendar.current.date(byAdding: .day, value: -1, to: noon)!
}
var dayAfter: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: noon)!
}
var noon: Date {
return Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
}
var month: Int {
return Calendar.current.component(.month, from: self)
}
var timeInterval: Int {
return Int(timeIntervalSince1970)
}
var isLastDayOfMonth: Bool {
return dayAfter.month != month
}
}
extension Date {
static var yesterday: Date { return Date().dayBefore }
static var tomorrow: Date { return Date().dayAfter }
static var lastHour: Date { return Calendar.current.date(byAdding: .hour, value: -1, to: Date())! }
static var lastMonth: Date { return Calendar.current.date(byAdding: .month, value: -1, to: Date())! }
var dayBefore: Date {
return Calendar.current.date(byAdding: .day, value: -1, to: startOfDay)!
}
var dayAfter: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: startOfDay)!
}
var startOfDay: Date {
return Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
}
var endOfDay: Date {
return Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: self)!
}
}

View File

@ -14,28 +14,38 @@ import RxDataSources
import RxSwift
import UIKit
enum MessageDeleteType: Int {
case lastHour = 0
case today
case todayAndYesterday
case allTime
var string: String {
return [
NSLocalizedString("lastHour"),
NSLocalizedString("today"),
NSLocalizedString("todayAndYesterday"),
NSLocalizedString("allTime")
][self.rawValue]
}
}
class MessageListViewController: BaseViewController<MessageListViewModel> {
let deleteButton: UIBarButtonItem = {
let btn = BKButton()
btn.setImage(UIImage(named: "baseline_delete_outline_black_24pt"), for: .normal)
btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
return UIBarButtonItem(customView: btn)
lazy var deleteButton: UIBarButtonItem = {
if #available(iOS 14.0, *) {
var menuElements = [UIMenuElement]()
for range in [MessageDeleteTimeRange.lastHour, .today, .todayAndYesterday, .lastMonth, .allTime] {
let action = UIAction(title: range.string) { [weak self] _ in
self?.clearAlert(range)
}
menuElements.append(action)
}
var subMenuElements = [UIMenuElement]()
for range in [MessageDeleteTimeRange.beforeOneHour, .beforeToday, .beforeYesterday, .beforeOneMonth] {
let action = UIAction(title: range.string) { [weak self] _ in
self?.clearAlert(range)
}
subMenuElements.append(action)
}
menuElements.append(UIMenu(title: NSLocalizedString("more"), children: subMenuElements))
let addNewMenu = UIMenu(
title: NSLocalizedString("clearFrom"),
children: menuElements
)
return UIBarButtonItem(image: UIImage(named: "baseline_delete_outline_black_24pt"), menu: addNewMenu)
} else {
let btn = BKButton()
btn.setImage(UIImage(named: "baseline_delete_outline_black_24pt"), for: .normal)
btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
return UIBarButtonItem(customView: btn)
}
}()
let groupButton: UIBarButtonItem = {
@ -77,7 +87,9 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
private let refreshRelay = PublishRelay<Void>()
/// 10
private let reloadRelay = PublishRelay<Void>()
///
private let clearRelay = PublishRelay<MessageDeleteTimeRange>()
override func makeUI() {
navigationItem.searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController?.obscuresBackgroundDuringPresentation = false
@ -90,6 +102,13 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
make.edges.equalToSuperview()
}
if #available(iOS 14.0, *) {
// iOS 14 使 UIMenu
} else {
// 使 UIAlertController
subscribeDeleteTap()
}
// tab
Client.shared.currentTabBarController?
.tabBarItemDidClick
@ -130,7 +149,8 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
reloadAnimation: .none,
deleteAnimation: .left
),
configureCell: { _, tableView, _, item -> UITableViewCell in
configureCell: { [weak self] _, tableView, _, item -> UITableViewCell in
guard let self else { return UITableViewCell() }
switch item {
case .message(let message):
@ -192,7 +212,7 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
loadMore: tableView.mj_footer!.rx.refresh.asDriver(),
itemDelete: tableView.rx.modelDeleted(MessageListCellItem.self).asDriver(),
itemDeleteInGroup: itemDeleteInGroupRelay.asDriver(onErrorDriveWith: .empty()),
delete: getBatchDeleteDriver(),
delete: clearRelay.asDriver(onErrorDriveWith: .empty()),
groupToggleTap: groupBtn.rx.tap.asDriver(),
searchText: navigationItem.searchController!.searchBar.rx.text.asObservable(),
reload: reloadRelay.asDriver(onErrorDriveWith: .empty())
@ -232,51 +252,46 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
.drive((groupButton.customView as! UIButton).rx.isHidden).disposed(by: rx.disposeBag)
}
private func getBatchDeleteDriver() -> Driver<MessageDeleteType> {
private func subscribeDeleteTap() {
guard let deleteBtn = deleteButton.customView as? BKButton else {
return Driver.never()
return
}
return deleteBtn.rx
.tap
.flatMapLatest { _ -> PublishRelay<MessageDeleteType> in
let relay = PublishRelay<MessageDeleteType>()
func alert(_ type: MessageDeleteType) {
let alertController = UIAlertController(title: nil, message: "\(NSLocalizedString("clearFrom"))\n\(type.string)", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("clear"), style: .destructive, handler: { _ in
relay.accept(type)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil))
self.navigationController?.present(alertController, animated: true, completion: nil)
deleteBtn.rx.tap.subscribe(onNext: { [weak self] _ in
guard let self else { return }
let alertController = UIAlertController(title: nil, message: NSLocalizedString("clearFrom"), preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: NSLocalizedString("lastHour"), style: .default, handler: { [weak self] _ in
self?.clearAlert(.lastHour)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("today"), style: .default, handler: { [weak self] _ in
self?.clearAlert(.today)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("todayAndYesterday"), style: .default, handler: { [weak self] _ in
self?.clearAlert(.todayAndYesterday)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("allTime"), style: .default, handler: { [weak self] _ in
self?.clearAlert(.allTime)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil))
if UIDevice.current.userInterfaceIdiom == .pad {
alertController.modalPresentationStyle = .popover
if #available(iOS 16.0, *) {
alertController.popoverPresentationController?.sourceItem = self.deleteButton
} else {
alertController.popoverPresentationController?.barButtonItem = self.deleteButton
}
let alertController = UIAlertController(title: nil, message: NSLocalizedString("clearFrom"), preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: NSLocalizedString("lastHour"), style: .default, handler: { _ in
alert(.lastHour)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("today"), style: .default, handler: { _ in
alert(.today)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("todayAndYesterday"), style: .default, handler: { _ in
alert(.todayAndYesterday)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("allTime"), style: .default, handler: { _ in
alert(.allTime)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil))
if UIDevice.current.userInterfaceIdiom == .pad {
alertController.modalPresentationStyle = .popover
if #available(iOS 16.0, *) {
alertController.popoverPresentationController?.sourceItem = self.deleteButton
} else {
alertController.popoverPresentationController?.barButtonItem = self.deleteButton
}
}
self.navigationController?.present(alertController, animated: true, completion: nil)
return relay
}
.asDriver(onErrorDriveWith: .empty())
self.navigationController?.present(alertController, animated: true, completion: nil)
}).disposed(by: rx.disposeBag)
}
func clearAlert(_ range: MessageDeleteTimeRange) {
let alertController = UIAlertController(title: nil, message: "\(NSLocalizedString("clearFrom"))\n\(range.string)", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("clear"), style: .destructive, handler: { [weak self] _ in
self?.clearRelay.accept(range)
}))
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil))
self.navigationController?.present(alertController, animated: true, completion: nil)
}
private func alertMessage(message: MessageItemModel, sourceView: UIView, sourceCell: UITableViewCell) {

View File

@ -37,7 +37,7 @@ class MessageListViewModel: ViewModel, ViewModelType {
///
var itemDeleteInGroup: Driver<MessageItemModel>
///
var delete: Driver<MessageDeleteType>
var delete: Driver<MessageDeleteTimeRange>
///
var groupToggleTap: Driver<Void>
///
@ -398,23 +398,11 @@ class MessageListViewModel: ViewModel, ViewModelType {
}).disposed(by: rx.disposeBag)
//
input.delete.drive(onNext: { [weak self] type in
guard let strongSelf = self else { return }
var date = Date()
switch type {
case .allTime:
date = Date(timeIntervalSince1970: 0)
case .todayAndYesterday:
date = Date.yesterday
case .today:
date = Date().noon
case .lastHour:
date = Date.lastHour
}
input.delete.drive(onNext: { [weak self] range in
guard let self else { return }
if let realm = try? Realm() {
guard let messages = strongSelf.getResults(filterGroups: filterGroups.value, searchText: nil)?.filter("createDate >= %@", date) else {
guard let messages = self.getResults(filterGroups: filterGroups.value, searchText: nil)?.filter("createDate >= %@ and createDate <= %@ ", range.startDate, range.endDate) else {
return
}
@ -423,8 +411,8 @@ class MessageListViewModel: ViewModel, ViewModelType {
}
}
strongSelf.page = 0
messagesRelay.accept([MessageSection(header: "model", messages: strongSelf.getNextPage())])
self.page = 0
messagesRelay.accept([MessageSection(header: "model", messages: self.getNextPage())])
}).disposed(by: rx.disposeBag)

View File

@ -0,0 +1,92 @@
//
// MessageDeleteTimeRange.swift
// Bark
//
// Created by huangfeng on 1/7/25.
// Copyright © 2025 Fin. All rights reserved.
//
import Foundation
enum MessageDeleteTimeRange {
///
case lastHour
///
case today
///
case todayAndYesterday
///
case lastMonth
///
case allTime
///
case beforeOneHour
///
case beforeToday
///
case beforeYesterday
///
case beforeOneMonth
var string: String {
switch self {
case .lastHour:
return NSLocalizedString("lastHour")
case .today:
return NSLocalizedString("today")
case .todayAndYesterday:
return NSLocalizedString("todayAndYesterday")
case .lastMonth:
return NSLocalizedString("lastMonth")
case .allTime:
return NSLocalizedString("allTime")
case .beforeOneHour:
return NSLocalizedString("beforeAnHour")
case .beforeToday:
return NSLocalizedString("beforeToday")
case .beforeYesterday:
return NSLocalizedString("beforeYesterday")
case .beforeOneMonth:
return NSLocalizedString("beforeAMonth")
}
}
var startDate: Date {
switch self {
case .lastHour:
return Date.lastHour
case .today:
return Date().startOfDay
case .todayAndYesterday:
return Date.yesterday
case .lastMonth:
return Date.lastMonth
case .allTime,
.beforeOneHour,
.beforeToday,
.beforeYesterday,
.beforeOneMonth:
return Date(timeIntervalSince1970: 0)
}
}
var endDate: Date {
switch self {
case .lastHour,
.today,
.todayAndYesterday,
.lastMonth,
.allTime:
return Date()
case .beforeOneHour:
return Date.lastHour
case .beforeToday:
return Date().startOfDay
case .beforeYesterday:
return Date.yesterday
case .beforeOneMonth:
return Date.lastMonth
}
}
}