Exemple #1
0
        // clear cache in untiy and start over (see why Im getting stuck in loading window in create group)

        void OpenContacts()
        {
            FriendsPhones friendsPhones = new FriendsPhones()
            {
                numbers = new List <string>()
            };

            ISN_CNContactStore.ShowContactsPickerUI((result) => {
                ContactSelectButton.SetActive(false);
                LoadingInvites.SetActive(true);
                if (result.IsSucceeded)
                {
                    foreach (var contact in result.Contacts)
                    {
                        string fullNumber = contact.Phones[0].FullNumber;
                        friendsPhones.numbers.Add(fullNumber);
                    }
                    FriendManagerScript FMScript = FriendManager.GetComponent <FriendManagerScript>();
                    StartCoroutine(FMScript.SendGroupRequest(groupName, true, friendsPhones, () => { GroupSuccessCreation(); }, () => { GroupFailCreation(); }));
                }
                else
                {
                    LoadingInvites.SetActive(false);
                    ErrorInvites.SetActive(true);
                    ErrorInvitesText.GetComponent <TMPro.TextMeshProUGUI>().text = "Hmmmm... server error! Try again from the main menu!";
                    StartCoroutine(CloseModal(3));
                }
            });
        }
        public IEnumerator SendGroupRequest(string groupName, bool withPhoneNumbers, FriendsPhones numbers, System.Action callbackSuccess, System.Action callbackFailure)
        {
            WWWForm form = new WWWForm();

            form.AddField("userID", roomID);
            form.AddField("name", groupName);
            form.AddField("numbers", JsonUtility.ToJson(numbers));
            UnityWebRequest www = UnityWebRequest.Post("https://circles-parellano.herokuapp.com/api/create-group-world", form);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                callbackFailure();
            }
            else
            {
                string     response  = www.downloadHandler.text;
                GroupData  group     = JsonUtility.FromJson <GroupData>(response);
                GameObject newButton = Instantiate(GroupButtonPrefab) as GameObject;
                newButton.transform.GetChild(1).GetChild(1).GetComponent <TMPro.TextMeshProUGUI>().text = group.name;
                newButton.GetComponent <Button>().onClick.AddListener(() => { GroupCallback(group.name, group.code, group); });
                newButton.transform.SetParent(FriendListContent.transform);
                newButton.transform.localScale = new Vector3(1, 1, 1);
                callbackSuccess();
                yield return(null);
            }
        }
        public void AddContacts()
        {
            FriendsPhones friendsPhones = new FriendsPhones()
            {
                numbers = new List <string>()
            };

            ISN_CNContactStore.ShowContactsPickerUI((result) => {
                uiManagerScript.LoadingInviteFriend();
                if (result.IsSucceeded)
                {
                    foreach (var contact in result.Contacts)
                    {
                        if (contact.Phones.Count > 0)
                        {
                            string fullNumber = contact.Phones[0].FullNumber;
                            friendsPhones.numbers.Add(fullNumber);
                        }
                    }
                    StartCoroutine(SendInvites(friendsPhones));
                }
                else
                {
                    uiManagerScript.ResultFriendInvite(false, "Hmmmm... Server error, try again!");
                }
            });
        }
        public void SubmitForm()
        {
            string text = CreateGroupInput.GetComponent <Text>().text;

            if (text.Trim() == "")
            {
                CreateGroupInput.SetActive(false);
                CreateGroupInput.SetActive(true);
                return;
            }
            FriendsPhones friendsPhones = new FriendsPhones()
            {
                numbers = new List <string>()
            };

            uiManagerScript.LoadingGroupCreation();
            StartCoroutine(SendGroupRequest(text, false, friendsPhones, () => { uiManagerScript.ResultGroupCreation(true); }, () => { uiManagerScript.ResultGroupCreation(false); }));
        }
        IEnumerator SendInvites(FriendsPhones numbers)
        {
            WWWForm form = new WWWForm();

            form.AddField("userID", roomID);
            form.AddField("numbers", JsonUtility.ToJson(numbers));
            form.AddField("code", currentGroupCode);
            UnityWebRequest www = UnityWebRequest.Post("https://circles-parellano.herokuapp.com/api/invite-friends", form);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                uiManagerScript.ResultFriendInvite(false, "Hmmmm... Server error, try again!");
            }
            else
            {
                string response = www.downloadHandler.text;
                uiManagerScript.ResultFriendInvite(true, "nn");
                yield return(response);
            }
        }