示例#1
0
        public List <UserVm> ApplyPrivacySettings(IEnumerable <UserVm> users, List <string> phones, long?userId = null)
        {
            if (phones == null)
            {
                throw new ArgumentNullException(nameof(phones));
            }
            if (users == null)
            {
                return(null);
            }
            ConcurrentBag <UserVm> result = new ConcurrentBag <UserVm>();

            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource())
            {
                var filterUsersDataTask = Task.Run(async() =>
                {
                    List <ContactDto> contacts = await contactsService.GetUsersContactsAsync(
                        userId.GetValueOrDefault(),
                        users.Select(opt => opt.Id.GetValueOrDefault()).ToList())
                                                 .ConfigureAwait(false);
                    List <Guid> groupsId = new List <Guid>();
                    foreach (var contact in contacts)
                    {
                        if (contact.GroupsId?.Any() ?? false)
                        {
                            groupsId.AddRange(contact.GroupsId);
                        }
                    }
                    List <GroupDto> groups = await groupsService.GetGroupsAsync(groupsId).ConfigureAwait(false);
                    foreach (var user in users)
                    {
                        var userGroups    = groups.Where(opt => opt.UserId == user.Id && opt.UsersId.Contains(userId.GetValueOrDefault()));
                        var contact       = contacts.FirstOrDefault(opt => opt.UserId == user.Id && opt.ContactUserId == userId);
                        int resultPrivacy = user.Privacy.ToInt32();
                        if (userGroups != null && userGroups.Any())
                        {
                            var privacyValues = userGroups.Select(opt => opt.PrivacySettings.GetValueOrDefault());
                            foreach (var value in privacyValues)
                            {
                                resultPrivacy |= value;
                            }
                        }
                        else if (contact != null)
                        {
                            resultPrivacy = (user.ContactsPrivacy?.ToInt32()).GetValueOrDefault() | user.Privacy.ToInt32();
                        }
                        var bitMask = new BitArray(BitConverter.GetBytes(resultPrivacy));
                        if ((user.Phones?.Any(opt => phones.Contains(opt.FullNumber)) ?? false) && !bitMask[15])
                        {
                            continue;
                        }
                        result.Add(ApplyPrivacySettings(user, bitMask, userId));
                    }
                }, cancellationTokenSource.Token);
                filterUsersDataTask.Wait();
            }
            return(result.ToList());
        }
        public async void LoadGroups()
        {
            if (Groups == null)
            {
                _allGroups = await _groupsService.GetGroupsAsync();

                Groups = new ObservableCollection <Group>(_allGroups);
            }
        }
 public void Resolve(GraphQLQuery graphQLQuery)
 {
     graphQLQuery.Field <ResponseListGraphType <GroupType> >(
         "groups",
         resolve: context => {
         var groups = _groupsService.GetGroupsAsync().GetAwaiter().GetResult();
         return(Response(groups));
     }
         );
 }
        public override Task ResolvePossibleConversationsAsync() =>
        Task.Run(async() => {
            ResetCancellationTokenSource(ref _getGroupsCancellationTokenSource);
            CancellationTokenSource cancellationTokenSource = _getGroupsCancellationTokenSource;

            try {
                List <GroupDTO> foundgroupDTOs = await _groupsService.GetGroupsAsync(cancellationTokenSource);

                ChargePossibleConverstionItems(foundgroupDTOs);
            }
            catch (OperationCanceledException) { }
            catch (ObjectDisposedException) { }
            catch (ServiceAuthenticationException) { }
            catch (Exception exc) {
                Crashes.TrackError(exc);

                await DialogService.ToastAsync(exc.Message);
            }
        });
示例#5
0
        public async Task <IList <GroupDto> > Get()
        {
            var groups = await _groupsService.GetGroupsAsync();

            return(groups);
        }
示例#6
0
        public Task <List <PostPublicityScope> > GetPossiblePostPublicityScopesAsync(CancellationTokenSource cancellationTokenSource) =>
        Task <List <PostPublicityScope> > .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            List <PostPublicityScope> possiblePublicityScopes = null;

            try {
                List <PostPublicityScope> groupsScope      = _postPublicityScopeFactory.BuildRawPublicityScope(await _groupsService.GetGroupsAsync(cancellationTokenSource));
                List <PostPublicityScope> teamMembersScope = _postPublicityScopeFactory.BuildRawPublicityScope(await _teamMemberService.GetTeamMembersAsync(cancellationTokenSource.Token, GlobalSettings.Instance.UserProfile.ProfileType == ProfileType.Parent));
                PostPublicityScope familyPostPublicity     = _postPublicityScopeFactory.BuildFamilyPublicityScope(await _familyService.GetFamilyAsync(cancellationTokenSource));

                possiblePublicityScopes = _postPublicityScopeFactory.BuildCompletedPublicityScopeList(groupsScope.Concat(teamMembersScope).ToArray(), familyPostPublicity);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);

                possiblePublicityScopes = _postPublicityScopeFactory.BuildCompletedPublicityScopeList(null);
            }

            return(possiblePublicityScopes);
        }, cancellationTokenSource.Token);
        public async Task <IActionResult> GetGroupsAsync()
        {
            var groups = await _groupsService.GetGroupsAsync();

            return(Ok(groups));
        }
示例#8
0
        public async Task <IActionResult> GetGroups(PagingModel pagingModel)
        {
            var groups = await _groupsService.GetGroupsAsync(pagingModel);

            return(Ok(groups));
        }