示例#1
0
        private void UpdateDCOptions(Uri uri)
        {
            Execute.BeginOnThreadPool(() =>
            {
                try
                {
                    var tempUri   = uri.OriginalString.Replace("%3A", ":");
                    var uriParams = TelegramUriMapper.ParseQueryString(tempUri);

                    var id            = Convert.ToInt32(uriParams["dc"]);
                    var addressParams = uriParams["addr"].Split(':');
                    var ipAddress     = addressParams[0];
                    var port          = Convert.ToInt32(addressParams[1]);

                    IoC.Get <IMTProtoService>().UpdateTransportInfoAsync(id, ipAddress, port,
                                                                         result =>
                    {
                        Execute.BeginOnUIThread(() => MessageBox.Show("App settings have been successfully updated.", AppResources.Info, MessageBoxButton.OK));
                    });
                }
                catch (Exception ex)
                {
                }
            });
        }
        private void Browser_OnNavigating(object sender, NavigatingEventArgs e)
        {
            if (e.Uri.ToString().StartsWith("tg://"))
            {
                e.Cancel = true;

                if (e.Uri.ToString().StartsWith("tg://resolve/?domain="))
                {
                    var previousEntry = NavigationService.BackStack.FirstOrDefault();
                    if (previousEntry != null &&
                        previousEntry.Source.ToString().Contains("DialogDetailsView.xaml"))
                    {
                        var user = ViewModel.PaymentInfo.With as TLUser45;
                        if (user != null && user.UserName != null)
                        {
                            Dictionary <string, string> uriParams = null;
                            try
                            {
                                uriParams = TelegramUriMapper.ParseQueryString(e.Uri.ToString());
                            }
                            catch (Exception ex)
                            {
                                Execute.ShowDebugMessage("Parse uri exception " + e.Uri + ex);
                            }
                            if (uriParams != null)
                            {
                                if (e.Uri.ToString().Contains("domain"))
                                {
                                    // /Protocol?encodedLaunchUri=tg://resolve/?domain=<username>&start=<access_token>
                                    // /Protocol?encodedLaunchUri=tg://resolve/?domain=<username>&startgroup=<access_token>
                                    // /Protocol?encodedLaunchUri=tg://resolve/?domain=<username>&post=<post_number>
                                    // /Protocol?encodedLaunchUri=tg://resolve/?domain=<username>&game=<game>
                                    var domain = uriParams["domain"];

                                    if (string.Equals(user.UserName.ToString(), domain, StringComparison.OrdinalIgnoreCase))
                                    {
                                        NavigationService.GoBack();
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    ViewModel.IsWorking = true;
                }
            }
        }
示例#3
0
        private void NavigateToContactFromPeopleHub(Uri uri)
        {
            Execute.BeginOnThreadPool(() =>
            {
                var tempUri = HttpUtility.UrlDecode(uri.ToString());
                try
                {
                    var uriParams = TelegramUriMapper.ParseQueryString(tempUri);

                    var userId        = Convert.ToInt32(uriParams["contact_ids"]);
                    var cachedContact = IoC.Get <ICacheService>().GetUser(new TLInt(userId));

                    if (cachedContact != null)
                    {
                        Thread.Sleep(1000); // waiting for backwardin animations
                        NavigateToUser(cachedContact, string.Empty);
                    }
                }
                catch (Exception ex)
                {
                    Execute.ShowDebugMessage(tempUri + " ex\n" + ex);
                }
            });
        }
示例#4
0
        private void NavigateToTelegramUriAsync(Uri uri)
        {
            Execute.BeginOnThreadPool(() =>
            {
                var tempUri = HttpUtility.UrlDecode(uri.ToString());

                Dictionary <string, string> uriParams = null;
                try
                {
                    uriParams = TelegramUriMapper.ParseQueryString(tempUri);
                }
                catch (Exception ex)
                {
                    Execute.ShowDebugMessage("Parse uri exception " + tempUri + ex);
                }
                if (uriParams != null)
                {
                    if (tempUri.Contains("domain"))
                    {
                        // /Protocol?encodedLaunchUri=tg://resolve/?domain=<username>&start=<access_token>
                        // /Protocol?encodedLaunchUri=tg://resolve/?domain=<username>&startgroup=<access_token>
                        var domain = uriParams["domain"];
                        PageKind pageKind;
                        var accessToken = GetAccessToken(uriParams, out pageKind);

                        var cachedContact = IoC.Get <ICacheService>().GetUsers().OfType <IUserName>().FirstOrDefault(x => string.Equals(x.UserName.ToString(), domain, StringComparison.OrdinalIgnoreCase)) as TLUserBase;

                        if (cachedContact != null)
                        {
                            Thread.Sleep(1000); // waiting for backwardin animations
                            NavigateToUser(cachedContact, accessToken, pageKind);
                        }
                        else
                        {
                            var mtProtoService = IoC.Get <IMTProtoService>();
                            NavigateToUsername(mtProtoService, domain, accessToken, pageKind);
                        }
                    }
                    else if (tempUri.Contains("invite"))
                    {
                        // /Protocol?encodedLaunchUri=tg://join/?invite=<group_access_token>
                        var link = uriParams["invite"];

                        var mtProtoService = IoC.Get <IMTProtoService>();
                        NavigateToInviteLink(mtProtoService, link);
                    }
                    else if (tempUri.Contains("set"))
                    {
                        // /Protocol?encodedLaunchUri=tg://addstickers/?set=<set_name>
                        var link = uriParams["set"];

                        var inputStickerSet = new TLInputStickerSetShortName {
                            ShortName = new TLString(link)
                        };

                        var mtProtoService = IoC.Get <IMTProtoService>();
                        var stateService   = IoC.Get <IStateService>();
                        NavigateToStickers(mtProtoService, stateService, inputStickerSet);
                    }
                    else if (tempUri.Contains("url"))
                    {
                        // /Protocol?encodedLaunchUri=tg://msg_url/?url=<url_address>&text=<description>
                        var url     = uriParams["url"];
                        string text = string.Empty;
                        if (uriParams.ContainsKey("text"))
                        {
                            text = uriParams["text"];
                        }

                        NavigateToForwarding(url, text);
                    }
                    else
                    {
                        Execute.ShowDebugMessage(tempUri);
                    }
                }
            });
        }