Ejemplo n.º 1
0
 private void Initialize()
 {
     EventAggregator.Current.Subscribe((object)this);
     this._helperGetFriendsAndMutual   = new AsyncHelper <BackendResult <FriendsAndMutualFriends, ResultCode> >((Action <Action <BackendResult <FriendsAndMutualFriends, ResultCode> > >)(a => UsersService.Instance.GetFriendsAndMutual(this._uid, a)));
     this._helperGetCurrentUserFriends = new AsyncHelper <BackendResult <List <User>, ResultCode> >((Action <Action <BackendResult <List <User>, ResultCode> > >)(a => UsersService.Instance.GetFriendsWithRequests((Action <BackendResult <AllFriendsList, ResultCode> >)(async(res) =>
     {//omg_re async
         if (res.ResultCode == ResultCode.Succeeded)
         {
             FriendsCache.Instance.SetFriends(res.ResultData.friends, res.ResultData.requests);
             await ContactsManager.Instance.SyncContactsAsync(res.ResultData.friends);
             this.RequestsViewModel = res.ResultData.requests;
             CountersManager.Current.Counters.friends = this.RequestsViewModel.menu_counter;
             EventAggregator.Current.Publish((object)new CountersChanged(CountersManager.Current.Counters));
         }
         Action <BackendResult <List <User>, ResultCode> > action = a;
         BackendResult <List <User>, ResultCode> backendResult    = new BackendResult <List <User>, ResultCode>();
         backendResult.Error       = res.Error;
         backendResult.ResultCode  = res.ResultCode;
         AllFriendsList resultData = res.ResultData;
         List <User> userList      = resultData != null ? resultData.friends : (List <User>)null;
         backendResult.ResultData  = userList;
         action(backendResult);
     }))));
     this._helperFriendsFromList = new AsyncHelper <BackendResult <List <User>, ResultCode> >((Action <Action <BackendResult <List <User>, ResultCode> > >)(a => UsersService.Instance.GetFriendsForList(this._lid, a)));
     this._allFriendsVM          = new GenericCollectionViewModel <List <User>, Group <FriendHeader> >((ICollectionDataProvider <List <User>, Group <FriendHeader> >) this)
     {
         NeedCollectionCountBeforeFullyLoading = true,
         RecreateCollectionOnRefresh           = true
     };
     this._onlineFriendsVM = new GenericCollectionViewModel <List <User>, FriendHeader>((ICollectionDataProvider <List <User>, FriendHeader>) this)
     {
         NeedCollectionCountBeforeFullyLoading = true
     };
     this._commonFriendsVM = new GenericCollectionViewModel <List <User>, FriendHeader>((ICollectionDataProvider <List <User>, FriendHeader>) this)
     {
         NeedCollectionCountBeforeFullyLoading = true
     };
     this._friendsListVM = new GenericCollectionViewModel <List <FriendsList>, FriendHeader>((ICollectionDataProvider <List <FriendsList>, FriendHeader>) this)
     {
         NeedCollectionCountBeforeFullyLoading = true
     };
     if (this._lid != 0)
     {
         return;
     }
     this._allFriendsVM.NoContentText  = CommonResources.NoContent_Friends;
     this._allFriendsVM.NoContentImage = "../Resources/NoContentImages/Friends.png";
 }
        private void Initialize()
        {
            EventAggregator.Current.Subscribe(this);
            this._helperGetFriendsAndMutual   = new AsyncHelper <BackendResult <FriendsAndMutualFriends, ResultCode> >((Action <Action <BackendResult <FriendsAndMutualFriends, ResultCode> > >)(a => UsersService.Instance.GetFriendsAndMutual(this._uid, a)));
            this._helperGetCurrentUserFriends = new AsyncHelper <BackendResult <List <User>, ResultCode> >((Action <Action <BackendResult <List <User>, ResultCode> > >)(a => UsersService.Instance.GetFriendsAndLists((Action <BackendResult <AllFriendsList, ResultCode> >)(async res =>
            {
                if (res.ResultCode == ResultCode.Succeeded)
                {//todo:bug
                    FriendsCache.Instance.SetFriends(res.ResultData.items, null /*res.ResultData.requests*/);
                    await ContactsManager.Instance.SyncContactsAsync(res.ResultData.items);
                    //this.RequestsViewModel = res.ResultData.requests;
                    //if (this.RequestsViewModel != null)
                    //{//todo:bug
                    //    CountersManager.Current.Counters.friends = this.RequestsViewModel.menu_counter;
                    //    EventAggregator.Current.Publish(new CountersChanged(CountersManager.Current.Counters));
                    //}
                }

                BackendResult <List <User>, ResultCode> backendResult = new BackendResult <List <User>, ResultCode>();
                backendResult.Error       = res.Error;
                backendResult.ResultCode  = res.ResultCode;
                AllFriendsList resultData = res.ResultData;
                //List<User> userList = resultData != null ? resultData.friends : null;
                //backendResult.ResultData = userList;
                a(backendResult);
            }))));
            //
            this._helperGetFriendsRequests = new AsyncHelper <BackendResult <List <User>, ResultCode> >((Action <Action <BackendResult <List <User>, ResultCode> > >)(a => UsersService.Instance.GetFriendRequests((Action <BackendResult <FriendRequestsMaterial, ResultCode> >)(res =>
            {
                if (res.ResultCode == ResultCode.Succeeded)
                {
                    if (this.RequestsViewModel == null)
                    {
                        this.RequestsViewModel = new FriendRequests();
                    }

                    FriendRequestsMaterial d = res.ResultData;

                    this.RequestsViewModel.count    = d.count;
                    this.RequestsViewModel.profiles = d.profiles;

                    foreach (FriendRequestsMaterial.FriendRequestItem f in d.items)
                    {
                        FriendRequest fr = new FriendRequest();
                        fr.message       = f.message;
                        fr.from          = f.user_id;
                        this.RequestsViewModel.requests.Add(fr);
                    }

                    CountersManager.Current.Counters.friends = this.RequestsViewModel.menu_counter;
                    EventAggregator.Current.Publish(new CountersChanged(CountersManager.Current.Counters));
                }

                BackendResult <List <User>, ResultCode> backendResult = new BackendResult <List <User>, ResultCode>();
                backendResult.Error               = res.Error;
                backendResult.ResultCode          = res.ResultCode;
                FriendRequestsMaterial resultData = res.ResultData;
                a(backendResult);
            }))));
            //
            this._helperFriendsFromList = new AsyncHelper <BackendResult <List <User>, ResultCode> >((Action <Action <BackendResult <List <User>, ResultCode> > >)(a => UsersService.Instance.GetFriendsForList(this._lid, a)));
            this._allFriendsVM          = new GenericCollectionViewModel <List <User>, Group <FriendHeader> >((ICollectionDataProvider <List <User>, Group <FriendHeader> >) this)
            {
                NeedCollectionCountBeforeFullyLoading = true,
                RecreateCollectionOnRefresh           = true
            };
            this._onlineFriendsVM = new GenericCollectionViewModel <List <User>, FriendHeader>((ICollectionDataProvider <List <User>, FriendHeader>) this)
            {
                NeedCollectionCountBeforeFullyLoading = true
            };
            this._commonFriendsVM = new GenericCollectionViewModel <List <User>, FriendHeader>((ICollectionDataProvider <List <User>, FriendHeader>) this)
            {
                NeedCollectionCountBeforeFullyLoading = true
            };
            this._friendsListVM = new GenericCollectionViewModel <List <FriendsList>, FriendHeader>((ICollectionDataProvider <List <FriendsList>, FriendHeader>) this)
            {
                NeedCollectionCountBeforeFullyLoading = true
            };
            if (this._lid != 0L)
            {
                return;
            }
            this._allFriendsVM.NoContentText  = CommonResources.NoContent_Friends;
            this._allFriendsVM.NoContentImage = "../Resources/NoContentImages/Friends.png";
        }