コード例 #1
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content = args.ItemContainer.ContentTemplateRoot as Grid;
            var chat    = args.Item as Chat;

            if (args.Phase == 0)
            {
                var title = content.Children[1] as TextBlock;
                title.Text = ViewModel.ProtoService.GetTitle(chat);
            }
            else if (args.Phase == 1)
            {
                if (chat.Type is ChatTypeSupergroup super)
                {
                    var supergroup = ViewModel.ProtoService.GetSupergroup(super.SupergroupId);
                    if (supergroup != null)
                    {
                        var subtitle = content.Children[2] as TextBlock;
                        subtitle.Text = MeUrlPrefixConverter.Convert(ViewModel.CacheService, supergroup.Username, true);
                    }
                }
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as ProfilePicture;
                photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36);
            }

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

            args.Handled = true;
        }
コード例 #2
0
        private void OnElementPrepared(Microsoft.UI.Xaml.Controls.ItemsRepeater sender, Microsoft.UI.Xaml.Controls.ItemsRepeaterElementPreparedEventArgs args)
        {
            var button  = args.Element as Button;
            var content = button.Content as Grid;

            var nearby = button.DataContext as ChatNearby;

            var chat = ViewModel.CacheService.GetChat(nearby.ChatId);

            if (chat == null)
            {
                return;
            }

            var title = content.Children[1] as TextBlock;

            title.Text = ViewModel.ProtoService.GetTitle(chat);

            if (ViewModel.CacheService.TryGetSupergroup(chat, out Supergroup supergroup))
            {
                var subtitle = content.Children[2] as TextBlock;
                subtitle.Text = string.Format("{0}, {1}", Converter.Distance(nearby.Distance), Locale.Declension("Members", supergroup.MemberCount));
            }
            else
            {
                var subtitle = content.Children[2] as TextBlock;
                subtitle.Text = Converter.Distance(nearby.Distance);
            }

            var photo = content.Children[0] as ProfilePicture;

            photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36);

            button.Command          = ViewModel.OpenChatCommand;
            button.CommandParameter = nearby;
        }
コード例 #3
0
        public JoinChatView(IProtoService protoService, ChatInviteLinkInfo info)
        {
            InitializeComponent();

            _protoService = protoService;

            Photo.Source = PlaceholderHelper.GetChat(protoService, info, 72, 72);

            Title.Text    = info.Title;
            Subtitle.Text = ConvertCount(info.MemberCount, info.MemberUserIds.Count == 0);

            if (info.MemberUserIds.Count > 0)
            {
                FooterPanel.Visibility = ConvertMoreVisibility(info.MemberCount, info.MemberUserIds.Count);
                Footer.Text            = ConvertMore(info.MemberCount, info.MemberUserIds.Count);

                Members.Visibility  = Visibility.Visible;
                Members.ItemsSource = protoService.GetUsers(info.MemberUserIds);
            }
            else
            {
                Members.Visibility = Visibility.Collapsed;
            }
        }
コード例 #4
0
        public SettingsStorageOptimizationPage(IProtoService protoService, StorageStatisticsByChat statistics)
        {
            InitializeComponent();

            PrimaryButtonText   = Strings.Resources.CacheClear;
            SecondaryButtonText = Strings.Resources.Close;

            var chat = protoService.GetChat(statistics.ChatId);

            TitleChat.Text = chat == null ? Strings.Additional.SettingsStorageOtherChats : protoService.GetTitle(chat);
            Subtitle.Text  = FileSizeConverter.Convert(statistics.Size, true);

            Photo.Source     = chat == null ? null : PlaceholderHelper.GetChat(protoService, chat, (int)Photo.Width);
            Photo.Visibility = chat == null ? Visibility.Collapsed : Visibility.Visible;

            StorageChartItem photo    = null;
            StorageChartItem video    = null;
            StorageChartItem document = null;
            StorageChartItem audio    = null;
            StorageChartItem voice    = null;
            StorageChartItem stickers = null;
            StorageChartItem local    = null;

            foreach (var fileType in statistics.ByFileType)
            {
                switch (fileType.FileType)
                {
                case FileTypePhoto _:
                    photo = new StorageChartItem(fileType);
                    break;

                case FileTypeVideo _:
                case FileTypeAnimation _:
                    video = video?.Add(fileType) ?? new StorageChartItem(fileType);
                    break;

                case FileTypeDocument _:
                    document = new StorageChartItem(fileType);
                    break;

                case FileTypeAudio _:
                    audio = new StorageChartItem(fileType);
                    break;

                case FileTypeVideoNote _:
                case FileTypeVoiceNote _:
                    voice = voice?.Add(fileType) ?? new StorageChartItem(fileType);
                    break;

                case FileTypeSticker _:
                    stickers = new StorageChartItem(fileType);
                    break;

                case FileTypeProfilePhoto _:
                case FileTypeWallpaper _:
                    break;

                default:
                    local = local?.Add(fileType) ?? new StorageChartItem(fileType);
                    break;
                }
            }

            var items = new[] { photo, video, document, audio, voice, stickers, local }.Where(x => x != null).ToList();

            List.ItemsSource = items;
            Chart.Items      = items;

            var size     = Chart.Items.Where(x => x.IsVisible).Sum(x => x.Size);
            var readable = FileSizeConverter.Convert(size, true).Split(' ');

            SizeLabel.Text = readable[0];
            UnitLabel.Text = readable[1];
        }
コード例 #5
0
 public void UpdateChatPhoto(Chat chat)
 {
     Photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 64);
 }
コード例 #6
0
 public void UpdateChatPhoto(Chat chat)
 {
     if (chat.Type is ChatTypePrivate privata && privata.UserId == _protoService.GetMyId())
     {
         Photo.Source = PlaceholderHelper.GetChat(null, chat, 48, 48);
     }
コード例 #7
0
        public DeleteChatPopup(IProtoService protoService, Chat chat, ChatList chatList, bool clear, bool asOwner = false)
        {
            InitializeComponent();

            Photo.Source = PlaceholderHelper.GetChat(protoService, chat, 36);

            var position = chat.GetPosition(chatList);

            if (position?.Source is ChatSourcePublicServiceAnnouncement)
            {
                Title.Text          = Strings.Resources.PsaHideChatAlertTitle;
                Subtitle.Text       = Strings.Resources.PsaHideChatAlertText;
                CheckBox.Visibility = Visibility.Collapsed;

                PrimaryButtonText   = Strings.Resources.PsaHide;
                SecondaryButtonText = Strings.Resources.Cancel;

                return;
            }

            Title.Text = clear ? Strings.Resources.ClearHistory : Strings.Resources.DeleteChatUser; // protoService.GetTitle(chat);

            var user       = protoService.GetUser(chat);
            var basicGroup = protoService.GetBasicGroup(chat);
            var supergroup = protoService.GetSupergroup(chat);

            var deleteAll = user != null && chat.Type is ChatTypePrivate privata && privata.UserId != protoService.Options.MyId && chat.CanBeDeletedForAllUsers;

            if (deleteAll)
            {
                CheckBox.Visibility = Visibility.Visible;

                var name = user.FirstName;
                if (string.IsNullOrEmpty(name))
                {
                    name = user.LastName;
                }

                if (clear)
                {
                    CheckBox.Content = string.Format(Strings.Resources.ClearHistoryOptionAlso, name);
                }
                else
                {
                    CheckBox.Content = string.Format(Strings.Resources.DeleteMessagesOptionAlso, name);
                }
            }

            if (clear)
            {
                if (user != null)
                {
                    if (chat.Type is ChatTypeSecret)
                    {
                        TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureClearHistoryWithSecretUser, user.GetFullName()));
                    }
                    else if (user.Id == protoService.Options.MyId)
                    {
                        TextBlockHelper.SetMarkdown(Subtitle, Strings.Resources.AreYouSureClearHistorySavedMessages);
                    }
                    else
                    {
                        TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureClearHistoryWithUser, user.GetFullName()));
                    }
                }
                else if (basicGroup != null)
                {
                    TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureClearHistoryGroup));
                }
                else if (supergroup != null)
                {
                    if (supergroup.IsChannel)
                    {
                        TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureClearHistoryChannel));
                    }
                    else if (string.IsNullOrEmpty(supergroup.Username))
                    {
                        TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureClearHistoryWithChat, chat.Title));
                    }
                    else
                    {
                        TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureClearHistoryGroup));
                    }
                }
            }
            else if (user != null)
            {
                if (chat.Type is ChatTypeSecret)
                {
                    TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureDeleteThisChatWithSecretUser, user.GetFullName()));
                }
                else if (user.Id == protoService.Options.MyId)
                {
                    TextBlockHelper.SetMarkdown(Subtitle, Strings.Resources.AreYouSureDeleteThisChatSavedMessages);
                }
                else
                {
                    TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureDeleteThisChatWithUser, user.GetFullName()));
                }

                if (user.Type is UserTypeBot)
                {
                    CheckBox.Visibility = Visibility.Visible;
                    CheckBox.Content    = Strings.Resources.BotStop;
                }
            }
            else if (basicGroup != null)
            {
                TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.AreYouSureDeleteAndExitName, chat.Title));
            }
            else if (supergroup != null)
            {
                if (asOwner)
                {
                    if (supergroup.IsChannel)
                    {
                        Subtitle.Text = Strings.Resources.ChannelDeleteAlert;
                    }
                    else
                    {
                        Subtitle.Text = Strings.Resources.MegaDeleteAlert;
                    }
                }
                else if (supergroup.IsChannel)
                {
                    TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.ChannelLeaveAlertWithName, chat.Title));
                }
                else
                {
                    TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.Resources.MegaLeaveAlertWithName, chat.Title));
                }
            }

            if (clear)
            {
                PrimaryButtonText = Strings.Resources.ClearHistory;
            }
            else if (user != null || basicGroup != null)
            {
                PrimaryButtonText = Strings.Resources.DeleteChatUser;
            }
            else if (supergroup != null)
            {
                if (supergroup.IsChannel)
                {
                    PrimaryButtonText = asOwner ? Strings.Resources.ChannelDeleteMenu : Strings.Resources.LeaveChannelMenu;
                }
                else
                {
                    PrimaryButtonText = asOwner ? Strings.Resources.DeleteMegaMenu : Strings.Resources.LeaveMegaMenu;
                }
            }

            SecondaryButtonText = Strings.Resources.Cancel;
        }
コード例 #8
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue == true)
            {
                // XAML has indicated that the item is no longer being shown, so add it to the recycle queue
                var tag = args.ItemContainer.Tag as string;

#if ENABLE_DEBUG_SPEW
                Debug.WriteLine($"Adding {args.ItemContainer.GetHashCode()} to {tag}");
#endif // ENABLE_DEBUG_SPEW

                var added = _typeToItemHashSetMapping[tag].Add(args.ItemContainer);

#if ENABLE_DEBUG_SPEW
                Debug.Assert(added == true, "Recycle queue should never have dupes. If so, we may be incorrectly reusing a container that is already in use!");
#endif // ENABLE_DEBUG_SPEW

                return;
            }

            var message = args.Item as MessageViewModel;

            var content = args.ItemContainer.ContentTemplateRoot as FrameworkElement;
            if (content is Grid grid)
            {
                var photo = grid.FindName("Photo") as ProfilePicture;
                if (photo != null)
                {
                    photo.Tag = message;

                    if (message.IsSaved())
                    {
                        if (message.ForwardInfo is MessageForwardedFromUser fromUser)
                        {
                            var user = message.ProtoService.GetUser(fromUser.SenderUserId);
                            if (user != null)
                            {
                                photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 32, 32);
                            }
                        }
                        else if (message.ForwardInfo is MessageForwardedPost post)
                        {
                            var chat = message.ProtoService.GetChat(post.ForwardedFromChatId);
                            if (chat != null)
                            {
                                photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 32, 32);
                            }
                        }
                    }
                    else
                    {
                        var user = message.GetSenderUser();
                        if (user != null)
                        {
                            photo.Source = PlaceholderHelper.GetUser(ViewModel.ProtoService, user, 32, 32);
                        }
                    }
                }

                content = grid.FindName("Bubble") as FrameworkElement;
            }

            if (content is MessageBubble bubble)
            {
                bubble.UpdateMessage(args.Item as MessageViewModel);
                args.Handled = true;
            }
            else if (content is MessageService service)
            {
                service.UpdateMessage(args.Item as MessageViewModel);
                args.Handled = true;
            }
        }
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content = args.ItemContainer.ContentTemplateRoot as Grid;
            var chat    = args.Item as Chat;

            if (args.Phase == 0)
            {
                var title = content.Children[1] as TextBlock;
                title.Text = ViewModel.ProtoService.GetTitle(chat);
            }
            else if (args.Phase == 1)
            {
                //var label = content.Children[2] as TextBlock;
                //var exception = chat.NotificationSettings;

                //String text;
                //bool enabled;
                //bool custom = exception.hasCustom;
                //int value = exception.notify;
                //int delta = exception.MuteFor;
                //if (value == 3 && delta != int.MaxValue)
                //{
                //    delta -= DateTime.Now.ToTimestamp();
                //    if (delta <= 0)
                //    {
                //        if (custom)
                //        {
                //            text = Strings.Resources.NotificationsCustom;
                //        }
                //        else
                //        {
                //            text = Strings.Resources.NotificationsUnmuted;
                //        }
                //    }
                //    else if (delta < 60 * 60)
                //    {
                //        text = string.Format(Strings.Resources.WillUnmuteIn, Locale.Declension("Minutes", delta / 60));
                //    }
                //    else if (delta < 60 * 60 * 24)
                //    {
                //        text = string.Format(Strings.Resources.WillUnmuteIn, Locale.Declension("Hours", (int)Math.Ceiling(delta / 60.0f / 60)));
                //    }
                //    else if (delta < 60 * 60 * 24 * 365)
                //    {
                //        text = string.Format(Strings.Resources.WillUnmuteIn, Locale.Declension("Days", (int)Math.Ceiling(delta / 60.0f / 60 / 24)));
                //    }
                //    else
                //    {
                //        text = null;
                //    }
                //}
                //else
                //{
                //    if (value == 0)
                //    {
                //        enabled = true;
                //    }
                //    else if (value == 1)
                //    {
                //        enabled = true;
                //    }
                //    else if (value == 2)
                //    {
                //        enabled = false;
                //    }
                //    else
                //    {
                //        enabled = false;
                //    }
                //    if (enabled && custom)
                //    {
                //        text = Strings.Resources.NotificationsCustom;
                //    }
                //    else
                //    {
                //        text = enabled ? Strings.Resources.NotificationsUnmuted : Strings.Resources.NotificationsMuted;
                //    }
                //}
                //if (text == null)
                //{
                //    text = Strings.Resources.NotificationsOff;
                //}

                //label.Text = text;
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as ProfilePicture;
                photo.Source = PlaceholderHelper.GetChat(ViewModel.ProtoService, chat, 36);
            }

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

            args.Handled = true;
        }
コード例 #10
0
 public void UpdateFile(Chat chat, File file)
 {
     Photo.Source = PlaceholderHelper.GetChat(null, chat, 48, 48);
 }
コード例 #11
0
 public void UpdateChatPhoto(Chat chat)
 {
     Photo.Source = PlaceholderHelper.GetChat(_protoService, chat, 48, 48);
 }