public SettingsStorageOptimizationPage(IProtoService protoService, ContentDialogBase dialog, StorageStatisticsByChat statistics)
        {
            InitializeComponent();

            _dialog = dialog;

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

            Title.Text    = chat == null ? "Other Chats" : protoService.GetTitle(chat);
            Subtitle.Text = FileSizeConverter.Convert(statistics.Size);

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

            List.ItemsSource = statistics.ByFileType.OrderByDescending(x => x.Size).ToList();

            foreach (var fileType in statistics.ByFileType)
            {
                switch (fileType.FileType)
                {
                case FileTypeAnimation animation:
                case FileTypeAudio audio:
                case FileTypeDocument document:
                case FileTypeNone none:
                case FileTypePhoto photo:
                case FileTypeUnknown unknown:
                case FileTypeVideo video:
                case FileTypeVideoNote videoNote:
                case FileTypeVoiceNote voiceNote:
                    List.SelectedItems.Add(fileType);
                    break;
                }
            }
        }
Пример #2
0
        private async void SendLocationExecute()
        {
            var page = new DialogSendLocationPage();

            var dialog = new ContentDialogBase();

            dialog.Content = page;

            page.Dialog = dialog;

            var confirm = await dialog.ShowAsync();

            if (confirm == ContentDialogBaseResult.OK)
            {
                if (page.Media is TLMessageMediaVenue venue)
                {
                    await SendGeoPointAsync(venue);
                }
                else if (page.Media is TLMessageMediaGeo geo && geo.Geo is TLGeoPoint geoPoint)
                {
                    await SendGeoPointAsync(geoPoint.Lat, geoPoint.Long);
                }
            }

            //NavigationService.Navigate(typeof(DialogSendLocationPage));
        }
Пример #3
0
        public async void Clear(StorageStatisticsByChat byChat)
        {
            if (byChat == null)
            {
                return;
            }

            var dialog = new ContentDialogBase();
            var page   = new SettingsStorageOptimizationPage(ProtoService, dialog, byChat);

            dialog.Content = page;

            var confirm = await dialog.ShowAsync();

            if (confirm != ContentDialogBaseResult.OK)
            {
                return;
            }

            var types = page.SelectedItems ?? new FileType[0];

            if (types.IsEmpty())
            {
                return;
            }

            var chatIds         = new long[0];
            var excludedChatIds = new long[0];

            if (byChat.ChatId != 0)
            {
                chatIds = new[] { byChat.ChatId };
            }
            else if (byChat != _totalStatistics)
            {
                excludedChatIds = _statistics.ByChat.Select(x => x.ChatId).Where(x => x != 0).ToArray();
            }

            IsLoading     = true;
            TaskCompleted = false;

            var response = await ProtoService.SendAsync(new OptimizeStorage(long.MaxValue, 0, int.MaxValue, 0, types, chatIds, excludedChatIds, 25));

            if (response is StorageStatistics statistics)
            {
                Statistics = statistics;
            }

            IsLoading     = false;
            TaskCompleted = true;
        }
        private async void SendLocationExecute()
        {
            var page = new DialogShareLocationPage();

            var dialog = new ContentDialogBase();

            dialog.Content = page;

            page.Dialog = dialog;
            //page.LiveLocation = !_liveLocationService.IsTracking(Peer.ToPeer());

            var confirm = await dialog.ShowAsync();

            if (confirm == ContentDialogBaseResult.OK)
            {
                var reply = GetReply(true);
                var input = page.Media;

                await SendMessageAsync(reply, input);

                //if (page.Media is TLMessageMediaVenue venue)
                //{
                //    await SendGeoAsync(venue);
                //}
                //else if (page.Media is TLMessageMediaGeoLive geoLive)
                //{
                //    if (geoLive.Geo == null || geoLive.Period == 0 || _liveLocationService.IsTracking(Peer.ToPeer()))
                //    {
                //        _liveLocationService.StopTracking(Peer.ToPeer());
                //    }
                //    else
                //    {
                //        await SendGeoAsync(geoLive);
                //    }
                //}
                //else if (page.Media is TLMessageMediaGeo geo && geo.Geo is TLGeoPoint geoPoint)
                //{
                //    await SendGeoAsync(geoPoint.Lat, geoPoint.Long);
                //}
            }

            //NavigationService.Navigate(typeof(DialogSendLocationPage));
        }
Пример #5
0
        private async void SendLocationExecute()
        {
            var page = new DialogSendLocationPage();

            var dialog = new ContentDialogBase();

            dialog.Content = page;

            page.Dialog       = dialog;
            page.LiveLocation = !_liveLocationService.IsTracking(Peer.ToPeer());

            var confirm = await dialog.ShowAsync();

            if (confirm == ContentDialogBaseResult.OK)
            {
                if (page.Media is TLMessageMediaVenue venue)
                {
                    await SendGeoAsync(venue);
                }
                else if (page.Media is TLMessageMediaGeoLive geoLive)
                {
                    if (geoLive.Geo == null || geoLive.Period == 0 || _liveLocationService.IsTracking(Peer.ToPeer()))
                    {
                        _liveLocationService.StopTracking(Peer.ToPeer());
                    }
                    else
                    {
                        await SendGeoAsync(geoLive);
                    }
                }
                else if (page.Media is TLMessageMediaGeo geo && geo.Geo is TLGeoPoint geoPoint)
                {
                    await SendGeoAsync(geoPoint.Lat, geoPoint.Long);
                }
            }

            //NavigationService.Navigate(typeof(DialogSendLocationPage));
        }
Пример #6
0
        private void Hide()
        {
            if (_callPage != null)
            {
                _callPage.BeginOnUIThread(() =>
                {
                    if (_callDialog != null)
                    {
                        _callDialog.IsOpen = false;
                        _callDialog        = null;
                    }
                    else if (_callLifetime != null)
                    {
                        _callLifetime.StopViewInUse();
                        _callLifetime.WindowWrapper.Window.Close();
                        _callLifetime = null;
                    }

                    _callPage.Dispose();
                    _callPage = null;
                });
            }
        }
Пример #7
0
        private async void Show(Call call, VoIPControllerWrapper controller)
        {
            if (_callPage == null)
            {
                if (ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "IsViewModeSupported") && ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay))
                {
                    _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller), 0);

                    _callLifetime.Released += (s, args) =>
                    {
                        _callPage.Dispose();
                        _callPage = null;
                    };
                }
                else
                {
                    _callPage = new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller);

                    _callDialog = new ContentDialogBase();
                    _callDialog.HorizontalAlignment = HorizontalAlignment.Stretch;
                    _callDialog.VerticalAlignment   = VerticalAlignment.Stretch;
                    _callDialog.Content             = _callPage;
                    _callDialog.IsOpen = true;
                }
            }

            _callPage.BeginOnUIThread(() =>
            {
                if (controller != null)
                {
                    _callPage.Connect(controller);
                }

                _callPage.Update(call);
            });
        }
Пример #8
0
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var deferral = args.GetDeferral();
            var message  = args.Request.Message;

            try
            {
                if (message.ContainsKey("caption") && message.ContainsKey("request"))
                {
                    var caption = message["caption"] as string;
                    var buffer  = message["request"] as string;
                    var req     = TLSerializationService.Current.Deserialize(buffer);

                    if (caption.Equals("voip.getUser") && req is TLPeerUser userPeer)
                    {
                        var user = InMemoryCacheService.Current.GetUser(userPeer.UserId);
                        if (user != null)
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(user) } });
                        }
                        else
                        {
                            //await args.Request.SendResponseAsync(new ValueSet { { "error", TLSerializationService.Current.Serialize(new TLRPCError { ErrorMessage = "USER_NOT_FOUND", ErrorCode = 404 }) } });
                        }
                    }
                    else if (caption.Equals("voip.getConfig"))
                    {
                        var config = InMemoryCacheService.Current.GetConfig();
                        await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(config) } });
                    }
                    else if (caption.Equals("voip.callInfo") && req is byte[] data)
                    {
                        using (var from = TLObjectSerializer.CreateReader(data.AsBuffer()))
                        {
                            var tupleBase = new TLTuple <int, TLPhoneCallBase, TLUserBase, string>(from);
                            var tuple     = new TLTuple <TLPhoneCallState, TLPhoneCallBase, TLUserBase, string>((TLPhoneCallState)tupleBase.Item1, tupleBase.Item2, tupleBase.Item3, tupleBase.Item4);

                            if (tuple.Item2 is TLPhoneCallDiscarded)
                            {
                                if (_phoneView != null)
                                {
                                    var newView = _phoneView;
                                    _phoneViewExists = false;
                                    _phoneView       = null;

                                    await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                    {
                                        newView.SetCall(tuple);
                                        newView.Dispose();

                                        if (newView.Dialog != null)
                                        {
                                            newView.Dialog.Hide();
                                        }
                                        else
                                        {
                                            Window.Current.Close();
                                        }
                                    });
                                }

                                return;
                            }

                            if (_phoneViewExists == false)
                            {
                                VoIPCallTask.Log("Creating VoIP UI", "Creating VoIP UI");

                                _phoneViewExists = true;

                                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                                {
                                    if (ApplicationView.GetForCurrentView().IsCompactOverlaySupported())
                                    {
                                        var newView   = CoreApplication.CreateNewView();
                                        var newViewId = 0;
                                        await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                        {
                                            var newPlayer          = new PhoneCallPage(true);
                                            Window.Current.Content = newPlayer;
                                            Window.Current.Activate();
                                            newViewId = ApplicationView.GetForCurrentView().Id;

                                            newPlayer.Dialog = null;
                                            newPlayer.SetCall(tuple);
                                            _phoneView = newPlayer;
                                        });

                                        var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                                        preferences.CustomSize = new Size(340, 200);

                                        var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences);
                                    }
                                    else
                                    {
                                        var dialog = new ContentDialogBase();
                                        dialog.VerticalAlignment   = VerticalAlignment.Stretch;
                                        dialog.HorizontalAlignment = HorizontalAlignment.Stretch;

                                        var newPlayer    = new PhoneCallPage(false);
                                        newPlayer.Dialog = dialog;
                                        newPlayer.SetCall(tuple);
                                        _phoneView = newPlayer;

                                        dialog.Content = newPlayer;
                                        await dialog.ShowAsync();
                                    }
                                });
                            }
                            else if (_phoneView != null)
                            {
                                VoIPCallTask.Log("VoIP UI already exists", "VoIP UI already exists");

                                await _phoneView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    _phoneView.SetCall(tuple);
                                });
                            }
                        }
                    }
                    else if (caption.Equals("voip.signalBars") && req is byte[] data2)
                    {
                        using (var from = TLObjectSerializer.CreateReader(data2.AsBuffer()))
                        {
                            var tuple = new TLTuple <int>(from);

                            if (_phoneView != null)
                            {
                                await _phoneView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    _phoneView.SetSignalBars(tuple.Item1);
                                });
                            }
                        }
                    }
                    else if (caption.Equals("voip.setCallRating") && req is TLInputPhoneCall peer)
                    {
                        Execute.BeginOnUIThread(async() =>
                        {
                            var dialog  = new PhoneCallRatingView();
                            var confirm = await dialog.ShowQueuedAsync();
                            if (confirm == ContentDialogResult.Primary)
                            {
                                await MTProtoService.Current.SetCallRatingAsync(peer, dialog.Rating, dialog.Rating >= 0 && dialog.Rating <= 3 ? dialog.Comment : null);
                            }
                        });
                    }
                    else
                    {
                        var response = await MTProtoService.Current.SendRequestAsync <object>(caption, req as TLObject);

                        if (response.IsSucceeded)
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(response.Result) } });
                        }
                        else
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "error", TLSerializationService.Current.Serialize(response.Error) } });
                        }
                    }
                }
            }
            finally
            {
                deferral.Complete();
            }
        }