public static FB_Attachment graphql_to_extensible_attachment(JToken data) { var story = data.get("story_attachment"); if (story == null) { return(null); } var target = story.get("target"); if (target == null) { return(new FB_UnsentMessage(uid: data.get("legacy_attachment_id")?.Value <string>())); } var _type = target.get("__typename")?.Value <string>(); if (_type == "MessageLocation") { return(FB_LocationAttachment._from_graphql(story)); } else if (_type == "MessageLiveLocation") { return(FB_LiveLocationAttachment._from_graphql(story)); } else if (new string[] { "ExternalUrl", "Story" }.Contains(_type)) { return(FB_ShareAttachment._from_graphql(story)); } return(null); }
public static FB_ShareAttachment _from_graphql(JToken data) { string url = data.get("url")?.Value <string>(); FB_ShareAttachment rtn = new FB_ShareAttachment( uid: data.get("deduplication_key")?.Value <string>(), author: data.get("target")?.get("actors")?.FirstOrDefault()?.get("id")?.Value <string>(), url: url, original_url: (url?.Contains("/l.php?u=") ?? false) ? Utils.get_url_parameter(url, "u") : url, title: data.get("title_with_entities")?.get("text")?.Value <string>(), description: data.get("description")?.get("text")?.Value <string>(), source: data.get("source")?.get("text")?.Value <string>() ); rtn.attachments = data.get("subattachments")?.Select(node => FB_Attachment.graphql_to_subattachment(node))?.ToList(); JToken media = data.get("media"); if (media != null && media.get("image") != null) { JToken image = media.get("image"); rtn.image_url = image.get("uri")?.Value <string>(); rtn.original_image_url = (rtn.image_url?.Contains("/safe_image.php") ?? false) ? Utils.get_url_parameter(rtn.image_url, "url") : rtn.image_url; rtn.image_width = image.get("width")?.Value <int>() ?? 0; rtn.image_height = image.get("height")?.Value <int>() ?? 0; } return(rtn); }