Example #1
0
        private async void UseActivatedArgs(IActivatedEventArgs args, INavigationService service)
        {
            if (service == null)
            {
                service = WindowContext.GetForCurrentView().NavigationServices.FirstOrDefault();
            }

            if (service == null || args == null)
            {
                return;
            }

            if (args is ShareTargetActivatedEventArgs share)
            {
                var package   = new DataPackage();
                var operation = share.ShareOperation.Data;
                if (operation.Contains(StandardDataFormats.ApplicationLink))
                {
                    package.SetApplicationLink(await operation.GetApplicationLinkAsync());
                }
                if (operation.Contains(StandardDataFormats.Bitmap))
                {
                    package.SetBitmap(await operation.GetBitmapAsync());
                }
                //if (operation.Contains(StandardDataFormats.Html))
                //{
                //    package.SetHtmlFormat(await operation.GetHtmlFormatAsync());
                //}
                //if (operation.Contains(StandardDataFormats.Rtf))
                //{
                //    package.SetRtf(await operation.GetRtfAsync());
                //}
                if (operation.Contains(StandardDataFormats.StorageItems))
                {
                    package.SetStorageItems(await operation.GetStorageItemsAsync());
                }
                if (operation.Contains(StandardDataFormats.Text))
                {
                    package.SetText(await operation.GetTextAsync());
                }
                //if (operation.Contains(StandardDataFormats.Uri))
                //{
                //    package.SetUri(await operation.GetUriAsync());
                //}
                if (operation.Contains(StandardDataFormats.WebLink))
                {
                    package.SetWebLink(await operation.GetWebLinkAsync());
                }

                App.ShareOperation = share.ShareOperation;
                App.DataPackage    = package.GetView();

                var options = new Windows.System.LauncherOptions();
                options.TargetApplicationPackageFamilyName = Package.Current.Id.FamilyName;

                await Windows.System.Launcher.LaunchUriAsync(new Uri("tg://"), options);
            }
            else if (args is VoiceCommandActivatedEventArgs voice)
            {
                Execute.Initialize();

                SpeechRecognitionResult speechResult = voice.Result;
                string command = speechResult.RulePath[0];

                if (command == "ShowAllDialogs")
                {
                    service.NavigateToMain(null);
                }
                if (command == "ShowSpecificDialog")
                {
                    //#TODO: Fix that this'll open a specific dialog
                    service.NavigateToMain(null);
                }
                else
                {
                    service.NavigateToMain(null);
                }
            }
            else if (args is ContactPanelActivatedEventArgs contact)
            {
                SetContactPanel(contact.ContactPanel);

                var backgroundBrush = Application.Current.Resources["TelegramTitleBarBackgroundBrush"] as SolidColorBrush;
                contact.ContactPanel.HeaderColor = backgroundBrush.Color;

                var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);

                var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                if (store != null && annotationStore != null)
                {
                    try
                    {
                        var full = await store.GetContactAsync(contact.Contact.Id);

                        if (full == null)
                        {
                            ContactPanelFallback(service);
                        }
                        else
                        {
                            var annotations = await annotationStore.FindAnnotationsForContactAsync(full);

                            var first = annotations.FirstOrDefault();
                            if (first == null)
                            {
                                ContactPanelFallback(service);
                            }
                            else
                            {
                                var remote = first.RemoteId;
                                if (int.TryParse(remote.Substring(1), out int userId))
                                {
                                    var response = await _lifetime.ActiveItem.ProtoService.SendAsync(new CreatePrivateChat(userId, false));

                                    if (response is Chat chat)
                                    {
                                        service.NavigateToChat(chat);
                                    }
                                }
                                else
                                {
                                    ContactPanelFallback(service);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if ((uint)ex.HResult == 0x80004004)
                        {
                            ContactPanelFallback(service);
                        }
                    }
                }
                else
                {
                    ContactPanelFallback(service);
                }
            }
            else if (args is ProtocolActivatedEventArgs protocol)
            {
                Execute.Initialize();

                if (App.ShareOperation != null)
                {
                    App.ShareOperation.ReportCompleted();
                    App.ShareOperation = null;
                }

                if (service?.Frame?.Content is MainPage page)
                {
                    page.Activate(protocol.Uri);
                }
                else
                {
                    service.NavigateToMain(protocol.Uri.ToString());
                }
            }
            //else if (args is CommandLineActivatedEventArgs commandLine && TryParseCommandLine(commandLine, out int id, out bool test))
            //{

            //}
            else
            {
                Execute.Initialize();

                var activate = args as ToastNotificationActivatedEventArgs;
                var launched = args as LaunchActivatedEventArgs;
                var launch   = activate?.Argument ?? launched?.Arguments;

                if (service?.Frame?.Content is MainPage page)
                {
                    page.Activate(launch);
                }
                else
                {
                    service.NavigateToMain(launch);
                }
            }
        }
Example #2
0
        public static async void NavigateToInviteLink(IProtoService protoService, INavigationService navigation, string link)
        {
            if (!link.StartsWith("http"))
            {
                link = "https://t.me/joinchat/" + link;
            }

            var response = await protoService.SendAsync(new CheckChatInviteLink(link));

            if (response is ChatInviteLinkInfo info)
            {
                if (info.ChatId != 0)
                {
                    navigation.NavigateToChat(info.ChatId);
                }
                else
                {
                    var dialog = new JoinChatView(protoService, info);

                    var confirm = await dialog.ShowAsync();

                    if (confirm == ContentDialogBaseResult.OK)
                    {
                        var import = await protoService.SendAsync(new JoinChatByInviteLink(link));

                        if (import is Ok)
                        {
                            await TLMessageDialog.ShowAsync("Joined", Strings.Resources.AppName, Strings.Resources.OK);
                        }
                        else if (import is Error error)
                        {
                            if (!error.CodeEquals(TLErrorCode.BAD_REQUEST))
                            {
                                Execute.ShowDebugMessage("messages.importChatInvite error " + error);
                                return;
                            }
                            if (error.TypeEquals(TLErrorType.INVITE_HASH_EMPTY) || error.TypeEquals(TLErrorType.INVITE_HASH_INVALID) || error.TypeEquals(TLErrorType.INVITE_HASH_EXPIRED))
                            {
                                //MessageBox.Show(Strings.Additional.GroupNotExistsError, Strings.Additional.Error, 0);
                                return;
                            }
                            else if (error.TypeEquals(TLErrorType.USERS_TOO_MUCH))
                            {
                                //MessageBox.Show(Strings.Additional.UsersTooMuch, Strings.Additional.Error, 0);
                                return;
                            }
                            else if (error.TypeEquals(TLErrorType.BOTS_TOO_MUCH))
                            {
                                //MessageBox.Show(Strings.Additional.BotsTooMuch, Strings.Additional.Error, 0);
                                return;
                            }
                            else if (error.TypeEquals(TLErrorType.USER_ALREADY_PARTICIPANT))
                            {
                                return;
                            }

                            Execute.ShowDebugMessage("messages.importChatInvite error " + error);
                        }
                    }
                }
            }
            else if (response is Error error)
            {
                if (!error.CodeEquals(TLErrorCode.BAD_REQUEST))
                {
                    Execute.ShowDebugMessage("messages.checkChatInvite error " + error);
                    return;
                }
                if (error.TypeEquals(TLErrorType.INVITE_HASH_EMPTY) || error.TypeEquals(TLErrorType.INVITE_HASH_INVALID) || error.TypeEquals(TLErrorType.INVITE_HASH_EXPIRED))
                {
                    //MessageBox.Show(Strings.Additional.GroupNotExistsError, Strings.Additional.Error, 0);
                    await TLMessageDialog.ShowAsync("This invite link is broken or has expired.", "Warning", "OK");

                    return;
                }

                Execute.ShowDebugMessage("messages.checkChatInvite error " + error);
            }
        }