예제 #1
0
    public static void UploadPostData(PostData data)
    {
        if (data.imageNames != null)
        {
            for (int i = 0; i < data.imageNames.Count; i++)
            {
                string image = data.imageNames[i];

                string imgType  = Path.GetExtension(image);
                string datePatt = @"yyyyMMddHHmmssfff";
                string imgName  = DateTime.UtcNow.ToString(datePatt, CultureInfo.InvariantCulture) + imgType;

                FirebaseHelper.UploadFile(image, imgName, "images");

                data.imageNames[i] = imgName;
            }
        }

        string json = JsonConvert.SerializeObject(data);

        byte[]            postTextbytes = Encoding.ASCII.GetBytes(json);
        CommunityUserData user          = CommunityUserDataHandler.Instance.user;

        FirebaseHelper.UploadBytes(postTextbytes, $"{user.num_posts}.json", $"posts/user/{user.uid}/");
        user.num_posts++;
    }
예제 #2
0
    public async static System.Threading.Tasks.Task <CommunityUserData> LoadFromServer(string uid)
    {
        string json = await FirebaseHelper.DownloadString($"CommunityUserData/{uid}.json");

        CommunityUserData user = JsonConvert.DeserializeObject <CommunityUserData>(json);

        return(user);
    }
예제 #3
0
    IEnumerator CreateCommunityProfile()
    {
        yield return(StartCoroutine(DownloadImage(fb_avatar_link)));

        CommunityUserData user = new CommunityUserData("FB" + AccessToken.CurrentAccessToken.UserId, fb_name, fb_avatar_name);

        user.WriteToCache();
        SceneManager.LoadScene("Community");
    }
예제 #4
0
 void Start()
 {
     user = CommunityUserDataHandler.Instance.user;
     Debug.Log(user.name + " " + user.avatar);
     foreach (string scope in user.post_scope)
     {
         DownloadPosts(scope);
     }
 }
    public void Start()
    {
        Debug.Log("Init User Data");
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(Instance);
        }

        user = CommunityUserData.LoadFromCache();
    }
예제 #6
0
    private async void GetCommunityProfile(AccessToken token)
    {
        string json = await FirebaseHelper.DownloadString($"CommunityUserData/FB{token.UserId}.json");

        if (string.IsNullOrEmpty(json))  // => new user
        {
            Debug.Log("Creating new profile");
            FB.API("me?fields=name,picture", HttpMethod.GET, FBGetProfile);
            return;
        }

        CommunityUserData.WriteToCache(json);
        SceneManager.LoadScene("Community");
    }
예제 #7
0
    public static CommunityUserData LoadFromCache()
    {
        string path;

        path = Application.persistentDataPath + "//Data//CommunityUserData.json";

        if (!File.Exists(path))
        {
            Debug.Log("Error: Couldn't find Local Community User Data");
            return(null);
        }

        FileStream JsonFile = new FileStream(path, FileMode.Open);

        StreamReader      reader = new StreamReader(JsonFile);
        string            json   = reader.ReadToEnd();
        CommunityUserData user   = JsonConvert.DeserializeObject <CommunityUserData>(json);

        reader.Close();
        return(user);
    }
예제 #8
0
    async void Start()
    {
        /* todo: Download and Load CommunityUserData when start
         * ...
         */

        // delete this later
        CommunityUserData user = new CommunityUserData();

        user.groups.Add(new Group("0000001", 0));
        // delete this later

        // Create User's Category GameObject
        foreach (string category_name in user.categories)
        {
            CreateCategory(category_name);
        }

        // Create User's Groups GameObject
        foreach (Group group in user.groups)
        {
            await CreateGroup(group.id, group.catagory_id);
        }
    }