Skip to content

Commit

Permalink
添加更多消息clear时间区间
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Jan 8, 2025
1 parent d9da712 commit 5bcfd1b
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 93 deletions.
8 changes: 8 additions & 0 deletions Bark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand Down Expand Up @@ -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>"; };
Expand All @@ -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>"; };
Expand Down Expand Up @@ -538,6 +542,7 @@
0604F7DD20620D3800B32F09 /* Model */ = {
isa = PBXGroup;
children = (
066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */,
06B1158E247BB1FB006D91FB /* Message.swift */,
067B2EB425693E38008B6BE1 /* MessageSection.swift */,
061E35852D1E5028009A2D6F /* MessageItemModel.swift */,
Expand Down Expand Up @@ -728,6 +733,7 @@
06EE1FD226843E9300586708 /* BarkTests.swift */,
06EE1FD426843E9300586708 /* Info.plist */,
063B909A272149BF00431EC2 /* HomeViewModelTests.swift */,
068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */,
);
path = BarkTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -1353,6 +1360,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
068A4B962D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift in Sources */,
06EE1FD326843E9300586708 /* BarkTests.swift in Sources */,
063B909B272149BF00431EC2 /* HomeViewModelTests.swift in Sources */,
);
Expand Down
140 changes: 139 additions & 1 deletion Bark/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down Expand Up @@ -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" : "最近一个月"
}
}
}
Expand Down Expand Up @@ -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" : {
Expand Down
69 changes: 69 additions & 0 deletions BarkTests/MessageDeleteTimeRangeTest.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
30 changes: 21 additions & 9 deletions Common/Date+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,39 @@ extension Date {
}
}

extension Date {
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: noon)!
return Calendar.current.date(byAdding: .day, value: -1, to: startOfDay)!
}

var dayAfter: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: noon)!
return Calendar.current.date(byAdding: .day, value: 1, to: startOfDay)!
}

var noon: Date {
var startOfDay: Date {
return Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
}

var month: Int {
return Calendar.current.component(.month, from: self)
}

var isLastDayOfMonth: Bool {
return dayAfter.month != month
var endOfDay: Date {
return Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: self)!
}
}
Loading

0 comments on commit 5bcfd1b

Please sign in to comment.