Beispiel #1
0
        public static FB_Thread graphql_to_thread(JToken thread)
        {
            if (thread["thread_type"].Value <string>().Equals("GROUP"))
            {
                return(GraphQL_JSON_Decoder.graphql_to_group(thread));
            }
            else if (thread["thread_type"].Value <string>().Equals("ROOM"))
            {
                return(GraphQL_JSON_Decoder.graphql_to_room(thread));
            }
            else if (thread["thread_type"].Value <string>().Equals("ONE_TO_ONE"))
            {
                var participants = thread["all_participants"]["nodes"].Select(node => node["messaging_actor"]);
                var user         = participants.Single(p => p["id"].Value <string>() == thread["thread_key"]["other_user_id"].Value <string>());

                if (user["big_image_src"] == null || user["big_image_src"].Type == JTokenType.Null)
                {
                    user["big_image_src"] = new JObject(new JProperty("uri", ""));
                }

                return(new FB_User(
                           uid: user["id"].Value <string>(),
                           url: user["url"]?.Value <string>(),
                           name: user["name"]?.Value <string>(),
                           first_name: user["short_name"]?.Value <string>(),
                           last_name: user["name"]?.Value <string>()?.Replace(user["short_name"]?.Value <string>(), "")?.Trim(),
                           is_friend: user["is_viewer_friend"]?.Value <bool>() ?? false,
                           gender: user["gender"]?.Value <string>(),
                           nickname: "",
                           color: ThreadColor.MESSENGER_BLUE,
                           emoji: "",
                           own_nickname: "",
                           affinity: 0,
                           photo: user["big_image_src"]["uri"]?.Value <string>(),
                           message_count: thread["messages_count"]?.Value <int>() ?? 0
                           ));
            }
            else
            {
                throw new FBchatException(string.Format("Unknown thread type: {0}", thread));
            }
        }
Beispiel #2
0
 public static FB_Thread graphql_to_thread(JToken thread)
 {
     if (thread["thread_type"].Value <string>().Equals("GROUP"))
     {
         return(GraphQL_JSON_Decoder.graphql_to_group(thread));
     }
     else if (thread["thread_type"].Value <string>().Equals("ROOM"))
     {
         return(GraphQL_JSON_Decoder.graphql_to_room(thread));
     }
     else if (thread["thread_type"].Value <string>().Equals("ONE_TO_ONE"))
     {
         var participants = thread["all_participants"]["nodes"].Select(node => node["messaging_actor"]);
         var user         = participants.Single(p => p["id"].Value <string>() == thread["thread_key"]["other_user_id"].Value <string>());
         return(GraphQL_JSON_Decoder.graphql_to_user(thread, user));
     }
     else
     {
         throw new FBchatException(string.Format("Unknown thread type: {0}", thread));
     }
 }