From b92a58144f7cc46cf3c602826d66504d7e0a5b29 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 25 Jul 2020 17:53:52 -0700 Subject: [PATCH] Remove references to no-longer-needed userDeleted property/column. --- Frameworks/Articles/ArticleStatus.swift | 15 ++++-------- .../ArticlesDatabase/ArticlesTable.swift | 23 ++++++++----------- Frameworks/ArticlesDatabase/Constants.swift | 1 - .../Extensions/ArticleStatus+Database.swift | 7 +++--- .../ArticlesDatabase/StatusesTable.swift | 8 +++---- .../Timeline/ArticlePasteboardWriter.swift | 1 - .../Timeline/TimelineViewController.swift | 2 +- Mac/Scriptability/Article+Scriptability.swift | 2 +- Shared/Commands/MarkStatusCommand.swift | 4 ---- Technotes/ArticlesAndStatuses.markdown | 4 ++-- .../MasterTimelineViewController.swift | 2 +- 11 files changed, 26 insertions(+), 43 deletions(-) diff --git a/Frameworks/Articles/ArticleStatus.swift b/Frameworks/Articles/ArticleStatus.swift index 4aaa8ee02..4ccc6b95c 100644 --- a/Frameworks/Articles/ArticleStatus.swift +++ b/Frameworks/Articles/ArticleStatus.swift @@ -19,7 +19,6 @@ public final class ArticleStatus: Hashable { public enum Key: String { case read = "read" case starred = "starred" - case userDeleted = "userDeleted" } public let articleID: String @@ -27,18 +26,16 @@ public final class ArticleStatus: Hashable { public var read = false public var starred = false - public var userDeleted = false - - public init(articleID: String, read: Bool, starred: Bool, userDeleted: Bool, dateArrived: Date) { + + public init(articleID: String, read: Bool, starred: Bool, dateArrived: Date) { self.articleID = articleID self.read = read self.starred = starred - self.userDeleted = userDeleted self.dateArrived = dateArrived } public convenience init(articleID: String, read: Bool, dateArrived: Date) { - self.init(articleID: articleID, read: read, starred: false, userDeleted: false, dateArrived: dateArrived) + self.init(articleID: articleID, read: read, starred: false, dateArrived: dateArrived) } public func boolStatus(forKey key: ArticleStatus.Key) -> Bool { @@ -47,8 +44,6 @@ public final class ArticleStatus: Hashable { return read case .starred: return starred - case .userDeleted: - return userDeleted } } @@ -58,8 +53,6 @@ public final class ArticleStatus: Hashable { read = status case .starred: starred = status - case .userDeleted: - userDeleted = status } } @@ -72,7 +65,7 @@ public final class ArticleStatus: Hashable { // MARK: - Equatable public static func ==(lhs: ArticleStatus, rhs: ArticleStatus) -> Bool { - return lhs.articleID == rhs.articleID && lhs.dateArrived == rhs.dateArrived && lhs.read == rhs.read && lhs.starred == rhs.starred && lhs.userDeleted == rhs.userDeleted + return lhs.articleID == rhs.articleID && lhs.dateArrived == rhs.dateArrived && lhs.read == rhs.read && lhs.starred == rhs.starred } } diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index 3324de127..a708abbc0 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -118,7 +118,7 @@ final class ArticlesTable: DatabaseTable { } let parameters = feedIDs.map { $0 as AnyObject } + [cutoffDate as AnyObject, cutoffDate as AnyObject] let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! - let whereClause = "feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?)) and userDeleted = 0" + let whereClause = "feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?))" return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters, withLimits: false) } @@ -133,13 +133,13 @@ final class ArticlesTable: DatabaseTable { } private func fetchStarredArticles(_ feedIDs: Set, _ database: FMDatabase) -> Set
{ - // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred = 1 and userDeleted = 0; + // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred = 1; if feedIDs.isEmpty { return Set
() } let parameters = feedIDs.map { $0 as AnyObject } let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! - let whereClause = "feedID in \(placeholders) and starred = 1 and userDeleted = 0" + let whereClause = "feedID in \(placeholders) and starred = 1" return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters, withLimits: false) } @@ -215,7 +215,7 @@ final class ArticlesTable: DatabaseTable { // 1. Ensure statuses for all the incoming articles. // 2. Create incoming articles with parsedItems. - // 3. Ignore incoming articles that are userDeleted || (!starred and really old) + // 3. Ignore incoming articles that are (!starred and really old) // 4. Fetch all articles for the feed. // 5. Create array of Articles not in database and save them. // 6. Create array of updated Articles and save what’s changed. @@ -309,7 +309,7 @@ final class ArticlesTable: DatabaseTable { queue.runInDatabase { (database) in let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! - let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?)) and read=0 and userDeleted=0;" + let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?)) and read=0;" var parameters = [Any]() parameters += Array(feedIDs) as [Any] @@ -330,7 +330,7 @@ final class ArticlesTable: DatabaseTable { let cutoffDate = articleCutoffDate queue.runInDatabase { (database) in - let sql = "select distinct feedID, count(*) from articles natural join statuses where read=0 and userDeleted=0 and (starred=1 or dateArrived>?) group by feedID;" + let sql = "select distinct feedID, count(*) from articles natural join statuses where read=0 and (starred=1 or dateArrived>?) group by feedID;" guard let resultSet = database.executeQuery(sql, withArgumentsIn: [cutoffDate]) else { DispatchQueue.main.async { @@ -361,7 +361,7 @@ final class ArticlesTable: DatabaseTable { queue.runInDatabase { (database) in let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! - let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 and starred=1 and userDeleted=0;" + let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 and starred=1;" let parameters = Array(feedIDs) as [Any] let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database) @@ -629,7 +629,7 @@ private extension ArticlesTable { // * Must be either 1) starred or 2) dateArrived must be newer than cutoff date. if withLimits { - let sql = "select * from articles natural join statuses where \(whereClause) and userDeleted=0 and (starred=1 or dateArrived>?);" + let sql = "select * from articles natural join statuses where \(whereClause) and (starred=1 or dateArrived>?);" return articlesWithSQL(sql, parameters + [articleCutoffDate as AnyObject], database) } else { @@ -644,7 +644,7 @@ private extension ArticlesTable { // * Must not be deleted. // * Must be either 1) starred or 2) dateArrived must be newer than cutoff date. - let sql = "select count(*) from articles natural join statuses where feedID=? and read=0 and userDeleted=0 and (starred=1 or dateArrived>?);" + let sql = "select count(*) from articles natural join statuses where feedID=? and read=0 and (starred=1 or dateArrived>?);" return numberWithSQLAndParameters(sql, [feedID, articleCutoffDate], in: database) } @@ -803,10 +803,7 @@ private extension ArticlesTable { } func statusIndicatesArticleIsIgnorable(_ status: ArticleStatus) -> Bool { - // Ignorable articles: either userDeleted==1 or (not starred and arrival date > 4 months). - if status.userDeleted { - return true - } + // Ignorable articles: not starred and arrival date > 4 months. if status.starred { return false } diff --git a/Frameworks/ArticlesDatabase/Constants.swift b/Frameworks/ArticlesDatabase/Constants.swift index 44e19ef00..ef3911eaa 100644 --- a/Frameworks/ArticlesDatabase/Constants.swift +++ b/Frameworks/ArticlesDatabase/Constants.swift @@ -42,7 +42,6 @@ struct DatabaseKey { // ArticleStatus static let read = "read" static let starred = "starred" - static let userDeleted = "userDeleted" static let dateArrived = "dateArrived" // Tag diff --git a/Frameworks/ArticlesDatabase/Extensions/ArticleStatus+Database.swift b/Frameworks/ArticlesDatabase/Extensions/ArticleStatus+Database.swift index b4d46650e..143a19536 100644 --- a/Frameworks/ArticlesDatabase/Extensions/ArticleStatus+Database.swift +++ b/Frameworks/ArticlesDatabase/Extensions/ArticleStatus+Database.swift @@ -15,9 +15,8 @@ extension ArticleStatus { convenience init(articleID: String, dateArrived: Date, row: FMResultSet) { let read = row.bool(forColumn: DatabaseKey.read) let starred = row.bool(forColumn: DatabaseKey.starred) - let userDeleted = row.bool(forColumn: DatabaseKey.userDeleted) - - self.init(articleID: articleID, read: read, starred: starred, userDeleted: userDeleted, dateArrived: dateArrived) + + self.init(articleID: articleID, read: read, starred: starred, dateArrived: dateArrived) } } @@ -29,7 +28,7 @@ extension ArticleStatus: DatabaseObject { } public func databaseDictionary() -> DatabaseDictionary? { - return [DatabaseKey.articleID: articleID, DatabaseKey.read: read, DatabaseKey.starred: starred, DatabaseKey.userDeleted: userDeleted, DatabaseKey.dateArrived: dateArrived] + return [DatabaseKey.articleID: articleID, DatabaseKey.read: read, DatabaseKey.starred: starred, DatabaseKey.dateArrived: dateArrived] } } diff --git a/Frameworks/ArticlesDatabase/StatusesTable.swift b/Frameworks/ArticlesDatabase/StatusesTable.swift index 745bd9efb..02b00eae7 100644 --- a/Frameworks/ArticlesDatabase/StatusesTable.swift +++ b/Frameworks/ArticlesDatabase/StatusesTable.swift @@ -13,7 +13,7 @@ import Articles // Article->ArticleStatus is a to-one relationship. // -// CREATE TABLE if not EXISTS statuses (articleID TEXT NOT NULL PRIMARY KEY, read BOOL NOT NULL DEFAULT 0, starred BOOL NOT NULL DEFAULT 0, userDeleted BOOL NOT NULL DEFAULT 0, dateArrived DATE NOT NULL DEFAULT 0); +// CREATE TABLE if not EXISTS statuses (articleID TEXT NOT NULL PRIMARY KEY, read BOOL NOT NULL DEFAULT 0, starred BOOL NOT NULL DEFAULT 0, dateArrived DATE NOT NULL DEFAULT 0); final class StatusesTable: DatabaseTable { @@ -75,15 +75,15 @@ final class StatusesTable: DatabaseTable { // MARK: - Fetching func fetchUnreadArticleIDs() -> Set { - return fetchArticleIDs("select articleID from statuses where read=0 and userDeleted=0;") + return fetchArticleIDs("select articleID from statuses where read=0;") } func fetchStarredArticleIDs() -> Set { - return fetchArticleIDs("select articleID from statuses where starred=1 and userDeleted=0;") + return fetchArticleIDs("select articleID from statuses where starred=1;") } func fetchArticleIDsForStatusesWithoutArticles() -> Set { - return fetchArticleIDs("select articleID from statuses s where (read=0 or starred=1) and userDeleted=0 and not exists (select 1 from articles a where a.articleID = s.articleID);") + return fetchArticleIDs("select articleID from statuses s where (read=0 or starred=1) and not exists (select 1 from articles a where a.articleID = s.articleID);") } func fetchArticleIDs(_ sql: String) -> Set { diff --git a/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift b/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift index f587b0e02..0362803ae 100644 --- a/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift +++ b/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift @@ -119,7 +119,6 @@ private extension ArticlePasteboardWriter { static let dateArrived = "dateArrived" static let read = "read" static let starred = "starred" - static let userDeleted = "userDeleted" static let authors = "authors" // Author diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 46f6f036f..b8e90f57f 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -548,7 +548,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr private func calculateRowHeight(showingFeedNames: Bool) -> CGFloat { let longTitle = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" let prototypeID = "prototype" - let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, userDeleted: false, dateArrived: Date()) + let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, bannerImageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) let prototypeCellData = TimelineCellData(article: prototypeArticle, showFeedName: showingFeedNames, feedName: "Prototype Feed Name", avatar: nil, showAvatar: false, featuredImage: nil) diff --git a/Mac/Scriptability/Article+Scriptability.swift b/Mac/Scriptability/Article+Scriptability.swift index eca5bb971..08381c8d6 100644 --- a/Mac/Scriptability/Article+Scriptability.swift +++ b/Mac/Scriptability/Article+Scriptability.swift @@ -127,7 +127,7 @@ class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjectConta @objc(deleted) var deleted:Bool { - return article.status.boolStatus(forKey:.userDeleted) + return false } @objc(imageURL) diff --git a/Shared/Commands/MarkStatusCommand.swift b/Shared/Commands/MarkStatusCommand.swift index 5d78d664a..9c1a26072 100644 --- a/Shared/Commands/MarkStatusCommand.swift +++ b/Shared/Commands/MarkStatusCommand.swift @@ -71,8 +71,6 @@ private extension MarkStatusCommand { static private let markUnreadActionName = NSLocalizedString("Mark Unread", comment: "command") static private let markStarredActionName = NSLocalizedString("Mark Starred", comment: "command") static private let markUnstarredActionName = NSLocalizedString("Mark Unstarred", comment: "command") - static private let markDeletedActionName = NSLocalizedString("Delete", comment: "command") - static private let markUndeletedActionName = NSLocalizedString("Undelete", comment: "command") static func actionName(_ statusKey: ArticleStatus.Key, _ flag: Bool) -> String { @@ -81,8 +79,6 @@ private extension MarkStatusCommand { return flag ? markReadActionName : markUnreadActionName case .starred: return flag ? markStarredActionName : markUnstarredActionName - case .userDeleted: - return flag ? markDeletedActionName : markUndeletedActionName } } diff --git a/Technotes/ArticlesAndStatuses.markdown b/Technotes/ArticlesAndStatuses.markdown index 818cee37f..4cee95529 100644 --- a/Technotes/ArticlesAndStatuses.markdown +++ b/Technotes/ArticlesAndStatuses.markdown @@ -6,7 +6,7 @@ In the database (see ArticlesDatabase), they’re stored in two separate tables: The articles table contains the columns you’d expect: `articleID`, `title`, `contentHTML`, and so on. -The statuses table contains `articleID`, `read`, `starred`, `userDeleted`, and `dateArrived` columns. +The statuses table contains `articleID`, `read`, `starred`, and `dateArrived` columns. This separation is deliberate. There are two main reasons: syncing, and strange behavior. @@ -34,4 +34,4 @@ With the article deleted — and since it has no pubDate — how can the app te Here’s how: it still has the status, and the status includes a `dateArrived` property which is in the distant past — and so NetNewsWire knows that it’s not new but old. -Note that statuses do get deleted eventually, too (in theory) — but that’s after a much longer period of time. \ No newline at end of file +Note that statuses do get deleted eventually, too (in theory) — but that’s after a much longer period of time. diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 7e445e536..d335a52b3 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -329,7 +329,7 @@ class MasterTimelineViewController: ProgressTableViewController, UndoableCommand let longTitle = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" let prototypeID = "prototype" - let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, userDeleted: false, dateArrived: Date()) + let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, bannerImageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) let prototypeCellData = MasterTimelineCellData(article: prototypeArticle, showFeedName: true, feedName: "Prototype Feed Name", avatar: nil, showAvatar: false, featuredImage: nil, numberOfLines: numberOfTextLines)