Skip to content

Commit 9af7535

Browse files
committed
Consider a change of enclosure link as a revision
1 parent bb39327 commit 9af7535

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Vienna/Sources/Database/Database.m

+16-7
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,8 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16011601
NSString * articleGuid = articleUpdate.guid;
16021602
NSInteger parentId = articleUpdate.parentId;
16031603
BOOL revised_flag = articleUpdate.isRevised;
1604+
BOOL hasenclosure_flag = articleUpdate.hasEnclosure;
1605+
NSString * articleEnclosure = articleUpdate.enclosure.vna_trimmed;
16041606

16051607
// if a last update date is not provided, use either publication date or current date
16061608
if (!lastUpdate || [lastUpdate timeIntervalSince1970] == 0) {
@@ -1624,26 +1626,30 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16241626
articleTitle = [NSString vna_stringByRemovingHTML:articleBody].vna_firstNonBlankLine;
16251627
}
16261628

1627-
// The article is revised if either the title or the body has changed.
1629+
// The article is revised if either the title, the body or the enclosure link has changed.
16281630

16291631
NSString * existingTitle = existingArticle.title;
16301632
BOOL isArticleRevised = ![existingTitle isEqualToString:articleTitle];
16311633
if (!isArticleRevised) {
1632-
__block NSString * existingBody = existingArticle.body;
1634+
__block NSString * existingBody;
1635+
__block NSString * existingEnclosure;
16331636
// the article text may not have been loaded yet, for instance if the folder is not displayed
16341637
if (existingBody == nil) {
16351638
[queue inDatabase:^(FMDatabase *db) {
1636-
FMResultSet * results = [db executeQuery:@"SELECT text FROM messages WHERE folder_id=? AND message_id=?",
1639+
FMResultSet * results = [db executeQuery:@"SELECT text, enclosure FROM messages WHERE folder_id=? AND message_id=?",
16371640
@(folderID), articleGuid];
16381641
if ([results next]) {
1639-
existingBody = [results stringForColumn:@"text"];
1642+
existingBody = [results stringForColumnIndex:0];
1643+
existingEnclosure = [results stringForColumnIndex:1];
16401644
} else {
16411645
existingBody = @"";
1646+
existingEnclosure = @"";
16421647
}
16431648
[results close];
16441649
}];
16451650
}
1646-
isArticleRevised = ![existingBody isEqualToString:articleBody];
1651+
isArticleRevised = ![existingBody isEqualToString:articleBody]
1652+
|| ![existingEnclosure isEqualToString:articleEnclosure];
16471653
}
16481654

16491655
if (isArticleRevised) {
@@ -1657,15 +1663,18 @@ -(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID wit
16571663
// Note: we never change the publication date
16581664
__block BOOL success;
16591665
[queue inDatabase:^(FMDatabase *db) {
1660-
success = [db executeUpdate:@"UPDATE messages SET parent_id=?, sender=?, link=?, date=?, "
1661-
@"read_flag=0, title=?, text=?, revised_flag=? WHERE folder_id=? AND message_id=?",
1666+
success = [db executeUpdate:@"UPDATE messages SET parent_id=?, sender=?, link=?, date=? "
1667+
@"read_flag=0, title=?, text=?, revised_flag=?, enclosure=?, hasenclosure_flag=? "
1668+
@"WHERE folder_id=? AND message_id=?",
16621669
@(parentId),
16631670
userName,
16641671
articleLink,
16651672
@(lastUpdateIntervalSince1970),
16661673
articleTitle,
16671674
articleBody,
16681675
@(revised_flag),
1676+
articleEnclosure,
1677+
@(hasenclosure_flag),
16691678
@(folderID),
16701679
articleGuid];
16711680

0 commit comments

Comments
 (0)