Skip to content

Commit

Permalink
always use the earliest date available for publication date
Browse files Browse the repository at this point in the history
only when there is a provided publication date on creation, use that one without questioning it
  • Loading branch information
TAKeanice authored and Eitot committed Aug 19, 2024
1 parent 8761e09 commit e9c4002
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Vienna/Sources/Database/Database.m
Original file line number Diff line number Diff line change
Expand Up @@ -1491,12 +1491,17 @@ -(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID

NSDate *currentDate = [NSDate date];

NSDate * lastUpdate = article.lastUpdate ? article.lastUpdate : currentDate;

// We set the publication date ourselves if it is not contained in the feed, and only once when the article is created
NSDate *publicationDate = article.publicationDate ? article.publicationDate : currentDate;
// use the given publication date or the earliest date available
NSDate *publicationDate = article.publicationDate
? article.publicationDate
: (lastUpdate && [lastUpdate isLessThan:currentDate]
? lastUpdate
: currentDate);
article.publicationDate = publicationDate;

NSDate * lastUpdate = article.lastUpdate ? article.lastUpdate : currentDate;

// Set some defaults
if (userName == nil) {
userName = @"";
Expand Down Expand Up @@ -1572,7 +1577,13 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit

//keep last update date the same if not set in the current version of the article
NSDate * lastUpdate = article.lastUpdate ? article.lastUpdate : existingArticle.lastUpdate;
//we do not update the publication date ever after inserting the article into the DB
//we do not make the publication date newer
NSDate * publicationDate = article.publicationDate && [article.publicationDate isLessThan:existingArticle.publicationDate]
? article.publicationDate
: (article.lastUpdate && [article.lastUpdate isLessThan:existingArticle.publicationDate]
? article.lastUpdate
: existingArticle.publicationDate);
article.publicationDate = publicationDate;

// Set some defaults
if (userName == nil) {
Expand All @@ -1586,6 +1597,7 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit

// Dates are stored as time intervals
NSTimeInterval lastUpdateIntervalSince1970 = lastUpdate.timeIntervalSince1970;
NSTimeInterval publicationIntervalSince1970 = publicationDate.timeIntervalSince1970;

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

Expand Down Expand Up @@ -1619,12 +1631,13 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit

__block BOOL success;
[queue inDatabase:^(FMDatabase *db) {
success = [db executeUpdate:@"UPDATE messages SET parent_id=?, sender=?, link=?, date=?, "
success = [db executeUpdate:@"UPDATE messages SET parent_id=?, sender=?, link=?, date=?, createddate=?, "
@"read_flag=0, title=?, text=?, revised_flag=? WHERE folder_id=? AND message_id=?",
@(parentId),
userName,
articleLink,
@(lastUpdateIntervalSince1970),
@(publicationIntervalSince1970),
articleTitle,
articleBody,
@(revised_flag),
Expand Down

0 comments on commit e9c4002

Please sign in to comment.