Пример #1
0
        public static FB_Page _from_graphql(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());
            }

            return(new FB_Page(
                       uid: data.get("id")?.Value <string>(),
                       url: data.get("url")?.Value <string>(),
                       city: data.get("city")?.get("name")?.Value <string>(),
                       category: data.get("category_type")?.Value <string>(),
                       photo: data.get("profile_picture")?.get("uri")?.Value <string>(),
                       name: data.get("name")?.Value <string>(),
                       message_count: data.get("messages_count")?.Value <int>() ?? 0,
                       plan: plan
                       ));
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
0
        public static FB_Marketplace _from_graphql(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()) : null;

            return(new FB_Marketplace(
                       uid: data.get("thread_key")?.get("thread_fbid")?.Value <string>(),
                       participants: new HashSet <string>(data.get("all_participants")?.get("nodes")?.Select(node => node.get("messaging_actor")?.get("id")?.Value <string>())),
                       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: data.get("image")?.get("uri")?.Value <string>(),
                       name: data.get("name")?.Value <string>(),
                       message_count: data.get("messages_count")?.Value <int>() ?? 0,
                       last_message_timestamp: last_message_timestamp,
                       plan: plan));
        }