예제 #1
0
        public LastSeenViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            _rules = StateService.PrivacyRules;
            StateService.PrivacyRules = null;

            MainRules = new List <TLPrivacyRuleBase>
            {
                new TLPrivacyValueAllowAll {
                    Label = AppResources.Everybody.ToLowerInvariant()
                },
                new TLPrivacyValueAllowContacts {
                    Label = AppResources.MyContacts.ToLowerInvariant()
                },
                new TLPrivacyValueDisallowAll {
                    Label = AppResources.Nobody.ToLowerInvariant()
                }
            };

            _selectedMainRule   = GetSelectedMainRule(MainRules, _rules, MainRules[0], MainRules[2]);
            _selectedAllowUsers = GetSelectedRule <TLPrivacyValueAllowUsers>(_rules) ?? new TLPrivacyValueAllowUsers {
                Users = new TLVector <TLInt>()
            };
            _selectedDisallowUsers = GetSelectedRule <TLPrivacyValueDisallowUsers>(_rules) ?? new TLPrivacyValueDisallowUsers {
                Users = new TLVector <TLInt>()
            };
            SwitchUsersVisibility(true);
            PropertyChanged += OnPropertyChanged;
        }
예제 #2
0
        private T GetSelectedRule <T>(TLPrivacyRules rules) where T : TLPrivacyRuleBase
        {
            T allowUsers = null;

            if (_rules != null)
            {
                allowUsers = (T)rules.Rules.FirstOrDefault(x => x is T);
            }

            return(allowUsers);
        }
예제 #3
0
        public void Handle(TLUpdatePrivacy privacy)
        {
            _rules = new TLPrivacyRules {
                Rules = privacy.Rules
            };

            SelectedMainRule    = GetSelectedMainRule(MainRules, _rules, MainRules[0], MainRules[2]);
            _selectedAllowUsers = GetSelectedRule <TLPrivacyValueAllowUsers>(_rules) ?? new TLPrivacyValueAllowUsers {
                Users = new TLVector <TLInt>()
            };
            _selectedDisallowUsers = GetSelectedRule <TLPrivacyValueDisallowUsers>(_rules) ?? new TLPrivacyValueDisallowUsers {
                Users = new TLVector <TLInt>()
            };
            SwitchUsersVisibility(false);

            UpdateSubtitles();
        }
예제 #4
0
        public void Handle(TLUpdatePrivacy privacy)
        {
            var result = new TLPrivacyRules {
                Rules = privacy.Rules
            };

            if (privacy.Key is TLPrivacyKeyStatusTimestamp)
            {
                LastSeenSubtitle = GetPrivacyString(result, out _lastSeenPrivacyRules);
            }
            else if (privacy.Key is TLPrivacyKeyPhoneCall)
            {
                PhoneCallsSubtitle = GetPrivacyString(result, out _phoneCallsPrivacyRules);
            }
            else if (privacy.Key is TLPrivacyKeyChatInvite)
            {
                GroupsSubtitle = GetPrivacyString(result, out _chatInvitePrivacyRules);
            }
            else
            {
                Execute.ShowDebugMessage("PrivacySecureViewModel.Handle TLUpdatePrivacy unknown key=" + privacy.Key);
            }
        }
        private void UpdateLastSeenString(TLPrivacyRules rules)
        {
            _privacyRules = rules;

            TLPrivacyRuleBase mainRule = null;
            var mainRuleString         = string.Empty;
            var minusCount             = 0;
            var plusCount = 0;

            foreach (var rule in rules.Rules)
            {
                if (rule is TLPrivacyValueAllowAll)
                {
                    mainRule       = rule;
                    mainRuleString = AppResources.Everybody;
                }

                if (rule is TLPrivacyValueAllowContacts)
                {
                    mainRule       = rule;
                    mainRuleString = AppResources.MyContacts;
                }

                if (rule is TLPrivacyValueDisallowAll)
                {
                    mainRule       = rule;
                    mainRuleString = AppResources.Nobody;
                }

                if (rule is TLPrivacyValueDisallowUsers)
                {
                    minusCount += ((TLPrivacyValueDisallowUsers)rule).Users.Count;
                }

                if (rule is TLPrivacyValueAllowUsers)
                {
                    plusCount += ((TLPrivacyValueAllowUsers)rule).Users.Count;
                }
            }

            if (mainRule == null)
            {
                mainRule       = new TLPrivacyValueDisallowAll();
                mainRuleString = AppResources.Nobody;
            }

            var countStrings = new List <string>();

            if (minusCount > 0)
            {
                countStrings.Add("-" + minusCount);
            }
            if (plusCount > 0)
            {
                countStrings.Add("+" + plusCount);
            }
            if (countStrings.Count > 0)
            {
                mainRuleString += string.Format(" ({0})", string.Join(", ", countStrings));
            }

            LastSeenSubtitle = mainRuleString.ToLowerInvariant();
        }
예제 #6
0
        private TLPrivacyRuleBase GetSelectedMainRule(List <TLPrivacyRuleBase> mainRules, TLPrivacyRules rules, TLPrivacyRuleBase defaultRule, TLPrivacyRuleBase noRules)
        {
            if (rules == null)
            {
            }
            else
            {
                foreach (var rule in rules.Rules)
                {
                    var mainRule = mainRules.FirstOrDefault(x => x.GetType() == rule.GetType());
                    if (mainRule != null)
                    {
                        return(mainRule);
                    }
                }

                return(noRules);
            }

            return(defaultRule);
        }
예제 #7
0
        private string GetPrivacyString(TLPrivacyRules rules, out TLPrivacyRules currentRules)
        {
            currentRules = rules;

            TLPrivacyRuleBase mainRule = null;
            var mainRuleString         = string.Empty;
            var minusCount             = 0;
            var plusCount = 0;

            foreach (var rule in rules.Rules)
            {
                if (rule is TLPrivacyValueAllowAll)
                {
                    mainRule       = rule;
                    mainRuleString = AppResources.Everybody;
                }

                if (rule is TLPrivacyValueAllowContacts)
                {
                    mainRule       = rule;
                    mainRuleString = AppResources.MyContacts;
                }

                if (rule is TLPrivacyValueDisallowAll)
                {
                    mainRule       = rule;
                    mainRuleString = AppResources.Nobody;
                }

                if (rule is TLPrivacyValueDisallowUsers)
                {
                    minusCount += ((TLPrivacyValueDisallowUsers)rule).Users.Count;
                }

                if (rule is TLPrivacyValueAllowUsers)
                {
                    plusCount += ((TLPrivacyValueAllowUsers)rule).Users.Count;
                }
            }

            if (mainRule == null)
            {
                mainRule       = new TLPrivacyValueDisallowAll();
                mainRuleString = AppResources.Nobody;
            }

            var countStrings = new List <string>();

            if (minusCount > 0)
            {
                countStrings.Add("-" + minusCount);
            }
            if (plusCount > 0)
            {
                countStrings.Add("+" + plusCount);
            }
            if (countStrings.Count > 0)
            {
                mainRuleString += string.Format(" ({0})", string.Join(", ", countStrings));
            }

            return(mainRuleString);
        }