forked from shadowfacts/Tusker
Shadowfacts
b47b08fa95
Also, copy the state between screens, so e.g. expanding a status in the timeline and then opening that conversation already has that status expanded. This intentionally doesn't store the sensitive attachment visibility state, since showing text when not necessary is less dangerous than for images. (Possibly a preference for this in the future?) Closes #55
49 lines
1.5 KiB
Swift
49 lines
1.5 KiB
Swift
//
|
|
// NotificationGroup.swift
|
|
// Pachyderm
|
|
//
|
|
// Created by Shadowfacts on 9/5/19.
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public class NotificationGroup {
|
|
public let notificationIDs: [String]
|
|
public let id: String
|
|
public let kind: Notification.Kind
|
|
public let statusState: StatusState?
|
|
|
|
init?(notifications: [Notification]) {
|
|
guard !notifications.isEmpty else { return nil }
|
|
self.notificationIDs = notifications.map { $0.id }
|
|
self.id = notifications.first!.id
|
|
self.kind = notifications.first!.kind
|
|
if kind == .mention {
|
|
self.statusState = .unknown
|
|
} else {
|
|
self.statusState = nil
|
|
}
|
|
}
|
|
|
|
public static func createGroups(notifications: [Notification], only allowedTypes: [Notification.Kind]) -> [NotificationGroup] {
|
|
return notifications.reduce(into: [[Notification]]()) { (groups, notification) in
|
|
if allowedTypes.contains(notification.kind),
|
|
let lastGroup = groups.last,
|
|
let firstStatus = lastGroup.first,
|
|
firstStatus.kind == notification.kind,
|
|
firstStatus.status?.id == notification.status?.id {
|
|
|
|
groups[groups.count - 1].append(notification)
|
|
} else {
|
|
groups.append([notification])
|
|
}
|
|
}.map {
|
|
NotificationGroup(notifications: $0)!
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension NotificationGroup: Identifiable {}
|