Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 500fa52

Browse files
committed
Don't assume Feedly values are non-null
Feedly's API sometimes returns null for summary, content, title, etc. Weirdly enough, it can even return null for `unread`, despite it not being marked as optional in the docs. Fixes #894
1 parent ef4a9c6 commit 500fa52

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

plugins/backend/feedly/feedlyAPI.vala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,17 @@ public class FeedReader.FeedlyAPI : Object {
403403
{
404404
Json.Object object = array.get_object_element(i);
405405
string id = object.get_string_member("id");
406-
string title = object.get_string_member("title");
407-
string? author = object.get_string_member("author");
408-
string summaryContent = object.has_member("summary") ? object.get_object_member("summary").get_string_member("content") : null;
409-
string content = object.has_member("content") ? object.get_object_member("content").get_string_member("content") : summaryContent;
410-
bool unread = object.get_boolean_member("unread");
411-
string url = object.has_member("alternate") ? object.get_array_member("alternate").get_object_element(0).get_string_member("href") : null;
412-
string feedID = object.get_object_member("origin").get_string_member("streamId");
406+
string? title = object.has_member("title") ? object.get_string_member("title") : null;
407+
string? author = object.has_member("author") ? object.get_string_member("author") : null;
408+
var summary = object.has_member("summary") ? object.get_object_member("summary") : null;
409+
string? summaryContent = summary != null && summary.has_member("content") ? summary.get_string_member("content") : null;
410+
var content_obj = object.has_member("content") ? object.get_object_member("content") : null;
411+
string? content = content_obj != null && content_obj.has_member("content") ? content_obj.get_string_member("content") : summaryContent;
412+
bool unread = object.has_member("unread") ? object.get_boolean_member("unread") : false;
413+
var alternate = object.has_member("alternate") ? object.get_array_member("alternate") : null;
414+
var first_alternate = alternate != null && alternate.get_length() >= 1 ? alternate.get_object_element(0) : null;
415+
string url = first_alternate != null && first_alternate.has_member("href") ? first_alternate.get_string_member("href") : null;
416+
string feedID = object.has_member("origin") ? object.get_object_member("origin").get_string_member("streamId") : null;
413417

414418
DateTime date = new DateTime.now_local();
415419
if(object.has_member("updated") && object.get_int_member("updated") > 0)

0 commit comments

Comments
 (0)