Make OPML generate in a consistent order when the Web Feed name is the same. Issue #1545

This commit is contained in:
Maurice Parker 2020-01-06 13:58:51 -07:00
parent f84abb81e2
commit 7824939c30
3 changed files with 24 additions and 3 deletions

View File

@ -1245,10 +1245,10 @@ extension Account: OPMLRepresentable {
public func OPMLString(indentLevel: Int, strictConformance: Bool) -> String {
var s = ""
for feed in topLevelWebFeeds.sorted(by: { $0.nameForDisplay < $1.nameForDisplay }) {
for feed in topLevelWebFeeds.sorted() {
s += feed.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
}
for folder in folders!.sorted(by: { $0.nameForDisplay < $1.nameForDisplay }) {
for folder in folders!.sorted() {
s += folder.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
}
return s

View File

@ -189,7 +189,7 @@ extension Folder: OPMLRepresentable {
var hasAtLeastOneChild = false
for feed in topLevelWebFeeds.sorted(by: { $0.nameForDisplay < $1.nameForDisplay }) {
for feed in topLevelWebFeeds.sorted() {
s += feed.OPMLString(indentLevel: indentLevel + 1, strictConformance: strictConformance)
hasAtLeastOneChild = true
}
@ -206,3 +206,14 @@ extension Folder: OPMLRepresentable {
}
}
// MARK: Set
extension Set where Element == Folder {
func sorted() -> Array<Folder> {
return sorted(by: { (folder1, folder2) -> Bool in
return folder1.nameForDisplay.localizedStandardCompare(folder2.nameForDisplay) == .orderedAscending
})
}
}

View File

@ -276,4 +276,14 @@ extension Set where Element == WebFeed {
func webFeedIDs() -> Set<String> {
return Set<String>(map { $0.webFeedID })
}
func sorted() -> Array<WebFeed> {
return sorted(by: { (webFeed1, webFeed2) -> Bool in
if webFeed1.nameForDisplay.localizedStandardCompare(webFeed2.nameForDisplay) == .orderedSame {
return webFeed1.url < webFeed2.url
}
return webFeed1.nameForDisplay.localizedStandardCompare(webFeed2.nameForDisplay) == .orderedAscending
})
}
}