forked from shadowfacts/Tusker
Fix notifications sometimes getting deleted in group merging
Closes #156
This commit is contained in:
parent
c71bf3ba23
commit
ddcb13dd28
|
@ -97,13 +97,14 @@ public struct NotificationGroup: Identifiable, Hashable {
|
|||
break
|
||||
}
|
||||
|
||||
|
||||
if canMerge(notification: firstGroupFromSecond.notifications.first!, into: lastGroup) {
|
||||
merged[merged.count - 1].append(group: firstGroupFromSecond)
|
||||
} else if merged.count >= 2 {
|
||||
let secondToLastGroup = merged[merged.count - 2]
|
||||
if allowedTypes.contains(secondToLastGroup.kind), canMerge(notification: firstGroupFromSecond.notifications.first!, into: secondToLastGroup) {
|
||||
merged[merged.count - 2].append(group: firstGroupFromSecond)
|
||||
} else {
|
||||
merged.append(firstGroupFromSecond)
|
||||
}
|
||||
} else {
|
||||
merged.append(firstGroupFromSecond)
|
||||
|
|
|
@ -148,9 +148,31 @@ class NotificationGroupTests: XCTestCase {
|
|||
"status": \(statusB)
|
||||
""".data(using: .utf8)!
|
||||
lazy var likeB = try! decoder.decode(Notification.self, from: likeBData)
|
||||
lazy var mentionBData = """
|
||||
lazy var likeB2Data = """
|
||||
{
|
||||
"id": "4",
|
||||
"type": "favourite",
|
||||
"created_at": "2019-11-23T07:29:18Z",
|
||||
"account": {
|
||||
"id": "2",
|
||||
"username": "bar",
|
||||
"acct": "bar",
|
||||
"display_name": "bar",
|
||||
"locked": false,
|
||||
"created_at": "2019-11-02T01:01:01Z",
|
||||
"followers_count": 0,
|
||||
"following_count": 0,
|
||||
"statuses_count": 0,
|
||||
"note": "",
|
||||
"url": "https://example.com/@bar",
|
||||
"uri": "https://example.com/@bar",
|
||||
},
|
||||
"status": \(statusB)
|
||||
""".data(using: .utf8)!
|
||||
lazy var likeB2 = try! decoder.decode(Notification.self, from: likeB2Data)
|
||||
lazy var mentionBData = """
|
||||
{
|
||||
"id": "5",
|
||||
"type": "mention",
|
||||
"created_at": "2019-11-23T07:29:18Z",
|
||||
"account": {
|
||||
|
@ -218,6 +240,17 @@ class NotificationGroupTests: XCTestCase {
|
|||
NotificationGroup(notifications: [likeA1, likeA2])!,
|
||||
NotificationGroup(notifications: [likeB])!,
|
||||
])
|
||||
|
||||
let group4 = NotificationGroup(notifications: [likeB2])!
|
||||
let group5 = NotificationGroup(notifications: [mentionB])!
|
||||
let merged3 = NotificationGroup.mergeGroups(first: [group1, group5, group2], second: [group4, group3], only: [.favourite])
|
||||
print(merged3.count)
|
||||
XCTAssertEqual(merged3, [
|
||||
group1,
|
||||
group5,
|
||||
NotificationGroup(notifications: [likeB, likeB2]),
|
||||
group3
|
||||
])
|
||||
}
|
||||
|
||||
func testDontMergeWithUngroupableInBetween() {
|
||||
|
|
Loading…
Reference in New Issue