Merge branch 'mac-candidate'

This commit is contained in:
Brent Simmons 2019-07-07 14:26:05 -07:00
commit 424daa0a5c
4 changed files with 37 additions and 51 deletions

View File

@ -18,6 +18,8 @@ import ArticlesDatabase
import RSWeb import RSWeb
import os.log import os.log
// Main thread only.
public extension Notification.Name { public extension Notification.Name {
static let AccountRefreshDidBegin = Notification.Name(rawValue: "AccountRefreshDidBegin") static let AccountRefreshDidBegin = Notification.Name(rawValue: "AccountRefreshDidBegin")
static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish") static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish")
@ -684,6 +686,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
// MARK: - Container // MARK: - Container
public func flattenedFeeds() -> Set<Feed> { public func flattenedFeeds() -> Set<Feed> {
assert(Thread.isMainThread)
if flattenedFeedsNeedUpdate { if flattenedFeedsNeedUpdate {
updateFlattenedFeeds() updateFlattenedFeeds()
} }

View File

@ -10,6 +10,8 @@ import Foundation
import RSCore import RSCore
import Articles import Articles
// Main thread only.
public extension Notification.Name { public extension Notification.Name {
static let AccountsDidChange = Notification.Name(rawValue: "AccountsDidChange") static let AccountsDidChange = Notification.Name(rawValue: "AccountsDidChange")
} }
@ -51,6 +53,7 @@ public final class AccountManager: UnreadCountProvider {
} }
public var activeAccounts: [Account] { public var activeAccounts: [Account] {
assert(Thread.isMainThread)
return Array(accountsDictionary.values.filter { $0.isActive }) return Array(accountsDictionary.values.filter { $0.isActive })
} }

View File

@ -602,8 +602,8 @@ private extension FeedbinAccountDelegate {
} }
func syncFolders(_ account: Account, _ tags: [FeedbinTag]?) { func syncFolders(_ account: Account, _ tags: [FeedbinTag]?) {
guard let tags = tags else { return } guard let tags = tags else { return }
assert(Thread.isMainThread)
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count) os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
@ -613,7 +613,6 @@ private extension FeedbinAccountDelegate {
if let folders = account.folders { if let folders = account.folders {
folders.forEach { folder in folders.forEach { folder in
if !tagNames.contains(folder.name ?? "") { if !tagNames.contains(folder.name ?? "") {
DispatchQueue.main.sync {
for feed in folder.topLevelFeeds { for feed in folder.topLevelFeeds {
account.addFeed(feed) account.addFeed(feed)
clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") clearFolderRelationship(for: feed, withFolderName: folder.name ?? "")
@ -622,7 +621,6 @@ private extension FeedbinAccountDelegate {
} }
} }
} }
}
let folderNames: [String] = { let folderNames: [String] = {
if let folders = account.folders { if let folders = account.folders {
@ -635,11 +633,9 @@ private extension FeedbinAccountDelegate {
// Make any folders Feedbin has, but we don't // Make any folders Feedbin has, but we don't
tagNames.forEach { tagName in tagNames.forEach { tagName in
if !folderNames.contains(tagName) { if !folderNames.contains(tagName) {
DispatchQueue.main.sync {
_ = account.ensureFolder(with: tagName) _ = account.ensureFolder(with: tagName)
} }
} }
}
} }
@ -691,6 +687,7 @@ private extension FeedbinAccountDelegate {
func syncFeeds(_ account: Account, _ subscriptions: [FeedbinSubscription]?) { func syncFeeds(_ account: Account, _ subscriptions: [FeedbinSubscription]?) {
guard let subscriptions = subscriptions else { return } guard let subscriptions = subscriptions else { return }
assert(Thread.isMainThread)
os_log(.debug, log: log, "Syncing feeds with %ld subscriptions.", subscriptions.count) os_log(.debug, log: log, "Syncing feeds with %ld subscriptions.", subscriptions.count)
@ -701,28 +698,23 @@ private extension FeedbinAccountDelegate {
for folder in folders { for folder in folders {
for feed in folder.topLevelFeeds { for feed in folder.topLevelFeeds {
if !subFeedIds.contains(feed.feedID) { if !subFeedIds.contains(feed.feedID) {
DispatchQueue.main.sync {
folder.removeFeed(feed) folder.removeFeed(feed)
} }
} }
} }
} }
}
for feed in account.topLevelFeeds { for feed in account.topLevelFeeds {
if !subFeedIds.contains(feed.feedID) { if !subFeedIds.contains(feed.feedID) {
DispatchQueue.main.sync {
account.removeFeed(feed) account.removeFeed(feed)
} }
} }
}
// Add any feeds we don't have and update any we do // Add any feeds we don't have and update any we do
subscriptions.forEach { subscription in subscriptions.forEach { subscription in
let subFeedId = String(subscription.feedID) let subFeedId = String(subscription.feedID)
DispatchQueue.main.sync {
if let feed = account.idToFeedDictionary[subFeedId] { if let feed = account.idToFeedDictionary[subFeedId] {
feed.name = subscription.name feed.name = subscription.name
// If the name has been changed on the server remove the locally edited name // If the name has been changed on the server remove the locally edited name
@ -735,14 +727,12 @@ private extension FeedbinAccountDelegate {
account.addFeed(feed) account.addFeed(feed)
} }
} }
}
} }
func syncTaggings(_ account: Account, _ taggings: [FeedbinTagging]?) { func syncTaggings(_ account: Account, _ taggings: [FeedbinTagging]?) {
guard let taggings = taggings else { return } guard let taggings = taggings else { return }
assert(Thread.isMainThread)
os_log(.debug, log: log, "Syncing taggings with %ld taggings.", taggings.count) os_log(.debug, log: log, "Syncing taggings with %ld taggings.", taggings.count)
@ -776,13 +766,11 @@ private extension FeedbinAccountDelegate {
// Move any feeds not in the folder to the account // Move any feeds not in the folder to the account
for feed in folder.topLevelFeeds { for feed in folder.topLevelFeeds {
if !taggingFeedIDs.contains(feed.feedID) { if !taggingFeedIDs.contains(feed.feedID) {
DispatchQueue.main.sync {
folder.removeFeed(feed) folder.removeFeed(feed)
clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") clearFolderRelationship(for: feed, withFolderName: folder.name ?? "")
account.addFeed(feed) account.addFeed(feed)
} }
} }
}
// Add any feeds not in the folder // Add any feeds not in the folder
let folderFeedIds = folder.topLevelFeeds.map { $0.feedID } let folderFeedIds = folder.topLevelFeeds.map { $0.feedID }
@ -793,19 +781,16 @@ private extension FeedbinAccountDelegate {
guard let feed = account.idToFeedDictionary[taggingFeedID] else { guard let feed = account.idToFeedDictionary[taggingFeedID] else {
continue continue
} }
DispatchQueue.main.sync {
saveFolderRelationship(for: feed, withFolderName: folderName, id: String(tagging.taggingID)) saveFolderRelationship(for: feed, withFolderName: folderName, id: String(tagging.taggingID))
folder.addFeed(feed) folder.addFeed(feed)
} }
} }
}
} }
let taggedFeedIDs = Set(taggings.map { String($0.feedID) }) let taggedFeedIDs = Set(taggings.map { String($0.feedID) })
// Remove all feeds from the account container that have a tag // Remove all feeds from the account container that have a tag
DispatchQueue.main.sync {
for feed in account.topLevelFeeds { for feed in account.topLevelFeeds {
if taggedFeedIDs.contains(feed.feedID) { if taggedFeedIDs.contains(feed.feedID) {
account.removeFeed(feed) account.removeFeed(feed)
@ -813,8 +798,6 @@ private extension FeedbinAccountDelegate {
} }
} }
}
func syncFavicons(_ account: Account, _ icons: [FeedbinIcon]?) { func syncFavicons(_ account: Account, _ icons: [FeedbinIcon]?) {
guard let icons = icons else { return } guard let icons = icons else { return }
@ -826,14 +809,11 @@ private extension FeedbinAccountDelegate {
for feed in account.flattenedFeeds() { for feed in account.flattenedFeeds() {
for (key, value) in iconDict { for (key, value) in iconDict {
if feed.homePageURL?.contains(key) ?? false { if feed.homePageURL?.contains(key) ?? false {
DispatchQueue.main.sync {
feed.faviconURL = value feed.faviconURL = value
}
break break
} }
} }
} }
} }

@ -1 +1 @@
Subproject commit afcbd0819c85b263acc892361ed840a9628eba4d Subproject commit b236f57627cb8aa3feac835689754d4863eb1788