Fix collapsible state not changing when post edited
This commit is contained in:
parent
13ec3366d3
commit
7d3c82f4b7
|
@ -12,6 +12,7 @@ import Foundation
|
||||||
public final class CollapseState: Sendable {
|
public final class CollapseState: Sendable {
|
||||||
public var collapsible: Bool?
|
public var collapsible: Bool?
|
||||||
public var collapsed: Bool?
|
public var collapsed: Bool?
|
||||||
|
public var statusPropertiesHash: Int?
|
||||||
|
|
||||||
public var unknown: Bool {
|
public var unknown: Bool {
|
||||||
collapsible == nil || collapsed == nil
|
collapsible == nil || collapsed == nil
|
||||||
|
|
|
@ -9,12 +9,24 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
|
||||||
|
protocol CollapseStateResolving {
|
||||||
|
var spoilerText: String { get }
|
||||||
|
}
|
||||||
|
|
||||||
|
extension StatusMO: CollapseStateResolving {}
|
||||||
|
extension StatusEdit: CollapseStateResolving {}
|
||||||
|
|
||||||
extension CollapseState {
|
extension CollapseState {
|
||||||
|
|
||||||
func resolveFor(status: StatusMO, height: CGFloat, textLength: Int? = nil) {
|
func resolveFor(status: CollapseStateResolving, height: () -> CGFloat, textLength: Int? = nil) -> Bool {
|
||||||
|
lazy var newHash = hashStatusProperties(status: status)
|
||||||
|
guard unknown || statusPropertiesHash != newHash else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
let longEnoughToCollapse: Bool
|
let longEnoughToCollapse: Bool
|
||||||
if Preferences.shared.collapseLongPosts,
|
if Preferences.shared.collapseLongPosts,
|
||||||
height > 600 || (textLength != nil && textLength! > 500) {
|
height() > 600 || (textLength != nil && textLength! > 500) {
|
||||||
longEnoughToCollapse = true
|
longEnoughToCollapse = true
|
||||||
} else {
|
} else {
|
||||||
longEnoughToCollapse = false
|
longEnoughToCollapse = false
|
||||||
|
@ -39,6 +51,12 @@ extension CollapseState {
|
||||||
self.collapsible = contentWarningCollapsible || longEnoughToCollapse
|
self.collapsible = contentWarningCollapsible || longEnoughToCollapse
|
||||||
// use ?? instead of || because the content warnig pref takes priority over length
|
// use ?? instead of || because the content warnig pref takes priority over length
|
||||||
self.collapsed = collapseDueToContentWarning ?? longEnoughToCollapse
|
self.collapsed = collapseDueToContentWarning ?? longEnoughToCollapse
|
||||||
|
self.statusPropertiesHash = newHash
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func hashStatusProperties(status: CollapseStateResolving) -> Int {
|
||||||
|
status.spoilerText.hashValue
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue