Skip to content

Commit

Permalink
Add
Browse files Browse the repository at this point in the history
  • Loading branch information
TAKeanice authored and Eitot committed Jul 21, 2024
1 parent d5f1dc7 commit 4360dd3
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 140 deletions.
16 changes: 8 additions & 8 deletions Vienna Tests/ArticleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ class ArticleTests: XCTestCase {
XCTAssertEqual(self.article.link, link)
}

func testDate() {
func testLastUpdate() {
let date = Date()

self.article.date = date
self.article.lastUpdate = date

XCTAssertEqual(self.article.date, date)
XCTAssertEqual(self.article.lastUpdate, date)
}

func testDateCreated() {
func testPublicationDate() {
let date = Date()

self.article.createdDate = date
self.article.publicationDate = date

XCTAssertEqual(self.article.createdDate, date)
XCTAssertEqual(self.article.publicationDate, date)
}

func testBody() {
Expand Down Expand Up @@ -193,9 +193,9 @@ class ArticleTests: XCTestCase {

func testCompatibilityDate() {
let date = Date()
let dateKeyPath = "articleData." + MA_Field_Date
let dateKeyPath = "articleData." + MA_Field_LastUpdate

self.article.date = date
self.article.lastUpdate = date

XCTAssertEqual(self.article.value(forKeyPath: dateKeyPath) as? Date, date)
}
Expand Down
16 changes: 8 additions & 8 deletions Vienna Tests/VNAArticleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ - (void)testLink
XCTAssertEqualObjects(self.article.link, Link);
}

- (void)testDate
- (void)testLastUpdate
{
NSDate *date = [NSDate date];

self.article.date = date;
self.article.lastUpdate = date;

XCTAssertEqualObjects(self.article.date, date);
XCTAssertEqualObjects(self.article.lastUpdate, date);
}

- (void)testDateCreated
- (void)testPublicationDate
{
NSDate *date = [NSDate date];

self.article.createdDate = date;
self.article.publicationDate = date;

XCTAssertEqualObjects(self.article.createdDate, date);
XCTAssertEqualObjects(self.article.publicationDate, date);
}

- (void)testBody
Expand Down Expand Up @@ -201,9 +201,9 @@ - (void)testMarkEnclosureDowloaded
- (void)testCompatibilityDate
{
NSDate *date = [NSDate date];
NSString *dateKeyPath = [@"articleData." stringByAppendingString:MA_Field_Date];
NSString *dateKeyPath = [@"articleData." stringByAppendingString:MA_Field_LastUpdate];

self.article.date = date;
self.article.lastUpdate = date;

XCTAssertEqualObjects([self.article valueForKeyPath:dateKeyPath], date);
}
Expand Down
8 changes: 4 additions & 4 deletions Vienna/Resources/Base.lproj/Predicates.strings
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"%[All,Any,None]@ of the following are true" = "Article matches %1$[all,any,none]@ of the following conditions";
"%[Author,Folder,Subject,Text]@ %[is,is not]@ %@" = "%1$[Author,Folder,Subject,Content]@ %2$[is,is not]@ %3$@";
"%[Author,Subject,Text]@ %[contains,does not contain]@ %@" = "%1$[Author,Subject,Content]@ %2$[contains,does not contain]@ %3$@";
"%[Date]@ %[is,is greater than or equal to,is less than,is less than or equal to]@ %[yesterday]@" = "%1$[Date]@ %2$[is,is after or is,is before,is before or is]@ %3$[yesterday]@";
"%[Date]@ %[is,is greater than,is greater than or equal to,is less than,is less than or equal to]@ %[last week]@" = "%1$[Date]@ %2$[is,is after,is after or is,is before,is before or is]@ %3$[last week]@";
"%[Date]@ %[is,is less than,is less than or equal to]@ %[today]@" = "%1$[Date]@ %2$[is,is before,is before or is]@ %3$[today]@";
"%[Date]@ %[less than ago,more than ago]@ %[days,hours,minutes,months,weeks,years]@ %@" = "%1$[Date]@ %2$[is in the last,is not in the last]@ %4$@ %3$[days,hours,minutes,months,weeks,years]@";
"%[Date]@ %[is,is greater than or equal to,is less than,is less than or equal to]@ %[yesterday]@" = "%1$[Last update]@ %2$[is,is after or is,is before,is before or is]@ %3$[yesterday]@";
"%[Date]@ %[is,is greater than,is greater than or equal to,is less than,is less than or equal to]@ %[last week]@" = "%1$[Last update]@ %2$[is,is after,is after or is,is before,is before or is]@ %3$[last week]@";
"%[Date]@ %[is,is less than,is less than or equal to]@ %[today]@" = "%1$[Last update]@ %2$[is,is before,is before or is]@ %3$[today]@";
"%[Date]@ %[less than ago,more than ago]@ %[days,hours,minutes,months,weeks,years]@ %@" = "%1$[Last update]@ %2$[is in the last,is not in the last]@ %4$@ %3$[days,hours,minutes,months,weeks,years]@";
"%[Deleted,Flagged,HasEnclosure,Read]@ is %[No,Yes]@" = "%1$[Is deleted,Is flagged,Has enclosure,Is read]@ %2$[No,Yes]@";
7 changes: 7 additions & 0 deletions Vienna/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -6109,6 +6109,7 @@
},
"Date" : {
"comment" : "Data field name visible in menu/article list/smart folder definition",
"extractionState" : "stale",
"localizations" : {
"cs" : {
"stringUnit" : {
Expand Down Expand Up @@ -6232,6 +6233,9 @@
}
}
},
"Date Published" : {
"comment" : "Data field name visible in menu/article list/smart folder definition"
},
"Delete" : {
"comment" : "Title of a button on an alert\n Title of a menu item",
"localizations" : {
Expand Down Expand Up @@ -12463,6 +12467,9 @@
}
}
},
"Last Update" : {
"comment" : "Data field name visible in menu/article list/smart folder definition"
},
"Link" : {
"comment" : "Data field name visible in menu/article list",
"localizations" : {
Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Alerts/SmartFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ - (void)prepareTemplates
[rowTemplates addObject:[VNASeparatorPredicateEditorRowTemplate new]];

// date < / > days / weeks / months / years old
NSPredicateEditorRowTemplate *dateCompareTemplate = [[VNADateWithUnitPredicateEditorRowTemplate alloc] initWithLeftExpressions:@[[NSExpression expressionForConstantValue:MA_Field_Date]]];
NSPredicateEditorRowTemplate *dateCompareTemplate = [[VNADateWithUnitPredicateEditorRowTemplate alloc] initWithLeftExpressions:@[[NSExpression expressionForConstantValue:MA_Field_LastUpdate]]];
[rowTemplates addObject:dateCompareTemplate];

// date = / < / <= today / yesterday / lastWeek
Expand Down
8 changes: 4 additions & 4 deletions Vienna/Sources/Criteria/Criteria+NSPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ extension Criteria: PredicateConvertible {
fallback = true
criteriaOperator = .equalTo
}
case MA_Field_Date:
case MA_Field_LastUpdate:
switch predicate.predicateOperatorType {
case .lessThan:
criteriaOperator = .before
Expand Down Expand Up @@ -231,14 +231,14 @@ extension Criteria: PredicateConvertible {
let value = self.value
let operatorType = self.operatorType

if field == MA_Field_Date, let unit = DateUnit.allCases.first(where: { value.hasSuffix($0.rawValue) }) {
if field == MA_Field_LastUpdate, let unit = DateUnit.allCases.first(where: { value.hasSuffix($0.rawValue) }) {
let countString = value
.replacingOccurrences(of: unit.rawValue, with: "")
.trimmingCharacters(in: CharacterSet.whitespaces)
guard let count = UInt(countString) else {
fatalError("malformed criteria value \(value)")
}
return DatePredicateWithUnit(field: MA_Field_Date, comparisonOperator: operatorType, count: count, unit: unit)
return DatePredicateWithUnit(field: MA_Field_LastUpdate, comparisonOperator: operatorType, count: count, unit: unit)
} else {
return buildComparisonPredicate(field, value, operatorType)
}
Expand Down Expand Up @@ -291,7 +291,7 @@ extension Criteria: PredicateConvertible {
// TODO: constants for fixed criteria values also for Criteria+SQL,
// e.g. YES, NO, yesterday, today, last week, ...

if field == MA_Field_Date && operatorType == .after && value == "yesterday" {
if field == MA_Field_LastUpdate && operatorType == .after && value == "yesterday" {
// Use canonical "is today" instead of "is after yesterday"
comparisonPredicate = NSComparisonPredicate(leftExpression: left, rightExpression: NSExpression(forConstantValue: "today"), modifier: .direct, type: .equalTo)
} else if operatorType == .notEqualTo && (value == "No" || value == "Yes") {
Expand Down
45 changes: 23 additions & 22 deletions Vienna/Sources/Database/Database.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ - (BOOL)setupInitialDatabase {
[self createInitialSmartFolder:NSLocalizedString(@"Unread Articles", nil) withCriteria:unreadCriteria];

// Create a criteria to show all articles received today
Criteria * todayCriteria = [[Criteria alloc] initWithField:MA_Field_Date operatorType:VNACriteriaOperatorEqualTo value:@"today"];
Criteria * todayCriteria = [[Criteria alloc] initWithField:MA_Field_LastUpdate operatorType:VNACriteriaOperatorEqualTo value:@"today"];
[self createInitialSmartFolder:NSLocalizedString(@"Today's Articles", nil) withCriteria:todayCriteria];

[self.databaseQueue inDatabase:^(FMDatabase *db) {
Expand Down Expand Up @@ -305,8 +305,8 @@ -(void)initaliseFields {
[self addField:MA_Field_GUID type:VNAFieldTypeInteger tag:VNAArticleFieldTagGUID sqlField:@"message_id" visible:NO width:72];
[self addField:MA_Field_Subject type:VNAFieldTypeString tag:VNAArticleFieldTagSubject sqlField:@"title" visible:YES width:472];
[self addField:MA_Field_Folder type:VNAFieldTypeFolder tag:VNAArticleFieldTagFolder sqlField:@"folder_id" visible:NO width:130];
[self addField:MA_Field_Date type:VNAFieldTypeDate tag:VNAArticleFieldTagDate sqlField:@"date" visible:YES width:152];
[self addField:MA_Field_CreatedDate type:VNAFieldTypeDate tag:VNAArticleFieldTagCreatedDate sqlField:@"createddate" visible:NO width:152];
[self addField:MA_Field_LastUpdate type:VNAFieldTypeDate tag:VNAArticleFieldTagLastUpdate sqlField:@"date" visible:YES width:152];
[self addField:MA_Field_PublicationDate type:VNAFieldTypeDate tag:VNAArticleFieldTagPublicationDate sqlField:@"createddate" visible:NO width:152];
[self addField:MA_Field_Parent type:VNAFieldTypeInteger tag:VNAArticleFieldTagParent sqlField:@"parent_id" visible:NO width:72];
[self addField:MA_Field_Author type:VNAFieldTypeString tag:VNAArticleFieldTagAuthor sqlField:@"sender" visible:YES width:138];
[self addField:MA_Field_Link type:VNAFieldTypeString tag:VNAArticleFieldTagLink sqlField:@"link" visible:NO width:138];
Expand All @@ -324,8 +324,8 @@ -(void)initaliseFields {
[self fieldByName:MA_Field_Deleted].displayName = NSLocalizedString(@"Deleted", @"Data field name visible in smart folder definition");
[self fieldByName:MA_Field_Subject].displayName = NSLocalizedString(@"Subject", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_Folder].displayName = NSLocalizedString(@"Folder", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_Date].displayName = NSLocalizedString(@"Date", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_CreatedDate].displayName = NSLocalizedString(@"Date Added", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_LastUpdate].displayName = NSLocalizedString(@"Last Update", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_PublicationDate].displayName = NSLocalizedString(@"Date Published", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_Author].displayName = NSLocalizedString(@"Author", @"Data field name visible in menu/article list/smart folder definition");
[self fieldByName:MA_Field_Text].displayName = NSLocalizedString(@"Text", @"Data field name visible in smart folder definition");
[self fieldByName:MA_Field_Summary].displayName = NSLocalizedString(@"Summary", @"Pseudo field name visible in menu/article list");
Expand Down Expand Up @@ -1478,7 +1478,7 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
// Extract the article data from the dictionary.
NSString * articleBody = article.body;
NSString * articleTitle = article.title;
NSDate * articleDate = article.date;
NSDate * lastUpdate = article.lastUpdate;
NSString * articleLink = article.link.vna_trimmed;
NSString * userName = article.author.vna_trimmed;
NSString * articleEnclosure = article.enclosure.vna_trimmed;
Expand All @@ -1490,12 +1490,12 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
BOOL deleted_flag = article.deleted;
BOOL hasenclosure_flag = article.hasEnclosure;

// We always set the created date ourselves
article.createdDate = [NSDate date];
// We set the publication date ourselves if it is not contained in the feed, and only once when the article is created
article.publicationDate = article.publicationDate == nil ? [NSDate date] : article.publicationDate;

// Set some defaults
if (articleDate == nil) {
articleDate = [NSDate date];
if (lastUpdate == nil) {
lastUpdate = [NSDate date];
}
if (userName == nil) {
userName = @"";
Expand All @@ -1507,9 +1507,10 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
}

// Dates are stored as time intervals
NSTimeInterval interval = articleDate.timeIntervalSince1970;
NSTimeInterval createdInterval = article.createdDate.timeIntervalSince1970;

NSTimeInterval lastUpdateIntervalSince1970 = lastUpdate.timeIntervalSince1970;
NSTimeInterval publicationIntervalSince1970 =
(article.publicationDate == nil ? [NSDate date] : article.publicationDate).timeIntervalSince1970;

__block BOOL success;
[queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
success = [db executeUpdate:@"INSERT INTO messages (message_id, parent_id, folder_id, sender, link, date, createddate, read_flag, marked_flag, deleted_flag, title, text, revised_flag, enclosure, hasenclosure_flag) "
Expand All @@ -1519,8 +1520,8 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID
@(folderID),
userName,
articleLink,
@(interval),
@(createdInterval),
@(lastUpdateIntervalSince1970),
@(publicationIntervalSince1970),
@(read_flag),
@(marked_flag),
@(deleted_flag),
Expand Down Expand Up @@ -1563,16 +1564,16 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
// Extract the data from the new state of article
NSString * articleBody = article.body;
NSString * articleTitle = article.title;
NSDate * articleDate = article.date;
NSDate * lastUpdate = article.lastUpdate;
NSString * articleLink = article.link.vna_trimmed;
NSString * userName = article.author.vna_trimmed;
NSString * articleGuid = article.guid;
NSInteger parentId = article.parentId;
BOOL revised_flag = article.revised;

// Set some defaults
if (articleDate == nil) {
articleDate = existingArticle.date;
if (lastUpdate == nil) {
lastUpdate = existingArticle.lastUpdate;
}
if (userName == nil) {
userName = @"";
Expand All @@ -1584,7 +1585,7 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
}

// Dates are stored as time intervals
NSTimeInterval interval = articleDate.timeIntervalSince1970;
NSTimeInterval lastUpdateIntervalSince1970 = lastUpdate.timeIntervalSince1970;

// The article is revised if either the title or the body has changed.

Expand Down Expand Up @@ -1623,7 +1624,7 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
@(parentId),
userName,
articleLink,
@(interval),
@(lastUpdateIntervalSince1970),
articleTitle,
articleBody,
@(revised_flag),
Expand Down Expand Up @@ -2198,8 +2199,8 @@ -(NSArray *)arrayOfArticles:(NSInteger)folderId filterString:(NSString *)filterS
article.title = [results stringForColumnIndex:6];
article.author = [results stringForColumnIndex:7];
article.link = [results stringForColumnIndex:8];
article.createdDate = [NSDate dateWithTimeIntervalSince1970:[results stringForColumnIndex:9].doubleValue];
article.date = [NSDate dateWithTimeIntervalSince1970:[results stringForColumnIndex:10].doubleValue];
article.publicationDate = [NSDate dateWithTimeIntervalSince1970:[results stringForColumnIndex:9].doubleValue];
article.lastUpdate = [NSDate dateWithTimeIntervalSince1970:[results stringForColumnIndex:10].doubleValue];
NSString * text = [results stringForColumnIndex:11];
article.body = text;
[article markRevised:[results intForColumnIndex:12]];
Expand Down
6 changes: 4 additions & 2 deletions Vienna/Sources/Fetching/OpenReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ -(void)feedRequestDone:(NSMutableURLRequest *)request response:(NSURLResponse *)
NSMutableArray *articleArray = [NSMutableArray array];

for (NSDictionary *newsItem in (NSArray *)subscriptionsDict[@"items"]) {
NSDate *articleDate = [NSDate dateWithTimeIntervalSince1970:[newsItem[@"published"] doubleValue]];
NSDate *publicationDate = [NSDate dateWithTimeIntervalSince1970:[newsItem[@"published"] doubleValue]];
NSDate *lastUpdate = [NSDate dateWithTimeIntervalSince1970:[newsItem[@"updated"] doubleValue]];
NSString *articleGuid = newsItem[@"id"];
Article *article = [[Article alloc] initWithGuid:articleGuid];
article.folderId = refreshedFolder.itemId;
Expand Down Expand Up @@ -611,7 +612,8 @@ -(void)feedRequestDone:(NSMutableURLRequest *)request response:(NSURLResponse *)
article.link = refreshedFolder.feedURL;
}

article.date = articleDate;
article.publicationDate = publicationDate == nil ? lastUpdate : publicationDate;
article.lastUpdate = lastUpdate == nil ? publicationDate : lastUpdate;

if ([newsItem[@"enclosure"] count] != 0) {
article.enclosure = newsItem[@"enclosure"][0][@"href"];
Expand Down
8 changes: 4 additions & 4 deletions Vienna/Sources/Fetching/RefreshManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,15 @@ -(void)finalizeFolderRefresh:(NSDictionary *)parameters
NSMutableArray *articleArray = [NSMutableArray array];
NSMutableArray *articleGuidArray = [NSMutableArray array];

NSDate *itemAlternativeDate = newFeed.modifiedDate;
NSDate *itemAlternativeDate = newFeed.modificationDate;
if (itemAlternativeDate == nil) {
itemAlternativeDate = [NSDate date];
}

// Parse off items.

for (id<VNAFeedItem> newsItem in newFeed.items) {
NSDate * articleDate = newsItem.modifiedDate;
NSDate * articleDate = newsItem.modificationDate;

NSString * articleGuid = newsItem.guid;

Expand Down Expand Up @@ -796,7 +796,7 @@ -(void)finalizeFolderRefresh:(NSDictionary *)parameters
// first, hack the initial article (which is probably the first loaded / most recent one)
NSString * firstFoundArticleNewGuid =
[NSString stringWithFormat:@"%ld-%@-%@-%@", (long)folderId,
[NSString stringWithFormat:@"%1.3f", firstFoundArticle.date.timeIntervalSince1970], firstFoundArticle.link,
[NSString stringWithFormat:@"%1.3f", firstFoundArticle.lastUpdate.timeIntervalSince1970], firstFoundArticle.link,
firstFoundArticle.title];
firstFoundArticle.guid = firstFoundArticleNewGuid;
articleGuidArray[articleIndex] = firstFoundArticleNewGuid;
Expand Down Expand Up @@ -838,7 +838,7 @@ -(void)finalizeFolderRefresh:(NSDictionary *)parameters
articleLink = feedLink;
}
article.link = articleLink;
article.date = articleDate;
article.lastUpdate = articleDate;
NSString * enclosureLink = newsItem.enclosure;
if ([enclosureLink isNotEqualTo:@""] && ![enclosureLink hasPrefix:@"http:"] && ![enclosureLink hasPrefix:@"https:"]) {
enclosureLink = [NSURL URLWithString:enclosureLink relativeToURL:url].absoluteString;
Expand Down
Loading

0 comments on commit 4360dd3

Please sign in to comment.