コード例 #1
0
    public void GetAllPendingFriends()
    {
        HTTPRequest www = new HTTPRequest(new Uri(GameManager.Instance.webURLPrefix + "pendingFriend?myId=" + GameManager.Instance.player._id), (request, response) => {
            HTTPResponse res = (HTTPResponse)response;
            if (res.IsSuccess)
            {
                Debug.Log(res.DataAsText);
                mItemDataList.Clear();
                pList.Clear();
                List <object> dic = Json.Decode(res.DataAsText) as List <object>;
                pList             = new List <PendingFriendData>();
                foreach (Dictionary <string, object> a in dic)
                {
                    UserData s          = new UserData();
                    PendingFriendData p = new PendingFriendData();
                    if (a.ContainsKey("_id"))
                    {
                        p._id = a["_id"].ToString();
                    }
                    if (a.ContainsKey("user"))
                    {
                        p.user = new User();
                        if (a.ContainsKey("_id"))
                        {
                            s.requestId = a["_id"].ToString();
                        }

                        foreach (KeyValuePair <string, object> t in a["user"] as Dictionary <string, object> )
                        {
                            if (t.Key.Contains("_id"))
                            {
                                p.user._id = t.Value.ToString();
                            }
                            if (t.Key.Contains("displayName"))
                            {
                                p.user.displayName = t.Value.ToString();
                            }
                            if (t.Key.Contains("username"))
                            {
                                p.user.username = t.Value.ToString();
                            }
                            if (t.Key.Contains("profileImageURL"))
                            {
                                p.user.profileImageURL = t.Value.ToString();
                            }
                        }
                    }

                    if (a.ContainsKey("touser"))
                    {
                        p.touser = new Touser();
                        foreach (KeyValuePair <string, object> t in a["touser"] as Dictionary <string, object> )
                        {
                            if (t.Key.Contains("_id"))
                            {
                                p.touser._id = t.Value.ToString();
                            }
                            if (t.Key.Contains("displayName"))
                            {
                                p.touser.displayName = t.Value.ToString();
                            }
                            if (t.Key.Contains("username"))
                            {
                                p.touser.username = t.Value.ToString();
                            }

                            if (t.Key.Contains("profileImageURL"))
                            {
                                p.touser.profileImageURL = t.Value.ToString();
                            }

                            if (t.Key.Contains("_id"))
                            {
                                s._id = t.Value.ToString();
                            }
                            if (t.Key.Contains("displayName"))
                            {
                                s.displayName = t.Value.ToString();
                            }
                            if (t.Key.Contains("username"))
                            {
                                s.username = t.Value.ToString();
                            }
                            if (t.Key.Contains("profileImageURL"))
                            {
                                s.profileImageURL = t.Value.ToString();
                            }
                        }
                    }


                    if (a.ContainsKey("status"))
                    {
                        p.status = a["status"].ToString();
                        if (a["status"].ToString() == "pending")
                        {
                            s.status = "pending";
                            mItemDataList.Add(s);
                        }
                    }
                    s.pd = p;
                    pList.Add(p);
                }
            }

            foreach (PendingFriendData u in pList)
            {
                if (u.status == "pending" && (u.touser.username == data.username || u.user.username == data.username))
                {
                    buttonName.text = "Pending";
                    buttonName.transform.parent.GetComponent <EventTrigger>().enabled = false;
                }
            }
        });

        if (GameManager.Instance.header == null)
        {
            return;
        }
        for (int i = 0; i < GameManager.Instance.header.Count; ++i)
        {
            foreach (KeyValuePair <string, List <string> > item in GameManager.Instance.header)
            {
                //Debug.Log(string.Format("{0}: {1}", item.Key, item.Value[0]));
                foreach (string val in item.Value)
                {
                    //Debug.Log(val);
                }
                www.AddField(item.Key, item.Value[0]);
            }
        }
        www.Send();
    }
コード例 #2
0
    public void GetAllPendingFriends()
    {
        dialog.SetActive(false);
        if (gameObject.name != "Friend Requests")
        {
            return;
        }
        HTTPRequest www = new HTTPRequest(new Uri(GameManager.Instance.webURLPrefix + "pendingFriend?myId=" + GameManager.Instance.player._id), (request, response) => {
            HTTPResponse res = (HTTPResponse)response;
            if (res.IsSuccess)
            {
                Debug.Log(res.DataAsText);
                mItemDataList.Clear();
                pList.Clear();
                List <object> dic = Json.Decode(res.DataAsText) as List <object>;
                pList             = new List <PendingFriendData>();
                foreach (Dictionary <string, object> a in dic)
                {
                    UserData s          = new UserData();
                    PendingFriendData p = new PendingFriendData();


                    Debug.Log(a["_id"].ToString());
                    if (a.ContainsKey("_id"))
                    {
                        p._id = a["_id"].ToString();
                    }
                    if (a.ContainsKey("user"))
                    {
                        p.user = new User();
                        if (a.ContainsKey("_id"))
                        {
                            s.requestId = a["_id"].ToString();
                        }

                        foreach (KeyValuePair <string, object> t in a["user"] as Dictionary <string, object> )
                        {
                            if (t.Key.Contains("_id"))
                            {
                                p.user._id = t.Value.ToString();
                            }
                            if (t.Key.Contains("displayName"))
                            {
                                p.user.displayName = t.Value.ToString();
                            }
                            if (t.Key.Contains("username"))
                            {
                                p.user.username = t.Value.ToString();
                            }
                            if (t.Key.Contains("profileImageURL"))
                            {
                                p.user.profileImageURL = t.Value.ToString();
                            }
                        }

                        Debug.Log("Simple User");
                    }

                    if (a.ContainsKey("touser"))
                    {
                        p.touser = new Touser();
                        foreach (KeyValuePair <string, object> t in a["touser"] as Dictionary <string, object> )
                        {
                            if (t.Key.Contains("_id"))
                            {
                                p.touser._id = t.Value.ToString();
                            }
                            if (t.Key.Contains("displayName"))
                            {
                                p.touser.displayName = t.Value.ToString();
                            }
                            if (t.Key.Contains("username"))
                            {
                                p.touser.username = t.Value.ToString();
                            }

                            if (t.Key.Contains("profileImageURL"))
                            {
                                p.touser.profileImageURL = t.Value.ToString();
                            }

                            if (t.Key.Contains("_id"))
                            {
                                s._id = t.Value.ToString();
                            }
                            if (t.Key.Contains("displayName"))
                            {
                                s.displayName = t.Value.ToString();
                            }
                            if (t.Key.Contains("username"))
                            {
                                s.username = t.Value.ToString();
                            }
                            if (t.Key.Contains("profileImageURL"))
                            {
                                s.profileImageURL = t.Value.ToString();
                            }
                        }

                        Debug.Log("To User");
                    }


                    if (a.ContainsKey("status"))
                    {
                        p.status = a["status"].ToString();
                        if (a["status"].ToString() == "pending")
                        {
                            s.status = "pending";
                            mItemDataList.Add(s);
                        }
                    }


                    /*UserData s = new UserData();
                     * if(a.ContainsKey("_id"))
                     *      s._id = a["_id"].ToString();
                     * if(a.ContainsKey("displayName"))
                     *      s.displayName = a["displayName"].ToString();
                     * if(a.ContainsKey("username"))
                     *      s.username = a["username"].ToString();
                     * if(a.ContainsKey("profileImageURL"))
                     *      s.profileImageURL = a["profileImageURL"].ToString();
                     * mItemDataList.Add(s);*/
                    s.pd = p;
                    pList.Add(p);
                }

                mTotalDataCount        = mItemDataList.Count;
                mIsWaittingRefreshData = true;
                mDataLoadLeftTime      = 1;
                mLoopListView.SetListItemCount(mTotalDataCount);
                //Debug.Log(mItemDataList.Count);
                //mLoopListView.RefreshAllShownItem();
            }
        });

        if (GameManager.Instance.header == null)
        {
            return;
        }
        for (int i = 0; i < GameManager.Instance.header.Count; ++i)
        {
            foreach (KeyValuePair <string, List <string> > item in GameManager.Instance.header)
            {
                //Debug.Log(string.Format("{0}: {1}", item.Key, item.Value[0]));
                foreach (string val in item.Value)
                {
                    //Debug.Log(val);
                }
                www.AddField(item.Key, item.Value[0]);
            }
        }
        www.Send();
    }