Skip to content

Commit 5bcfd1b

Browse files
committed
添加更多消息clear时间区间
1 parent d9da712 commit 5bcfd1b

7 files changed

+415
-93
lines changed

Bark.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
066890082D1946D500E106F2 /* MessageItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066890072D1946D500E106F2 /* MessageItemView.swift */; };
101101
0668900B2D19525400E106F2 /* ShowLessAndClearView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0668900A2D19525400E106F2 /* ShowLessAndClearView.swift */; };
102102
0668900D2D19582400E106F2 /* MessageGroupHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0668900C2D19582400E106F2 /* MessageGroupHeaderView.swift */; };
103+
066DF4822D2D31A60092B04E /* MessageDeleteTimeRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */; };
103104
066E0C8C2BB6AC9A00873838 /* AddSoundCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */; };
104105
0672CB06256903F700570C9D /* MessageListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0672CB05256903F700570C9D /* MessageListViewModel.swift */; };
105106
06787C392A710568008ABDD7 /* GesturePassTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06787C382A710568008ABDD7 /* GesturePassTextView.swift */; };
@@ -112,6 +113,7 @@
112113
0687F2AA2CCB7FA500B2A52F /* UIFont+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */; };
113114
06885EB6247FB9880004A303 /* MessageSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */; };
114115
0689CF4C2C7484A7007203A6 /* BarkTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */; };
116+
068A4B962D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */; };
115117
068EC15827ED99C900D5D11E /* ServerListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15727ED99C900D5D11E /* ServerListViewController.swift */; };
116118
068EC15A27ED99E700D5D11E /* ServerListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15927ED99E700D5D11E /* ServerListViewModel.swift */; };
117119
068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068F66B2247BD84C00DAD25A /* MessageListViewController.swift */; };
@@ -343,6 +345,7 @@
343345
066890072D1946D500E106F2 /* MessageItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageItemView.swift; sourceTree = "<group>"; };
344346
0668900A2D19525400E106F2 /* ShowLessAndClearView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowLessAndClearView.swift; sourceTree = "<group>"; };
345347
0668900C2D19582400E106F2 /* MessageGroupHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageGroupHeaderView.swift; sourceTree = "<group>"; };
348+
066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDeleteTimeRange.swift; sourceTree = "<group>"; };
346349
066E0C8B2BB6AC9A00873838 /* AddSoundCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddSoundCell.swift; sourceTree = "<group>"; };
347350
0672CB05256903F700570C9D /* MessageListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewModel.swift; sourceTree = "<group>"; };
348351
06787C382A710568008ABDD7 /* GesturePassTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturePassTextView.swift; sourceTree = "<group>"; };
@@ -355,6 +358,7 @@
355358
0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extension.swift"; sourceTree = "<group>"; };
356359
06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSettingsViewController.swift; sourceTree = "<group>"; };
357360
0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkTabBarController.swift; sourceTree = "<group>"; };
361+
068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDeleteTimeRangeTest.swift; sourceTree = "<group>"; };
358362
068EC15727ED99C900D5D11E /* ServerListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewController.swift; sourceTree = "<group>"; };
359363
068EC15927ED99E700D5D11E /* ServerListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewModel.swift; sourceTree = "<group>"; };
360364
068F66B2247BD84C00DAD25A /* MessageListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewController.swift; sourceTree = "<group>"; };
@@ -538,6 +542,7 @@
538542
0604F7DD20620D3800B32F09 /* Model */ = {
539543
isa = PBXGroup;
540544
children = (
545+
066DF4812D2D31A30092B04E /* MessageDeleteTimeRange.swift */,
541546
06B1158E247BB1FB006D91FB /* Message.swift */,
542547
067B2EB425693E38008B6BE1 /* MessageSection.swift */,
543548
061E35852D1E5028009A2D6F /* MessageItemModel.swift */,
@@ -728,6 +733,7 @@
728733
06EE1FD226843E9300586708 /* BarkTests.swift */,
729734
06EE1FD426843E9300586708 /* Info.plist */,
730735
063B909A272149BF00431EC2 /* HomeViewModelTests.swift */,
736+
068A4B952D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift */,
731737
);
732738
path = BarkTests;
733739
sourceTree = "<group>";
@@ -1256,6 +1262,7 @@
12561262
065BE4502563D939002A8CA4 /* SoundCellViewModel.swift in Sources */,
12571263
06F08EA729B1DDFE006AB9CA /* Error+Extension.swift in Sources */,
12581264
0687F2A82CCB791A00B2A52F /* UIFont+Extension.swift in Sources */,
1265+
066DF4822D2D31A60092B04E /* MessageDeleteTimeRange.swift in Sources */,
12591266
06B1158F247BB1FB006D91FB /* Message.swift in Sources */,
12601267
06BCAE562CDB19260092867A /* GroupMuteSettingManager.swift in Sources */,
12611268
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */,
@@ -1353,6 +1360,7 @@
13531360
isa = PBXSourcesBuildPhase;
13541361
buildActionMask = 2147483647;
13551362
files = (
1363+
068A4B962D2E11CD00982449 /* MessageDeleteTimeRangeTest.swift in Sources */,
13561364
06EE1FD326843E9300586708 /* BarkTests.swift in Sources */,
13571365
063B909B272149BF00431EC2 /* HomeViewModelTests.swift in Sources */,
13581366
);

Bark/Localizable.xcstrings

+139-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,98 @@
369369
}
370370
}
371371
},
372+
"beforeAMonth" : {
373+
"extractionState" : "manual",
374+
"localizations" : {
375+
"en" : {
376+
"stringUnit" : {
377+
"state" : "translated",
378+
"value" : "Before a month"
379+
}
380+
},
381+
"tr" : {
382+
"stringUnit" : {
383+
"state" : "needs_review",
384+
"value" : "Bir Ay Önce"
385+
}
386+
},
387+
"zh-Hans" : {
388+
"stringUnit" : {
389+
"state" : "needs_review",
390+
"value" : "一个月之前"
391+
}
392+
}
393+
}
394+
},
395+
"beforeAnHour" : {
396+
"extractionState" : "manual",
397+
"localizations" : {
398+
"en" : {
399+
"stringUnit" : {
400+
"state" : "translated",
401+
"value" : "Before an hour"
402+
}
403+
},
404+
"tr" : {
405+
"stringUnit" : {
406+
"state" : "needs_review",
407+
"value" : "Bir Saat Önce"
408+
}
409+
},
410+
"zh-Hans" : {
411+
"stringUnit" : {
412+
"state" : "needs_review",
413+
"value" : "一小时之前"
414+
}
415+
}
416+
}
417+
},
418+
"beforeToday" : {
419+
"extractionState" : "manual",
420+
"localizations" : {
421+
"en" : {
422+
"stringUnit" : {
423+
"state" : "translated",
424+
"value" : "Before today"
425+
}
426+
},
427+
"tr" : {
428+
"stringUnit" : {
429+
"state" : "translated",
430+
"value" : "Bugünden Önce"
431+
}
432+
},
433+
"zh-Hans" : {
434+
"stringUnit" : {
435+
"state" : "translated",
436+
"value" : "今天之前"
437+
}
438+
}
439+
}
440+
},
441+
"beforeYesterday" : {
442+
"extractionState" : "manual",
443+
"localizations" : {
444+
"en" : {
445+
"stringUnit" : {
446+
"state" : "translated",
447+
"value" : "Before yesterday"
448+
}
449+
},
450+
"tr" : {
451+
"stringUnit" : {
452+
"state" : "needs_review",
453+
"value" : "Dünden Önce"
454+
}
455+
},
456+
"zh-Hans" : {
457+
"stringUnit" : {
458+
"state" : "needs_review",
459+
"value" : "昨天之前"
460+
}
461+
}
462+
}
463+
},
372464
"buildDesc" : {
373465
"extractionState" : "manual",
374466
"localizations" : {
@@ -1835,7 +1927,30 @@
18351927
"zh-Hans" : {
18361928
"stringUnit" : {
18371929
"state" : "translated",
1838-
"value" : "过去一小时"
1930+
"value" : "最近一小时"
1931+
}
1932+
}
1933+
}
1934+
},
1935+
"lastMonth" : {
1936+
"extractionState" : "manual",
1937+
"localizations" : {
1938+
"en" : {
1939+
"stringUnit" : {
1940+
"state" : "translated",
1941+
"value" : "The last month"
1942+
}
1943+
},
1944+
"tr" : {
1945+
"stringUnit" : {
1946+
"state" : "translated",
1947+
"value" : "Son Ay"
1948+
}
1949+
},
1950+
"zh-Hans" : {
1951+
"stringUnit" : {
1952+
"state" : "translated",
1953+
"value" : "最近一个月"
18391954
}
18401955
}
18411956
}
@@ -1886,6 +2001,29 @@
18862001
}
18872002
}
18882003
},
2004+
"more" : {
2005+
"extractionState" : "manual",
2006+
"localizations" : {
2007+
"en" : {
2008+
"stringUnit" : {
2009+
"state" : "translated",
2010+
"value" : "More"
2011+
}
2012+
},
2013+
"tr" : {
2014+
"stringUnit" : {
2015+
"state" : "translated",
2016+
"value" : "Daha"
2017+
}
2018+
},
2019+
"zh-Hans" : {
2020+
"stringUnit" : {
2021+
"state" : "translated",
2022+
"value" : "更多"
2023+
}
2024+
}
2025+
}
2026+
},
18892027
"MoreActions" : {
18902028
"extractionState" : "manual",
18912029
"localizations" : {
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// MessageDeleteTimeRangeTest.swift
3+
// BarkTests
4+
//
5+
// Created by huangfeng on 1/8/25.
6+
// Copyright © 2025 Fin. All rights reserved.
7+
//
8+
@testable import Bark
9+
import Testing
10+
11+
struct MessageDeleteTimeRangeTest {
12+
@Test("检查时间范围区间是否正确", arguments: [
13+
MessageDeleteTimeRange.lastHour,
14+
MessageDeleteTimeRange.today,
15+
MessageDeleteTimeRange.todayAndYesterday,
16+
MessageDeleteTimeRange.lastMonth,
17+
MessageDeleteTimeRange.allTime,
18+
MessageDeleteTimeRange.beforeOneHour,
19+
MessageDeleteTimeRange.beforeToday,
20+
MessageDeleteTimeRange.beforeYesterday,
21+
MessageDeleteTimeRange.beforeOneMonth
22+
])
23+
func testRange(range: MessageDeleteTimeRange) async throws {
24+
let now = Date()
25+
let lastHour = Calendar.current.date(byAdding: .hour, value: -1, to: now)!
26+
let today = now.startOfDay
27+
let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: today)!.startOfDay
28+
let lastMonth = Calendar.current.date(byAdding: .month, value: -1, to: now)!
29+
30+
switch range {
31+
case .lastHour:
32+
let startDate = range.startDate
33+
let endDate = range.endDate
34+
#expect(startDate.timeInterval == lastHour.timeInterval && endDate.timeInterval == now.timeInterval)
35+
case .today:
36+
let startDate = range.startDate
37+
let endDate = range.endDate
38+
#expect(startDate.timeInterval == today.timeInterval && endDate.timeInterval == now.timeInterval)
39+
case .todayAndYesterday:
40+
let startDate = range.startDate
41+
let endDate = range.endDate
42+
#expect(startDate.timeInterval == yesterday.timeInterval && endDate.timeInterval == now.timeInterval)
43+
case .lastMonth:
44+
let startDate = range.startDate
45+
let endDate = range.endDate
46+
#expect(startDate.timeInterval == lastMonth.timeInterval && endDate.timeInterval == now.timeInterval)
47+
case .allTime:
48+
let startDate = range.startDate
49+
let endDate = range.endDate
50+
#expect(startDate.timeInterval == 0 && endDate.timeInterval == now.timeInterval)
51+
case .beforeOneHour:
52+
let startDate = range.startDate
53+
let endDate = range.endDate
54+
#expect(startDate.timeInterval == 0 && endDate.timeInterval == lastHour.timeInterval)
55+
case .beforeToday:
56+
let startDate = range.startDate
57+
let endDate = range.endDate
58+
#expect(startDate.timeInterval == 0 && endDate.timeInterval == today.timeInterval)
59+
case .beforeYesterday:
60+
let startDate = range.startDate
61+
let endDate = range.endDate
62+
#expect(startDate.timeInterval == 0 && endDate.timeInterval == yesterday.timeInterval)
63+
case .beforeOneMonth:
64+
let startDate = range.startDate
65+
let endDate = range.endDate
66+
#expect(startDate.timeInterval == 0 && endDate.timeInterval == lastMonth.timeInterval)
67+
}
68+
}
69+
}

Common/Date+Extension.swift

+21-9
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,39 @@ extension Date {
4444
}
4545
}
4646

47+
extension Date {
48+
var month: Int {
49+
return Calendar.current.component(.month, from: self)
50+
}
51+
52+
var timeInterval: Int {
53+
return Int(timeIntervalSince1970)
54+
}
55+
56+
var isLastDayOfMonth: Bool {
57+
return dayAfter.month != month
58+
}
59+
}
60+
4761
extension Date {
4862
static var yesterday: Date { return Date().dayBefore }
4963
static var tomorrow: Date { return Date().dayAfter }
5064
static var lastHour: Date { return Calendar.current.date(byAdding: .hour, value: -1, to: Date())! }
65+
static var lastMonth: Date { return Calendar.current.date(byAdding: .month, value: -1, to: Date())! }
66+
5167
var dayBefore: Date {
52-
return Calendar.current.date(byAdding: .day, value: -1, to: noon)!
68+
return Calendar.current.date(byAdding: .day, value: -1, to: startOfDay)!
5369
}
5470

5571
var dayAfter: Date {
56-
return Calendar.current.date(byAdding: .day, value: 1, to: noon)!
72+
return Calendar.current.date(byAdding: .day, value: 1, to: startOfDay)!
5773
}
5874

59-
var noon: Date {
75+
var startOfDay: Date {
6076
return Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
6177
}
6278

63-
var month: Int {
64-
return Calendar.current.component(.month, from: self)
65-
}
66-
67-
var isLastDayOfMonth: Bool {
68-
return dayAfter.month != month
79+
var endOfDay: Date {
80+
return Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: self)!
6981
}
7082
}

0 commit comments

Comments
 (0)