Ejemplo n.º 1
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content = args.ItemContainer.ContentTemplateRoot as Grid;
            var user    = args.Item as User;

            if (args.Phase == 0)
            {
                var title = content.Children[1] as TextBlock;
                title.Text = user.GetFullName();
            }
            else if (args.Phase == 1)
            {
                var subtitle = content.Children[2] as TextBlock;
                subtitle.Text = LastSeenConverter.GetLabel(user, false);
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as ProfilePicture;
                photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36, 36);
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(OnContainerContentChanging);
            }

            args.Handled = true;
        }
Ejemplo n.º 2
0
        public void UpdateUser(IProtoService protoService, ContainerContentChangingEventArgs args, TypedEventHandler <ListViewBase, ContainerContentChangingEventArgs> callback)
        {
            var user = args.Item as User;

            if (user == null)
            {
                return;
            }

            if (args.Phase == 0)
            {
                TitleLabel.Text = user.GetFullName();
            }
            else if (args.Phase == 1)
            {
                SubtitleLabel.Text = LastSeenConverter.GetLabel(user, false);
            }
            else if (args.Phase == 2)
            {
                Photo.Source = PlaceholderHelper.GetUser(protoService, user, 36);
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(callback);
            }

            args.Handled = true;
        }
Ejemplo n.º 3
0
        public void UpdateUser(IProtoService protoService, User user, ContainerContentChangingEventArgs args, TypedEventHandler <ListViewBase, ContainerContentChangingEventArgs> callback)
        {
            if (args.Phase == 0)
            {
                TitleLabel.Text    = user.GetFullName();
                Premium.Visibility = user.IsPremium && protoService.IsPremiumAvailable
                    ? Visibility.Visible
                    : Visibility.Collapsed;
            }
            else if (args.Phase == 1)
            {
                SubtitleLabel.Text  = LastSeenConverter.GetLabel(user, false);
                SubtitleLabel.Style = BootStrapper.Current.Resources[user.Status is UserStatusOnline ? "AccentCaptionTextBlockStyle" : "InfoCaptionTextBlockStyle"] as Style;
            }
            else if (args.Phase == 2)
            {
                Photo.SetUser(protoService, user, 36);
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(callback);
            }

            args.Handled = true;
        }
        public void UpdateUser(Chat chat, User user, bool secret)
        {
            Title.Text = user.GetFullName();
            Subtitle.Text = LastSeenConverter.GetLabel(user, true);
            Photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 64);

            Verified.Visibility = user.IsVerified ? Visibility.Visible : Visibility.Collapsed;
        }
Ejemplo n.º 5
0
        public void UpdateUser(Chat chat, User user, bool secret)
        {
            Subtitle.Text = LastSeenConverter.GetLabel(user, true);

            Verified.Visibility = user.IsVerified ? Visibility.Visible : Visibility.Collapsed;

            UserPhone.Badge      = PhoneNumber.Format(user.PhoneNumber);
            UserPhone.Visibility = string.IsNullOrEmpty(user.PhoneNumber) ? Visibility.Collapsed : Visibility.Visible;

            Username.Badge      = $"{user.Username}";
            Username.Visibility = string.IsNullOrEmpty(user.Username) ? Visibility.Collapsed : Visibility.Visible;

            DescriptionTitle.Text = user.Type is UserTypeBot ? Strings.Resources.DescriptionPlaceholder : Strings.Resources.UserBio;

            if (user.Id == ViewModel.CacheService.Options.MyId)
            {
                NotificationsPanel.Visibility = Visibility.Collapsed;
            }
            else
            {
                NotificationsPanel.Visibility = Visibility.Visible;
            }

            if (secret)
            {
                UserStartSecret.Visibility = Visibility.Collapsed;
            }
            else
            {
                if (user.Type is UserTypeBot || user.Id == ViewModel.CacheService.Options.MyId)
                {
                    MiscPanel.Visibility       = Visibility.Collapsed;
                    UserStartSecret.Visibility = Visibility.Collapsed;
                }
                else
                {
                    MiscPanel.Visibility       = Visibility.Visible;
                    UserStartSecret.Visibility = Visibility.Visible;
                }

                SecretLifetime.Visibility = Visibility.Collapsed;
                SecretHashKey.Visibility  = Visibility.Collapsed;
            }

            // Unused:
            Location.Visibility = Visibility.Collapsed;

            GroupLeave.Visibility  = Visibility.Collapsed;
            GroupInvite.Visibility = Visibility.Collapsed;

            ChannelMembersPanel.Visibility = Visibility.Collapsed;
            MembersPanel.Visibility        = Visibility.Collapsed;
            //Admins.Visibility = Visibility.Collapsed;
            //Banned.Visibility = Visibility.Collapsed;
            //Restricted.Visibility = Visibility.Collapsed;
            //Members.Visibility = Visibility.Collapsed;
        }
Ejemplo n.º 6
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content = args.ItemContainer.ContentTemplateRoot as Grid;
            var member  = args.Item as ChatMember;

            content.Tag = member;

            var user = ViewModel.ProtoService.GetUser(member.UserId);

            if (user == null)
            {
                return;
            }

            if (args.Phase == 0)
            {
                var photo = content.Children[0] as ProfilePicture;
                photo.Source = null;

                var title = content.Children[1] as TextBlock;
                title.Text = user.GetFullName();
            }
            else if (args.Phase == 1)
            {
                var subtitle = content.Children[2] as TextBlock;
                subtitle.Text = LastSeenConverter.GetLabel(user, false);

                if (member.Status is ChatMemberStatusAdministrator administrator)
                {
                    var label = content.Children[3] as TextBlock;
                    label.Text = string.IsNullOrEmpty(administrator.CustomTitle) ? Strings.Resources.ChannelAdmin : administrator.CustomTitle;
                }
                else if (member.Status is ChatMemberStatusCreator creator)
                {
                    var label = content.Children[3] as TextBlock;
                    label.Text = string.IsNullOrEmpty(creator.CustomTitle) ? Strings.Resources.ChannelCreator : creator.CustomTitle;
                }
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as ProfilePicture;
                photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36);
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(OnContainerContentChanging);
            }

            args.Handled = true;
        }
Ejemplo n.º 7
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            Item = null;
            Full = null;

            var user = parameter as TLUser;
            var peer = parameter as TLPeerUser;

            if (peer != null)
            {
                user = CacheService.GetUser(peer.Id) as TLUser;
            }

            if (user != null)
            {
                Item = user;
                RaisePropertyChanged(() => IsEditEnabled);
                RaisePropertyChanged(() => AreNotificationsEnabled);
                RaisePropertyChanged(() => PhoneVisibility);
                RaisePropertyChanged(() => AddToGroupVisibility);
                RaisePropertyChanged(() => HelpVisibility);
                RaisePropertyChanged(() => ReportVisibility);
                RaisePropertyChanged(() => AddContactVisibility);

                var full = CacheService.GetFullUser(user.Id);
                if (full == null)
                {
                    var response = await ProtoService.GetFullUserAsync(user.ToInputUser());

                    if (response.IsSucceeded)
                    {
                        full = response.Result;
                    }
                }
                else
                {
                    ProtoService.GetFullUserAsync(user.ToInputUser(), null);
                }

                if (full != null)
                {
                    Full = full;
                    RaisePropertyChanged(() => IsPhoneCallsAvailable);
                    RaisePropertyChanged(() => AboutVisibility);
                    RaisePropertyChanged(() => BlockVisibility);
                    RaisePropertyChanged(() => UnblockVisibility);
                    RaisePropertyChanged(() => StopVisibility);
                    RaisePropertyChanged(() => UnstopVisibility);
                    RaisePropertyChanged(() => AddContactVisibility);
                }

                LastSeen = LastSeenConverter.GetLabel(user, true);

                Aggregator.Subscribe(this);
            }
        }
Ejemplo n.º 8
0
        public void UpdateUser(Chat chat, User user, bool secret)
        {
            Subtitle.Text = LastSeenConverter.GetLabel(user, true);

            Verified.Visibility = user.IsVerified ? Visibility.Visible : Visibility.Collapsed;

            UserPhone.Content    = PhoneNumber.Format(user.PhoneNumber);
            UserPhone.Visibility = string.IsNullOrEmpty(user.PhoneNumber) ? Visibility.Collapsed : Visibility.Visible;

            Username.Content    = $"@{user.Username}";
            Username.Visibility = string.IsNullOrEmpty(user.Username) ? Visibility.Collapsed : Visibility.Visible;

            DescriptionTitle.Text       = user.Type is UserTypeBot ? "About" : Strings.Resources.UserBio;
            DescriptionTitle.Visibility = Visibility.Visible;
            DescriptionLabel.Padding    = new Thickness(12, 0, 12, 12);

            if (user.Id == ViewModel.ProtoService.GetMyId())
            {
                Notifications.Visibility = Visibility.Collapsed;
            }
            else
            {
                Notifications.Visibility = Visibility.Visible;
            }

            if (secret)
            {
                UserStartSecret.Visibility = Visibility.Collapsed;
            }
            else
            {
                if (user.Type is UserTypeBot || user.Id == ViewModel.ProtoService.GetMyId())
                {
                    UserStartSecret.Visibility = Visibility.Collapsed;
                }
                else
                {
                    UserStartSecret.Visibility = Visibility.Visible;
                }

                SecretLifetime.Visibility = Visibility.Collapsed;
                SecretHashKey.Visibility  = Visibility.Collapsed;
            }

            // Unused:
            GroupLeave.Visibility  = Visibility.Collapsed;
            GroupInvite.Visibility = Visibility.Collapsed;

            EventLog.Visibility   = Visibility.Collapsed;
            Admins.Visibility     = Visibility.Collapsed;
            Banned.Visibility     = Visibility.Collapsed;
            Restricted.Visibility = Visibility.Collapsed;
            Members.Visibility    = Visibility.Collapsed;
        }
Ejemplo n.º 9
0
 public void Handle(TLUpdateUserStatus statusUpdate)
 {
     Execute.BeginOnUIThread(() =>
     {
         if (With is TLUser user)
         {
             LastSeen = LastSeenConverter.GetLabel(user, true);
         }
         else
         {
             //if (online > -1)
             //{
             //    if (statusUpdate.Status.GetType() == typeof(TLUserStatusOnline)) online++;
             //    else online--;
             //    LastSeen = participantCount + " members" + ((online > 0) ? (", " + online + " online") : "");
             //}
         }
     });
 }
        private void Search_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                //var photo = content.Children[0] as ProfilePicture;
                //photo.Source = null;

                return;
            }

            var result = args.Item as SearchResult;
            var chat   = result.Chat;
            var user   = result.User ?? ViewModel.ProtoService.GetUser(chat);

            if (user == null)
            {
                return;
            }

            var content = args.ItemContainer.ContentTemplateRoot as Grid;

            if (content == null)
            {
                return;
            }

            if (args.Phase == 0)
            {
                var title = content.Children[1] as TextBlock;
                title.Text = user.GetFullName();
            }
            else if (args.Phase == 1)
            {
                var subtitle = content.Children[2] as TextBlock;
                if (result.IsPublic)
                {
                    subtitle.Text = $"@{user.Username}";
                }
                else
                {
                    subtitle.Text = LastSeenConverter.GetLabel(user, true);
                }

                if (ApiInfo.CanUseTextHighlighters)
                {
                    if (subtitle.Text.StartsWith($"@{result.Query}", StringComparison.OrdinalIgnoreCase))
                    {
                        var highligher = new TextHighlighter();
                        highligher.Foreground = new SolidColorBrush(Colors.Red);
                        highligher.Background = new SolidColorBrush(Colors.Transparent);
                        highligher.Ranges.Add(new TextRange {
                            StartIndex = 1, Length = result.Query.Length
                        });

                        subtitle.TextHighlighters.Add(highligher);
                    }
                    else
                    {
                        subtitle.TextHighlighters.Clear();
                    }
                }
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as ProfilePicture;
                photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 36);
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(Search_ContainerContentChanging);
            }

            args.Handled = true;
        }
 public void UpdateUserStatus(Chat chat, User user)
 {
     Subtitle.Text = LastSeenConverter.GetLabel(user, true);
 }
Ejemplo n.º 12
0
        private async Task <string> GetSubtitle()
        {
            if (With is TLUser user)
            {
                return(LastSeenConverter.GetLabel(user, true));
            }
            else if (With is TLChannel channel && channel.HasAccessHash && channel.AccessHash.HasValue)
            {
                var full = Full as TLChannelFull;
                if (full == null)
                {
                    full = CacheService.GetFullChat(channel.Id) as TLChannelFull;
                }

                if (full == null)
                {
                    var response = await ProtoService.GetFullChannelAsync(new TLInputChannel { ChannelId = channel.Id, AccessHash = channel.AccessHash.Value });

                    if (response.IsSucceeded)
                    {
                        full = response.Result.FullChat as TLChannelFull;
                    }
                }

                if (full == null)
                {
                    return(string.Empty);
                }

                if (channel.IsBroadcast && full.HasParticipantsCount)
                {
                    return(string.Format("{0} members", full.ParticipantsCount ?? 0));
                }
                else if (full.HasParticipantsCount)
                {
                    var config = CacheService.GetConfig();
                    if (config == null)
                    {
                        return(string.Format("{0} members", full.ParticipantsCount ?? 0));
                    }

                    var participants = await ProtoService.GetParticipantsAsync(channel.ToInputChannel(), new TLChannelParticipantsRecent(), 0, config.ChatSizeMax, 0);

                    if (participants.IsSucceeded && participants.Result is TLChannelsChannelParticipants channelParticipants)
                    {
                        full.Participants = participants.Result;

                        if (full.ParticipantsCount <= config.ChatSizeMax)
                        {
                            var count = 0;
                            foreach (var item in channelParticipants.Users.OfType <TLUser>())
                            {
                                if (item.HasStatus && item.Status is TLUserStatusOnline)
                                {
                                    count++;
                                }
                            }

                            if (count > 1)
                            {
                                return(string.Format("{0} members, {1} online", full.ParticipantsCount ?? 0, count));
                            }
                        }
                    }

                    return(string.Format("{0} members", full.ParticipantsCount ?? 0));
                }
            }
Ejemplo n.º 13
0
        public void UpdateSearchResult(IProtoService protoService, ContainerContentChangingEventArgs args, TypedEventHandler <ListViewBase, ContainerContentChangingEventArgs> callback)
        {
            var result = args.Item as SearchResult;

            args.ItemContainer.Tag = result.Chat;

            if (args.Phase == 0)
            {
                TitleLabel.Style = BootStrapper.Current.Resources[result?.Chat?.Type is ChatTypeSecret ? "SecretBodyTextBlockStyle" : "BodyTextBlockStyle"] as Style;

                if (result.Chat != null)
                {
                    TitleLabel.Text = protoService.GetTitle(result.Chat);
                }
                else if (result.User != null)
                {
                    TitleLabel.Text = result.User.GetFullName();
                }

                var verified = false;
                var premium  = false;

                if (result.Chat != null)
                {
                    if (protoService.TryGetUser(result.Chat, out User user))
                    {
                        verified = user.IsVerified;
                        premium  = user.IsPremium && protoService.IsPremiumAvailable && user.Id != protoService.Options.MyId;
                    }
                    else if (protoService.TryGetSupergroup(result.Chat, out Supergroup supergroup))
                    {
                        verified = supergroup.IsVerified;
                        premium  = false;
                    }
                }
                else if (result.User != null)
                {
                    verified = result.User.IsVerified;
                    premium  = result.User.IsPremium && protoService.IsPremiumAvailable;
                }

                if (premium || verified)
                {
                    Premium.Glyph      = premium ? Icons.Premium16 : Icons.Verified16;
                    Premium.Visibility = Visibility.Visible;
                }
                else
                {
                    Premium.Visibility = Visibility.Collapsed;
                }
            }
            else if (args.Phase == 1)
            {
                if (result.User != null || (result.Chat != null && (result.Chat.Type is ChatTypePrivate privata || result.Chat.Type is ChatTypeSecret)))
                {
                    var user = result.User ?? protoService.GetUser(result.Chat);
                    if (result.IsPublic)
                    {
                        SubtitleLabel.Text = $"@{user.Username}";
                    }
                    else if (protoService.IsSavedMessages(user))
                    {
                        SubtitleLabel.Text = Strings.Resources.ThisIsYou;
                    }
                    else
                    {
                        SubtitleLabel.Text = LastSeenConverter.GetLabel(user, true);
                    }
                }
                else if (result.Chat != null && result.Chat.Type is ChatTypeSupergroup super)
                {
                    var supergroup = protoService.GetSupergroup(super.SupergroupId);
                    if (result.IsPublic)
                    {
                        if (supergroup.MemberCount > 0)
                        {
                            SubtitleLabel.Text = string.Format("@{0}, {1}", supergroup.Username, Locale.Declension(supergroup.IsChannel ? "Subscribers" : "Members", supergroup.MemberCount));
                        }
                        else
                        {
                            SubtitleLabel.Text = $"@{supergroup.Username}";
                        }
                    }
                    else if (supergroup.MemberCount > 0)
                    {
                        SubtitleLabel.Text = Locale.Declension(supergroup.IsChannel ? "Subscribers" : "Members", supergroup.MemberCount);
                    }
                    else
                    {
                        SubtitleLabel.Text = string.Empty;
                    }
                }
                else
                {
                    SubtitleLabel.Text = string.Empty;
                }

                if (SubtitleLabel.Text.StartsWith($"@{result.Query}", StringComparison.OrdinalIgnoreCase))
                {
                    var highligher = new TextHighlighter();
                    highligher.Foreground = new SolidColorBrush(Colors.Red);
                    highligher.Background = new SolidColorBrush(Colors.Transparent);
                    highligher.Ranges.Add(new TextRange {
                        StartIndex = 1, Length = result.Query.Length
                    });

                    SubtitleLabel.TextHighlighters.Add(highligher);
                }
                else
                {
                    SubtitleLabel.TextHighlighters.Clear();
                }
            }