diff options
author | Brendan Long <self@brendanlong.com> | 2017-10-17 17:39:19 +0300 |
---|---|---|
committer | Brendan Long <self@brendanlong.com> | 2017-10-17 17:39:19 +0300 |
commit | 797e5f8187dfa094e367c09726e1c1c32510c1ed (patch) | |
tree | 4bcd46b9212c7208be66fdbe208dd7f81a3787bd | |
parent | dcb57f0c5537fcd7c83e892af3fd8f9b177e701d (diff) |
Centralize Article null checks
-rw-r--r-- | plugins/backend/bazqux/bazquxAPI.vala | 2 | ||||
-rw-r--r-- | plugins/backend/feedbin/feedbinInterface.vala | 12 | ||||
-rw-r--r-- | plugins/backend/feedhq/feedhqAPI.vala | 6 | ||||
-rw-r--r-- | plugins/backend/feedly/feedlyAPI.vala | 12 | ||||
-rw-r--r-- | plugins/backend/fresh/freshAPI.vala | 11 | ||||
-rw-r--r-- | plugins/backend/inoreader/InoReaderAPI.vala | 4 | ||||
-rw-r--r-- | plugins/backend/local/localInterface.vala | 5 | ||||
-rw-r--r-- | plugins/backend/oldreader/oldreaderAPI.vala | 4 | ||||
-rw-r--r-- | plugins/backend/owncloud/OwncloudNewsAPI.vala | 12 | ||||
-rw-r--r-- | plugins/backend/ttrss/ttrssAPI.vala | 18 | ||||
-rw-r--r-- | src/DataBaseReadOnly.vala | 12 | ||||
-rw-r--r-- | src/Model/Article.vala | 26 |
12 files changed, 57 insertions, 67 deletions
diff --git a/plugins/backend/bazqux/bazquxAPI.vala b/plugins/backend/bazqux/bazquxAPI.vala index 2cd75cde..54372565 100644 --- a/plugins/backend/bazqux/bazquxAPI.vala +++ b/plugins/backend/bazqux/bazquxAPI.vala @@ -384,7 +384,7 @@ public class FeedReader.bazquxAPI : GLib.Object { marked ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, object.get_object_member("summary").get_string_member("content"), "", - (object.get_string_member("author") == "") ? null : object.get_string_member("author"), + object.get_string_member("author"), new DateTime.from_unix_local(object.get_int_member("published")), -1, tags, diff --git a/plugins/backend/feedbin/feedbinInterface.vala b/plugins/backend/feedbin/feedbinInterface.vala index f45c5009..6b1cf26e 100644 --- a/plugins/backend/feedbin/feedbinInterface.vala +++ b/plugins/backend/feedbin/feedbinInterface.vala @@ -720,15 +720,15 @@ public class FeedReader.FeedbinInterface : Peas.ExtensionBase, FeedServerInterfa articles.add( new Article( entry.id.to_string(), - entry.title != null ? entry.title : "", - entry.url != null ? entry.url : "", + entry.title, + entry.url, entry.feed_id.to_string(), unread_ids.contains(entry.id) ? ArticleStatus.UNREAD : ArticleStatus.READ, starred_ids.contains(entry.id) ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, - entry.content != null ? entry.content : "", - entry.summary != null ? entry.summary : "", - entry.author != null ? entry.author : "", - entry.published != null ? entry.published : (entry.created_at != null ? entry.created_at : new DateTime.now_utc()), + entry.content, + entry.summary, + entry.author, + entry.published != null ? entry.published : entry.created_at, -1, null, null) diff --git a/plugins/backend/feedhq/feedhqAPI.vala b/plugins/backend/feedhq/feedhqAPI.vala index e5fe2f10..565da039 100644 --- a/plugins/backend/feedhq/feedhqAPI.vala +++ b/plugins/backend/feedhq/feedhqAPI.vala @@ -374,9 +374,9 @@ public class FeedReader.FeedHQAPI : GLib.Object { object.get_object_member("origin").get_string_member("streamId"), read ? ArticleStatus.READ : ArticleStatus.UNREAD, marked ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, - "", - "", - "", + null, + null, + null, new DateTime.from_unix_local(object.get_int_member("published")), -1, tags, diff --git a/plugins/backend/feedly/feedlyAPI.vala b/plugins/backend/feedly/feedlyAPI.vala index 7601291c..210f0e47 100644 --- a/plugins/backend/feedly/feedlyAPI.vala +++ b/plugins/backend/feedly/feedlyAPI.vala @@ -361,12 +361,12 @@ public class FeedReader.FeedlyAPI : Object { { Json.Object object = array.get_object_element(i); string id = object.get_string_member("id"); - string title = object.has_member("title") ? object.get_string_member("title") : "No title specified"; - string? author = object.has_member("author") ? object.get_string_member("author") : null; - string summaryContent = object.has_member("summary") ? object.get_object_member("summary").get_string_member("content") : ""; + string title = object.get_string_member("title"); + string? author = object.get_string_member("author"); + string summaryContent = object.has_member("summary") ? object.get_object_member("summary").get_string_member("content") : null; string content = object.has_member("content") ? object.get_object_member("content").get_string_member("content") : summaryContent; bool unread = object.get_boolean_member("unread"); - string url = object.has_member("alternate") ? object.get_array_member("alternate").get_object_element(0).get_string_member("href") : ""; + string url = object.has_member("alternate") ? object.get_array_member("alternate").get_object_element(0).get_string_member("href") : null; string feedID = object.get_object_member("origin").get_string_member("streamId"); DateTime date = new DateTime.now_local(); @@ -428,11 +428,11 @@ public class FeedReader.FeedlyAPI : Object { title, url, feedID, - (unread) ? ArticleStatus.UNREAD : ArticleStatus.READ, + unread ? ArticleStatus.UNREAD : ArticleStatus.READ, marked, content, //summaryContent, - "", + null, author, date, // timestamp includes msecs so divide by 1000 to get rid of them -1, diff --git a/plugins/backend/fresh/freshAPI.vala b/plugins/backend/fresh/freshAPI.vala index c953d95a..a1aa296c 100644 --- a/plugins/backend/fresh/freshAPI.vala +++ b/plugins/backend/fresh/freshAPI.vala @@ -265,13 +265,6 @@ public class FeedReader.freshAPI : Object { } } - string? author = null; - if(object.has_member("author")) - { - author = (object.get_string_member("author") == "") ? null : object.get_string_member("author"); - } - - articles.add(new Article( id, object.get_string_member("title"), @@ -280,8 +273,8 @@ public class FeedReader.freshAPI : Object { read ? ArticleStatus.READ : ArticleStatus.UNREAD, marked ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, object.get_object_member("summary").get_string_member("content"), - "", - author, + null, + object.get_string_member("author"), new DateTime.from_unix_local(object.get_int_member("published")), -1, null, diff --git a/plugins/backend/inoreader/InoReaderAPI.vala b/plugins/backend/inoreader/InoReaderAPI.vala index e85beabd..278f7f12 100644 --- a/plugins/backend/inoreader/InoReaderAPI.vala +++ b/plugins/backend/inoreader/InoReaderAPI.vala @@ -379,8 +379,8 @@ public class FeedReader.InoReaderAPI : GLib.Object { read ? ArticleStatus.READ : ArticleStatus.UNREAD, marked ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, object.get_object_member("summary").get_string_member("content"), - "", - (object.get_string_member("author") == "") ? null : object.get_string_member("author"), + null, + object.get_string_member("author"), new DateTime.from_unix_local(object.get_int_member("published")), -1, tags, diff --git a/plugins/backend/local/localInterface.vala b/plugins/backend/local/localInterface.vala index 37dc91ea..6f22d8d7 100644 --- a/plugins/backend/local/localInterface.vala +++ b/plugins/backend/local/localInterface.vala @@ -621,10 +621,9 @@ public class FeedReader.localInterface : Peas.ExtensionBase, FeedServerInterface if(articleURL.has_prefix("/")) articleURL = Feed.getURL() + articleURL.substring(1); - var Article = new Article - ( + var Article = new Article( articleID, - (item.title != null) ? m_utils.convert(item.title, locale) : "No Title :(", + (item.title != null) ? m_utils.convert(item.title, locale) : null, articleURL, Feed.getFeedID(), ArticleStatus.UNREAD, diff --git a/plugins/backend/oldreader/oldreaderAPI.vala b/plugins/backend/oldreader/oldreaderAPI.vala index 2b23d68e..dbc7030c 100644 --- a/plugins/backend/oldreader/oldreaderAPI.vala +++ b/plugins/backend/oldreader/oldreaderAPI.vala @@ -360,8 +360,8 @@ public class FeedReader.OldReaderAPI : GLib.Object { read ? ArticleStatus.READ : ArticleStatus.UNREAD, marked ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, object.get_object_member("summary").get_string_member("content"), - "", - (object.get_string_member("author") == "") ? null : object.get_string_member("author"), + null, + object.get_string_member("author"), new DateTime.from_unix_local(object.get_int_member("published")), -1, tags, diff --git a/plugins/backend/owncloud/OwncloudNewsAPI.vala b/plugins/backend/owncloud/OwncloudNewsAPI.vala index b4f29b07..72dbfd07 100644 --- a/plugins/backend/owncloud/OwncloudNewsAPI.vala +++ b/plugins/backend/owncloud/OwncloudNewsAPI.vala @@ -237,7 +237,6 @@ public class FeedReader.OwncloudNewsAPI : GLib.Object { ArticleStatus unread = article_node.get_boolean_member("unread") ? ArticleStatus.UNREAD : ArticleStatus.READ; ArticleStatus marked = article_node.get_boolean_member("starred") ? ArticleStatus.MARKED : ArticleStatus.UNMARKED; - string? author = article_node.has_member("author") ? article_node.get_string_member("author") : null; var media = new Gee.ArrayList<string>(); if(article_node.has_member("enclosureLink") && article_node.get_string_member("enclosureLink") != null @@ -257,8 +256,8 @@ public class FeedReader.OwncloudNewsAPI : GLib.Object { unread, marked, article_node.get_string_member("body"), - "", - author, + null, + article_node.get_string_member("author"), new DateTime.from_unix_local(article_node.get_int_member("pubDate")), -1, null, // tags @@ -308,9 +307,8 @@ public class FeedReader.OwncloudNewsAPI : GLib.Object { ArticleStatus unread = article_node.get_boolean_member("unread") ? ArticleStatus.UNREAD : ArticleStatus.READ; ArticleStatus marked = article_node.get_boolean_member("starred") ? ArticleStatus.MARKED : ArticleStatus.UNMARKED; - string? author = article_node.has_member("author") ? article_node.get_string_member("author") : null; - var media = new Gee.ArrayList<string>(); + var media = new Gee.ArrayList<string>(); if(article_node.has_member("enclosureLink") && article_node.get_string_member("enclosureLink") != null && article_node.has_member("enclosureMime") && article_node.get_string_member("enclosureMime") != null) { @@ -328,8 +326,8 @@ public class FeedReader.OwncloudNewsAPI : GLib.Object { unread, marked, article_node.get_string_member("body"), - "", - author, + null, + article_node.get_string_member("author"), new DateTime.from_unix_local(article_node.get_int_member("pubDate")), -1, null, // tags diff --git a/plugins/backend/ttrss/ttrssAPI.vala b/plugins/backend/ttrss/ttrssAPI.vala index ed668267..cf75909c 100644 --- a/plugins/backend/ttrss/ttrssAPI.vala +++ b/plugins/backend/ttrss/ttrssAPI.vala @@ -499,11 +499,11 @@ public class FeedReader.ttrssAPI : GLib.Object { headline_node.get_string_member("title"), headline_node.get_string_member("link"), headline_node.get_string_member("feed_id"), - (headline_node.get_boolean_member("unread")) ? ArticleStatus.UNREAD : ArticleStatus.READ, - (headline_node.get_boolean_member("marked")) ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, - "", - "", - (headline_node.get_string_member("author") == "") ? null : headline_node.get_string_member("author"), + headline_node.get_boolean_member("unread") ? ArticleStatus.UNREAD : ArticleStatus.READ, + headline_node.get_boolean_member("marked") ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, + null, + null, + headline_node.get_string_member("author"), new DateTime.from_unix_local(headline_node.get_int_member("updated")), -1, tags, @@ -615,11 +615,11 @@ public class FeedReader.ttrssAPI : GLib.Object { article_node.get_string_member("title"), article_node.get_string_member("link"), article_node.get_string_member("feed_id"), - (article_node.get_boolean_member("unread")) ? ArticleStatus.UNREAD : ArticleStatus.READ, - (article_node.get_boolean_member("marked")) ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, + article_node.get_boolean_member("unread") ? ArticleStatus.UNREAD : ArticleStatus.READ, + article_node.get_boolean_member("marked") ? ArticleStatus.MARKED : ArticleStatus.UNMARKED, article_node.get_string_member("content"), - "", - (article_node.get_string_member("author") == "") ? null : article_node.get_string_member("author"), + null, + article_node.get_string_member("author"), new DateTime.from_unix_local(article_node.get_int_member("updated")), -1, tags, diff --git a/src/DataBaseReadOnly.vala b/src/DataBaseReadOnly.vala index 404a47cd..e369bdd9 100644 --- a/src/DataBaseReadOnly.vala +++ b/src/DataBaseReadOnly.vala @@ -604,7 +604,7 @@ public class FeedReader.DataBaseReadOnly : GLib.Object { stmt.column_text(1), // feedID (ArticleStatus)stmt.column_int(7), // unread (ArticleStatus)stmt.column_int(8), // marked - "", // html + null, // html stmt.column_text(6), // preview stmt.column_text(4), // author new GLib.DateTime.from_unix_local(stmt.column_int(10)), // date @@ -638,8 +638,8 @@ public class FeedReader.DataBaseReadOnly : GLib.Object { while(stmt.step() == Sqlite.ROW) { articles.set(stmt.column_text(0), - new Article(stmt.column_text(0), "", "", "", (ArticleStatus)stmt.column_int(1), - (ArticleStatus)stmt.column_int(2), "", "", null, new GLib.DateTime.now_local())); + new Article(stmt.column_text(0), null, null, null, (ArticleStatus)stmt.column_int(1), + (ArticleStatus)stmt.column_int(2), null, null, null, new GLib.DateTime.now_local())); } stmt.reset(); return articles; @@ -1466,14 +1466,14 @@ public class FeedReader.DataBaseReadOnly : GLib.Object { { tmp.add(new Article( stmt.column_text(0), // articleID - "", // title + null, // title stmt.column_text(1), // url stmt.column_text(4), // feedID ArticleStatus.UNREAD, // unread ArticleStatus.UNMARKED, // marked stmt.column_text(3), // html stmt.column_text(2), // preview - "", // author + null, // author new GLib.DateTime.now_local() // date )); } @@ -1593,7 +1593,7 @@ public class FeedReader.DataBaseReadOnly : GLib.Object { stmt.column_text(1), // feedID (ArticleStatus)stmt.column_int(7), // unread (ArticleStatus)stmt.column_int(8), // marked - "", // html + null, // html stmt.column_text(6), // preview stmt.column_text(4), // author new GLib.DateTime.from_unix_local(stmt.column_int(10)), // date diff --git a/src/Model/Article.vala b/src/Model/Article.vala index 989f996f..9749c042 100644 --- a/src/Model/Article.vala +++ b/src/Model/Article.vala @@ -52,15 +52,15 @@ public class FeedReader.Article : GLib.Object { } public Article (string articleID, - string title, - string url, - string feedID, + string? title, + string? url, + string? feedID, ArticleStatus unread, ArticleStatus marked, - string html, - string preview, + string? html, + string? preview, string? author, - GLib.DateTime date, + GLib.DateTime? date, int sortID = 0, Gee.List<string>? tags = null, Gee.List<string>? media = null, @@ -68,16 +68,16 @@ public class FeedReader.Article : GLib.Object { int lastModified = 0) { m_articleID = articleID; - m_title = title; - m_url = url; - m_html = html; - m_preview = preview; - m_feedID = feedID; - m_author = author; + m_title = title != null ? title : ""; + m_url = url != null ? url : ""; + m_html = html != null ? html : ""; + m_preview = preview != null ? preview : ""; + m_feedID = feedID != null ? feedID : ""; + m_author = author != "" ? author : null; // This one is actually nullable m_unread = unread; m_marked = marked; m_sortID = sortID; - m_date = date; + m_date = date != null ? date : new DateTime.now_utc(); m_guidHash = guidHash; m_lastModified = lastModified; |