public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer == null)
            {
                return(Task.CompletedTask);
            }

            using (var from = TLObjectSerializer.CreateReader(buffer.AsBuffer()))
            {
                var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm, TLPaymentRequestedInfo, TLPaymentsValidatedRequestedInfo, TLShippingOption>(from);

                Message     = tuple.Item1;
                Invoice     = tuple.Item1.Media as TLMessageMediaInvoice;
                PaymentForm = tuple.Item2;

                // TODO: real hint
                PasswordHint = Strings.Android.LoginPassword;

                if (_paymentForm.HasSavedCredentials && _paymentForm.SavedCredentials is TLPaymentSavedCredentialsCard savedCard)
                {
                    CredentialsTitle = savedCard.Title;
                }

                _info          = tuple.Item3;
                _requestedInfo = tuple.Item4;
                _shipping      = tuple.Item5;
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm>(from);

                    Message     = tuple.Item1;
                    Invoice     = tuple.Item1.Media as TLMessageMediaInvoice;
                    PaymentForm = tuple.Item2;

                    var info = PaymentForm.HasSavedInfo ? PaymentForm.SavedInfo : new TLPaymentRequestedInfo();
                    if (info.ShippingAddress == null)
                    {
                        info.ShippingAddress = new TLPostAddress();
                    }

                    Info            = info;
                    SelectedCountry = Country.Countries.FirstOrDefault(x => x.Code.Equals(info.ShippingAddress.CountryIso2, StringComparison.OrdinalIgnoreCase));
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 3
0
 private void ListView_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (e.ClickedItem is TLChannelParticipantAdmin participant && participant.User != null)
     {
         ViewModel.NavigationService.Navigate(typeof(ChannelAdminRightsPage), TLTuple.Create(ViewModel.Item.ToPeer(), participant));
     }
 }
Esempio n. 4
0
        public void SetCall(TLTuple <TLPhoneCallState, TLPhoneCallBase, TLUserBase, string> tuple)
        {
            if (_disposed)
            {
                return;
            }

            if (_state != tuple.Item1)
            {
                Debug.WriteLine("[{0:HH:mm:ss.fff}] State changed in app: " + tuple.Item1, DateTime.Now);

                _state             = tuple.Item1;
                StateLabel.Content = StateToLabel(tuple.Item1);

                if (tuple.Item1 == TLPhoneCallState.Established)
                {
                    SignalBarsLabel.Visibility = Visibility.Visible;
                    StartUpdatingCallDuration();

                    if (_emojis != null)
                    {
                        for (int i = 0; i < _emojis.Length; i++)
                        {
                            var imageLarge = FindName($"LargeEmoji{i}") as Image;
                            var source     = Emoji.BuildUri(_emojis[i]);

                            imageLarge.Source = new BitmapImage(new Uri(source));
                        }
                    }
                }
            }

            if (tuple.Item2 is TLPhoneCallRequested call)
            {
            }

            if (tuple.Item3 is TLUser user)
            {
                if (user.HasPhoto && user.Photo is TLUserProfilePhoto)
                {
                    Image.Source         = DefaultPhotoConverter.Convert(user.Photo, true) as ImageSource;
                    GrabPanel.Background = new SolidColorBrush(Colors.Transparent);
                }
                else
                {
                    Image.Source         = null;
                    GrabPanel.Background = BindConvert.Current.Bubble(user.Id);
                }

                FromLabel.Text        = user.FullName;
                DescriptionLabel.Text = string.Format(Strings.Android.CallEmojiKeyTooltip, user.FirstName);
            }

            if (tuple.Item4.Length > 0)
            {
                _emojis = tuple.Item4.Split(' ');
            }
        }
        private void ParticipantRestrictExecute(TLChannelParticipantBase participant)
        {
            if (_item == null)
            {
                return;
            }

            NavigationService.Navigate(typeof(ChannelBannedRightsPage), TLTuple.Create(_item.ToPeer(), participant));
        }
Esempio n. 6
0
        public async void OnSignalBarsChanged(int count)
        {
            if (_connection != null)
            {
                VoIPCallTask.Log("Mediator initialized", "Informing foreground about signal bars");

                var data = TLTuple.Create(count);
                await _connection.SendMessageAsync(new ValueSet { { "caption", "voip.signalBars" }, { "request", TLSerializationService.Current.Serialize(data) } });
            }
        }
Esempio n. 7
0
        private async Task UpdateCallAsync()
        {
            if (_connection != null)
            {
                VoIPCallTask.Log("Mediator initialized", "Informing foreground about current call");

                var data = TLTuple.Create((int)_state, _phoneCall, _user, _emojis != null ? string.Join(" ", _emojis) : string.Empty);
                await _connection.SendMessageAsync(new ValueSet { { "caption", "voip.callInfo" }, { "request", TLSerializationService.Current.Serialize(data) } });
            }
        }
Esempio n. 8
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer == null)
            {
                return(Task.CompletedTask);
            }

            using (var from = TLObjectSerializer.CreateReader(buffer.AsBuffer()))
            {
                var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm, TLPaymentRequestedInfo, TLPaymentsValidatedRequestedInfo, TLShippingOption>(from);

                Message     = tuple.Item1;
                Invoice     = tuple.Item1.Media as TLMessageMediaInvoice;
                PaymentForm = tuple.Item2;

                _info          = tuple.Item3;
                _requestedInfo = tuple.Item4;
                _shipping      = tuple.Item5;

                if (_paymentForm.HasNativeProvider && _paymentForm.HasNativeParams && _paymentForm.NativeProvider.Equals("stripe"))
                {
                    IsNativeUsed    = true;
                    SelectedCountry = null;

                    var json = JsonObject.Parse(_paymentForm.NativeParams.Data);

                    NeedCountry        = json.GetNamedBoolean("need_country", false);
                    NeedZip            = json.GetNamedBoolean("need_zip", false);
                    NeedCardholderName = json.GetNamedBoolean("need_cardholder_name", false);

                    _publishableKey = json.GetNamedString("publishable_key", string.Empty);
                }
                else
                {
                    IsNativeUsed = false;
                    RaisePropertyChanged("Navigate");
                }

                //var info = PaymentForm.HasSavedInfo ? PaymentForm.SavedInfo : new TLPaymentRequestedInfo();
                //if (info.ShippingAddress == null)
                //{
                //    info.ShippingAddress = new TLPostAddress();
                //}

                //Info = info;
                //SelectedCountry = null;
            }

            return(Task.CompletedTask);
        }
Esempio n. 9
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer == null)
            {
                return(Task.CompletedTask);
            }

            using (var from = TLObjectSerializer.CreateReader(buffer.AsBuffer()))
            {
                var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm, TLPaymentRequestedInfo, TLPaymentsValidatedRequestedInfo, TLShippingOption, string, string, bool>(from);

                Message          = tuple.Item1;
                Invoice          = tuple.Item1.Media as TLMessageMediaInvoice;
                PaymentForm      = tuple.Item2;
                Info             = tuple.Item3;
                Shipping         = tuple.Item5;
                CredentialsTitle = string.IsNullOrEmpty(tuple.Item6) ? null : tuple.Item6;
                Bot      = tuple.Item2.Users.FirstOrDefault(x => x.Id == tuple.Item2.BotId) as TLUser;
                Provider = tuple.Item2.Users.FirstOrDefault(x => x.Id == tuple.Item2.ProviderId) as TLUser;

                if (_paymentForm.HasSavedCredentials && _paymentForm.SavedCredentials is TLPaymentSavedCredentialsCard savedCard && _credentialsTitle == null)
                {
                    CredentialsTitle = savedCard.Title;
                }

                var amount = 0L;
                foreach (var price in _paymentForm.Invoice.Prices)
                {
                    amount += price.Amount;
                }

                if (_shipping != null)
                {
                    foreach (var price in _shipping.Prices)
                    {
                        amount += price.Amount;
                    }
                }

                TotalAmount = amount;

                _requestedInfo = tuple.Item4;
                _credentials   = tuple.Item7;
                _save          = tuple.Item8;
            }

            return(Task.CompletedTask);
        }
Esempio n. 10
0
        //public RelayCommand<TLKeyboardButtonBase> KeyboardButtonCommand => new RelayCommand<TLKeyboardButtonBase>(KeyboardButtonExecute);
        public async void KeyboardButtonExecute(TLKeyboardButtonBase button, TLMessage message)
        {
            if (button is TLKeyboardButtonBuy buyButton)
            {
                if (message.Media is TLMessageMediaInvoice invoiceMedia && invoiceMedia.HasReceiptMsgId)
                {
                    var response = await ProtoService.GetPaymentReceiptAsync(invoiceMedia.ReceiptMsgId.Value);

                    if (response.IsSucceeded)
                    {
                        NavigationService.Navigate(typeof(PaymentReceiptPage), TLTuple.Create(message, response.Result));
                    }
                }
                else
                {
                    var response = await ProtoService.GetPaymentFormAsync(message.Id);

                    if (response.IsSucceeded)
                    {
                        if (response.Result.Invoice.IsEmailRequested || response.Result.Invoice.IsNameRequested || response.Result.Invoice.IsPhoneRequested || response.Result.Invoice.IsShippingAddressRequested)
                        {
                            NavigationService.NavigateToPaymentFormStep1(message, response.Result);
                        }
                        else if (response.Result.HasSavedCredentials)
                        {
                            if (ApplicationSettings.Current.TmpPassword != null)
                            {
                                if (ApplicationSettings.Current.TmpPassword.ValidUntil < TLUtils.Now + 60)
                                {
                                    ApplicationSettings.Current.TmpPassword = null;
                                }
                            }

                            if (ApplicationSettings.Current.TmpPassword != null)
                            {
                                NavigationService.NavigateToPaymentFormStep5(message, response.Result, null, null, null, null, null, true);
                            }
                            else
                            {
                                NavigationService.NavigateToPaymentFormStep4(message, response.Result, null, null, null);
                            }
                        }
                        else
                        {
                            NavigationService.NavigateToPaymentFormStep3(message, response.Result, null, null, null);
                        }
                    }
                }
            }
Esempio n. 11
0
        private void ParticipantEditExecute(TLChannelParticipantBase participant)
        {
            if (_item == null)
            {
                return;
            }

            if (participant is TLChannelParticipantAdmin)
            {
                NavigationService.Navigate(typeof(ChannelAdminRightsPage), TLTuple.Create(_item.ToPeer(), participant));
            }
            else if (participant is TLChannelParticipantBanned)
            {
                NavigationService.Navigate(typeof(ChannelBannedRightsPage), TLTuple.Create(_item.ToPeer(), participant));
            }
        }
Esempio n. 12
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLMessage, TLPaymentsPaymentReceipt>(from);

                    _message = tuple.Item1;
                    Invoice  = tuple.Item1.Media as TLMessageMediaInvoice;
                    Receipt  = tuple.Item2;
                    Bot      = tuple.Item2.Users.FirstOrDefault(x => x.Id == tuple.Item2.BotId) as TLUser;
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 13
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLMessage, TLPaymentsPaymentForm, TLPaymentRequestedInfo, TLPaymentsValidatedRequestedInfo>(from);

                    Message       = tuple.Item1;
                    Invoice       = tuple.Item1.Media as TLMessageMediaInvoice;
                    PaymentForm   = tuple.Item2;
                    RequestedInfo = tuple.Item4;

                    _info = tuple.Item3;
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 14
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var buffer = TLSerializationService.Current.Deserialize((string)e.Parameter) as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <string, string, string, TLMessage>(from);

                    _shareMessage = tuple.Item4;

                    TitleLabel.Text    = tuple.Item1;
                    UsernameLabel.Text = "@" + tuple.Item2;

                    TitleLabel.Visibility    = string.IsNullOrWhiteSpace(tuple.Item1) ? Visibility.Collapsed : Visibility.Visible;
                    UsernameLabel.Visibility = string.IsNullOrWhiteSpace(tuple.Item2) ? Visibility.Collapsed : Visibility.Visible;

                    View.Navigate(new Uri(tuple.Item3));
                }
            }
        }
Esempio n. 15
0
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var deferral = args.GetDeferral();
            var message  = args.Request.Message;

            if (message.ContainsKey("update"))
            {
                var buffer = message["update"] as string;
                var update = TLSerializationService.Current.Deserialize(buffer) as TLUpdatePhoneCall;
                if (update != null)
                {
                    Handle(update);
                }
            }
            else if (message.ContainsKey("caption"))
            {
                var caption = message["caption"] as string;
                if (caption.Equals("phone.discardCall"))
                {
                    if (_phoneCall != null)
                    {
                        var buffer  = message["request"] as string;
                        var payload = TLSerializationService.Current.Deserialize <byte[]>(buffer);
                        var reader  = new TLBinaryReader(payload);
                        var req     = new TLTuple <double>(reader);
                        reader.Dispose();

                        var missed   = _state == TLPhoneCallState.Ringing || (_state == TLPhoneCallState.Waiting && _outgoing);
                        var declined = _state == TLPhoneCallState.WaitingIncoming;
                        TLPhoneCallDiscardReasonBase reason = missed
                            ? new TLPhoneCallDiscardReasonMissed()
                            : declined
                            ? (TLPhoneCallDiscardReasonBase) new TLPhoneCallDiscardReasonBusy()
                            : new TLPhoneCallDiscardReasonHangup();

                        var req2 = new TLPhoneDiscardCall {
                            Peer = _phoneCall.ToInputPhoneCall(), Reason = reason, Duration = (int)req.Item1
                        };

                        const string caption2 = "phone.discardCall";
                        var          response = await SendRequestAsync <TLUpdatesBase>(caption2, req2);

                        if (response.IsSucceeded)
                        {
                            if (response.Result is TLUpdates updates)
                            {
                                var update = updates.Updates.FirstOrDefault(x => x is TLUpdatePhoneCall) as TLUpdatePhoneCall;
                                if (update != null)
                                {
                                    Handle(update);
                                }
                            }
                        }
                    }
                    else if (_systemCall != null)
                    {
                        _systemCall.AnswerRequested -= OnAnswerRequested;
                        _systemCall.RejectRequested -= OnRejectRequested;
                        _systemCall.NotifyCallEnded();
                        _systemCall = null;
                    }
                    else if (_deferral != null)
                    {
                        _deferral.Complete();
                    }
                }
                else if (caption.Equals("phone.mute") || caption.Equals("phone.unmute"))
                {
                    if (_controller != null)
                    {
                        _controller.SetMicMute(caption.Equals("phone.mute"));

                        var coordinator = VoipCallCoordinator.GetDefault();
                        if (caption.Equals("phone.mute"))
                        {
                            coordinator.NotifyMuted();
                        }
                        else
                        {
                            coordinator.NotifyUnmuted();
                        }
                    }
                }
                else if (caption.Equals("voip.startCall"))
                {
                    var buffer = message["request"] as string;
                    var req    = TLSerializationService.Current.Deserialize <TLUser>(buffer);

                    _user = req;
                    OutgoingCall(req.Id, req.AccessHash.Value);
                }
                else if (caption.Equals("voip.debugString"))
                {
                    if (_controller != null)
                    {
                        await args.Request.SendResponseAsync(new ValueSet { { "result", _controller.GetDebugString() }, { "version", VoIPControllerWrapper.GetVersion() } });
                    }
                }
            }
            else if (message.ContainsKey("voip.callInfo"))
            {
                if (_phoneCall != null)
                {
                    await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(_phoneCall) } });
                }
                else
                {
                    await args.Request.SendResponseAsync(new ValueSet { { "error", false } });
                }
            }

            deferral.Complete();
        }
Esempio n. 16
0
 private async void Hangup_Click(object sender, RoutedEventArgs e)
 {
     var duration = _state == TLPhoneCallState.Established ? DateTime.Now - _started : TimeSpan.Zero;
     await VoIPConnection.Current.SendRequestAsync("phone.discardCall", TLTuple.Create(duration.TotalSeconds));
 }
Esempio n. 17
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLPeerChannel, TLChannelParticipantBase>(from);
                    if (tuple.Item2 is TLChannelParticipant participant)
                    {
                        IsAdminAlready = false;

                        tuple.Item2 = new TLChannelParticipantAdmin
                        {
                            UserId      = participant.UserId,
                            Date        = participant.Date,
                            IsCanEdit   = true,
                            AdminRights = new TLChannelAdminRights
                            {
                                IsChangeInfo     = true,
                                IsPinMessages    = true,
                                IsInviteLink     = true,
                                IsInviteUsers    = true,
                                IsBanUsers       = true,
                                IsDeleteMessages = true,
                                IsEditMessages   = true,
                                IsPostMessages   = true,
                                IsAddAdmins      = false
                            }
                        };
                    }
                    else if (tuple.Item2 is TLChannelParticipantBanned banned)
                    {
                        IsAdminAlready = false;

                        tuple.Item2 = new TLChannelParticipantAdmin
                        {
                            UserId      = banned.UserId,
                            Date        = banned.Date,
                            IsCanEdit   = true,
                            AdminRights = new TLChannelAdminRights
                            {
                                IsChangeInfo     = true,
                                IsPinMessages    = true,
                                IsInviteLink     = true,
                                IsInviteUsers    = true,
                                IsBanUsers       = true,
                                IsDeleteMessages = true,
                                IsEditMessages   = true,
                                IsPostMessages   = true,
                                IsAddAdmins      = false
                            }
                        };
                    }

                    Channel = CacheService.GetChat(tuple.Item1.ChannelId) as TLChannel;
                    Item    = tuple.Item2 as TLChannelParticipantAdmin;

                    IsAddAdmins      = _item.AdminRights.IsAddAdmins;
                    IsPinMessages    = _item.AdminRights.IsPinMessages;
                    IsInviteLink     = _item.AdminRights.IsInviteLink;
                    IsInviteUsers    = _item.AdminRights.IsInviteUsers;
                    IsBanUsers       = _item.AdminRights.IsBanUsers;
                    IsDeleteMessages = _item.AdminRights.IsDeleteMessages;
                    IsEditMessages   = _item.AdminRights.IsEditMessages;
                    IsPostMessages   = _item.AdminRights.IsPostMessages;
                    IsChangeInfo     = _item.AdminRights.IsChangeInfo;

                    var user = tuple.Item2.User;
                    if (user == null)
                    {
                        return;
                    }

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

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

                    Full = full;
                }
            }
        }
Esempio n. 18
0
 public static void NavigateToPaymentFormStep5(this INavigationService service, MessageViewModel message, PaymentForm paymentForm, TLPaymentRequestedInfo info, TLPaymentsValidatedRequestedInfo validatedInfo, TLShippingOption shipping, string title, string credentials, bool save)
 {
     service.Navigate(typeof(PaymentFormStep5Page), TLTuple.Create(message, paymentForm, info, validatedInfo, shipping, title ?? string.Empty, credentials ?? string.Empty, save));
 }
Esempio n. 19
0
 public static void NavigateToPaymentFormStep4(this INavigationService service, MessageViewModel message, PaymentForm paymentForm, TLPaymentRequestedInfo info, TLPaymentsValidatedRequestedInfo validatedInfo, TLShippingOption shipping)
 {
     service.Navigate(typeof(PaymentFormStep4Page), TLTuple.Create(message, paymentForm, info, validatedInfo, shipping));
 }
Esempio n. 20
0
 public static void NavigateToPaymentFormStep1(this INavigationService service, MessageViewModel message, PaymentForm paymentForm)
 {
     service.Navigate(typeof(PaymentFormStep1Page), TLTuple.Create(message, paymentForm));
 }
Esempio n. 21
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 = new TLBinaryReader(data))
                        {
                            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();
                                        Window.Current.Close();
                                    });
                                }

                                return;
                            }

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

                                _phoneViewExists = true;

                                PhoneCallPage       newPlayer = null;
                                CoreApplicationView newView   = CoreApplication.CreateNewView();
                                var newViewId = 0;
                                await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    newPlayer = new PhoneCallPage();
                                    Window.Current.Content = newPlayer;
                                    Window.Current.Activate();
                                    newViewId = ApplicationView.GetForCurrentView().Id;

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

                                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                                {
                                    if (ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "IsViewModeSupported") && ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay))
                                    {
                                        var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                                        preferences.CustomSize = new Size(340, 200);

                                        var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences);
                                    }
                                    else
                                    {
                                        //await ApplicationViewSwitcher.SwitchAsync(newViewId);
                                        await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
                                    }
                                });
                            }
                            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 = new TLBinaryReader(data2))
                        {
                            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();
            }
        }
Esempio n. 22
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            var buffer = parameter as byte[];

            if (buffer != null)
            {
                using (var from = new TLBinaryReader(buffer))
                {
                    var tuple = new TLTuple <TLPeerChannel, TLChannelParticipantBase>(from);
                    if (tuple.Item2 is TLChannelParticipant participant)
                    {
                        IsBannedAlready = false;

                        tuple.Item2 = new TLChannelParticipantBanned
                        {
                            UserId       = participant.UserId,
                            Date         = participant.Date,
                            BannedRights = new TLChannelBannedRights
                            {
                                IsViewMessages = true,
                                IsSendMessages = false,
                                IsSendMedia    = false,
                                IsSendStickers = false,
                                IsSendGifs     = false,
                                IsSendGames    = false,
                                IsSendInline   = false,
                                IsEmbedLinks   = false
                            }
                        };
                    }
                    else if (tuple.Item2 is TLChannelParticipantAdmin admin)
                    {
                        IsBannedAlready = false;

                        tuple.Item2 = new TLChannelParticipantBanned
                        {
                            UserId       = admin.UserId,
                            Date         = admin.Date,
                            BannedRights = new TLChannelBannedRights
                            {
                                IsViewMessages = true,
                                IsSendMessages = false,
                                IsSendMedia    = false,
                                IsSendStickers = false,
                                IsSendGifs     = false,
                                IsSendGames    = false,
                                IsSendInline   = false,
                                IsEmbedLinks   = false
                            }
                        };
                    }

                    Channel = CacheService.GetChat(tuple.Item1.ChannelId) as TLChannel;
                    Item    = tuple.Item2 as TLChannelParticipantBanned;

                    IsEmbedLinks   = _item.BannedRights.IsEmbedLinks;
                    IsSendInline   = _item.BannedRights.IsSendInline;
                    IsSendGames    = _item.BannedRights.IsSendGames;
                    IsSendGifs     = _item.BannedRights.IsSendGifs;
                    IsSendStickers = _item.BannedRights.IsSendStickers;
                    IsSendMedia    = _item.BannedRights.IsSendMedia;
                    IsSendMessages = _item.BannedRights.IsSendMessages;
                    IsViewMessages = _item.BannedRights.IsViewMessages;

                    var user = tuple.Item2.User;
                    if (user == null)
                    {
                        return;
                    }

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

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

                    Full = full;
                }
            }
        }