示例#1
0
        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
                       ));
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
        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>()));
        }
示例#5
0
 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>()
                ));
 }
示例#6
0
 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>()
                ));
 }
示例#7
0
 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>()));
 }
示例#8
0
        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));
        }
示例#9
0
 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>()));
 }
示例#10
0
        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));
        }
示例#11
0
        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);
        }