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_LocationAttachment _from_graphql(JToken data) { var url = data.get("url")?.Value <string>(); var address = Utils.get_url_parameter(Utils.get_url_parameter(url, "u"), "where1"); double latitude = 0, longitude = 0; try { var split = address.Split(new[] { ", " }, StringSplitOptions.None); latitude = Double.Parse(split[0]); longitude = Double.Parse(split[1]); address = null; } catch (Exception) { } var rtn = new FB_LocationAttachment( uid: data.get("deduplication_key")?.Value <string>(), latitude: latitude, longitude: longitude, address: address); var media = data.get("media"); if (media != null && media.get("image") != null) { var image = media.get("image"); rtn.image_url = image?.get("uri")?.Value <string>(); rtn.image_width = image?.get("width")?.Value <int>() ?? 0; rtn.image_height = image?.get("height")?.Value <int>() ?? 0; } rtn.url = url; return(rtn); }