private async void ClearCacheExecute()
        {
            IsLoading = true;

            var folder = await StorageFolder.GetFolderFromPathAsync(FileUtils.GetTempFileName(string.Empty));

            var queryOptions = new QueryOptions();

            queryOptions.FolderDepth = FolderDepth.Deep;

            var query  = folder.CreateFileQueryWithOptions(queryOptions);
            var result = await query.GetFilesAsync();

            foreach (var file in result)
            {
                try
                {
                    await file.DeleteAsync();
                    await UpdateCacheSizeAsync();
                }
                catch { }
            }

            IsLoading = false;

            await UpdateCacheSizeAsync();

            await TLMessageDialog.ShowAsync("Done", "Done", "Done");
        }
Пример #2
0
        private async void DialogDeleteExecute(Chat chat)
        {
            var message = Strings.Resources.AreYouSureDeleteAndExit;

            if (chat.Type is ChatTypePrivate || chat.Type is ChatTypeSecret)
            {
                message = Strings.Resources.AreYouSureDeleteThisChat;
            }
            else if (chat.Type is ChatTypeSupergroup super)
            {
                message = super.IsChannel ? Strings.Resources.ChannelLeaveAlert : Strings.Resources.MegaLeaveAlert;
            }

            var confirm = await TLMessageDialog.ShowAsync(message, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel);

            if (confirm == ContentDialogResult.Primary)
            {
                if (chat.Type is ChatTypeSecret secret)
                {
                    await ProtoService.SendAsync(new CloseSecretChat(secret.SecretChatId));
                }
                else if (chat.Type is ChatTypeBasicGroup || chat.Type is ChatTypeSupergroup)
                {
                    await ProtoService.SendAsync(new SetChatMemberStatus(chat.Id, ProtoService.GetMyId(), new ChatMemberStatusLeft()));
                }

                ProtoService.Send(new DeleteChatHistory(chat.Id, true));
            }
        }
Пример #3
0
        protected override async void SendExecute(User user)
        {
            if (user == null)
            {
                return;
            }

            var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.AreYouSureSecretChat, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel);

            if (confirm != ContentDialogResult.Primary)
            {
                return;
            }

            Function request;

            var existing = ProtoService.GetSecretChatForUser(user.Id);

            if (existing != null)
            {
                request = new CreateSecretChat(existing.Id);
            }
            else
            {
                request = new CreateNewSecretChat(user.Id);
            }

            var response = await ProtoService.SendAsync(request);

            if (response is Chat chat)
            {
                NavigationService.NavigateToChat(chat);
                NavigationService.RemoveLast();
            }
        }
        private async void ForgotExecute()
        {
            if (_passwordBase == null)
            {
                // TODO: ...
                return;
            }

            if (_passwordBase.HasRecovery)
            {
                IsLoading = true;

                var response = await LegacyService.RequestPasswordRecoveryAsync();

                if (response.IsSucceeded)
                {
                    await TLMessageDialog.ShowAsync(string.Format("We have sent a recovery code to the e-mail you provided:\n\n{0}", response.Result.EmailPattern), "Telegram", "OK");
                }
                else if (response.Error != null)
                {
                    IsLoading = false;
                    await new TLMessageDialog(response.Error.ErrorMessage ?? "Error message", response.Error.ErrorCode.ToString()).ShowQueuedAsync();
                }
            }
            else
            {
                await TLMessageDialog.ShowAsync("Since you haven't provided a recovery e-mail when setting up your password, your remaining options are either to remember your password or to reset your account.", "Sorry", "OK");

                //IsResettable = true;
            }
        }
Пример #5
0
        private async void UnblockExecute()
        {
            if (Item is TLUser user)
            {
                var confirm = await TLMessageDialog.ShowAsync(Strings.Android.AreYouSureUnblockContact, Strings.Android.AppName, Strings.Android.OK, Strings.Android.Cancel);

                if (confirm != ContentDialogResult.Primary)
                {
                    return;
                }

                var result = await ProtoService.UnblockAsync(user.ToInputUser());

                if (result.IsSucceeded && result.Result)
                {
                    if (Full is TLUserFull full)
                    {
                        full.IsBlocked = false;
                        full.RaisePropertyChanged(() => full.IsBlocked);
                    }

                    CacheService.Commit();
                    Aggregator.Publish(new TLUpdateUserBlocked {
                        UserId = user.Id, Blocked = false
                    });

                    if (user.IsBot)
                    {
                        NavigationService.GoBack();
                    }
                }
            }
        }
Пример #6
0
        //public static void ProcessError(IDispatcherWrapper fragment, Error error, Type request, params object[] args)
        //{
        //    if (error.Code == 406 || error.Message == null)
        //    {
        //        return null;
        //    }

        //    if (request is TL_account_saveSecureValue || request is TL_account_getAuthorizationForm)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred + "\n" + error.Message);
        //        }
        //    }
        //    else if (request is TL_channels_joinChannel ||
        //     request is TL_channels_editAdmin ||
        //     request is TL_channels_inviteToChannel ||
        //     request is TL_messages_addChatUser ||
        //     request is TL_messages_startBot ||
        //     request is TL_channels_editBanned)
        //    {
        //        if (fragment != null)
        //        {
        //            ShowAddUserAlert(error.Message, fragment, (Boolean)args[0]);
        //        }
        //        else
        //        {
        //            if (error.Message.equals("PEER_FLOOD"))
        //            {
        //                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 1);
        //            }
        //        }
        //    }
        //    else if (request is TL_messages_createChat)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowFloodWaitAlert(fragment, error.Message);
        //        }
        //        else
        //        {
        //            ShowAddUserAlert(fragment, error.Message, false);
        //        }
        //    }
        //    else if (request is TL_channels_createChannel)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowFloodWaitAlert(fragment, error.Message);
        //        }
        //        else
        //        {
        //            ShowAddUserAlert(fragment, error.Message, false);
        //        }
        //    }
        //    else if (request is TL_messages_editMessage)
        //    {
        //        if (!error.Message.Equals("MESSAGE_NOT_MODIFIED"))
        //        {
        //            if (fragment != null)
        //            {
        //                ShowSimpleAlert(fragment, Strings.Resources.EditMessageError);
        //            }
        //            else
        //            {
        //                ShowSimpleToast(fragment, Strings.Resources.EditMessageError);
        //            }
        //        }
        //    }
        //    else if (request is TL_messages_sendMessage ||
        //              request is TL_messages_sendMedia ||

        //              request is TL_messages_sendBroadcast ||
        //              request is TL_messages_sendInlineBotResult ||

        //              request is TL_messages_forwardMessages)
        //    {
        //        if (error.Message.Equals("PEER_FLOOD"))
        //        {
        //            NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.needShowAlert, 0);
        //        }
        //    }
        //    else if (request is TL_messages_importChatInvite)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else if (error.Message.Equals("USERS_TOO_MUCH"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.JoinToGroupErrorFull);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.JoinToGroupErrorNotExist);
        //        }
        //    }
        //    else if (request is TL_messages_getAttachedStickers)
        //    {
        //        if (fragment != null && fragment.getParentActivity() != null)
        //        {
        //            Toast.makeText(fragment.getParentActivity(), Strings.Resources.ErrorOccurred + "\n" + error.text, Toast.LENGTH_SHORT).show();
        //        }
        //    }
        //    else if (request is TL_account_confirmPhone || request is TL_account_verifyPhone || request is TL_account_verifyEmail)
        //    {
        //        if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID") || error.Message.Contains("CODE_INVALID") || error.Message.Contains("CODE_EMPTY"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED") || error.Message.Contains("EMAIL_VERIFY_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, error.Message);
        //        }
        //    }
        //    else if (request is TL_auth_resendCode)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else if (error.Code != -1000)
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred + "\n" + error.Message);
        //        }
        //    }
        //    else if (request is TL_account_sendConfirmPhoneCode)
        //    {
        //        if (error.Code == 400)
        //        {
        //            return ShowSimpleAlert(fragment, Strings.Resources.CancelLinkExpired);
        //        }
        //        else if (error.Message != null)
        //        {
        //            if (error.Message.StartsWith("FLOOD_WAIT"))
        //            {
        //                return ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //            }
        //            else
        //            {
        //                return ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred);
        //            }
        //        }
        //    }
        //    else if (request is TL_account_changePhone)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, error.Message);
        //        }
        //    }
        //    else if (request is TL_account_sendChangePhoneCode)
        //    {
        //        if (error.Message.Contains("PHONE_NUMBER_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidPhoneNumber);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EMPTY") || error.Message.Contains("PHONE_CODE_INVALID"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.InvalidCode);
        //        }
        //        else if (error.Message.Contains("PHONE_CODE_EXPIRED"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.CodeExpired);
        //        }
        //        else if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else if (error.Message.StartsWith("PHONE_NUMBER_OCCUPIED"))
        //        {
        //            ShowSimpleAlert(fragment, LocaleController.formatString("ChangePhoneNumberOccupied", R.string.ChangePhoneNumberOccupied, (String)args[0]));
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred);
        //        }
        //    }
        //    else if (request is TL_updateUserName)
        //    {
        //        switch (error.Message)
        //        {
        //            case "USERNAME_INVALID":
        //                ShowSimpleAlert(fragment, Strings.Resources.UsernameInvalid);
        //                break;
        //            case "USERNAME_OCCUPIED":
        //                ShowSimpleAlert(fragment, Strings.Resources.UsernameInUse);
        //                break;
        //            default:
        //                ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred);
        //                break;
        //        }
        //    }
        //    else if (request is TL_contacts_importContacts)
        //    {
        //        if (error == null || error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.FloodWait);
        //        }
        //        else
        //        {
        //            ShowSimpleAlert(fragment, Strings.Resources.ErrorOccurred + "\n" + error.Message);
        //        }
        //    }
        //    else if (request is TL_account_getPassword || request is TL_account_getTmpPassword)
        //    {
        //        if (error.Message.StartsWith("FLOOD_WAIT"))
        //        {
        //            ShowSimpleToast(fragment, getFloodWaitString(error.Message));
        //        }
        //        else
        //        {
        //            ShowSimpleToast(fragment, error.Message);
        //        }
        //    }
        //    else if (request is TL_payments_sendPaymentForm)
        //    {
        //        switch (error.Message)
        //        {
        //            case "BOT_PRECHECKOUT_FAILED":
        //                ShowSimpleToast(fragment, Strings.Resources.PaymentPrecheckoutFailed);
        //                break;
        //            case "PAYMENT_FAILED":
        //                ShowSimpleToast(fragment, Strings.Resources.PaymentFailed);
        //                break;
        //            default:
        //                ShowSimpleToast(fragment, error.Message);
        //                break;
        //        }
        //    }
        //    else if (request is TL_payments_validateRequestedInfo)
        //    {
        //        switch (error.Message)
        //        {
        //            case "SHIPPING_NOT_AVAILABLE":
        //                ShowSimpleToast(fragment, Strings.Resources.PaymentNoShippingMethod);
        //                break;
        //            default:
        //                ShowSimpleToast(fragment, error.Message);
        //                break;
        //        }
        //    }
        //}

        private static async void ShowPeerFloodAlert(IDispatcherWrapper fragment, int reason)
        {
            var dialog = new TLMessageDialog();

            dialog.Title             = Strings.Resources.AppName;
            dialog.PrimaryButtonText = Strings.Resources.OK;

            if (reason != 2)
            {
                dialog.SecondaryButtonText   = Strings.Resources.MoreInfo;
                dialog.SecondaryButtonClick += (s, args) =>
                {
                    MessageHelper.NavigateToUsername(null, null, "spambot", null, null, null);
                };
            }

            if (reason == 0)
            {
                dialog.Message = Strings.Resources.NobodyLikesSpam1;
            }
            else if (reason == 1)
            {
                dialog.Message = Strings.Resources.NobodyLikesSpam2;
            }
            else if (reason == 2)
            {
                //builder.setMessage((String)args[1]);
            }

            await dialog.ShowQueuedAsync();
        }
Пример #7
0
        protected override async void SendExecute(User user)
        {
            var count = ProtoService.GetOption <OptionValueInteger>("forwarded_messages_count_max");

            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            if (user == null)
            {
                return;
            }

            var confirm = await TLMessageDialog.ShowAsync(string.Format(Strings.Resources.AddToTheGroup, user.GetFullName()), Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel);

            if (confirm != ContentDialogResult.Primary)
            {
                return;
            }

            ProtoService.Send(new AddChatMember(chat.Id, user.Id, count?.Value ?? 0));

            NavigationService.GoBack();
        }
Пример #8
0
        private async void ResetExecute()
        {
            var confirm = await TLMessageDialog.ShowAsync("This action can't be undone.\n\nIf you reset your account, all your messages and chats will be deleted.", "Warning", "Reset", "Cancel");

            if (confirm == ContentDialogResult.Primary)
            {
                IsLoading = true;

                var response = await ProtoService.DeleteAccountAsync("Forgot password");

                if (response.IsSucceeded)
                {
                    var logout = await ProtoService.LogOutAsync();

                    var state = new SignUpPage.NavigationParameters
                    {
                        PhoneNumber = _parameters.PhoneNumber,
                        PhoneCode   = _parameters.PhoneCode,
                        Result      = _parameters.Result,
                    };

                    NavigationService.Navigate(typeof(SignUpPage), state);
                }
                else if (response.Error != null)
                {
                    IsLoading = false;
                    await new TLMessageDialog(response.Error.ErrorMessage ?? "Error message", response.Error.ErrorCode.ToString()).ShowQueuedAsync();
                }
            }
        }
Пример #9
0
        private async void DeleteExecute()
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            if (chat.Type is ChatTypeBasicGroup basic)
            {
                var message = Strings.Resources.MegaDeleteAlert;
                var confirm = await TLMessageDialog.ShowAsync(message, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel);

                if (confirm == ContentDialogResult.Primary)
                {
                    await ProtoService.SendAsync(new SetChatMemberStatus(chat.Id, ProtoService.GetMyId(), new ChatMemberStatusLeft()));

                    var response = await ProtoService.SendAsync(new DeleteChatHistory(chat.Id, true));

                    if (response is Ok)
                    {
                        NavigationService.RemovePeerFromStack(chat.Id);
                    }
                    else if (response is Error error)
                    {
                        // TODO: ...
                    }
                }
            }
        }
Пример #10
0
        private async void RevokeLinkExecute(TLChannel channel)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Android.AppName;
            dialog.Message             = string.Format(Strings.Android.RevokeLinkAlert, channel.Username, channel.DisplayName);
            dialog.PrimaryButtonText   = Strings.Android.RevokeButton;
            dialog.SecondaryButtonText = Strings.Android.Cancel;

            var confirm = await dialog.ShowQueuedAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UpdateUsernameAsync(channel.ToInputChannel(), string.Empty);

                if (response.IsSucceeded)
                {
                    channel.HasUsername = false;
                    channel.Username    = null;
                    channel.RaisePropertyChanged(() => channel.HasUsername);
                    channel.RaisePropertyChanged(() => channel.Username);

                    HasTooMuchUsernames = false;
                    AdminedPublicChannels.Clear();
                }
            }
        }
Пример #11
0
        private async void ForgotExecute()
        {
            if (_parameters == null)
            {
                // TODO: ...
                return;
            }

            if (_parameters.HasRecoveryEmailAddress)
            {
                IsLoading = true;

                var response = await ProtoService.SendAsync(new RequestAuthenticationPasswordRecovery());

                if (response is Error error)
                {
                    IsLoading = false;
                    await TLMessageDialog.ShowAsync(error.Message, Strings.Resources.AppName, Strings.Resources.OK);
                }
            }
            else
            {
                await TLMessageDialog.ShowAsync(Strings.Resources.RestorePasswordNoEmailText, Strings.Resources.RestorePasswordNoEmailTitle, Strings.Resources.OK);

                IsResettable = true;
            }
        }
Пример #12
0
        private async void UseActivatedArgs(IActivatedEventArgs args, INavigationService service, AuthorizationState state)
        {
            try
            {
                switch (state)
                {
                case AuthorizationStateReady ready:
                    //App.Current.NavigationService.Navigate(typeof(Views.MainPage));
                    UseActivatedArgs(args, service);
                    break;

                case AuthorizationStateWaitPhoneNumber waitPhoneNumber:
                    Execute.Initialize();
                    service.Navigate(typeof(Views.IntroPage));
                    break;

                case AuthorizationStateWaitCode waitCode:
                    service.Navigate(waitCode.IsRegistered ? typeof(Views.SignIn.SignInSentCodePage) : typeof(Views.SignIn.SignUpPage));
                    break;

                case AuthorizationStateWaitPassword waitPassword:
                    if (!string.IsNullOrEmpty(waitPassword.RecoveryEmailAddressPattern))
                    {
                        await TLMessageDialog.ShowAsync(string.Format(Strings.Resources.RestoreEmailSent, waitPassword.RecoveryEmailAddressPattern), Strings.Resources.AppName, Strings.Resources.OK);
                    }

                    service.Navigate(typeof(Views.SignIn.SignInPasswordPage));
                    break;
                }
            }
            catch { }
        }
Пример #13
0
        private async void Initialize()
        {
            if (!Settings.IsContactsSyncRequested)
            {
                Settings.IsContactsSyncRequested = true;

                var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.ContactsPermissionAlert, Strings.Resources.AppName, Strings.Resources.ContactsPermissionAlertContinue, Strings.Resources.ContactsPermissionAlertNotNow);

                if (confirm != Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                {
                    Settings.IsContactsSyncEnabled = false;
                    await _contactsService.RemoveAsync();
                }

                if (Settings.IsContactsSyncEnabled)
                {
                    ProtoService.Send(new GetContacts(), async result =>
                    {
                        if (result is Telegram.Td.Api.Users users)
                        {
                            await _contactsService.SyncAsync(users);
                        }
                    });
                }
            }
        }
Пример #14
0
        private async void Option_Click(object sender, RoutedEventArgs e)
        {
            if (_message?.SchedulingState != null)
            {
                await TLMessageDialog.ShowAsync(Strings.Resources.MessageScheduledVote, Strings.Resources.AppName, Strings.Resources.OK);

                return;
            }

            var button = sender as PollOptionControl;

            if (button.IsChecked == true)
            {
                return;
            }

            var option = button.Tag as PollOption;

            if (option == null)
            {
                return;
            }

            var poll = _message?.Content as MessagePoll;

            if (poll == null)
            {
                return;
            }

            _message.Delegate.VotePoll(_message, option);
        }
Пример #15
0
        private async void ParticipantRemoveExecute(TLChatParticipantBase participant)
        {
            if (participant == null || participant.User == null)
            {
                return;
            }

            var confirm = await TLMessageDialog.ShowAsync(string.Format("Do you want to remove {0} from the group {1}?", participant.User.FullName, _item.DisplayName), "Remove", "OK", "Cancel");

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.DeleteChatUserAsync(_item.Id, participant.User.ToInputUser());

                if (response.IsSucceeded)
                {
                    if (response.Result is TLUpdates updates)
                    {
                        var newMessage = updates.Updates.OfType <TLUpdateNewMessage>().FirstOrDefault();
                        if (newMessage != null)
                        {
                            Aggregator.Publish(newMessage);
                        }
                    }
                }
            }
        }
Пример #16
0
        private async void UnblockExecute()
        {
            if (Item is TLUser user)
            {
                var confirm = await TLMessageDialog.ShowAsync("Are you sure you want to unblock this contact?", "Telegram", "OK", "Cancel");

                if (confirm != ContentDialogResult.Primary)
                {
                    return;
                }

                var result = await ProtoService.UnblockAsync(user.ToInputUser());

                if (result.IsSucceeded && result.Result)
                {
                    CacheService.Commit();
                    Aggregator.Publish(new TLUpdateUserBlocked {
                        UserId = user.Id, Blocked = false
                    });

                    if (user.IsBot)
                    {
                        NavigationService.GoBack();
                    }
                }
            }
        }
Пример #17
0
        private async void ChatsClearExecute()
        {
            var chats = SelectedItems.ToList();

            var confirm = await TLMessageDialog.ShowAsync(Strings.Resources.AreYouSureClearHistoryFewChats, Locale.Declension("ChatsSelected", chats.Count), Strings.Resources.ClearHistory, Strings.Resources.Cancel);

            if (confirm == ContentDialogResult.Primary)
            {
                Delegate?.ShowChatsUndo(chats, UndoType.Clear, items =>
                {
                    foreach (var undo in items)
                    {
                        _deletedChats.Remove(undo.Id);
                        Handle(undo.Id, undo.Order);
                    }
                }, items =>
                {
                    var clear = items.FirstOrDefault();
                    if (clear == null)
                    {
                        return;
                    }

                    ProtoService.Send(new DeleteChatHistory(clear.Id, false, false));
                });
            }

            Delegate?.SetSelectionMode(false);
            SelectedItems.Clear();
        }
Пример #18
0
        private async void SendExecute()
        {
            var response = await ProtoService.SendAsync(new ImportContacts(new[] { new Contact() }));

            if (response is ImportedContacts imported)
            {
                if (imported.UserIds.Count > 0)
                {
                    var create = await ProtoService.SendAsync(new CreatePrivateChat(imported.UserIds[0], false));

                    if (create is Chat chat)
                    {
                        NavigationService.NavigateToChat(chat);
                    }
                }
                else
                {
                    await TLMessageDialog.ShowAsync(Strings.Resources.ContactNotRegistered, Strings.Resources.AppName, Strings.Resources.Invite, Strings.Resources.Cancel);
                }
            }
            else
            {
                await TLMessageDialog.ShowAsync(Strings.Resources.ContactNotRegistered, Strings.Resources.AppName, Strings.Resources.Invite, Strings.Resources.Cancel);
            }
        }
Пример #19
0
        private static async void ShowPeerFloodAlert(int reason)
        {
            var dialog = new TLMessageDialog();

            dialog.Title             = Branding.ServiceName;
            dialog.PrimaryButtonText = Strings.Android.OK;

            if (reason != 2)
            {
                dialog.SecondaryButtonText   = Strings.Android.MoreInfo;
                dialog.SecondaryButtonClick += (s, args) =>
                {
                    MessageHelper.NavigateToUsername("spambot", null, null, null);
                };
            }

            if (reason == 0)
            {
                dialog.Message = Strings.Android.NobodyLikesSpam1;
            }
            else if (reason == 1)
            {
                dialog.Message = Strings.Android.NobodyLikesSpam2;
            }
            else if (reason == 2)
            {
                //builder.setMessage((String)args[1]);
            }

            await dialog.ShowQueuedAsync();
        }
Пример #20
0
        private async void RevokeLinkExecute(Chat chat)
        {
            if (chat.Type is ChatTypeSupergroup super)
            {
                var supergroup = ProtoService.GetSupergroup(super.SupergroupId);
                if (supergroup == null)
                {
                    return;
                }

                var dialog = new TLMessageDialog();
                dialog.Title               = Strings.Resources.AppName;
                dialog.Message             = string.Format(Strings.Resources.RevokeLinkAlert, supergroup.Username, chat.Title);
                dialog.PrimaryButtonText   = Strings.Resources.RevokeButton;
                dialog.SecondaryButtonText = Strings.Resources.Cancel;

                var confirm = await dialog.ShowQueuedAsync();

                if (confirm == ContentDialogResult.Primary)
                {
                    var response = await ProtoService.SendAsync(new SetSupergroupUsername(supergroup.Id, string.Empty));

                    if (response is Ok)
                    {
                        HasTooMuchUsernames = false;
                        AdminedPublicChannels.Clear();
                    }
                }
            }
        }
Пример #21
0
        private async void TerminateExecute(ConnectedWebsite session)
        {
            var bot = ProtoService.GetUser(session.BotUserId);

            if (bot == null)
            {
                return;
            }

            var dialog = new TLMessageDialog();

            dialog.Title               = Strings.Resources.AppName;
            dialog.Message             = string.Format(Strings.Resources.TerminateWebSessionQuestion, session.DomainName);
            dialog.PrimaryButtonText   = Strings.Resources.OK;
            dialog.SecondaryButtonText = Strings.Resources.Cancel;
            dialog.CheckBoxLabel       = string.Format(Strings.Resources.TerminateWebSessionStop, bot.FirstName);

            var terminate = await dialog.ShowQueuedAsync();

            if (terminate == ContentDialogResult.Primary)
            {
                var response = await ProtoService.SendAsync(new DisconnectWebsite(session.Id));

                if (response is Ok)
                {
                    Items.Remove(session);
                }
                else if (response is Error error)
                {
                    Execute.ShowDebugMessage("auth.resetWebAuthotization error " + error);
                }

                ProtoService.Send(new BlockUser(bot.Id));
            }
        }
Пример #22
0
        private async void DeleteExecute()
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            if (chat.Type is ChatTypeSupergroup super)
            {
                var message = super.IsChannel ? Strings.Resources.ChannelDeleteAlert : Strings.Resources.MegaDeleteAlert;
                var confirm = await TLMessageDialog.ShowAsync(message, Strings.Resources.AppName, Strings.Resources.OK, Strings.Resources.Cancel);

                if (confirm == ContentDialogResult.Primary)
                {
                    var response = await ProtoService.SendAsync(new DeleteSupergroup(super.SupergroupId));

                    if (response is Ok)
                    {
                        NavigationService.RemovePeerFromStack(chat.Id);
                    }
                    else if (response is Error error)
                    {
                        // TODO: ...
                    }
                }
            }
        }
Пример #23
0
        private async void Stickers_Click(object sender, RoutedEventArgs e)
        {
            var channel = ViewModel.With as TLChannel;

            if (channel != null && channel.HasBannedRights && (channel.BannedRights.IsSendStickers || channel.BannedRights.IsSendGifs))
            {
                await TLMessageDialog.ShowAsync("The admins of this group restricted you from posting stickers here.", "Warning", "OK");

                return;
            }

            if (StickersPanel.Visibility == Visibility.Collapsed)
            {
                Focus(FocusState.Programmatic);
                TextField.Focus(FocusState.Programmatic);

                InputPane.GetForCurrentView().TryHide();

                StickersPanel.Visibility = Visibility.Visible;

                ViewModel.OpenStickersCommand.Execute(null);
            }
            else
            {
                Focus(FocusState.Programmatic);
                TextField.Focus(FocusState.Keyboard);

                StickersPanel.Visibility = Visibility.Collapsed;
            }
        }
Пример #24
0
        private async void SendExecute()
        {
            var contact = new TLInputPhoneContact
            {
                ClientId  = GetHashCode(),
                FirstName = FirstName,
                LastName  = LastName,
                Phone     = "+" + PhoneCode + PhoneNumber
            };

            var response = await ProtoService.ImportContactsAsync(new TLVector <TLInputContactBase> {
                contact
            });

            if (response.IsSucceeded)
            {
                if (response.Result.Users.Count > 0)
                {
                    Aggregator.Publish(new TLUpdateContactLink
                    {
                        UserId      = response.Result.Users[0].Id,
                        MyLink      = new TLContactLinkContact(),
                        ForeignLink = new TLContactLinkUnknown()
                    });
                }
                else
                {
                    await TLMessageDialog.ShowAsync(Strings.Android.ContactNotRegistered, Strings.Android.AppName, Strings.Android.Invite, Strings.Android.Cancel);
                }
            }
            else
            {
                await TLMessageDialog.ShowAsync(Strings.Android.ContactNotRegistered, Strings.Android.AppName, Strings.Android.Invite, Strings.Android.Cancel);
            }
        }
Пример #25
0
        private async void CallExecute()
        {
            if (_item == null || _full == null)
            {
                return;
            }

            if (_full.IsPhoneCallsAvailable && !_item.IsSelf && ApiInformation.IsApiContractPresent("Windows.ApplicationModel.Calls.CallsVoipContract", 1))
            {
                try
                {
                    var coordinator = VoipCallCoordinator.GetDefault();
                    var result      = await coordinator.ReserveCallResourcesAsync("Unigram.Tasks.VoIPCallTask");

                    if (result == VoipPhoneCallResourceReservationStatus.Success)
                    {
                        await VoIPConnection.Current.SendRequestAsync("voip.startCall", _item);
                    }
                }
                catch
                {
                    await TLMessageDialog.ShowAsync("Something went wrong. Please, try to close and relaunch the app.", "Unigram", "OK");
                }
            }
        }
Пример #26
0
        public void Handle(UpdateServiceNotification update)
        {
            var caption = update.Content.GetCaption();

            if (caption == null)
            {
                return;
            }

            var text = caption.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            WindowContext.Default().Dispatcher.Dispatch(async() =>
            {
                if (update.Type.StartsWith("AUTH_KEY_DROP_"))
                {
                    var confirm = await TLMessageDialog.ShowAsync(text, Strings.Resources.AppName, Strings.Resources.LogOut, Strings.Resources.Cancel);
                    if (confirm == ContentDialogResult.Primary)
                    {
                        _protoService.Send(new Destroy());
                    }
                }
                else
                {
                    await TLMessageDialog.ShowAsync(text, Strings.Resources.AppName, Strings.Resources.OK);
                }
            });
        }
Пример #27
0
        private async void RevokeLinkExecute(TLChannel channel)
        {
            var dialog = new TLMessageDialog();

            dialog.Title               = "Revoke link";
            dialog.Message             = string.Format("Are you sure you want to revoke the link t.me/{0}?\r\n\r\nThe channel \"{1}\" will become private.", channel.Username, channel.DisplayName);
            dialog.PrimaryButtonText   = "Revoke";
            dialog.SecondaryButtonText = "Cancel";

            var confirm = await dialog.ShowAsync();

            if (confirm == ContentDialogResult.Primary)
            {
                var response = await ProtoService.UpdateUsernameAsync(channel.ToInputChannel(), string.Empty);

                if (response.IsSucceeded)
                {
                    channel.HasUsername = false;
                    channel.Username    = null;
                    channel.RaisePropertyChanged(() => channel.HasUsername);
                    channel.RaisePropertyChanged(() => channel.Username);

                    HasTooMuchUsernames = false;
                    AdminedPublicChannels.Clear();
                }
            }
        }
Пример #28
0
        private async void ForgotExecute()
        {
            if (_parameters == null)
            {
                // TODO: ...
                return;
            }

            if (_parameters.Password.HasRecovery)
            {
                IsLoading = true;

                var response = await ProtoService.RequestPasswordRecoveryAsync();

                if (response.IsSucceeded)
                {
                    await TLMessageDialog.ShowAsync(string.Format(Strings.Android.RestoreEmailSent, response.Result.EmailPattern), Strings.Android.AppName, Strings.Android.OK);

                    // TODO: show recovery page
                }
                else if (response.Error != null)
                {
                    IsLoading = false;
                    await TLMessageDialog.ShowAsync(response.Error.ErrorMessage, Strings.Android.AppName, Strings.Android.OK);
                }
            }
            else
            {
                await TLMessageDialog.ShowAsync(Strings.Android.RestorePasswordNoEmailText, Strings.Android.RestorePasswordNoEmailTitle, Strings.Android.OK);

                IsResettable = true;
            }
        }
        public async Task <bool> VerifyRightsAsync(Chat chat, Func <ChatMemberStatusRestricted, bool> permission, string forever, string temporary)
        {
            if (chat.Type is ChatTypeSupergroup super)
            {
                var supergroup = ProtoService.GetSupergroup(super.SupergroupId);
                if (supergroup == null)
                {
                    return(false);
                }

                if (supergroup.Status is ChatMemberStatusRestricted restricted && !permission(restricted))
                {
                    if (restricted.IsForever())
                    {
                        await TLMessageDialog.ShowAsync(forever, Strings.Resources.AppName, Strings.Resources.OK);
                    }
                    else
                    {
                        await TLMessageDialog.ShowAsync(string.Format(temporary, BindConvert.Current.BannedUntil(restricted.RestrictedUntilDate)), Strings.Resources.AppName, Strings.Resources.OK);
                    }

                    return(true);
                }
            }

            return(false);
        }
Пример #30
0
        protected override async void DeleteExecute()
        {
            var confirm = await TLMessageDialog.ShowAsync(Strings.Android.AreYouSureDeletePhoto, Strings.Android.AppName, Strings.Android.OK, Strings.Android.Cancel);

            if (confirm == ContentDialogResult.Primary && _selectedItem is GalleryPhotoItem item)
            {
                //var response = await ProtoService.UpdateProfilePhotoAsync(new TLInputPhotoEmpty());
                var response = await ProtoService.DeletePhotosAsync(new TLVector <TLInputPhotoBase> {
                    new TLInputPhoto {
                        Id = item.Photo.Id, AccessHash = item.Photo.AccessHash
                    }
                });

                if (response.IsSucceeded)
                {
                    var index = Items.IndexOf(item);
                    if (index < Items.Count - 1)
                    {
                        Items.Remove(item);
                        SelectedItem = Items[index > 0 ? index - 1 : index];
                        TotalItems--;
                    }
                    else
                    {
                        NavigationService.GoBack();
                    }
                }
            }
        }