Skip to content

Commit 750dded

Browse files
committed
Keep the existing update date if none is provided
As suggested by @TAKeanice's comment in issue ViennaRSS#1832 ViennaRSS#1832 (comment)
1 parent d0177a4 commit 750dded

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Vienna/Sources/Database/Database.m

+14-16
Original file line numberDiff line numberDiff line change
@@ -1604,18 +1604,6 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16041604
BOOL hasenclosure_flag = articleUpdate.hasEnclosure;
16051605
NSString * articleEnclosure = articleUpdate.enclosure.vna_trimmed;
16061606

1607-
// if a last update date is not provided, use either publication date or current date
1608-
if (!lastUpdate || [lastUpdate timeIntervalSince1970] == 0) {
1609-
lastUpdate = articleUpdate.publicationDate;
1610-
if (!lastUpdate || [lastUpdate timeIntervalSince1970] == 0) {
1611-
lastUpdate = [NSDate date];
1612-
}
1613-
articleUpdate.lastUpdate = lastUpdate;
1614-
}
1615-
1616-
// Dates are stored as time intervals
1617-
NSTimeInterval lastUpdateIntervalSince1970 = lastUpdate.timeIntervalSince1970;
1618-
16191607
// Set some defaults
16201608
if (userName == nil) {
16211609
userName = @"";
@@ -1633,15 +1621,18 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16331621
if (!isArticleRevised) {
16341622
__block NSString * existingBody = existingArticle.body;
16351623
__block NSString * existingEnclosure = existingArticle.enclosure;
1624+
__block NSDate * existingLastUpdate;
16361625
// the article text may not have been loaded yet, for instance if the folder is not displayed
16371626
if (existingBody == nil) {
16381627
[queue inDatabase:^(FMDatabase *db) {
1639-
FMResultSet * results = [db executeQuery:@"SELECT text, enclosure FROM messages WHERE folder_id=? AND message_id=?",
1628+
FMResultSet * results = [db executeQuery:@"SELECT date, text, enclosure FROM messages WHERE folder_id=? AND message_id=?",
16401629
@(folderID), articleGuid];
16411630
if ([results next]) {
1642-
existingBody = [results stringForColumnIndex:0];
1643-
existingEnclosure = [results stringForColumnIndex:1];
1644-
} else {
1631+
existingLastUpdate = [NSDate dateWithTimeIntervalSince1970:[results stringForColumnIndex:0].doubleValue];
1632+
existingBody = [results stringForColumnIndex:1];
1633+
existingEnclosure = [results stringForColumnIndex:2];
1634+
} else { // should never occur; set sensible fallbacks anyway
1635+
existingLastUpdate = articleUpdate.publicationDate;
16451636
existingBody = @"";
16461637
existingEnclosure = @"";
16471638
}
@@ -1650,8 +1641,15 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16501641
}
16511642
isArticleRevised = ![existingBody isEqualToString:articleBody]
16521643
|| (articleEnclosure != nil && ![existingEnclosure isEqualToString:articleEnclosure]);
1644+
// if a last update date is not provided in articleUpdate, use the one previously stored in database
1645+
if (!lastUpdate || [lastUpdate timeIntervalSince1970] == 0) {
1646+
lastUpdate = existingLastUpdate;
1647+
}
16531648
}
16541649

1650+
// Dates are stored as time intervals
1651+
NSTimeInterval lastUpdateIntervalSince1970 = lastUpdate.timeIntervalSince1970;
1652+
16551653
if (isArticleRevised) {
16561654
// Articles preexisting in database should be marked as revised.
16571655
// New articles created during the current refresh should not be marked as revised,

0 commit comments

Comments
 (0)