internal 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 = FB_Image._from_uri(image); rtn.original_image_url = (rtn.image.url?.Contains("/safe_image.php") ?? false) ? Utils.get_url_parameter(rtn.image.url, "url") : rtn.image.url; } return(rtn); }
internal static FB_Sticker _from_graphql(JToken data) { if (data == null) { return(null); } var sticker = new FB_Sticker(uid: data.get("id")?.Value <string>()); if (data.get("pack") != null) { sticker.pack = data.get("pack")?.get("id")?.Value <string>(); } if (data.get("sprite_image") != null) { sticker.is_animated = true; sticker.medium_sprite_image = data.get("sprite_image")?.get("uri")?.Value <string>(); sticker.large_sprite_image = data.get("sprite_image_2x")?.get("uri")?.Value <string>(); sticker.frames_per_row = data.get("frames_per_row")?.Value <int>() ?? 0; sticker.frames_per_col = data.get("frames_per_column")?.Value <int>() ?? 0; sticker.frame_count = data.get("frame_count")?.Value <long>() ?? 0; sticker.frame_rate = data.get("frame_rate")?.Value <float>() ?? 0; } sticker.image = FB_Image._from_url_or_none(data); if (data.get("label") != null) { sticker.label = data.get("label")?.Value <string>(); } return(sticker); }
internal 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) { rtn.image = FB_Image._from_uri_or_none(media?.get("image")); } rtn.url = url; return(rtn); }
internal static FB_Group _from_graphql(Session session, JToken data) { if (data.get("image") == null) { data["image"] = new JObject(new JProperty("uri", "")); } var c_info = FB_Group._parse_customization_info(data); var last_message_timestamp = data.get("last_message")?.get("nodes")?.FirstOrDefault()?.get("timestamp_precise")?.Value <string>(); var plan = data.get("event_reminders")?.get("nodes")?.FirstOrDefault() != null?FB_Plan._from_graphql(data.get("event_reminders")?.get("nodes")?.FirstOrDefault(), session) : null; return(new FB_Group( uid: data.get("thread_key")?.get("thread_fbid")?.Value <string>(), session: session, participants: new HashSet <FB_Thread>(FB_Thread._parse_participants(data.get("all_participants"), session)), nicknames: (Dictionary <string, string>)c_info.GetValueOrDefault("nicknames"), color: (string)c_info.GetValueOrDefault("color"), emoji: (JToken)c_info.GetValueOrDefault("emoji"), admins: new HashSet <string>(data.get("thread_admins")?.Select(node => node.get("id")?.Value <string>())), approval_mode: data.get("approval_mode")?.Value <bool>() ?? false, approval_requests: data.get("group_approval_queue") != null ? new HashSet <string>(data.get("group_approval_queue")?.get("nodes")?.Select(node => node.get("requester")?.get("id")?.Value <string>())) : null, photo: FB_Image._from_uri_or_none(data?.get("image")), name: data.get("name")?.Value <string>(), message_count: data.get("messages_count")?.Value <int>() ?? 0, last_message_timestamp: last_message_timestamp, plan: plan)); }
internal static FB_Page _from_graphql(Session session, JToken data) { if (data.get("profile_picture") == null) { data["profile_picture"] = new JObject(new JProperty("uri", "")); } if (data.get("city") == null) { data["city"] = new JObject(new JProperty("name", "")); } FB_Plan plan = null; if (data.get("event_reminders") != null && data.get("event_reminders")?.get("nodes") != null) { plan = FB_Plan._from_graphql(data.get("event_reminders")?.get("nodes")?.FirstOrDefault(), session); } return(new FB_Page( uid: data.get("id")?.Value <string>(), session: session, url: data.get("url")?.Value <string>(), city: data.get("city")?.get("name")?.Value <string>(), category: data.get("category_type")?.Value <string>(), photo: FB_Image._from_uri_or_none(data?.get("profile_picture")), name: data.get("name")?.Value <string>(), message_count: data.get("messages_count")?.Value <int>() ?? 0, plan: plan )); }
/// <summary> /// Represents a Facebook thread /// </summary> /// <param name="uid"></param> /// <param name="session"></param> /// <param name="photo"></param> /// <param name="name"></param> /// <param name="last_message_timestamp"></param> /// <param name="message_count"></param> /// <param name="plan"></param> public FB_Thread(string uid, Session session, FB_Image photo = null, string name = null, string last_message_timestamp = null, int message_count = 0, FB_Plan plan = null) { this.uid = uid; this.session = session; this.photo = photo; this.name = name; this.last_message_timestamp = last_message_timestamp; this.message_count = message_count; this.plan = plan; }
/// <summary> /// Represents a Facebook page. Inherits `Thread` /// </summary> /// <param name="uid"></param> /// <param name="session"></param> /// <param name="photo"></param> /// <param name="name"></param> /// <param name="message_count"></param> /// <param name="plan"></param> /// <param name="url"></param> /// <param name="city"></param> /// <param name="likes"></param> /// <param name="sub_title"></param> /// <param name="category"></param> public FB_Page(string uid, Session session, FB_Image photo = null, string name = null, int message_count = 0, FB_Plan plan = null, string url = null, string city = null, int likes = 0, string sub_title = null, string category = null) : base(uid, session, photo, name, message_count: message_count, plan: plan) { // Represents a Facebook page. Inherits `Thread` this.url = url; this.city = city; this.likes = likes; this.sub_title = sub_title; this.category = category; }
internal static FB_VideoAttachment _from_subattachment(JToken data) { JToken media = data.get("media"); return(new FB_VideoAttachment( duration: media.get("playable_duration_in_ms")?.Value <int>() ?? 0, preview_url: media.get("playable_url")?.Value <string>(), medium_image: FB_Image._from_uri_or_none(media?.get("image")), uid: data.get("target")?.get("video_id")?.Value <string>())); }
internal static FB_VideoAttachment _from_list(JToken data) { return(new FB_VideoAttachment( width: data?.get("original_dimensions")?.get("x")?.Value <int>() ?? 0, height: data?.get("original_dimensions")?.get("y")?.Value <int>() ?? 0, small_image: FB_Image._from_uri_or_none(data?.get("image")), medium_image: FB_Image._from_uri_or_none(data?.get("image1")), large_image: FB_Image._from_uri_or_none(data?.get("image2")), uid: data?.get("legacy_attachment_id")?.Value <string>() )); }
internal static FB_ImageAttachment _from_list(JToken data) { return(new FB_ImageAttachment( width: data?.get("original_dimensions")?.get("x")?.Value <int>() ?? 0, height: data?.get("original_dimensions")?.get("y")?.Value <int>() ?? 0, thumbnail: FB_Image._from_uri_or_none(data?.get("image")), large_preview: FB_Image._from_uri_or_none(data?.get("image2")), preview: FB_Image._from_uri_or_none(data?.get("image1")), uid: data?.get("legacy_attachment_id")?.Value <string>() )); }
/// <summary> /// Represents a Facebook group. Inherits `Thread` /// </summary> /// <param name="uid"></param> /// <param name="session"></param> /// <param name="photo"></param> /// <param name="name"></param> /// <param name="message_count"></param> /// <param name="last_message_timestamp"></param> /// <param name="plan"></param> /// <param name="participants"></param> /// <param name="nicknames"></param> /// <param name="color"></param> /// <param name="emoji"></param> /// <param name="admins"></param> /// <param name="approval_mode"></param> /// <param name="approval_requests"></param> /// <param name="join_link"></param> public FB_Group(string uid, Session session, FB_Image photo = null, string name = null, int message_count = 0, string last_message_timestamp = null, FB_Plan plan = null, ISet <FB_Thread> participants = null, Dictionary <string, string> nicknames = null, string color = null, JToken emoji = null, ISet <string> admins = null, bool approval_mode = false, ISet <string> approval_requests = null, string join_link = null) : base(uid, session, photo, name, message_count: message_count, last_message_timestamp: last_message_timestamp, plan: plan) { this.participants = participants ?? new HashSet <FB_Thread>(); this.nicknames = nicknames ?? new Dictionary <string, string>(); this.color = color ?? ThreadColor.MESSENGER_BLUE; this.emoji = emoji; this.admins = admins ?? new HashSet <string>(); this.approval_mode = approval_mode; this.approval_requests = approval_requests ?? new HashSet <string>(); this.join_link = join_link; }
internal static FB_VideoAttachment _from_graphql(JToken data) { return(new FB_VideoAttachment( width: data.get("original_dimensions")?.get("width")?.Value <int>() ?? 0, height: data.get("original_dimensions")?.get("height")?.Value <int>() ?? 0, duration: data.get("playable_duration_in_ms")?.Value <int>() ?? 0, preview_url: data.get("playable_url")?.Value <string>(), small_image: FB_Image._from_uri_or_none(data?.get("chat_image")), medium_image: FB_Image._from_uri_or_none(data?.get("inbox_image")), large_image: FB_Image._from_uri_or_none(data?.get("large_image")), uid: data.get("legacy_attachment_id")?.Value <string>())); }
/// <summary> /// Represents a video that has been sent as a Facebook attachment /// </summary> /// <param name="uid"></param> /// <param name="size"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="duration"></param> /// <param name="preview_url"></param> /// <param name="small_image"></param> /// <param name="medium_image"></param> /// <param name="large_image"></param> public FB_VideoAttachment(string uid = null, int size = 0, int width = 0, int height = 0, int duration = 0, string preview_url = null, FB_Image small_image = null, FB_Image medium_image = null, FB_Image large_image = null) : base(uid) { this.size = size; this.width = width; this.height = height; this.duration = duration; this.preview_url = preview_url; this.small_image = small_image; this.medium_image = medium_image; this.large_image = large_image; }
/// <summary> /// Represents an image that has been sent as a Facebook attachment /// </summary> /// <param name="uid"></param> /// <param name="original_extension"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="is_animated"></param> /// <param name="thumbnail"></param> /// <param name="preview"></param> /// <param name="large_preview"></param> /// <param name="animated_preview"></param> public FB_ImageAttachment(string uid = null, string original_extension = null, int width = 0, int height = 0, bool is_animated = false, FB_Image thumbnail = null, FB_Image preview = null, FB_Image large_preview = null, FB_Image animated_preview = null) : base(uid) { this.original_extension = original_extension; this.width = width; this.height = height; this.is_animated = is_animated; this.thumbnail = thumbnail; this.preview = preview; this.large_preview = large_preview; this.animated_preview = animated_preview; }
internal static FB_User _from_thread_fetch(Session session, JToken data) { var c_info = FB_User._parse_customization_info(data); var participants = data.get("all_participants")?.get("nodes")?.Select(node => node.get("messaging_actor")); var user = participants.Where((p) => p.get("id")?.Value <string>() == data.get("thread_key")?.get("other_user_id")?.Value <string>())?.FirstOrDefault(); var last_message_timestamp = data.get("last_message")?.get("nodes")?.FirstOrDefault()?.get("timestamp_precise")?.Value <string>(); var name = user.get("name")?.Value <string>(); var first_name = user.get("first_name")?.Value <string>() ?? user.get("short_name")?.Value <string>(); var last_name = first_name != null?name?.Replace(first_name, "")?.Trim() : null; var gender = GENDER.graphql_GENDERS["UNKNOWN"]; if (data.get("gender")?.Type == JTokenType.Integer) { gender = GENDER.standard_GENDERS[data.get("gender")?.Value <int>() ?? 0]; } else { int gender_int = 0; if (int.TryParse(data.get("gender")?.Value <string>(), out gender_int)) { gender = GENDER.standard_GENDERS[gender_int]; } else { gender = GENDER.graphql_GENDERS[data.get("gender")?.Value <string>() ?? "UNKNOWN"]; } }; var plan = data.get("event_reminders")?.get("nodes")?.FirstOrDefault() != null?FB_Plan._from_graphql(data.get("event_reminders")?.get("nodes")?.FirstOrDefault(), session) : null; return(new FB_User( uid: user.get("id")?.Value <string>(), session: session, url: user.get("url")?.Value <string>(), name: name, first_name: first_name, last_name: last_name, is_friend: user.get("is_viewer_friend")?.Value <bool>() ?? false, gender: gender, affinity: user.get("viewer_affinity")?.Value <float>() ?? 0, nickname: (string)c_info.GetValueOrDefault("nickname"), color: (string)c_info.GetValueOrDefault("color"), emoji: (JToken)c_info.GetValueOrDefault("emoji"), own_nickname: (string)c_info.GetValueOrDefault("own_nickname"), photo: FB_Image._from_uri_or_none(user?.get("big_image_src")), message_count: data.get("messages_count")?.Value <int>() ?? 0, last_message_timestamp: last_message_timestamp, //last_active = _util.millis_to_datetime(int(data["updated_time_precise"])), plan: plan)); }
internal static FB_ImageAttachment _from_graphql(JToken data) { return(new FB_ImageAttachment( original_extension: data.get("original_extension")?.Value <string>() ?? data.get("filename")?.Value <string>()?.Split('-')[0], width: data.get("original_dimensions")?.get("width")?.Value <int>() ?? 0, height: data.get("original_dimensions")?.get("height")?.Value <int>() ?? 0, is_animated: data.get("__typename")?.Value <String>() == "MessageAnimatedImage", thumbnail: FB_Image._from_uri_or_none(data?.get("thumbnail")), preview: FB_Image._from_uri_or_none(data?.get("preview")) ?? FB_Image._from_uri_or_none(data?.get("preview_image")), large_preview: FB_Image._from_uri_or_none(data?.get("large_preview")), animated_preview: FB_Image._from_uri_or_none(data?.get("animated_image")), uid: data.get("legacy_attachment_id")?.Value <string>())); }
/// <summary> /// Represents a Facebook user. Inherits `Thread` /// </summary> /// <param name="uid"></param> /// <param name="session"></param> /// <param name="photo"></param> /// <param name="name"></param> /// <param name="message_count"></param> /// <param name="last_message_timestamp"></param> /// <param name="plan"></param> /// <param name="url"></param> /// <param name="first_name"></param> /// <param name="last_name"></param> /// <param name="is_friend"></param> /// <param name="gender"></param> /// <param name="affinity"></param> /// <param name="nickname"></param> /// <param name="own_nickname"></param> /// <param name="color"></param> /// <param name="emoji"></param> public FB_User(string uid, Session session, FB_Image photo = null, string name = null, int message_count = 0, string last_message_timestamp = null, FB_Plan plan = null, string url = null, string first_name = null, string last_name = null, bool is_friend = false, string gender = null, float affinity = 0, string nickname = null, string own_nickname = null, string color = null, JToken emoji = null) : base(uid, session, photo, name, message_count: message_count, last_message_timestamp: last_message_timestamp, plan: plan) { this.url = url; this.first_name = first_name; this.last_name = last_name ?? (first_name != null ? name?.Replace(first_name, "")?.Trim() : null); this.is_friend = is_friend; this.gender = gender; this.affinity = affinity; this.nickname = nickname; this.own_nickname = own_nickname; this.color = color ?? ThreadColor.MESSENGER_BLUE; this.emoji = emoji; }
internal static FB_User _from_graphql(Session session, JToken data) { var c_info = FB_User._parse_customization_info(data); var plan = data.get("event_reminders")?.get("nodes")?.FirstOrDefault() != null? FB_Plan._from_graphql(data.get("event_reminders")?.get("nodes")?.FirstOrDefault(), session) : null; var name = data.get("name")?.Value <string>(); var first_name = data.get("first_name")?.Value <string>() ?? data.get("short_name")?.Value <string>(); var last_name = first_name != null?name?.Replace(first_name, "")?.Trim() : null; var gender = GENDER.graphql_GENDERS["UNKNOWN"]; if (data.get("gender")?.Type == JTokenType.Integer) { gender = GENDER.standard_GENDERS[data.get("gender")?.Value <int>() ?? 0]; } else { int gender_int = 0; if (int.TryParse(data.get("gender")?.Value <string>(), out gender_int)) { gender = GENDER.standard_GENDERS[gender_int]; } else { gender = GENDER.graphql_GENDERS[data.get("gender")?.Value <string>() ?? "UNKNOWN"]; } }; return(new FB_User( uid: data.get("id")?.Value <string>(), session: session, url: data.get("url")?.Value <string>(), name: name, first_name: first_name, last_name: last_name, is_friend: data.get("is_viewer_friend")?.Value <bool>() ?? false, gender: gender, affinity: data.get("viewer_affinity")?.Value <float>() ?? 0, nickname: (string)c_info.GetValueOrDefault("nickname"), color: (string)c_info.GetValueOrDefault("color"), emoji: (JToken)c_info.GetValueOrDefault("emoji"), own_nickname: (string)c_info.GetValueOrDefault("own_nickname"), photo: FB_Image._from_uri_or_none(data?.get("profile_picture")), message_count: data.get("messages_count")?.Value <int>() ?? 0, plan: plan)); }
internal static new FB_LiveLocationAttachment _from_graphql(JToken data) { var target = data.get("target"); var rtn = new FB_LiveLocationAttachment( uid: target.get("live_location_id")?.Value <string>(), latitude: target.get("coordinate")?.get("latitude")?.Value <double>() ?? 0, longitude: target.get("coordinate")?.get("longitude")?.Value <double>() ?? 0, name: data.get("title_with_entities")?.get("text")?.Value <string>(), expiration_time: target.get("expiration_time")?.Value <string>(), is_expired: target.get("is_expired")?.Value <bool>() ?? false); var media = data.get("media"); if (media != null && media.get("image") != null) { rtn.image = FB_Image._from_uri_or_none(media?.get("image")); } rtn.url = data.get("url")?.Value <string>(); return(rtn); }
/// <summary> /// Represents a shared item (eg. URL) that has been sent as a Facebook attachment. /// </summary> /// <param name="uid"></param> /// <param name="author"></param> /// <param name="url"></param> /// <param name="original_url"></param> /// <param name="title"></param> /// <param name="description"></param> /// <param name="source"></param> /// <param name="image"></param> /// <param name="original_image_url"></param> /// <param name="attachments"></param> public FB_ShareAttachment(string uid = null, string author = null, string url = null, string original_url = null, string title = null, string description = null, string source = null, FB_Image image = null, string original_image_url = null, List <FB_Attachment> attachments = null) : base(uid) { this.author = author; this.url = url; this.original_url = original_url; this.title = title; this.description = description; this.source = source; this.image = image; this.original_image_url = original_image_url; this.attachments = attachments; }
/// <summary> /// Represents a user location /// Latitude and longitude OR address is provided by Facebook /// </summary> /// <param name="uid"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="image"></param> /// <param name="url"></param> /// <param name="address"></param> public FB_LocationAttachment(string uid = null, double latitude = 0, double longitude = 0, FB_Image image = null, string url = null, string address = null) : base(uid) { this.latitude = latitude; this.longitude = longitude; this.image = image; this.url = url; this.address = address; }
/// <summary> /// Represents a live user location /// </summary> /// <param name="uid"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="image"></param> /// <param name="url"></param> /// <param name="address"></param> /// <param name="name"></param> /// <param name="expiration_time"></param> /// <param name="is_expired"></param> public FB_LiveLocationAttachment(string uid = null, double latitude = 0, double longitude = 0, FB_Image image = null, string url = null, string address = null, string name = null, string expiration_time = null, bool is_expired = false) : base(uid, latitude, longitude, image, url, address) { this.name = name; this.expiration_time = expiration_time; this.is_expired = is_expired; }
internal static FB_Image _from_url_or_none(JToken data) { return((data?.get("url") != null) ? FB_Image._from_url(data) : null); }